I have a root file, which has a TTree named “CollectionTree”, It has a branch (class), which has sub-branches (also class) and sub-sub-branches (class member). The branch is named “McEventCollection_p5_GEN_EVENT”, and it has a sub-branch “m_genParticles”, and the sub-sub-branches are “m_pz”…etc.Then how could I read the deepest class members? For example, I can draw it in command lines by:
But it cannot work for TBranch *b1 = (TBranch *) CollectionTree->GetBranch(“McEventCollection_p5_GEN_EVENT.m_genParticles.m_pz”);
I would like to read it event by event. Could someone give me a little help? Thank you very much
(Beside the setup that your experiment might already provide to read the files) you have a few choices. You could use the result TTree::MakeSelector or TTree:::MakeProxy or you could use the TTreeFormula class directly.
PS. [quote]But it cannot work for TBranch *b1 = (TBranch *) CollectionTree->GetBranch(“McEventCollection_p5_GEN_EVENT.m_genParticles.m_pz”);[/quote]This is likely because either the event collection or m_genParticles is not split and does not have its own branch.
I am in the same situation, I want to read event by event but reading the latest comment “This is likely because either the event collection or m_genParticles is not split and does not have its own branch.” it seems it is not possible. Could you please confirm it?
Here some information:
root  _file0->ls()
TFile** mc12_8TeV.110070.EVNT._00010.pool.root /tmp/cescobar/test_110070_00010/mc12_8TeV.110070.EVNT._00010.pool.root
TFile* mc12_8TeV.110070.EVNT._00010.pool.root /tmp/cescobar/test_110070_00010/mc12_8TeV.110070.EVNT._00010.pool.root
OBJ: TTree CollectionTree CollectionTree : 0 at: 0x1716d890
KEY: TTree ##Shapes;1 ##Shapes
KEY: TTree ##Links;1 ##Links
KEY: TTree ##Params;1 ##Params
KEY: TTree CollectionTree;1 CollectionTree
KEY: TTree POOLContainer;1 POOLContainer
KEY: TTree MetaData;1 MetaData
KEY: TTree MetaDataHdr;1 MetaDataHdr
root  CollectionTree->Print()
*Tree :CollectionTree: CollectionTree *
*Entries : 5000 : Total = 230416106 bytes File Size = 86247418 *
*Br 0 :EventInfo_p3_McEventInfo : EventInfo_p3 *
*Entries : 5000 : Total Size= 552696 bytes File Size = 31782 *
*Baskets : 18 : Basket Size= 32000 bytes Compression= 17.37 *
*Br 1 :McEventCollection_p5_GEN_EVENT : McEventCollection_p5 *
*Entries : 5000 : Total Size= 229862924 bytes File Size = 86173157 *
*Baskets : 4958 : Basket Size= 32000 bytes Compression= 2.67 *
Though CollectionTree->Draw(“McEventCollection_p5_GEN_EVENT.m_genParticles.m_pz”); also works for me.
What is failing in your case?
Basically what I want is to access the branch in an event by event basis. I have tried with CollectionTree->MakeClass(“test”) but the variables m_signalProcessId, m_eventNbr, etc (I can see then with TBRowser and plot with CollectionTree->Draw) that are inside McEventCollection_p5_GEN_EVENT are not included in test.h
I have copied a root file and the test.C/h files here: ~cescobar/public/RootTalk
Your print output did not show there there was a sub-branch for McEventCollection_p5_GEN_EVENT.m_genParticles.m_pz and if it is missing from the result of MakeClass that would confirm that it is not there.
You should try the MakeProxy instead.
Well, it is weird because if one opens the root file one can see a sub-branch structure with TBrowser (see attachment).
I will try to with MakeProxy.
Well, with MakeProxy it seems the sub-structure is shown (see attachment) but not sure how to integrate the output of MakeProxy in my framework. I was expecting something similar to the output of MakeClass. So, I am wondering if it is a possibility of using MakeClass but unrolling the classes that are not split as MakeProxy does? I think this will solve my problem.
ClassForEventGenerator.h (20.7 KB)
You should be able to use the result of MakeProxy in a similar way as the MakeClass result (You may have to copy/paste the Loop routine from a MakeClass to the MakeProxy).
I have been trying to integrate the output of MakeProxy in my framework but it seems this is not trivial at all. I would be happier if I could use something more similar to the output of MakeClass (which is much simpler). Anyhow, after investigating a bit it seems the problem is that the leaves in the tree CollectionTree are TNonSplitBrowsable.
I have been trying to see how to loop over these king of objects but I couldn’t find anything.
There is only a few ways. Use the result of MakeProxy or use the TTreeReader (available only ROOT 6) or load the shared library that defines the classes of the object.
I am not sure ‘why’ it is harder to use/embed the result of MakeProxy in your environment. In first approximation you should be able to derive a class from the skeleton and make it behave similarly to MakeClass.
You should be able to use a loop very similar to the one in MakeClass except that the GetEntry ought to be replace by fDirector.SetReadEntry(entry);
and then you can use the name of the branch directly without having to worry about loading the branch.