Problem when calling a function within Tree->Draw() metho


1/ I want to use a function in a TTree->Draw() method.
But when I execute the command, I got the following error message:

root [1] .L
root [2] .L lib/
root [3] TFile t(“files/g3.root”)
root [4] TTree *mt = AMSRoot
root [5] mt->Draw(“edepTot(pEcalhit(0),nEcalHit())”,“nEcalHit()>0”)
AMSEventR::ctor-I-SingletonInitialized 0x8eb07e0
AMSEventR::dtor-I-Destroying 1
AMSEventR::dtor-I-ResettingHead 0
*ERROR 30 :
Bad numerical expression : “edepTot(pEcalhit(0),nEcalHit())”

The function signature is: Float_t edepTot(EcalHitR *ptEcalHit,Int_t num)
EcalHitR is a Object which inherit from TObjet.

When I do the same thing with a simple function like:

Int_t sum(Int_t n1,Int_t index)
Int_t fEdepTotal = 0;
for (Int_t i = 0 ; i < index ; i++ )
fEdepTotal = fEdepTotal + n1;

return fEdepTotal;


the root [5] mt->Draw(“sum(nEcalHit(),nEcalHit())”,“nEcalHit()>0”)
is working

any idea ?
Thank you for your help.


Hi Jean,

Currently TFormula (and hence TTreeFormula and hence TTree::Draw) suppors call ONLY to function that takes arithmetic arguments and return an arithmetic value.

In particular, EcalHitR * is NOT supported.