Hello guys,
I have a problem that probably you could solve easily.
I have an existing tree with a certain number of branches.
I would like to get some of these branches and dump them, with a DIFFERENT name, into another tree (which will be saved into another file).
First question: is there a faster way than looping over the entries of the tree? I mean also a function that avoids somehow to loop…
In addition, some other branches I would like to manipulate them and then dump , with a DIFFERENT name, into another tree.
-----------Example of My code--------------
TChain *ch = new TChain(“oldtree”);
ch->Add(input_file);
ch->SetBranchStatus("*",0);
ch->SetBranchStatus(“run”,1); // branch that I would like to copy with a new name into the new file
ch->SetBranchAddress(“run”,&run);
//-------------------opening output file-----------------------
TFile *output_file = new TFile(“newfile.oot”, “RECREATE”);
//-----------------------------------------new Tree definition
TTree* newtree = new TTree(“newTree”, “New Output Tree”);
newtree = oldtree->CloneTree();
newtree->GetBranch(“run”)->SetTitle(“bs_Run”);
newtree->GetBranch(“run”)->SetName(“bs_Run”);
ch->SetBranchStatus(“event”,1); // branch that I want to manipulate first
ch->SetBranchAddress(“event”,&event);
newtree->Branch(“bs_Event”, &bs_Event, “bs_Event/I”);
for (Int_t iEntry = 0; iEntry < nentries; ++iEntry){
ch->GetEntry(iEntry);
bs_Event = event*1000;//dummy manipulation
newtree->Fill();
}//end of loop over the entries
newtree->Write(“newtree”);
Second question: how do I avoid to write also the old tree into the new file?
In the way reported above I get also “oldtree” into my newfile.
Thank you in advance
Matteo