TVector2: output phi range from -pi to pi?

Hello,

I constructed a TVector2 and I notice that the phi output, TVector2.Phi(), is in the range 0 to 2pi. How can I make this match CMS notation so that the phi output range is instead -pi to pi?

I see there is a " Phi_mpi_pi( Double_t x)" member for TVector2, but I’m not sure how to use it since it takes a double as the input and I’m confused as to what double I would be inputting.

Snippets from my code:

TVector2 Q_T;
// set up Vector
float px_1=(jetPt[1])*(cos(jetPhi[1]));
float py_1=(jetPt[1])*(sin(jetPhi[1]));
float px_2=(jetPt[0])*(cos(jetPhi[0]));
float py_2=(jetPt[0])*(sin(jetPhi[0]));
Q_T.Set(px_1+px_2,  py_1+py_2);

cout << Q_T.Phi() << endl; // outputs Phi from 0 to pi

Thanks for any help!
Cole

Please read tips for efficient and successful posting and posting code

ROOT Version: ROOT 6.30/04
Platform: Ubuntu 22.04.3 LTS
Compiler: Not Provided


Hi,

cout << Q_T.Phi() << endl; // outputs Phi from 0 to 2*pi
cout << TVector2::Phi_mpi_pi(Q_T.Phi()) << endl; // outputs Phi from -pi to +pi