After a lot of trying, reading the forum post and played with the root examples I want your help
I produced with makeClass a .C and .h file based on an ntuple that I am having. I built my analysis
on the .C file and everything is working fine. Lately I thought about from the giving ntuple to build
a new one and write there only the events that are passing the cuts. So you can imagine I cannot
I followed several examples on that with no luck. So what I am doing:
I am having a function called run in wich I pass all the files I want for the analysis. This builds the
chain of files and is calling the Loop function to loop over the entries. In the Loop function on Line
104-107 I make a new file with a clone tree from the old one. I put inside the filename fixed cause
I cannot do it dynamically. (in run function I usually enter something like run(mc00*) and gets all
the files in the directory). After that on line 123 I copy the branch addresses of the oldtree to the
newtree and on line 472 I have newtree->Fill() (after all the cuts). I write the tree close the file and etc
The result is a tree with the same branches but with zero values. I really cannot explain this. An help
is much appreciated. I attach the files you need to give a try here. (.C .h) The ntuple is placed in
afs/cern.ch/user/g/giakov/public/ called mcSample.root
I have root 5.27/04 on my mac with leopard 10.5.8 with gcc 4.2.1 Also to mention I classically compile
the .C file inside root .L file.C+ with no problem.
The part that is missing in your code is a call to oldtree->GetEntry(iEntry);
Without this call, you never load/read the data you are intending on copying. Also in using the parameter iEntry I assume that the entries of the âoldtreeâ are exactly aligned with the entry of the tree that you are using to decide the cut (i.e. the one pointed to by fChain). Also the call to CopyAddresses in your case is superfluous has it is already done by the call to CloneTree.
Thank you so muchâŚit worked )
I wanted also to ask if itâs possible to take the file dynamically. I pass the files inside the run function like this:
run(âMonteCarlo00*â)
because I have
MonteCarlo0001.root
MonteCarlo0002.root
MonteCarlo0003.root
âŚ
and itâs working but when Iâm trying to get the tree of the fChain Iike that
TTree oldtree = (TTree)fChain->GetCurrentFile()->Get(âphysicsâ);
where physics itâs the name of my TTree I get *** Break *** segmentation violation
Thanks for the response. I changed the code but still getting *** Break *** segmentation violation.
I attach the new one .C and the .h is the same as above. Also my ntuple is in
afs/cern.ch/user/g/giakov/public/ called mcSample.root
The TTree object returns by TTree oldtree = (TTree)fChain->GetCurrentFile()->Get(âphysicsâ);
or by fChain->GetTree() will be destroyed the next time the chain move to a new file and thus,
the oldtree->GetEntry() will segfault. What you will need to do is something like:
TTree *oldchain = fChain->Clone(); // Duplicate the chain itself)
...
TTree *newtree = oldchain->CloneTree(0); // Duplicate the structure
...
oldchain->GetEntry(iEntry);
...
newtree->Fill();
Note this complication is necessary in your case because you can not directly (as this time) Clone a TTree/TChain that is set in MakeClass mode.