Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:34:01

0001 #ifndef RecoEgamma_EgammaElectronAlgos_ElectronUtilities_H
0002 #define RecoEgamma_EgammaElectronAlgos_ElectronUtilities_H
0003 
0004 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0005 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
0006 #include "DataFormats/Math/interface/Point3D.h"
0007 #include "DataFormats/Math/interface/Vector3D.h"
0008 #include "DataFormats/Math/interface/normalizedPhi.h"
0009 
0010 //===============================================================
0011 // Convert between flavors of points and vectors,
0012 // assuming existence of x(), y() and z().
0013 //===============================================================
0014 
0015 template <typename Type1, typename Type2>
0016 void ele_convert(const Type1& obj1, Type2& obj2) {
0017   obj2 = Type2(obj1.x(), obj1.y(), obj1.z());
0018 }
0019 
0020 //===============================================================
0021 // When wanting to compute and compare several characteristics of
0022 // one or two points, relatively to a given origin
0023 //===============================================================
0024 
0025 class EleRelPoint {
0026 public:
0027   EleRelPoint(const math::XYZPoint& p, const math::XYZPoint& origin)
0028       : relP_(p.x() - origin.x(), p.y() - origin.y(), p.z() - origin.z()) {}
0029   EleRelPoint(const GlobalPoint& p, const math::XYZPoint& origin)
0030       : relP_(p.x() - origin.x(), p.y() - origin.y(), p.z() - origin.z()) {}
0031   EleRelPoint(const math::XYZPoint& p, const GlobalPoint& origin)
0032       : relP_(p.x() - origin.x(), p.y() - origin.y(), p.z() - origin.z()) {}
0033   EleRelPoint(const GlobalPoint& p, const GlobalPoint& origin)
0034       : relP_(p.x() - origin.x(), p.y() - origin.y(), p.z() - origin.z()) {}
0035   double eta() { return relP_.eta(); }
0036   double phi() { return normalizedPhi(relP_.phi()); }
0037   double perp() { return std::sqrt(relP_.x() * relP_.x() + relP_.y() * relP_.y()); }
0038 
0039 private:
0040   math::XYZVector relP_;
0041 };
0042 
0043 class EleRelPointPair {
0044 public:
0045   EleRelPointPair(const math::XYZPoint& p1, const math::XYZPoint& p2, const math::XYZPoint& origin)
0046       : relP1_(p1.x() - origin.x(), p1.y() - origin.y(), p1.z() - origin.z()),
0047         relP2_(p2.x() - origin.x(), p2.y() - origin.y(), p2.z() - origin.z()) {}
0048   EleRelPointPair(const GlobalPoint& p1, const math::XYZPoint& p2, const math::XYZPoint& origin)
0049       : relP1_(p1.x() - origin.x(), p1.y() - origin.y(), p1.z() - origin.z()),
0050         relP2_(p2.x() - origin.x(), p2.y() - origin.y(), p2.z() - origin.z()) {}
0051   EleRelPointPair(const math::XYZPoint& p1, const GlobalPoint& p2, const math::XYZPoint& origin)
0052       : relP1_(p1.x() - origin.x(), p1.y() - origin.y(), p1.z() - origin.z()),
0053         relP2_(p2.x() - origin.x(), p2.y() - origin.y(), p2.z() - origin.z()) {}
0054   EleRelPointPair(const math::XYZPoint& p1, const math::XYZPoint& p2, const GlobalPoint& origin)
0055       : relP1_(p1.x() - origin.x(), p1.y() - origin.y(), p1.z() - origin.z()),
0056         relP2_(p2.x() - origin.x(), p2.y() - origin.y(), p2.z() - origin.z()) {}
0057   EleRelPointPair(const GlobalPoint& p1, const GlobalPoint& p2, const math::XYZPoint& origin)
0058       : relP1_(p1.x() - origin.x(), p1.y() - origin.y(), p1.z() - origin.z()),
0059         relP2_(p2.x() - origin.x(), p2.y() - origin.y(), p2.z() - origin.z()) {}
0060   EleRelPointPair(const math::XYZPoint& p1, const GlobalPoint& p2, const GlobalPoint& origin)
0061       : relP1_(p1.x() - origin.x(), p1.y() - origin.y(), p1.z() - origin.z()),
0062         relP2_(p2.x() - origin.x(), p2.y() - origin.y(), p2.z() - origin.z()) {}
0063   EleRelPointPair(const GlobalPoint& p1, const math::XYZPoint& p2, const GlobalPoint& origin)
0064       : relP1_(p1.x() - origin.x(), p1.y() - origin.y(), p1.z() - origin.z()),
0065         relP2_(p2.x() - origin.x(), p2.y() - origin.y(), p2.z() - origin.z()) {}
0066   EleRelPointPair(const GlobalPoint& p1, const GlobalPoint& p2, const GlobalPoint& origin)
0067       : relP1_(p1.x() - origin.x(), p1.y() - origin.y(), p1.z() - origin.z()),
0068         relP2_(p2.x() - origin.x(), p2.y() - origin.y(), p2.z() - origin.z()) {}
0069   auto dEta() { return (relP1_.eta() - relP2_.eta()); }
0070   auto dPhi() { return normalizedPhi(relP1_.barePhi() - relP2_.barePhi()); }
0071   auto dZ() { return (relP1_.z() - relP2_.z()); }
0072   auto dPerp() { return (relP1_.perp() - relP2_.perp()); }
0073 
0074 private:
0075   GlobalVector relP1_;
0076   GlobalVector relP2_;
0077 };
0078 
0079 //===============================================================
0080 // Low level functions for the computing of characteristics
0081 // relatively to a given origin. Not meant to improve
0082 // performance, but rather for the easy later localization
0083 // of all such transformations.
0084 //===============================================================
0085 
0086 template <typename PointType>
0087 double relative_eta(const PointType& p, const PointType& origin) {
0088   return (p - origin).eta();
0089 }
0090 
0091 template <typename PointType>
0092 double relative_phi(const PointType& p, const PointType& origin) {
0093   return normalizedPhi((p - origin).phi());
0094 }
0095 
0096 #endif