where “cutgselection” would correspond to the selection imposed by TCutG.
If CopyTree can’t handle it, I could run a loop over the ntuple and check for every entry TCutG::IsInside(), but then how do I add a single entry (as received from GetEntry(i) to my new ntuple?
Hi, TNtupleD *ntSel = (TNtupleD*)ntuple->CopyTree("cutgselection"); should work. However, note that by definition, this will copy any entry that has at least one match (i.e. if your selection is on a collection within the entry, all the elements of the collection are copied when one or more match the criterium).
I can vaguely imagine trying something with Olivier’s suggestion of TEventList (although it is not clear to me how to turn the TEventList back into a TTree/TNtupleD).
I am confused by Philippe’s reply. When I wrote CopyTree(“cutgselection”), the “cutgselection” was just meant as a placeholder for something that would actually give me the selection defined by the TCutG… as it stands it will most certainly NOT work! Did you perhaps misunderstand the question? If not, I would appreciate a working example (could be based on on the hist/FirstContour.C tutorial, which provides an example of a TCutG).
The parameter to CopyTree follows the same syntax as the parameter to TTree::Draw. So apriori with your earlier example, you ought to doTNtupleD *ntSel = (TNtupleD*)ntuple->CopyTree(cutg->GetName());
Wow, yes, this actually works right away!! I seriously underestimated ROOT, how silly of me! (I take comfort in the fact that Olivier did not know either… )