Hello again,
I’m trying to sum the contents of a TBranch taken from a subset of a TTree, and I’m doing so as follows:
TStopwatch timer1;
outFile->cd();
timer1.Start();
TTree *scuttree = sintuplecut[i]->CopyTree(cutstring+otherCuts); //copy subset of original TTree to new TTree
timer1.Stop();
cout << "copying tree took: " << timer1.RealTime() << " seconds" << endl;
s[cut][i][k] = scuttree->GetEntries(); //Number of entries copied
ep[cut][i][k] = 0.0;
Float_t val = 0.0;
scuttree->SetBranchAddress(weightname,&val);
for(UInt_t l=0; l<s[cut][i][k]; l++){ //loop over copied entries to sum val
scuttree->GetEntry(l);
ep[cut][i][k] += (Double_t)val;
}
scuttree->Delete();
This works, but because it is copying a (large) portion of a (large) TTree it takes a very long time. I intend to do this very many times altering the selection string (which is why there are 3D vectors ), so I am looking for something faster.
Is there a way to select a subset of entries from a TTree using a selection string that I can then loop/iterate over without having to create a new TTree? I have been looking at TSelector and TTreePlayer but I can’t tell if these are the right methods to use, or even how to use them.
Thanks,
Conor