CMS 3D CMS Logo

IsoDepositDirection.h
Go to the documentation of this file.
1 #ifndef RecoCandidate_IsoDepositDirection_H
2 #define RecoCandidate_IsoDepositDirection_H
3 
9 #include <cmath>
10 #include <sstream>
11 #include <iostream>
12 
15 
16 namespace reco {
17  namespace isodeposit {
18 
19  class Direction {
20  public:
21 
22  struct Distance {
23  float deltaR;
24  float relativeAngle;
25  bool operator < (const Distance & rd2) const { return deltaR < rd2.deltaR; };
26  };
27 
28  Direction(double eta = 0., double phi = 0.) : theEta(eta), thePhi(phi) {
29  while( thePhi < 0.0 ) thePhi += 2*M_PI;
30  while( thePhi >= 2*M_PI ) thePhi -= 2*M_PI;
31  };
32 
33  double eta() const { return theEta; }
34  double phi() const { return thePhi; }
35  double theta() const { return acos(tanh(theEta)); }
36 
37  inline bool operator==(const Direction & d2) {
38  if ( this == &d2 ) return true;
39  if ( deltaR(d2) < 1.e-4) return true;
40  return false;
41  }
42 
43  inline double deltaR2(const Direction & dir2) const {
44  return reco::deltaR2(*this, dir2);
45  }
46  inline double deltaR(const Direction & dir2) const {
47  return reco::deltaR(*this, dir2);
48  }
49 
50  Distance operator- (const Direction & dir2) const {
52  double dR = deltaR(dir2);
53  double dEta = theEta-dir2.eta();
54  double dPhi = reco::deltaPhi(thePhi,dir2.phi());
55 
56  result.relativeAngle = (dR > 1.e-4) ? atan2(dPhi,dEta) : 0.;
57  result.deltaR = dR;
58  return result;
59  }
60 
61  Direction operator+ (const Distance & relDir) const {
62  double eta = theEta + relDir.deltaR*cos(relDir.relativeAngle);
63  double phi = thePhi + relDir.deltaR*sin(relDir.relativeAngle);
64  return Direction(eta,phi);
65  }
66 
67  std::string print() const {
68  std::ostringstream str;
69  str<<" (Eta="<<theEta<< "," << "Phi=" <<thePhi<<")";
70  return str.str();
71  }
72 
73  private:
74  float theEta;
75  float thePhi;
76  };
77 
78  } //namespace isodeposit
79 } //namespace reco
80 
81 #endif
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:22
Direction operator+(const Distance &relDir) const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Distance operator-(const Direction &dir2) const
double deltaR2(const Direction &dir2) const
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
#define M_PI
bool operator<(const Distance &rd2) const
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
Direction(double eta=0., double phi=0.)
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
fixed size matrix
bool operator==(const Direction &d2)
#define str(s)
double deltaR(const Direction &dir2) const