Calculating the delta-phi correctly can be annoying, as you would need to ensure the result is always in the range of [-π, π]. Or you could just use a simple trigonometric function:

double dphi = std::acos(std::cos(phi1 - phi2));


However, the above result is always positive. If you care about the sign, you could work with cos θ instead:

double cos_dphi = std::cos(phi1 - phi2);


The one-liner can come in handy when you want to plot delta-phi from the ROOT command prompt.