CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ElectronUtilities.h
Go to the documentation of this file.
1 #ifndef RecoEgamma_EgammaElectronAlgos_ElectronUtilities_H
2 #define RecoEgamma_EgammaElectronAlgos_ElectronUtilities_H
3 
8 #include <CLHEP/Units/GlobalPhysicalConstants.h>
9 
10 
11 //===============================================================
12 // For an stl collection of pointers, enforce the deletion
13 // of pointed objects in case of exception.
14 //===============================================================
15 
16 template <typename StlColType>
17 class ExceptionSafeStlPtrCol : public StlColType
18  {
19  public :
20  ExceptionSafeStlPtrCol() : StlColType() {}
22  {
23  typename StlColType::const_iterator it ;
24  for ( it = StlColType::begin() ; it != StlColType::end() ; it++ )
25  { delete (*it) ; }
26  }
27  } ;
28 
29 
30 //===============================================================
31 // Normalization of angles
32 //===============================================================
33 
34 template <typename RealType>
35 RealType normalized_phi( RealType phi )
36  {
37  if (phi>CLHEP::pi)
38  { phi -= (2*CLHEP::pi) ; }
39  if (phi<-CLHEP::pi)
40  { phi += (2*CLHEP::pi) ; }
41  return phi ;
42  }
43 
44 
45 //===============================================================
46 // Convert between flavors of points and vectors,
47 // assuming existence of x(), y() and z().
48 //===============================================================
49 
50 template <typename Type1, typename Type2>
51 void ele_convert( const Type1 & obj1, Type2 & obj2 )
52  { obj2 = Type2(obj1.x(),obj1.y(),obj1.z()) ; }
53 
54 
55 //===============================================================
56 // When wanting to compute and compare several characteristics of
57 // one or two points, relatively to a given origin
58 //===============================================================
59 
61  {
62  public :
63  EleRelPoint( const math::XYZPoint & p, const math::XYZPoint & origin ) : relP_(p.x()-origin.x(),p.y()-origin.y(),p.z()-origin.z()) {}
64  EleRelPoint( const GlobalPoint & p, const math::XYZPoint & origin ) : relP_(p.x()-origin.x(),p.y()-origin.y(),p.z()-origin.z()) {}
65  EleRelPoint( const math::XYZPoint & p, const GlobalPoint & origin ) : relP_(p.x()-origin.x(),p.y()-origin.y(),p.z()-origin.z()) {}
66  EleRelPoint( const GlobalPoint & p, const GlobalPoint & origin ) : relP_(p.x()-origin.x(),p.y()-origin.y(),p.z()-origin.z()) {}
67  double eta() { return relP_.eta() ; }
68  double phi() { return normalized_phi(relP_.phi()) ; }
69  double perp() { return sqrt(relP_.x()*relP_.x()+relP_.y()*relP_.y()) ; }
70  private :
72  } ;
73 
75  {
76  public :
77  EleRelPointPair( const math::XYZPoint & p1, const math::XYZPoint & p2, const math::XYZPoint & origin ) : relP1_(p1.x()-origin.x(),p1.y()-origin.y(),p1.z()-origin.z()), relP2_(p2.x()-origin.x(),p2.y()-origin.y(),p2.z()-origin.z()) {}
78  EleRelPointPair( const GlobalPoint & p1, const math::XYZPoint & p2, const math::XYZPoint & origin ) : relP1_(p1.x()-origin.x(),p1.y()-origin.y(),p1.z()-origin.z()), relP2_(p2.x()-origin.x(),p2.y()-origin.y(),p2.z()-origin.z()) {}
79  EleRelPointPair( const math::XYZPoint & p1, const GlobalPoint & p2, const math::XYZPoint & origin ) : relP1_(p1.x()-origin.x(),p1.y()-origin.y(),p1.z()-origin.z()), relP2_(p2.x()-origin.x(),p2.y()-origin.y(),p2.z()-origin.z()) {}
80  EleRelPointPair( const math::XYZPoint & p1, const math::XYZPoint & p2, const GlobalPoint & origin ) : relP1_(p1.x()-origin.x(),p1.y()-origin.y(),p1.z()-origin.z()), relP2_(p2.x()-origin.x(),p2.y()-origin.y(),p2.z()-origin.z()) {}
81  EleRelPointPair( const GlobalPoint & p1, const GlobalPoint & p2, const math::XYZPoint & origin ) : relP1_(p1.x()-origin.x(),p1.y()-origin.y(),p1.z()-origin.z()), relP2_(p2.x()-origin.x(),p2.y()-origin.y(),p2.z()-origin.z()) {}
82  EleRelPointPair( const math::XYZPoint & p1, const GlobalPoint & p2, const GlobalPoint & origin ) : relP1_(p1.x()-origin.x(),p1.y()-origin.y(),p1.z()-origin.z()), relP2_(p2.x()-origin.x(),p2.y()-origin.y(),p2.z()-origin.z()) {}
83  EleRelPointPair( const GlobalPoint & p1, const math::XYZPoint & p2, const GlobalPoint & origin ) : relP1_(p1.x()-origin.x(),p1.y()-origin.y(),p1.z()-origin.z()), relP2_(p2.x()-origin.x(),p2.y()-origin.y(),p2.z()-origin.z()) {}
84  EleRelPointPair( const GlobalPoint & p1, const GlobalPoint & p2, const GlobalPoint & origin ) : relP1_(p1.x()-origin.x(),p1.y()-origin.y(),p1.z()-origin.z()), relP2_(p2.x()-origin.x(),p2.y()-origin.y(),p2.z()-origin.z()) {}
85  double dEta() { return (relP1_.eta()-relP2_.eta()) ; }
86  double dPhi() { return normalized_phi(relP1_.phi()-relP2_.phi()) ; }
87  double dZ() { return (relP1_.z()-relP2_.z()) ; }
88  double dPerp() { return normalized_phi(relP1_.perp()-relP2_.perp()) ; }
89  private :
92  } ;
93 
94 
95 //===============================================================
96 // Low level functions for the computing of characteristics
97 // relatively to a given origin. Not meant to improve
98 // performance, but rather for the easy later localization
99 // of all such transformations.
100 //===============================================================
101 
102 template <typename PointType>
103 double relative_eta( const PointType & p, const PointType & origin )
104  { return (p-origin).eta() ; }
105 
106 template <typename PointType>
107 double relative_phi( const PointType & p, const PointType & origin )
108  { return normalized_phi((p-origin).phi()) ; }
109 
110 
111 #endif
112 
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:72
EleRelPoint(const GlobalPoint &p, const math::XYZPoint &origin)
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
EleRelPointPair(const GlobalPoint &p1, const GlobalPoint &p2, const math::XYZPoint &origin)
float float float z
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)
RealType normalized_phi(RealType phi)
T sqrt(T t)
Definition: SSEVec.h:48
T z() const
Definition: PV3DBase.h:64
EleRelPointPair(const math::XYZPoint &p1, const GlobalPoint &p2, const GlobalPoint &origin)
GlobalVector relP1_
#define end
Definition: vmac.h:37
GlobalVector relP2_
double p2[4]
Definition: TauolaWrapper.h:90
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:30
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)
T eta() const
Definition: PV3DBase.h:76
#define begin
Definition: vmac.h:30
double p1[4]
Definition: TauolaWrapper.h:89
double pi
Definition: DDAxes.h:10
math::XYZVector relP_
Definition: DDAxes.h:10