[ROOT] Sub-entries in brances of a tree

From: Christian Holm Christensen (cholm@hehi03.nbi.dk)
Date: Fri Jun 16 2000 - 18:08:59 MEST


Hi ROOT team and others, 

Is it possible to have some sort of sub-entries in a branch of a Tree? 

What I'd like to do is something like: 

   TClonesArray* array  = new TClonesArray("TParticle");
   TTree*        tree   = new TTree("tree", "A Tree");
   TBranch*      branch = new TBranch("branch",&array);

   for (Int_t runNo = 0; runNo < 100; runNo++) {
     for (Int_t eventNo = 0; eventNo < 1000; eventNo++) {
       for (Int_t trackNo = 0; trackNo < 10000; trackNo++) {
         new ((*array)[trackNo]) TParticle(0,0,0,0,0,
					   1.1, 2.2, 3.3, 4.4,
					   1.1, 2.2, 3.3, 4.4);
       }
       branch->Fill();
     }   
     tree->Fill();
   }

So that "tree->GetEntries() == 100", while for each of these entries, 
"branch->GetEntries() == 1000", to make up a grand total of 100,000
arrays of 10,000 TParticle's (circa 137 GB of data!). 

Then one could loop on each "tree"-level entry, and for each of those
loop on each "branch"-level entry to get to the arrays. 

One way to do something similar, is to define a class, like 

  class Event : public  TObject {
    Int_t         fRun;
    Int_t         fEvent;
    TClonesArray* fTracks;
  public:
    Event(void) { fTracks = new TClonesArray("TParticle"); }
    TClonesArray* GetTracks(void) { return fTracks; }
    void          SetEvent(int e) { fEvent = e; }
    void          SetRun(int e) { fRun = e; }
    void          Clear(void) { fTracks->Clear(); fEvent = fRun = 0; }
    ClassDef("Event",1) // RunEvent class 
  }
  ;

And then do 

   tree->BuildIndex("fRun","fEvent");

after filling "tree" with Event objects. And then, when reading:

   while (tree->GetEntryWithIndex(runNo,eventNo) > 0) { ... }

However, it's not really the same, and demands quote some
bookkeeping. 

Anyway, I was just wondering. 

Also, I sort of stumbled over this the other day: On Unix - Suppose
you've installed ROOT in "/usr/local/lib/root", then in some script
you can put the line "#!/usr/local/lib/root", and the script may be
executed from the command line. For example the following ROOT script
may be executed from the command line:

--- hello.C - cut below ---------------------
#!/usr/local/lib/root/bin/root 

{
  cout << "Hello world" << endl; 
}
--- EOF - cut above -------------------------

I'm reporting this, since I though it fun, and since I don't recall
seeing anything like this mentioned anywhere. I prefer the name
"script" for a file like the one above, since a script is
interpretted, while a macro is translated or expanded. 

Cheers, 

Christian  -----------------------------------------------------------
Holm Christensen                             Phone:  (+45) 35 35 96 91 
  Sankt Hansgade 23, 1. th.                  Office: (+45) 353  25 305 
  DK-2200 Copenhagen N                       Web:    www.nbi.dk/~cholm    
  Denmark                                    Email:       cholm@nbi.dk



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:28 MET