Re: Event/TTree reading

From: Dmitry Naumov <>
Date: Fri, 15 Dec 2006 15:03:31 +0300

Hi Rene,

let me be more precise. My Event has a structure like this: class Event {

      Header *fHeader;
      Hits       *fHits;


in the simulation chain (VMC ) we do something like this:

// generate events: propagate tracks. fEvent is Event* object if ( fEvent->GetTracksNumber() > kMaxTracksNumber) {

      // reached limit: save the event, clear it, save to the TTree and continue simulation saving the information into the new entry of TTree



The output Tree is saved with Event as branch. As the result we have something like this in the output TTree:

entry 0 Event 0
entry 1 Event 1

entry 2 Event 2 (event is splitted and continued in the next entries)
entry 3 Event 2 (continued from entry 2)
entry 4 Event 2 (continued from entry 2)
entry 5 Event 3
entry 6 Event 4

and so on.

Now if I want to read these events in the analysis code I have to handle somehow that entries 0,1,5,6 return me fully contained Event(s), while entries 2,3,4 belong to the same Event 2 Therefore if I want say to fill two histos (one with energy of initial particle, another with energy released in the detector) I encounter a problem:
for (int i(0); i<tree->GetEntries(); i++) {

       h1->Fill(ev->GetHeader()->Energy());// this will fill the 
histogram three times with the same Event 2 (entries 2,3,4)
       h2->Fill(ev->GetHits()->GetTotalEnergyReleased()); // this will 
fill the histogram with smaller energy released because Event 2 is stored as three entries 2,3,4


Therefore I have to take care somehow about a correct handling of these events when I read them.

Thank you for your considerations, Dmitry

Rene Brun wrote:
> Hi Dmitry,
> I am afraid that you will have to provide more information if you want
> to get a meaningful answer.
> Did you look at the friend trees. See TTree::AddFriend.
> Rene Brun
> Dmitry Naumov wrote:
>> Dear Rooters,
>> may I ask your advice on the following problem. We save simulated
>> events into a TTree object. However sometimes the events are too
>> large and we split them into pieces and save each piece as an entry
>> of the TTree. This works OK. What would be a clever way to read these
>> events from the TTree?
>> A simple code which we had before (before splitting) is not useful
>> anymore:
>> // open the tree
>> Event *ev=0;
>> tree->SetBranchAddress("fEvent",&ev);
>> do (int i(0); i<tree->GetEntries()l i++) {
>> tree->GetEntry(i);
>> // do something with ev: fill its global information (energy,
>> position, etc), fill its hits
>> }
>> Following this way the concept of entry as an event is no more
>> working, and we have to organize something like "SubEvent" and do
>> cycle over ev->GetSubEvents() entries or so. This is the way I have
>> in mind. However before trying to realize it it would be great if
>> ROOT/C++ gurus could give an advice on that. [Building the whole
>> event from different entries of TTree is not OK because the event
>> might not fit into the memory].
>> Thank you in advance, Dmitry
Received on Fri Dec 15 2006 - 13:03:27 MET

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:32:02 MET