To calculate an angle difference within a range of -pi and pi, one can use C++ expression fmod in TTree.Draw and TTree.Scan, but it has an odd “truncated” definition, which breaks the group symmetry. When calculating angle between two objects as it ranges from -2pi to 2pi, and fmod(dphi,2*pi) is essentially identity (x=y) in this range.
To properly map the answer to a range between -pi and pi, one can do fmod(phi1-phi2+3*pi,2*pi)-pi, in which the 3*pi serves to move the input out of the discontinuity and centers the range at 0.
However, as more angles are involved, the shift will have to increase. And it would be good if there is a simpler method.
Hi @sciencecw , TTree::Draw and TTree::Scan and the TTreeFormula expression syntax are not being evolved anymore, I think what you mention is the best solution to the problem.
Thanks for the help. That is the right function. I thought nothing other than TMath are loaded into TTree::Draw syntax. Is this information found anywhere in the ROOT reference?
I think the doc on TTree::Draw() is quite clear - you might have been able to find that yourself
The expressions can use all the operations and built-in functions supported by TFormula (see TFormula::Analyze()), including free functions taking numerical arguments (e.g. TMath::Bessel()). In addition, you can call member functions taking numerical arguments. For example, these are two valid expressions: