CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  struct Distance {
22  float deltaR;
24  bool operator<(const Distance& rd2) const { return deltaR < rd2.deltaR; };
25  };
26 
27  Direction(double eta = 0., double phi = 0.) : theEta(eta), thePhi(phi) {
28  while (thePhi < 0.0)
29  thePhi += 2 * M_PI;
30  while (thePhi >= 2 * M_PI)
31  thePhi -= 2 * M_PI;
32  };
33 
34  double eta() const { return theEta; }
35  double phi() const { return thePhi; }
36  double theta() const { return acos(tanh(theEta)); }
37 
38  inline bool operator==(const Direction& d2) {
39  if (this == &d2)
40  return true;
41  if (deltaR(d2) < 1.e-4)
42  return true;
43  return false;
44  }
45 
46  inline double deltaR2(const Direction& dir2) const { return reco::deltaR2(*this, dir2); }
47  inline double deltaR(const Direction& dir2) const { return reco::deltaR(*this, dir2); }
48 
49  Distance operator-(const Direction& dir2) const {
51  double dR = deltaR(dir2);
52  double dEta = theEta - dir2.eta();
53  double dPhi = reco::deltaPhi(thePhi, dir2.phi());
54 
55  result.relativeAngle = (dR > 1.e-4) ? atan2(dPhi, dEta) : 0.;
56  result.deltaR = dR;
57  return result;
58  }
59 
60  Direction operator+(const Distance& relDir) const {
61  double eta = theEta + relDir.deltaR * cos(relDir.relativeAngle);
62  double phi = thePhi + relDir.deltaR * sin(relDir.relativeAngle);
63  return Direction(eta, phi);
64  }
65 
66  std::string print() const {
67  std::ostringstream str;
68  str << " (Eta=" << theEta << ","
69  << "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:26
Direction operator+(const Distance &relDir) const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Distance operator-(const Direction &dir2) const
tuple result
Definition: mps_fire.py:311
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:30
Direction(double eta=0., double phi=0.)
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
bool operator==(const Direction &d2)
#define str(s)
double deltaR(const Direction &dir2) const