Problem with tree SetAlias

I have the following problem: I’ve built a TTree with two branches:

Now I would like to add an Alias to rotate energy1. If I write:
t1.SetAlias(“energy_new”,“energy1cos(theta) - energy2sin(theta)”);
it says:
Error in TTreeFormula::Compile: Bad numerical expression : "theta"
Error in TTreeFormula::DefinedVariable: The substitution of the alias “termico_new” by “energy1cos(theta) - energy2sin(theta)” failed.

If, instead of cos and sin I write 0.805883 and 0.592075 (the numerical value of sin and cos) everything works…why? I can’t find the problem…
Thank you!!

The definition of an alias can use only names known to the Tree, eg in your case “energy1” and “energy2”. If you want to create an alias depending on some constants defined in your program, you can do something like

double theta = TMath::Pi()/4; t1.SetAlias("energy_new",Form("energy1*cos(%g) - energy2*sin(%g)",theta,theta));

Thak you :slight_smile:
I have tryed, but it says…

Can’t call TTree::SetAlias(“energy_new”,Form(“energy1_new”,“energy1cos(%g) - energy2sin(%g)”,theta,theta)) in current scope Ruota.C:115:
Possible candidates are…
(in TTree)
/usr/lib/root/5.18/ -1:-1 0 public: virtual Bool_t TTree::SetAlias(const char* aliasName,const char* aliasFormula);


ops! I found the problem…I have to write:
t1.SetAlias(“energy1_new”,Form(“energy1cos(%g) - energy2sin(%g)”,theta,theta));
instead of
t1.SetAlias(Form(“energy1_new”,“energy1cos(%g) - energy2sin(%g)”,theta,theta));
now it works!
thank you very much :smiley: