Dear all,
I’m trying to write a TTree with two branches, but these branches have a different number of entries.
In details, I would like to write informations about events in the first branch; in the second branch I would insert informations about each track of an event in every layer of my detector. To do this, I used the method TBranch::Fill(). Just to give you an idea of what I’m doing, I report a simple and short demonstration case:
[code]TFile *f1 = new TFile(“myfile.root”,“RECREATE”);
TTree *t = new TTree(“t”,"");
TBranch *ev;
TBranch *trk;
//definition of two structures: event, track
ev = t->Branch(“event”,&event,“Ep/D:px/d:py/D:pz/D:idev/I”);
trk = t->Branch(“trk”,&track,“px/D:py/D:pz/D:sx/D:sy/D:E/D:idev/I:id/I:layer/I:lp/I:mp/I:pp/I”);
//first loop on events
for(int i = 0 ; i < nEvents ; ++i) {
//the structure event is filled
ev->Fill();
//second loop inside the first one on the tracks on each layer
for(int itrk=0 ; itrk<ntracks ; itrk++){
//the structure track is filled
trk->Fill();
}
}
f1->Write();
f1->Close(); [/code]
I have no errors in executing this script, and if I look to the created tree in the file with t->Print(), I have this output:
[code]******************************************************************************
*Tree :t : *
*Entries : 0 : Total = 360905 bytes File Size = 186992 *
-
: : Tree compression factor = 1.93 *
*Br 0 :event : Ep/D:px/d:py/D:pz/D:idev/I *
*Entries : 3 : Total Size= 982 bytes File Size = 170 *
*Baskets : 1 : Basket Size= 32000 bytes Compression= 1.04 *
…
*Br 1 :trk : px/D:py/D:pz/D:sx/D:sy/D:E/D:idev/I:id/I:layer/I:lp/I: *
-
| mp/I:pp/I *
*Entries : 4963 : Total Size= 359559 bytes File Size = 185932 *
*Baskets : 12 : Basket Size= 32000 bytes Compression= 1.93 *
…[/code]
Notice that in this case the loop on events arrived just to nEvents=2.
How can I access data in the branches? The method t->Draw() doesn’t work, I suppose because the Entries in the tree are 0!
Is this the correct way to do the job? Do you have any suggestion?
Thank you.
Regards,
Fabio