Size of a vector in an NTuple in interactive mode

Hello,

I have an NTuple with a branch ptLeptons which is a std::vector.

I can then do a plot like:
NTuple.Draw(ptLeptons[0]);
or with a cut like this
NTuple.Draw(ptLeptons[0], “ptLeptons[0] > 50”);

But how do I access the size of the array? Say I only want those events where there are at least 3 leptons.

[code]root [32] NTuple.Draw(“lepPt[0]”,“lepPt.size()>2”)
Warning in TTreeFormula::DefinedVariable: Can not call method on content of vector in lepPt.size()

Error in TTreeFormula::Compile: Part of the Variable “lepPt.size()” exists but some of it is not accessible or useable
[/code]

However, when using a TSelector, doing SetBranchAddress, GetEntry and so on the full vector and thus also the size() is available. But how to access this when drawing things interactively? (an easy solution is of course to store an additional branch “sizeLepPt”, but as the size() is already stored in the vector, this should not be needed)

Is this possible at all? People I have asked suggested I should be using arrays instead of vectors and store the number of array entries separately. Do you agree on this, so should I get rid of std::vectors in the ntuple?

Hi,

Yes, you can access it via the @ ‘operator’ which indicates to TTree::Draw that you want to access the collection rather than its content:NTuple.Draw("lepPt[0]","lepPt@.size()>2");

See TTree::Draw documentation and the User’s Guide for more details.

Cheers,
Philippe.

Thanks!