I’m saving simulation data in a TTree organized in four simple branches. Each branch collects just an integer for each entity. Since I save a large amount of entries (e.g. 10^10 per) Tree the loop over all events requires a lot of time.
For some analysis I need to select a subset of events meeting a certain condition e.g. all entries with value between X and Y in branch number 1.
Currently I’m looping over all entries, read all branch values for each event and select via “if”-condition.
Is there any smart way to access such entries without having to loop over all entries in order to reduce analysis time?
Double_t X = 0.0;
Double_t Y = 1.0;
t->Draw("branch1",TString::Format("branch1 > %g && branch1 < %g", X, Y));
If your selection is complicated, it may be worth it to make TCut objects ahead of time and compose them, instead of using a TString::Format.
If you want to use a certain cut, but then use many different draw commands with the same selection, you can also use a TEventList or TEntryList thing. If you search for “Saving the result of Draw to a TEventList” at http://root.cern.ch/root/html/TTree.html#TTree:Draw@1 you can find the documentation about that. I’m not sure if it’s necessarily faster, but doing it this way will mean that your subsequent draw commands won’t have to actually check the condition that you set, since you saved the list of events or entries that passed your cuts.