I have an input
.root file that has a ton of events stored in a
TTree, and I want to write out only a subset of the events (but all the branches/leaves) that satisfy some specific cuts.
The way I have implemented it now is to initialize a
TTree *output_tree =(TTree*) fChain->CloneTree(0) so that the structure of the input tree is cloned, but I don’t necessarily store any of the events a priori. Then, I loop through the input events (
fChain->GetEntry(i);), check if the desired cuts are satisfied, and, if so, store the specific event
output_tree->Fill();. Finally, write the
output_tree into a output file.
I see that the events are getting written properly and the size of the output file is correct. I can even access the values of the
output_tree in a different analysis code and plot them.
However, I cannot seem to be able to plot the results in an interactive mode, using TBrowser or even by explicitly creating
TFile and getting
TTree from it. To be more specific, the canvas just says “Empty.” (Even within the interactive mode,
TTree->Print() gives the correct output (it has the correct number of entries, all the branches/leaves that should have been copied from the input, etc.) It is just the plots that do not seem to work.)
Any idea why this is happening? Also, is there a better way to copy a subset
TTree of interest that possibly avoids this issue?