Hi everybody,
I have the following problem. I try to add a branch to a tree and to save the new tree (the one with one additional branch) in a new file.
here is the macro I use:
{
//Open the old file and get the tree
TFile f(“studentntuples.root_repos”);
f.cd(“StudentSampleAlg”);
TTree* nt1=gDirectory->Get(“1”);
//open the new file and create the new tree as a clone of the old one
TFile *g = new TFile(“modifiedntuples.root”, “RECREATE”);
TTree *newtree = nt1->CloneTree();
//delete the old tree and close the old file
nt1.Delete();
f.Close();
Float_t px, py, energy, transmom;
//add the branch to the new tree and try to fill it
newtree.Branch(“transmom”, &transmom, “transverse momentum/F”);
newtree->SetBranchAddress(“px”, &px);
newtree->SetBranchAddress(“py”, &py);
newtree->SetBranchAddress(“transmom”, &transmom);
int nentries=newtree->GetEntries();
cout<<nentries<<endl;
for( int i=0; i < nentries; i++){
newtree->GetEvent(i);
transmom = sqrt( pxpx + pypy);
newtree.Fill();
}
newtree.Write();
g->Write();
newtree.Delete();
g.Close();}
If I try to draw the new branch after a add it:
newtree->SetBranchAddress(“transmom”, &transmom);
newtree.Draw(“transmom”)
I get nentries in the one single bin (always the same but I do not know
what is actually giving that number)
If I draw the new branch after filling/writing the tree
newtree.Write();
newtree.Draw(“transmom”);
I get some strange histogram having double of the number of entries is supose to have and looking as the sum of the histogram descriebed above and the actual transmom histogram.
Could you please help me to understand what happen?
Thank you very much in advance,
Have a nice day,
Raluca