Filling a trees after applying condition

Dear Rooters

I have two trees (channel0 & channel1), each have two branches (t, signal)
I am aiming to read these two trees, and make a condition on (t)- Coincidence , if this condition apply, the code should creat new file and save new tree with the same branches but only include the events that apply the condition .

so I wrote this macro (Part of the macro)

ULong64_t t,t1,t0;
TTree * mytree0 = (TTree*)myfile->Get("Channel0");
	mytree0->SetBranchAddress("t",&t0);
	mytree0->SetBranchAddress("signal",&s0);

TTree * mytree1 = (TTree*)myfile->Get("Channel1");
	mytree1->SetBranchAddress("t",&t1);
	mytree1->SetBranchAddress("signal",&s1);

newTree->Branch("t0",&t0,"t0");
    newTree->Branch("signal",&s0,"s0/I");


if(abs((int)t0-(int)t1)<=coinwindow){
Tree->Fill();} 

with this macro, I should find a newtree with two branches (t and s), filled with the same timing of t0, but part of the signals.
but I got t around zero,

PS. the values of (t) is in nano sec

whats wrong with this logic

cheers


ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


The “Part of the macro” is insufficient (nothing can be judged from it).
You would need to post your full macro plus the output of “Channel0->Print();” and “Channel1->Print();” (or the original ROOT file with these trees for inspection).

How to “copy a subset of a Tree to a new Tree”:
${ROOTSYS}/tutorials/tree/copytree.C
${ROOTSYS}/tutorials/tree/copytree2.C
${ROOTSYS}/tutorials/tree/copytree3.C

Thanks
I followed copytree3.C to write the macro
herein a full macro

TFile * myfile = new TFile(input_rootfile,"READ");
	
	TTree * mytree0 = (TTree*)myfile->Get("Channel_00");
	mytree0->SetBranchAddress("t",&t0);
	mytree0->SetBranchAddress("ch",&ch0);
	mytree0->SetBranchAddress("s",&s0);
	int entries_ch0 = mytree0->GetEntries();
	
	TTree * mytree1 = (TTree*)myfile->Get("Channel_01");
	mytree1->SetBranchAddress("t",&t1);
	mytree1->SetBranchAddress("ch",&ch1);
	mytree1->SetBranchAddress("s",&s1);
	int entries_ch1 = mytree1->GetEntries();


     TTree *Tree = new TTree("Tree","coin");
     Tree->Branch("t",&t0,"t0/D");
    Tree->Branch("ch",&ch0,"ch0/I");
    Tree->Branch("signal",&s0,"s0/I");

int coinwindow=10;
	int loopnr=0;
		while(1){
		loopnr++;
		if(t0==99999999999999999999 && t1==99999999999999999999 )
			break;
		
		if(abs((int)t0-(int)t1)<=coinwindow){
			//cout << abs((int)t0-(int)t1)<<"Coincidenc" << endl;
			
                 Tree->Fill();
			
		} 


if(t0<t1) {
			
			entry_ch0++;
			mytree0->GetEntry(entry_ch0);
			if(entry_ch0>entries_ch0) {
			t0=99999999999999999999;
				
			}
			continue;
			
		}
		else{
			entry_ch1++;
			mytree1->GetEntry(entry_ch1);
			if(entry_ch1>entries_ch1) {
				t1=99999999999999999999;
							}
						continue;
			
		}

         }

  TreeFile= Tree->GetCurrentFile();
  TreeFile->Write();
  TreeFile->Close();
  delete TreeFile;
}

I think we really need your “input_rootfile” for inspection.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.