Removing events in a root file


I have a root file that contains a tree and some histograms.
For some reason i want to remove some events.
Is there a way to just remove events from the file ? Or do I have to copy the tree in a new file after selecting only the events that I don’t want to remove ? And would this also remove the events in the histograms (that are not in the tree, but in the file) ?

Thank you very much for you help

Hi and welcome to the forum!

The TTree was maybe used to generate the histograms - you’d need to regenerate them with the updated TTree once you have removed entries.

TTrees are read-only; the way to remove entries is indeed to write the entries you want to keep into a new TTree. See tutorials/tree/copytree3.C for how to do that with bare TTree, or even simpler, use RDataFrame::Snapshot().

Cheers, Axel