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