I’m likely to have an easy question, but I can’t figure it out.
I have a tree, a brach of which is the following object:
class MyEvent : public TObject
{
...
std::vector<double> TrkAx;
...
ClassDef(MyEvent, 1)
}
Then, in the analysis, I can draw the first element of the `TrkAx’ array like this:
myTree->Draw(“myBranch.TrkAx[0]”);
Is there a way to get the size of the vector? Something like this:
myTree->Draw(“myBranch.TrkAx.size”);
[quote] //
// Accessing collection objects
// ============================
//
// TTree::Draw default’s handling of collections is to assume that any
// request on a collection pertain to it content. For example, if fTracks
// is a collection of Track objects, the following:
// tree->Draw(“event.fTracks.fPx”);
// will plot the value of fPx for each Track objects inside the collection.
// Also
// tree->Draw(“event.fTracks.size()”);
// would plot the result of the member function Track::size() for each
// Track object inside the collection.
// To access information about the collection itself, TTree::Draw support
// the ‘@’ notation. If a variable which points to a collection is prefixed
// or postfixed with ‘@’, the next part of the expression will pertain to
// the collection object. For example:
// tree->Draw(“event.@fTracks.size()”);
// will plot the size of the collection refered to by fTracks (i.e the number
[/quote] // of Track objects).
[quote=“brun”]Hi Kaspi,
The doc of TTree::Draw says
Rene[/quote]
Sorry, I must have missed it. I apologize.
If I use the “@” convention, it works. But if use it without “@”:
chain.Draw("branchT2EV.TrkAx.size()", cut);
I get the following error message:
Warning in <TTreeFormula::DefinedVariable>: Can not call method on content of vector<double> in branchT2EV.TrkAx.size()
Error in <TTreeFormula::Compile>: Part of the Variable "branchT2EV.TrkAx.size()" exists but some of it is not accessible or useable
As said in the doc (correctly I believe) the “@” indicates that the function like “size()” here applies to teh collection itself and not the member(s) of the collection.
[quote=“brun”]hi Kašpi
As said in the doc (correctly I believe) the “@” indicates that the function like “size()” here applies to teh collection itself and not the member(s) of the collection.
Rene[/quote]