TTree::Draw with objects?


Let us suppose that I have a tree with “mag:theta:phi”. I am trying to do the following:

tree->Draw(“TVector3().SetMagThetaPhi(mag, theta, phi).x()”);

But it does not work :unamused: I get the following:

*ERROR 30 :
Bad numerical expression : "TVector3(…

On the other hand


works :smiley:

Is there any way to make the first expression to work in ROOT?

Thanks!!! :wink:


your expression is not valid c++. You’ll have to spell out the conversion, i.e.
tree->Draw(“mag*cos(theta)*sin(phi)”); (as far as I remember :slight_smile:

Is it possible to add two branches which are TLorentzVector type and THEN apply a method such as TLorentzVector::M()? Example:
Here branch1, branch2, and branch3 are all of type TLorentzVector:

tree->Draw("(branch1 + branch2 - branch3).M()");

note that tree->Draw(“branch1.M()”); works fine.

[quote]Here branch1, branch2, and branch3 are all of type TLorentzVector:
Code: tree->Draw("(branch1 + branch2 - branch3).M()");
[/quote]No it is not possible directly. There are 2 issues. First TTreeFormula does no see overload operator and second it can not pass object to the function it calls (it can only use method and function taking and returning numerical values).
Instead use the new tree proxy mechanim. Create a file sum.C which containing:

double sum() { double result = 0; TLorentzVector sum = branch1; sum += branch2; sum += branch3; return sum.M(); }
And do