Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:23

0001 #ifndef JET_JETUTIL_H
0002 #define JET_JETUTIL_H 1
0003 
0004 #include <cmath>
0005 #include <algorithm>
0006 
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 class EtGreater {
0016 public:
0017   template <typename T>
0018   bool operator()(const T& i, const T& j) {
0019     return (i.et() > j.et());
0020   }
0021 };
0022 
0023 class JetUtil {
0024 public:
0025   static double Phi_0_2pi(double x) {
0026     while (x >= 2 * M_PI)
0027       x -= 2 * M_PI;
0028     while (x < 0.)
0029       x += 2 * M_PI;
0030     return x;
0031   }
0032 
0033   static double Phi_mpi_pi(double x) {
0034     while (x >= M_PI)
0035       x -= 2 * M_PI;
0036     while (x < -M_PI)
0037       x += 2 * M_PI;
0038     return x;
0039   }
0040 
0041   static double dPhi(double phi1, double phi2) {
0042     phi1 = Phi_0_2pi(phi1);
0043     phi2 = Phi_0_2pi(phi2);
0044     return Phi_mpi_pi(phi1 - phi2);
0045   }
0046 
0047   static double radius(double eta1, double phi1, double eta2, double phi2) {
0048     const double TWOPI = 2.0 * M_PI;
0049 
0050     phi1 = Phi_0_2pi(phi1);
0051     phi2 = Phi_0_2pi(phi2);
0052 
0053     double dphi = Phi_0_2pi(phi1 - phi2);
0054     dphi = std::min(dphi, TWOPI - dphi);
0055     double deta = eta1 - eta2;
0056 
0057     return sqrt(deta * deta + dphi * dphi);
0058   }
0059 
0060   template <typename T1, typename T2>
0061   static double radius(const T1& t1, const T2& t2) {
0062     return radius(t1->eta(), t1->phi(), t2->eta(), t2->phi());
0063   }
0064 };
0065 #endif