Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:36

0001 #ifndef RecoCandidate_IsoDepositDirection_H
0002 #define RecoCandidate_IsoDepositDirection_H
0003 
0004 /** \class isolation::Direction
0005  *  Simple eta-phi direction
0006  *  \author M. Zanetti
0007  */
0008 
0009 #include <cmath>
0010 #include <sstream>
0011 #include <iostream>
0012 
0013 #include "DataFormats/Math/interface/deltaR.h"
0014 #include "DataFormats/Math/interface/deltaPhi.h"
0015 
0016 namespace reco {
0017   namespace isodeposit {
0018 
0019     class Direction {
0020     public:
0021       struct Distance {
0022         float deltaR;
0023         float relativeAngle;
0024         bool operator<(const Distance& rd2) const { return deltaR < rd2.deltaR; };
0025       };
0026 
0027       Direction(double eta = 0., double phi = 0.) : theEta(eta), thePhi(phi) {
0028         while (thePhi < 0.0)
0029           thePhi += 2 * M_PI;
0030         while (thePhi >= 2 * M_PI)
0031           thePhi -= 2 * M_PI;
0032       };
0033 
0034       double eta() const { return theEta; }
0035       double phi() const { return thePhi; }
0036       double theta() const { return acos(tanh(theEta)); }
0037 
0038       inline bool operator==(const Direction& d2) {
0039         if (this == &d2)
0040           return true;
0041         if (deltaR(d2) < 1.e-4)
0042           return true;
0043         return false;
0044       }
0045 
0046       inline double deltaR2(const Direction& dir2) const { return reco::deltaR2(*this, dir2); }
0047       inline double deltaR(const Direction& dir2) const { return reco::deltaR(*this, dir2); }
0048 
0049       Distance operator-(const Direction& dir2) const {
0050         Distance result;
0051         double dR = deltaR(dir2);
0052         double dEta = theEta - dir2.eta();
0053         double dPhi = reco::deltaPhi(thePhi, dir2.phi());
0054 
0055         result.relativeAngle = (dR > 1.e-4) ? atan2(dPhi, dEta) : 0.;
0056         result.deltaR = dR;
0057         return result;
0058       }
0059 
0060       Direction operator+(const Distance& relDir) const {
0061         double eta = theEta + relDir.deltaR * cos(relDir.relativeAngle);
0062         double phi = thePhi + relDir.deltaR * sin(relDir.relativeAngle);
0063         return Direction(eta, phi);
0064       }
0065 
0066       std::string print() const {
0067         std::ostringstream str;
0068         str << " (Eta=" << theEta << ","
0069             << "Phi=" << thePhi << ")";
0070         return str.str();
0071       }
0072 
0073     private:
0074       float theEta;
0075       float thePhi;
0076     };
0077 
0078   }  //namespace isodeposit
0079 }  //namespace reco
0080 
0081 #endif