[ROOT] Looping over array entries with TTree::Draw

From: Sue Kasahara (schubert@hep.umn.edu)
Date: Fri Aug 06 2004 - 22:54:17 MEST


Hi roottalk,
I'm having trouble looping over entries in array variables using
TTree::Draw under a specific circumstance.
I've placed an example in:
http://www.hep.umn.edu/~schubert/roottest/ntptest.tar.gz
The example consists of three simple classes:

class NtpShower : public TObject {
...
  Float_t fEnergy; // shower energy

  ClassDef(NtpShower,1) //A reconstructed shower
};

class NtpEvent: public TObject {
...
  Int_t fEventNo; // event number
  Int_t fNShower; // number of showers in this event
  Int_t* fShwInd; //[fNShower] array of indices into shower TClonesArray

  ClassDef(NtpEvent,1) //A reconstructed event
};

class NtpRecord:public TObject {
...
  TClonesArray* fShowers; //~> Array of showers
  TClonesArray* fEvents;    //-> Array of events

  ClassDef(NtpRecord,1) //A reconstructed spill record
};

These classes are set up so that the user can use the shower indices stored
in the NtpEvent class to map back to the NtpShower objects stored in the 
fShowers
TClonesArray.

In the test program FillNtp, a tree is created with a single main branch 
to hold NtpRecord objects,
split at level = 99,  One NtpRecord is generated and the fShowers array 
is filled with 3 NtpShowers:
// shower 0 has fEnergy 10
// shower 1 has fEnergy 20
// shower 2 has fEnergy 30
and 4 NtpEvents:
// event 0 has 2 showers with fShwInd values of 0 &1
// event 1 has 0 showers
// event 2 has 1 shower with fShwInd value of 2
// event 3 has 0 showers

Now I try to use the arrays in a Draw (or Scan loop) and I find that the 
results aren't what I expect.
For example,
  tree -> 
Scan("fShowers[fEvents[].fShwInd[0]].fEnergy","fEvents[].fNShower > 0");
yields:
***********************************
*    Row   * Instance * fShowers[ *
***********************************
*        0 *        0 *        10 *
***********************************
==> 1 selected entry
instead of the expected 2 entries.  I can get 2 entries if I leave off 
the selection string, but I find
I need this selection string to avoid array out of bounds if the first 
argument to Scan or Draw
becomes more complicated, e.g.:
  tree -> Scan("fEvents[].fNShower:fShowers[fEvents[].fShwInd[0]].fEnergy");
causes a rather enormous list of array indexing errors.
Is this a bug or is there an error in the way I'm expressing the loop 
over the arrays?
Thanks,
-Sue



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:09 MET