Problem using copytree with vectors


I’m trying to use TTree::CopyTree to copy selected events from a TTree using a function I wrote to select which events to copy.

My code looks something like:

TTree* newTree = fChain->CopyTree(“myCode::Selection(lepton_n)”);

Where “lepton_n” is a variable from the original tree. This works fine as long as the function I’m calling takes floats or ints as arguments, however I would like to be able to use a function that requires vector*'s as input.

However attempting to pass vector*'s gives me the error:

Error in TTreeFormula::Compile: Bad numerical expression : “myCode::Selection( … )”

Any help would be greatly appreciated!



[quote]however I would like to be able to use a function that requires vector*'s as input.[/quote]In part due to the semantic issue with the implicit loop implemented by TTree::Draw/TTreeFormula only function that takes simple type as argument are supported in this context.

Instead, you will need to use a different mechanism to generate a TEntryList selecting the entry and then attach this entry and call CopyTree without any explicit selection.fChain->SetEntryList(entry_list); TTree* newTree = fChain->CopyTree(); // This will copy only the entry included in the EntryList.

To generate the entryList you can use TTree::Draw in its MakeProxy mode (passing a script name rather than an expression). See the TTree::Draw and TTree::MakeProxy documentation for more details.