Hi Jeff,
> Pain #1 - reattaching the Tree in the ROOT file seems to be much more
> complex than hi/fil 1 charm.root was
>
> Pain #2 - I don't see an easy way to go thru the entire Tree and plot
> say the magnitudes of the four-momenta (I thought the tree was
> supposed to keep all the object code intact which is why we were using
> C++ ... oh dear).
>
...
>
> ppsi.Mag() is the biggest disappointment. What is the use of having
> all these objects in the tree if I can't use their methods?
>
> Pain #3 - wading thru the documentation gives me no clue of how to do
> what I want to do, except for possibly the contorted, non-simple
> method shown under "The General Way" on URL
>
> http://root.cern.ch/root/HowtoReadTree.html
>
> Say it ain't so!!! Isn't OO supposed to make my life easier?
>
I agree that it is difficult to find the way through the documentation.
But if you know how to use it its quite powerful.
I changed your macro to store objects and not numbers in the tree.
The important point is to provide the ClassName and the address of
a pointer to the object in tree->Branch(...):
// #-> charm.py -- simulate j/psi electroproduction at JLab
// c++ version i hope
// from Numeric import * [ left over from python version ]
// from vec4 import *
// import RNG
// #-> simulation driver parameters
void createTree(int howmany = 100)
{
float mj = 3096.88; // # J/psi mass in MeV
float me = 0.510999; // # electron mass
float mp = 938.272;
float beamen = 11.0 * 1000.0; // # GeV * 1000 MeV/GeV
float ll_the = (3.1415926 / 180) * 1.0; // last number is e- angle LL
in deg
float ul_the = (3.1415926 / 180) * 20.0; // last number is e- angle UL
in deg
// above is stored in radians since we will need to take cosines
// below is not
float ll_phe = -93.0; // LL on e- azimuthal angle (degrees now)
float ul_phe = -87.0;
float ll_pe = 2275; // LL on scat electron momentum (MeV/c)
float ul_pe = 2780;
// #-> set up random generators for electron. strategy: create sample
// #-> arrays at start of program, just take values from them during
// #-> execution
TF1 *thegen = new TF1("thegen","sin(x)",ll_the,ul_the);
TF1 *phegen = new TF1("phegen","1.0", ll_phe,ul_phe);
TF1 *pegen = new TF1("pegen", "1.0", ll_pe, ul_pe );
// #-> set up four-momenta for beam and target, which should not
change
TLorentzVector *beam = new TLorentzVector();
beam->SetVectM(TVector3(0,0,beamen),me);
TLorentzVector *targ =new TLorentzVector(0.0,0.0,0.0,mp);
TFile hfile("charm.root","RECREATE","Charm");
TTree *tree = new TTree("T","Charm Electroproduction");
int nev = 0;
TLorentzVector *scat = new TLorentzVector(1,1,1,1);
TLorentzVector *X = new TLorentzVector();
int buf = 32000; // default in TTree
tree->Branch("beam","TLorentzVector",&beam, buf, 0);
tree->Branch("targ","TLorentzVector",&targ, buf, 0);
tree->Branch("scat","TLorentzVector",&scat, buf, 0);
tree->Branch("ppsi","TLorentzVector",&X, buf,0);
for ( int nev = 1; nev <= howmany; nev++) {
float thtmp = thegen.GetRandom();
float phtmp = phegen.GetRandom();
float ptmp = pegen.GetRandom();
scat->SetVectM(TVector3(ptmp*sin(thtmp)*cos(phtmp),
ptmp*sin(thtmp)*sin(phtmp),
ptmp*cos(thtmp)),
me);
*X = *beam + *targ - *scat;
tree->Fill();
}
hfile.Write();
hfile.Close();
}
usage:
to create a tree:
root> .L createTree.C
root> createTree(1000)
root> .q
to use the tree:
root> TFile f("charm.root")
root> T->Draw("ppsi.X()")
root> T->Draw("ppsi.Mag()")
root> T->Draw("ppsi.X():ppsi.Y()","ppsiMag()>4000","lego")
...
If you need the full flexibility you can use
T->MakeClass("Charm")
and edit the created Charm::Loop() method.
Hope that helps,
Peter
PS: A good starting point is the Fermi Root 102 Class
available via http://www-pat.fnal.gov/root/
Peter Malzacher, FNAL, GSI
P.Malzacher@gsi.de
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:17 MET