[ROOT] Correction on TTree: drawing leaves with different # of entries

From: Gene Van Buren (gene@bnl.gov)
Date: Fri Apr 14 2000 - 18:41:27 MEST


I got some of the details wrong in my previous email.
I had tested it with 2 SVs per event, but I've made
more accurate conclusions with more than 2 SVs
per event:

Gene Van Buren wrote:

> Hi there. I'm trying to create a TTree with two main
> branches: one for a primary vertex (PV) for an event,
> and one for secondary vertices (SV) for an event. I'm
> using TClonesArrays for both so that only the data
> members I need get read in from file.
>
> For every event, there's just one PV, but many SVs.
>
> Both PVs and SVs have 3 data members indicating
> their X,Y,Z position. What I would like to be able to
> do is examine deltaX, deltaY, and deltaZ for each
> SV, where deltaX = X(SV) - X(PV), etc.
>
> Now, I know that the TTree somehow keeps events
> separated, such that if I read back into TClonesArrays,
> only one PV gets read in for each event, and the
> proper number of SVs get read in for each event.
>
> What I'd like to do is something like:
> tree.Draw("SV.X-PV.X");

Here's what I should have said:

This indeed gives an entry for each SV, but PV.X
is zero for the second SV. The reason for this appears
to be in TTreeFormula::EvalInstance. This bit of code
is smart enough to know that if you ask for entries
past the number that are in a given leaf for an event,
then use the first entry for that leaf.

However, this bit of logic fails for the second entry,
because it asks the leaf how many data entires
there are:

       if (instance < leaf->GetNdata()) param[i] =
leaf->GetValue(instance);
       else                             param[i] = leaf->GetValue(0);

TLeaf for some reason sets its data member fNdata to
the count+1 in TLeaf::ResetAddress:

   if (fLeafCount) fNdata = fLen*(fLeafCount->GetMaximum() + 1);

There's only one PV.X entry, but fNdata gets set to 2. Thus, on
the second SV.X entry, instance = 1, and that's still less than 2,
so the PV.X leaf returns a value zero.

An additional oddity is that the above only happens if I do:
  tree.Draw("PV.X");
BEFORE
  tree.Draw("SV.X-PV.X");

If I do not draw the PV.X values before the difference values,
then ALL PV.X values are assumed zero, and it is in fact just like
  tree.Draw("SV.X");
!!!


> Any ideas on a solution to this? Has anyone else
> tried to deal with this?
>
> TTree::Draw is orders of magnitude faster than
> creating arrays, reading the TTree into them event
> by event, and filling histograms from the data in
> the arrays, so I'm hoping to be able to stick with it.
>
> -Gene



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