ATLAS Offline Software
Loading...
Searching...
No Matches
P4BaseEEtaPhiM.h
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
5*/
6
7#ifndef FOURMOM_P4BASEEETAPHIM_H
8#define FOURMOM_P4BASEEETAPHIM_H
9
10// STL includes
11#include <cmath>
12#include <ostream>
13#include <sstream>
14#include <iomanip>
15
16// CLHEP includes
17#include "CLHEP/Vector/LorentzVector.h"
18#include "CLHEP/Units/SystemOfUnits.h"
19
30
31
33{
34 public:
35
37 virtual ~P4BaseEEtaPhiM();
38
40 // Const methods:
42
45
46 double px() const;
47 double py() const;
48 double pz() const;
49 virtual double m() const = 0;
50 double m2() const;
51 double rapidity() const;
52 double p() const;
53 double p2() const;
54 virtual double eta() const = 0;
55 virtual double phi() const = 0;
56 virtual double e() const = 0;
57 double et() const;
58 double pt() const;
59 double iPt() const;
60 double sinPhi() const;
61 double cosPhi() const;
62 double tanTh() const;
63 double cosTh() const;
64 double sinTh() const;
65 double cotTh() const;
66 CLHEP::HepLorentzVector hlv() const;
67
69 std::ostream& dump( std::ostream& out ) const;
72
74 // Non-const methods:
76
78 // Protected data:
80 private:
81};
82
84// Inline methods:
86
89
90inline double P4BaseEEtaPhiM::px() const
91{
92 return this->pt()*cos(this->phi());
93}
94
95inline double P4BaseEEtaPhiM::py() const
96{
97 return this->pt()*sin(this->phi());
98}
99
100inline double P4BaseEEtaPhiM::pz() const
101{
102 return this->p()*this->cosTh();
103}
104
105inline double P4BaseEEtaPhiM::m2() const
106{
107 const double mass = this->m();
108 return mass*mass;
109}
110
111inline double P4BaseEEtaPhiM::p() const
112{
113 const double theM=this->m();
114 const double theE=this->e();
115 // if (theM==0.) return theE ;
116 // else return sqrt(theE*theE-theM*theM);
117 //DR from Frank Paige
118 // if negative energy point in the opposite direction
119 // BUT eta and phi still the same !!!
120 if (theM==0.) {
121 return theE;
122 } else {
123 double eSign = (theE >= 0.) ? +1. : -1.;
124 return eSign*std::sqrt(theE*theE-theM*theM);
125 }
126
127}
128
129inline double P4BaseEEtaPhiM::p2() const
130{
138 const double mass = this->m();
139 const double ene = this->e();
140
141 return ene*ene - mass*mass;
142}
143
144inline double P4BaseEEtaPhiM::et() const
145{
146 return this->e()*this->sinTh();
147}
148
149inline double P4BaseEEtaPhiM::rapidity() const
150 {
151 const double theE=this->e();
152 const double thePz=this->pz();
153 return 0.5*std::log((theE+thePz)/(theE-thePz));
154 }
155
156inline double P4BaseEEtaPhiM::pt() const
157{
158 return this->p()*this->sinTh();
159}
160
161inline double P4BaseEEtaPhiM::iPt() const
162{
163 return 1./this->pt();
164}
165
166inline double P4BaseEEtaPhiM::cosPhi() const
167{
168 return std::cos(this->phi());
169}
170
171inline double P4BaseEEtaPhiM::sinPhi() const
172{
173 return std::sin(this->phi());
174}
175
176
177inline double P4BaseEEtaPhiM::tanTh() const
178{
179 double theEta=this->eta();
180 if ( std::abs(theEta)>710) {
181 theEta=theEta>0 ? 710 : -710;
182 return 1./std::sinh(theEta);
183 }
184 return 1./this->cotTh();
185}
186
187inline double P4BaseEEtaPhiM::cosTh() const
188{
189 return std::tanh(this->eta());
190}
191
192inline double P4BaseEEtaPhiM::sinTh() const
193{
194 // avoid numeric overflow if very large eta
195
196 double aEta=std::abs(this->eta());
197 if ( aEta>710) {
198 aEta=710;
199 }
200
201 return 1./std::cosh(aEta);
202}
203
204inline double P4BaseEEtaPhiM::cotTh() const
205{
206 return std::sinh(this->eta());
207}
208
209inline CLHEP::HepLorentzVector P4BaseEEtaPhiM::hlv() const
210{
211 //minimize the number of calculation and dereference
212 const double theE = this->e();
213 const double theCosTh = this->cosTh();
214
215 // DR from Frank Paige
216 // negative energy point in opposite direction
217 // BUT Eta and Phi still the same
218 // double theP=theE;
219
220 const double theP = this->p();
221
222 const double theSinTh = std::sqrt(1.-theCosTh*theCosTh);
223 const double thePt = theP*theSinTh;
224 const double thePx = thePt*this->cosPhi();
225 const double thePy = thePt*this->sinPhi();
226 const double thePz = theP*theCosTh;
227
228 return CLHEP::HepLorentzVector(thePx,thePy,thePz,theE);
229}
230
231inline std::ostream& P4BaseEEtaPhiM::dump( std::ostream& out ) const
232{
233 std::stringstream s;
234 s << "[e,eta,phi,m] ="
235 << std::right << std::scientific << std::setprecision(8)
236 << std::setw(16) << this->e()
237 << std::setw(16) << this->eta()
238 << std::setw(16) << this->phi()
239 << std::setw(16) << this->m();
240
241 out << s.str();
242 return out;
243
244}
245
246
247#endif // FOURMOM_P4BASEEETAPHIM_H
248
P4BaseEEtaPhiM is a base class for classes with 4-momentum behavior, for which E, eta,...
double sinPhi() const
double px() const
{@ a la I4Momentum -like interface
virtual double phi() const =0
virtual double m() const =0
virtual double eta() const =0
double et() const
double cosPhi() const
double rapidity() const
double tanTh() const
double pt() const
virtual ~P4BaseEEtaPhiM()
virtual destructor needed for inheritance
double pz() const
double py() const
double cotTh() const
double cosTh() const
std::ostream & dump(std::ostream &out) const
Print I4Momentum content.
CLHEP::HepLorentzVector hlv() const
double sinTh() const
double p() const
virtual double e() const =0
double p2() const
double iPt() const
double m2() const
-event-from-file