Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:42

0001 #ifndef Math_notmalizedPhi_h
0002 #define Math_notmalizedPhi_h
0003 #include "DataFormats/Math/interface/deltaPhi.h"
0004 #include <algorithm>
0005 
0006 // return a value of phi into interval [-pi,+pi]

0007 template <typename T>
0008 constexpr T normalizedPhi(T phi) {
0009   return reco::reduceRange(phi);
0010 }
0011 
0012 // cernlib V306

0013 template <typename T>
0014 constexpr T proxim(T b, T a) {
0015   constexpr T c1 = 2. * M_PI;
0016   constexpr T c2 = 1 / c1;
0017   return b + c1 * std::round(c2 * (a - b));
0018 }
0019 
0020 #include <iostream>
0021 
0022 // smallest range

0023 template <typename T>
0024 constexpr bool checkPhiInSymRange(T phi, T phi1, T phi2, float maxDphi = float(M_PI)) {
0025   // symmetrize

0026   if (phi2 < phi1)
0027     std::swap(phi1, phi2);
0028   return checkPhiInRange(phi, phi1, phi2, maxDphi);
0029 }
0030 
0031 // counterclock-wise range

0032 template <typename T>
0033 constexpr bool checkPhiInRange(T phi, T phi1, T phi2, float maxDphi = float(M_PI)) {
0034   phi2 = proxim(phi2, phi1);
0035   constexpr float c1 = 2. * M_PI;
0036   if (phi2 < phi1)
0037     phi2 += c1;
0038   auto dphi = std::min(maxDphi, 0.5f * (phi2 - phi1));
0039   auto phiA = phi1 + dphi;
0040   phi = proxim(phi, phiA);
0041   return std::abs(phiA - phi) < dphi;
0042 
0043   /* old "alternative algo"

0044     constexpr T c1 = 2.*M_PI;

0045     phi1 = normalizedPhi(phi1);

0046     phi2 = proxim(phi2,phi1);

0047     if (phi2<phi1) phi2+=c1;

0048     // phi & phi1 are in [-pi,pi] range...

0049     return ( (phi1 <= phi) & (phi <= phi2) )

0050 //           || ( (phi1 <= phi-c1) & (phi-c1 <= phi2) )

0051            || ( (phi1 <= phi+c1) & (phi+c1 <= phi2) );

0052     */
0053 }
0054 
0055 #endif