Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-18 02:12:29

0001 #ifndef JETUTILMC_H
0002 #define JETUTILMC_H
0003 
0004 #include <cmath>
0005 #include <TMath.h>
0006 namespace {
0007   class PtGreater {
0008   public:
0009     template <typename T>
0010     bool operator()(const T& i, const T& j) {
0011       return (i.pt() > j.pt());
0012     }
0013   };
0014 
0015   inline double Phi_0_2pi(double x) {
0016     while (x >= 2 * M_PI)
0017       x -= 2 * M_PI;
0018     while (x < 0.)
0019       x += 2 * M_PI;
0020     return x;
0021   }
0022 
0023   inline double Phi_mpi_pi(double x) {
0024     while (x >= M_PI)
0025       x -= 2 * M_PI;
0026     while (x < -M_PI)
0027       x += 2 * M_PI;
0028     return x;
0029   }
0030 
0031   inline double dPhi(double phi1, double phi2) {
0032     phi1 = Phi_0_2pi(phi1);
0033     phi2 = Phi_0_2pi(phi2);
0034     return Phi_mpi_pi(phi1 - phi2);
0035   }
0036 
0037   inline double radius(double eta1, double phi1, double eta2, double phi2) {
0038     const double TWOPI = 2.0 * M_PI;
0039 
0040     phi1 = Phi_0_2pi(phi1);
0041     phi2 = Phi_0_2pi(phi2);
0042 
0043     double dphi = Phi_0_2pi(phi1 - phi2);
0044     dphi = TMath::Min(dphi, TWOPI - dphi);
0045     double deta = eta1 - eta2;
0046 
0047     return sqrt(deta * deta + dphi * dphi);
0048   }
0049 
0050   template <typename T1, typename T2>
0051   double radius(const T1& t1, const T2& t2) {
0052     return radius(t1->eta(), t1->phi(), t2->eta(), t2->phi());
0053   }
0054 }  // namespace
0055 
0056 #endif