TTree "copied" but not drawing on TBrowser (asking again)

*I asked this question on the forum a while ago, but didn’t solve the issue at the time, so I am asking again.


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 i by output_tree->Fill();. Finally, write the output_tree into an 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?

Sorry to have missed your post the first time.
Can you post the faulty ROOT file (or a subset of it) ?
Also indicates the exact Draw() command you are typing.

Actually, Olivier hasn’t missed your previous question - he wrote:

Also, I suggest you post your full script here. How are you applying your cuts? Are you working with SetBranchAddress? Maybe there is some bug in your script causing undefined behavior and thus leading to a root file broken in a “funny” way?

If you are just applying simple cuts, you could also try to use CopyTree instead of CloneTree, for example:

auto treeWithCutsApplied = sourceTree->CopyTree("answer > 42");
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.