Dear Philippe,
I don’t know if I got you right, in any case here there is the whole code (w/o variables declaration) with the Tree::Fill().
I’ll try what you suggest in any case.
Thank you
cheers
Elena
tree = new TTree("USR111","User Ntuple example"); // name (has to be unique) and title of the Ntuple
tree->Branch("Run", &Run, "Run/I");
tree->Branch("Xprim", &Xprim, "Xprim/F");
tree->Branch("Yprim", &Yprim, "Yprim/F");
tree->Branch("Zprim", &Zprim, "Zprim/F");
tree->Branch("Nout", &Nout, "Nout/I");
tree->Branch("Ch2prim",&Ch2prim,"Chi2prim/F");
tree->Branch("Y", &Y, "Y/F");
tree->Branch("W", &W, "W/F");
tree->Branch("Xf", &Xf, "Xf/F");
tree->Branch("Q2", &Q2, "Q2/F");
tree->Branch("Xbj", &Xbj, "Xbj/F");
tree->Branch("Mmiss", &Mmiss, "Mmiss/F");
tree->Branch("Df", &Df, "Df/F");
tree->Branch("Ebeam", &Ebeam, "Ebeam/F");
//for the cross-check
tree->Branch("Bvtx", &Bvtx, "Bvtx/I");
tree->Branch("imu1", &imu1, "imu1/I");
tree->Branch("Ebeam1", &Ebeam1, "Ebeam1/F");
tree->Branch("target", &target, "target/I");
tree->Branch("l_pion", &l_pion, "l_pion/F");
tree->Branch("l_kaon", &l_kaon, "l_kaon/F");
tree->Branch("l_pro", &l_pro, "l_pro/F");
tree->Branch("l_bg", &l_bg, "l_bg/F");
tree->Branch("z",&z,"z/F");
first=false;
} // end of histogram booking
//---------------
Run = e.RunNum();
if(method == 1) { // method # 1 (starting from vertex loop)
int Bvtx = e.iBestPrimaryVertex();
h1[26]->Fill(Bvtx);//number of events
if(Bvtx >=0){
const PaVertex& v = e.vVertex(Bvtx);
int imu0 = v.InParticle(); // get beam mu index
int imu1 = v.iMuPrim(); // get scattered mu index
h1[27]->Fill( (imu0!=-1)? imu1 : -1 ); //number of BPV
if(imu0 != -1 && imu1!= -1) {
const PaParticle& Mu0 = e.vParticle(imu0); // it's beam muon
const PaParticle& Mu1 = e.vParticle(imu1); // it's scattered muon
const PaTPar& ParamMu0 = Mu0.ParInVtx(Bvtx); // fitted mu parameters in the primary vertex
const PaTPar& ParamMu1 = Mu1.ParInVtx(Bvtx); // fitted mu' parameters in the primary vertex
TLorentzVector LzVecMu0 = ParamMu0.LzVec(M_mu); // calculate beam mu Lorentz vector
TLorentzVector LzVecMu1 = ParamMu1.LzVec(M_mu); // calculate scattered mu Lorentz vector
h1[28]->Fill(imu1 ); //# reconstructed muons
if(LzVecMu0.E()>140 && LzVecMu0.E()<180){
Ebeam1= LzVecMu0.E();
h1[25]->Fill(LzVecMu0.E());//energy beam
h1[23]->Fill(v.Pos(2));//Zprim before the target cut
//if(PaAlgo::CrossCells(ParamMu0,Run)== true && Commented to verify the Luigi's numbers
if(PaAlgo::InTarget(ParamMu0,'U',Run)== true ||
PaAlgo::InTarget(ParamMu0,'C',Run)== true ||
PaAlgo::InTarget(ParamMu0,'D',Run)== true ) {
h1[29]->Fill(imu1);//3 of scattered muons off the target
target=imu1;
// calculate some kinematic variables
Y = (LzVecMu0.E()-LzVecMu1.E())/LzVecMu0.E();
Q2 = PaAlgo::Q2 (LzVecMu0, LzVecMu1);
Xbj = PaAlgo::xbj(LzVecMu0, LzVecMu1);
W = sqrt(PaAlgo::W2 (LzVecMu0, LzVecMu1));
TLorentzVector q = LzVecMu0 - LzVecMu1; // virtual photon's 4-vector
TLorentzVector p(0,0,0,M_Pr); // proton's 4-vector (in rest)
int myMask = 8 | 256;//inclusione dell'outer & middle trg 17/01/2012
if((e.TrigMask()&myMask)>0){
h1[1] ->Fill(v.Pos(2)); // fill vertex Z position
h1[2] ->Fill(v.NOutParticles()); // histogram number of outgoing particles in the vertex
h1[3] ->Fill(W); // fill W histogarm
h1[5]->Fill(Mmiss); //fill missing energy
h1[6]->Fill(Y); //fill Y
h1[10]->Fill(Q2); // fill Q2 histogarm
h1[11]->Fill(Xbj); // fill Xbj histogarm
// fill N-tuple's variables.
Xprim = v.Pos(0);
Yprim = v.Pos(1);
Zprim = v.Pos(2);
if(isnan(Zprim)) cout<<"Zprim is nan (1)!"<<endl;
Ch2prim = v.Chi2();
Nout = v.NOutParticles();
Ebeam= LzVecMu0.E();
h1[7]->Fill(Zprim);
h1[8]->Fill(Yprim);
h1[9]->Fill(Xprim);
h1[12]->Fill(Ebeam);
//inserendo nuovi tagli per l'identificazione degli adroni
// have a look on other particles in the vertex
//condizione sulla coordinata z
PaTPar MaxMomParam;
double maxP = 0;
int ih=-1;
TLorentzVector LzVecOut(0,0,0,0); // for sum 4-vectors of all created particles
for(int j = 0; j < v.NOutParticles(); j++) { // loop over outgoing particles of the vertex
int ip = v.iOutParticle(j); // index of outgoing particle
const PaParticle& p = e.vParticle(ip);
const PaTrack& t= e.vTrack(ip) ;//reference to track ip
float zfirst = t.ZFirst();
float zlast = t.ZLast();
float xx0 = t.XX0();
if(zfirst<350 && zlast>350 && xx0<15){
if(p.IsMuPrim()) continue; // skip mu'
const PaTPar& param = p.ParInVtx(Bvtx);
LzVecOut += param.LzVec(M_pi); // add 4-vector to sum
if(param.Mom() > maxP) { // search max. mom. particle
maxP = param.Mom();
ih=ip;
MaxMomParam = param;
TLorentzVector q = LzVecMu0 - LzVecMu1; // virtual photon's 4-vector
TLorentzVector p(0,0,0,M_Pr); // proton's 4-vector (in rest)
double Mx2 = (LzVecMu0 + p - (LzVecMu1+LzVecOut)).M2();
Mmiss = (Mx2 - M_Pr*M_Pr)/(2*M_Pr);
if(ih != -1) { // "leading" hadron had found
TLorentzVector LzVecHadron = MaxMomParam.LzVec(M_pi);
z= LzVecHadron.E()/(LzVecMu0.E()-LzVecMu1.E());//hadron fraction momentum
if(z>0.2 && z<0.85){
Xf = PaAlgo::Xf(LzVecMu0, LzVecMu1, LzVecHadron);
h1[4]->Fill(Xf); // fill Xf of hardron
h1[30]->Fill(z); //fill hadron fraction momentum
PaPid id;
if(id.CheckRichInfo(e.vTrack(ip))==true){
l_pion = id.GetLike(0,e.vTrack(ip));//pion LH
l_kaon = id.GetLike(1,e.vTrack(ip));//kaon LH
l_pro = id.GetLike(2,e.vTrack(ip));//proton LH
l_bg = id.GetLike(5,e.vTrack(ip));//background LH
h1[31]->Fill(id.LikePid(e.vTrack(ip))); //fill unidentified hadrons
PaTPar Hout;//cosi' nn funziona
if(param.Extrapolate(z_rich,Hout)==true){
if(Hout.Theta()>10 || Hout.Theta()<120){
if(l_pion>l_bg && l_pion>l_kaon && l_pion>l_pro)
{
h1[32]->Fill(l_pion); //fill pion LH value
}
if(l_kaon>1.24*l_bg && l_kaon>1.02*l_pion && l_kaon>l_pro)
{
h1[33]->Fill(l_kaon);//fill kaon LH value
}
tree->Fill(); // store Ntuple entry.
}//theta_rich condition
}//extraploated track for getting theta
}//chechrichinfo condition
}//condizione su energia hadron
}//condizione sulla z e sulla radiation length
}//loop ih!=-1
}//param.Mom()>maxP
}//loop
}//if del trg mask
Phast::Ref().h_file = tree->GetCurrentFile(); // "refresh" pointer to histogram file
}//condizione in target
}//condizione sul fascio
}//condizione sui muoni entranti e uscenti
}//conteggio dei Bvtx
}//chiude il metodo 1
if(Q2 > 0.01) e.TagToSave();
}