CMS 3D CMS Logo

ElectronUtilities.h
Go to the documentation of this file.
1 #ifndef RecoEgamma_EgammaElectronAlgos_ElectronUtilities_H
2 #define RecoEgamma_EgammaElectronAlgos_ElectronUtilities_H
3 
9 
10 //===============================================================
11 // Convert between flavors of points and vectors,
12 // assuming existence of x(), y() and z().
13 //===============================================================
14 
15 template <typename Type1, typename Type2>
16 void ele_convert(const Type1& obj1, Type2& obj2) {
17  obj2 = Type2(obj1.x(), obj1.y(), obj1.z());
18 }
19 
20 //===============================================================
21 // When wanting to compute and compare several characteristics of
22 // one or two points, relatively to a given origin
23 //===============================================================
24 
25 class EleRelPoint {
26 public:
27  EleRelPoint(const math::XYZPoint& p, const math::XYZPoint& origin)
28  : relP_(p.x() - origin.x(), p.y() - origin.y(), p.z() - origin.z()) {}
29  EleRelPoint(const GlobalPoint& p, const math::XYZPoint& origin)
30  : relP_(p.x() - origin.x(), p.y() - origin.y(), p.z() - origin.z()) {}
31  EleRelPoint(const math::XYZPoint& p, const GlobalPoint& origin)
32  : relP_(p.x() - origin.x(), p.y() - origin.y(), p.z() - origin.z()) {}
33  EleRelPoint(const GlobalPoint& p, const GlobalPoint& origin)
34  : relP_(p.x() - origin.x(), p.y() - origin.y(), p.z() - origin.z()) {}
35  double eta() { return relP_.eta(); }
36  double phi() { return normalizedPhi(relP_.phi()); }
37  double perp() { return std::sqrt(relP_.x() * relP_.x() + relP_.y() * relP_.y()); }
38 
39 private:
41 };
42 
44 public:
46  : relP1_(p1.x() - origin.x(), p1.y() - origin.y(), p1.z() - origin.z()),
47  relP2_(p2.x() - origin.x(), p2.y() - origin.y(), p2.z() - origin.z()) {}
49  : relP1_(p1.x() - origin.x(), p1.y() - origin.y(), p1.z() - origin.z()),
50  relP2_(p2.x() - origin.x(), p2.y() - origin.y(), p2.z() - origin.z()) {}
52  : relP1_(p1.x() - origin.x(), p1.y() - origin.y(), p1.z() - origin.z()),
53  relP2_(p2.x() - origin.x(), p2.y() - origin.y(), p2.z() - origin.z()) {}
55  : relP1_(p1.x() - origin.x(), p1.y() - origin.y(), p1.z() - origin.z()),
56  relP2_(p2.x() - origin.x(), p2.y() - origin.y(), p2.z() - origin.z()) {}
57  EleRelPointPair(const GlobalPoint& p1, const GlobalPoint& p2, const math::XYZPoint& origin)
58  : relP1_(p1.x() - origin.x(), p1.y() - origin.y(), p1.z() - origin.z()),
59  relP2_(p2.x() - origin.x(), p2.y() - origin.y(), p2.z() - origin.z()) {}
60  EleRelPointPair(const math::XYZPoint& p1, const GlobalPoint& p2, const GlobalPoint& origin)
61  : relP1_(p1.x() - origin.x(), p1.y() - origin.y(), p1.z() - origin.z()),
62  relP2_(p2.x() - origin.x(), p2.y() - origin.y(), p2.z() - origin.z()) {}
63  EleRelPointPair(const GlobalPoint& p1, const math::XYZPoint& p2, const GlobalPoint& origin)
64  : relP1_(p1.x() - origin.x(), p1.y() - origin.y(), p1.z() - origin.z()),
65  relP2_(p2.x() - origin.x(), p2.y() - origin.y(), p2.z() - origin.z()) {}
66  EleRelPointPair(const GlobalPoint& p1, const GlobalPoint& p2, const GlobalPoint& origin)
67  : relP1_(p1.x() - origin.x(), p1.y() - origin.y(), p1.z() - origin.z()),
68  relP2_(p2.x() - origin.x(), p2.y() - origin.y(), p2.z() - origin.z()) {}
69  auto dEta() { return (relP1_.eta() - relP2_.eta()); }
70  auto dPhi() { return normalizedPhi(relP1_.barePhi() - relP2_.barePhi()); }
71  auto dZ() { return (relP1_.z() - relP2_.z()); }
72  auto dPerp() { return (relP1_.perp() - relP2_.perp()); }
73 
74 private:
77 };
78 
79 //===============================================================
80 // Low level functions for the computing of characteristics
81 // relatively to a given origin. Not meant to improve
82 // performance, but rather for the easy later localization
83 // of all such transformations.
84 //===============================================================
85 
86 template <typename PointType>
87 double relative_eta(const PointType& p, const PointType& origin) {
88  return (p - origin).eta();
89 }
90 
91 template <typename PointType>
92 double relative_phi(const PointType& p, const PointType& origin) {
93  return normalizedPhi((p - origin).phi());
94 }
95 
96 #endif
EleRelPointPair(const GlobalPoint &p1, const math::XYZPoint &p2, const GlobalPoint &origin)
EleRelPointPair(const math::XYZPoint &p1, const GlobalPoint &p2, const math::XYZPoint &origin)
T perp() const
Definition: PV3DBase.h:69
EleRelPoint(const GlobalPoint &p, const math::XYZPoint &origin)
T z() const
Definition: PV3DBase.h:61
constexpr T normalizedPhi(T phi)
Definition: normalizedPhi.h:8
T eta() const
Definition: PV3DBase.h:73
EleRelPointPair(const GlobalPoint &p1, const GlobalPoint &p2, const math::XYZPoint &origin)
T barePhi() const
Definition: PV3DBase.h:65
EleRelPointPair(const GlobalPoint &p1, const math::XYZPoint &p2, const math::XYZPoint &origin)
EleRelPoint(const math::XYZPoint &p, const math::XYZPoint &origin)
EleRelPointPair(const math::XYZPoint &p1, const math::XYZPoint &p2, const math::XYZPoint &origin)
EleRelPointPair(const math::XYZPoint &p1, const math::XYZPoint &p2, const GlobalPoint &origin)
T sqrt(T t)
Definition: SSEVec.h:23
EleRelPointPair(const math::XYZPoint &p1, const GlobalPoint &p2, const GlobalPoint &origin)
GlobalVector relP1_
GlobalVector relP2_
EleRelPointPair(const GlobalPoint &p1, const GlobalPoint &p2, const GlobalPoint &origin)
EleRelPoint(const GlobalPoint &p, const GlobalPoint &origin)
EleRelPoint(const math::XYZPoint &p, const GlobalPoint &origin)
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
double relative_eta(const PointType &p, const PointType &origin)
double relative_phi(const PointType &p, const PointType &origin)
void ele_convert(const Type1 &obj1, Type2 &obj2)
math::XYZVector relP_