Re: [ROOT] Accessing member functions from a TTree...

From: Matthieu Guillo (guillo@jlab.org)
Date: Mon Mar 12 2001 - 01:15:44 MET


Hi Matthew,

Be carefull to fill your tree carefully, I had a similar problem once: I
thought I was filling the tree properly and when I looked at it back, it
was empty.
The tree.branch method expect a reference to a pointer. So if you make all
your calculations using TLorentzVectors objects, don't forget to reference
to them through a pointer. Eg:

// file and tree definition
TFile f("MonBoSape1","RECREATE");
TTree tree("tree","roidesfauxhaies");  // sorry for the french joke 

// pointers to 4-vectors 
// !!! Warning, one declaration per line when using pointers. C++ sucks.
TLorentzVector* pv4PiMinus = NULL;     // pointer for the piminus branch
TLorentzVector* pv4Proton = NULL;      // pointer for the proton branch

// branches definition
tree.Branch("piminus", "TLorentzVector", &pv4PiMinus, 32000, 0);  // pi-
in not split mode
tree.Branch("proton", "TLorentzVector", &pv4Proton, 32000, 0); // proton
in not split mode
 
// Ok, lets make some calculations
TLorentzVector v4PiMinus, v4Proton;

// Calculations goes there
..........................
.........................

// referencing
pv4PiMinus = &v4PiMinus;
pv4Proton = &v4Proton;

// and filling  
tree.Fill();

An other possibility is to create TLorentzVectors from the heap but then
you have to keep tracks of them to prevent memory leak and you have also
the burden to deference them when using very common operators like +, -.

When you analyse your data in the tree, don't forget to load the physics
library as it is not done automatically when starting a ROOT session. Then
you can call any method you want:

.L $ROOTSYS/lib/libPhysics.so;
TFile f("MonBoSape1");
TTree* tree = (TTree*) f.Get("tree");
tree->Draw("piminus.X():piminus.Y()","proton.Beta()>0.6");  // pi- px Vs.
py for fast proton.

Hope it helps otherwise I can send you some of my files.

Matthieu Guillo
University of South Carolina
Thomas Jefferson National Laboratory
Office 71 trailer 16
Phone: 757-269-5551



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:39 MET