I have several trees, one for each sample (backgrounds + signal), I want to be able to put all of them in a chain like the TChain does, but then I want to be able to access independently each tree sample in the .C file, so that in one run I can make separate histogram for backgrounds and signal. For example, in one run I want to be able to:
loop over background 1 -> Fill histogram bkg1 -> save root file 1
loop over background 2 -> Fill histogram bkg2 -> save root file 2
loop over background n -> Fill histogram bkgn -> save root file n
As I understood the TChain will add all the samples in one Tree, so I can´t access independently each tree. Does anyone have an idea how I can do that with root?
If you want to access individual ROOT files, do NOT create a TChain. Simply loop over your files, and analyse one at a time.
but can I still make a MakeClass on one tree and then do not specify this tree to be read in the header, but instead to make a loop on all the tree directly in the .C file?
If you look at the skeleton source code generated by TTree::MakeClass, you’ll notice that the class constructor has one parameter “(TTree *tree)”. You can use your own “tree” (you open ROOT files yourself and pass a pointer to an existing “tree” to the class constructor).
Of course, you can also “enhance” the source code, adding additional parameters here and there and/or adding class methods (e.g. which would allow you to “open” and “close” files one by one on demand) and so on.
Well, you can simply run multiple independent ROOT sessions simultaneously (e.g. start one “root” per each ROOT file).
Otherwise, see PROOF and PROOF: Parallel Processing, and in particular PROOF-Lite.
Note: you will need to use TTree::MakeSelector or TTree::MakeProxy (I don’t know which one is preferred) instead of TTree::MakeClass.
thank you very much for you help, I managed to make what I needed with one of the idea you proposed.