Re: TTree as a database

Rene Brun (Rene.Brun@cern.ch)
Fri, 17 Apr 1998 09:12:10 +0200


William J Deninger wrote:
>
> Rene,
>
> Sorry, but that "=" was an email typing mistake. Given the preexisting
> tree:
>
> TTree tree
> TBranch raw
> Int_t run_number
> TClonesArray wires of TMpxEvent
> TMpxEvent
> Int_t time
> Int_t index
> T3DPoint location
>
> I would like to append data associated with each of the TMpxEvents in the
> TClonesArray. Ideally, I wish one could append the preexisting tree in the
> following manner.
>
> case (A):
>
> TTree tree
> TBranch raw
> Int_t run_number
> TClonesArray wires("TMpxEvent",n)
> TMpxEvent (1)
> Int_t time
> Int_t index
> T3DPoint location
>
> Bool_t ambiguity
> Float_t drift_distance
> Float_t drift_error
> ...
> TMpxEvent (n)
> Int_t time
> Int_t index
> T3DPoint location
>
> Bool_t ambiguity
> Float_t drift_distance
> Float_t drift_error
>
> Unfortunately, the only way of adding to a tree is by adding TBranches which
> (I believe) can not be correlated to the preexisting members in the
> TClonesArray wires.
>
> case (B):
>
> TTree tree
> TBranch raw
> Int_t run_number
> TClonesArray wires("TMpxEvent",n)
> TMpxEvent (1)
> Int_t time
> Int_t index
> T3DPoint location
> ...
> TMpxEvent (n)
> Int_t time
> Int_t index
> T3DPoint location
>
> TBranch corralate to wires TClonesArray
> TClonesArray wires("TMpxAppendingObject",n)
> TMpxAppendingObject (1)
> Bool_t ambiguity
> Float_t drift_distance
> Float_t drift_error
> ...
> TMpxAppendingObject (n)
> Bool_t ambiguity
> Float_t drift_distance
> Float_t drift_error
>
> For each time entry there is one drift_distance.
> tree->Draw("wires.drift_distance","time<100") doesn't correctly histogram
> drift_distance according to its given time. How might one add to the tree
> in order to get the behavior found in case (A)?
>

The current TTree::Draw function has the following limitations:
1- you cannot correlate two variables from 2 different trees.
I intend to remove this limitation in the future.

2- If one of the variables is an array (or TClonesArray),
you cannot mix it with another variable from a different array.
For example if A is an array and B another array and C a simple
variable,
a, you can do:
T.Draw("A","C<0")
b, you cannot do:
T.Draw("A","B<0")
case a implies two loops (on events, then on the array A itself).
case b implies 3 loops and is subject to interpretation of the
array notation syntax. A and B arrays have different length.

These are limitations of the TTree::Draw function, not limitations
of the Tree functionality. In your case, if I understand correctly
what you want to do, you should create two Trees, one T1 with the
raw data and a second tree T2 with the added information.
The analysis function could look like:
Int_t nentries = T1->GetEntries(); //assume T2 has the same
for (Int_t event=0;event<nentries;event++) {
T1->GetEvent(event);
T2->GetEvent(event);
// your selection procedure and histogramming
}

Rene Brun