other question TTree and TClonesArray

From: Pasha Murat (murat@cdfsga.fnal.gov)
Date: Sun Mar 01 1998 - 23:03:07 MET


	Hi Dirk,

with your notations

Track* t = fEvent->GetTracks()->At(i);

gives you pointer to i-th track stored in TClonesArray.
See TClonesArray.h if you need more details.

						Regards, Pasha.
--------------------------------------------------------------------------------
Dirk Meier writes:
 > 
 > 
 > Hi
 > 
 > I went to the famous eventa.cxx example and try to extract
 > the data from the TClonesArray of Track.
 > 
 > Therefore I modified eventa.cxx to
 > 
 > //*CMZ :  1.00/09 24/04/97  11.01.18  by  Rene Brun
 > //*-- Author :    Rene Brun   10/01/97
 > {
 > //  This macro read all events generated by the test program Event
 > //  provided in $ROOTSYS/test.
 > //
 > //  NOTE: Before executing this macro, you must have executed the macro
 > eventload.
 > //
 > //  This small program simply counts the number of bytes read and dump
 > //  the first 3 events.
 >  
 >    gROOT->Reset();
 >  
 > //   Connect file generated in $ROOTSYS/test
 >    TFile f("Event.root");
 >  
 > //   Read Tree named "T" in memory. Tree pointer is assigned the same name
 >    TTree *T = (TTree*)f.Get("T");
 >  
 > //   Create a timer object to benchmark this loop
 >    TStopwatch timer;
 >    timer.Start();
 >  
 > //   Start main loop on all events
 >    Event *event = new Event();
 >    
 >    TClonesArray *tracks = event->GetTracks();
 > 
 >    //TBranch *branch = T->GetBranch("event");  
 >    //branch->SetAddress(&event);
 > 
 >    T->SetBranchAddress("event", &event);
 >    Int_t nevent = T->GetEntries();
 >    Int_t nb = 0;
 >    Float_t  ran;   // <--- declare a variable for some track value
 >    for (Int_t i=0;i<nevent;i++) {
 >       if(i%50 == 0) {
 > 	printf("Event:%d ",i);
 > 	ran = tracks.GetRandom(); // <-- !!!! here I do not know how to
 >                                   //retrieve data from TClonesArray!!!!!!!!! 
 > 	printf("has %d tracks at T=%f with value %f\n",
 > 	   event->fNtrack, event->fTemperature, ran);
 > 	// retrieving event data like e.g. fNtrack or fTemperature works
 >         // how is it possible to access the data in the TClonesArray????
 >       }
 >       nb += T->GetEvent(i);                  //read complete event in
 > memory
 >       if (i < 3) event->Dump();              //dump the first 3 events
 >       event->Clear();                        //clear tracks array
 >    }
 >  
 > //  Stop timer and print results
 >    timer.Stop();
 >    Float_t mbytes = 0.000001*nb;
 >    Double_t rtime = timer.RealTime();
 >    Double_t ctime = timer.CpuTime();
 >    printf("RealTime=%f seconds, CpuTime=%f seconds\n",rtime,ctime);
 >    printf("You read %f Mbytes/Realtime seconds\n",mbytes/rtime);
 >    printf("You read %f Mbytes/Cputime seconds\n",mbytes/ctime);
 >    printf("%d events and %d bytes read.\n",nevent,nb);
 >  
 >    f.Close();
 > }
 >  
 > Could you give me an example of how to retrieve the data from the 
 > TClonesArray (this would likely solve the question I had in the 
 > last mail).
 > 
 > merci bien
 > Dirk
 > 



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:30 MET