ATLAS Offline Software
Loading...
Searching...
No Matches
P4BasePtEtaPhiM.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_P4BASEPTETAPHIM_H
8#define FOURMOM_P4BASEPTETAPHIM_H
9
10// STL includes
11#include <cmath>
12#include <sstream>
13#include <ostream>
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 ~P4BasePtEtaPhiM();
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 p() const;
52 double p2() const;
53 virtual double eta() const = 0;
54 virtual double phi() const = 0;
55 double e() const;
56 double et() const;
57 virtual double pt() const = 0;
58 double iPt() const;
59 double rapidity() const;
60 double cosPhi() const;
61 double sinPhi() 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;
70
73
74 // Not in @c I4Momentum interface
75 // double tanTh() const;
76
78 // Non-const methods:
80
82 // Private data:
84 private:
85
86};
87
89// Inline methods:
91
94
95inline double P4BasePtEtaPhiM::px() const
96{
97 return this->pt() * std::cos(this->phi());
98}
99
100inline double P4BasePtEtaPhiM::py() const
101{
102 return this->pt() * std::sin(this->phi());
103}
104
105inline double P4BasePtEtaPhiM::pz() const
106{
107 return this->pt()/this->tanTh();
108}
109
110inline double P4BasePtEtaPhiM::m2() const
111{
112 const double mass = this->m();
113 return mass*mass;
114}
115
116inline double P4BasePtEtaPhiM::p() const
117{
118 const double thePt = this->pt();
119 const double thePz = this->pz();
120
121 //DR from Frank Paige
122 // if negative pt point in the opposite direction
123 // BUT eta and phi still the same !!!
124
125 const double eSign = (thePt >= 0.) ? +1. : -1.;
126 return eSign * std::sqrt( thePt*thePt + thePz*thePz );
127}
128
129inline double P4BasePtEtaPhiM::p2() const
130{
131 // This method has been implemented so as to give the same as would be
132 // obtained from pow((this->p()),2) with this->p() implemented according to
133 // Frank Paige's algorithm above.
134
135 const double pt = this->pt();
136 const double pz = this->pz();
137
138 return pt*pt + pz*pz;
139}
140
141inline double P4BasePtEtaPhiM::e() const
142{
143 const double theMass = this->m();
144 const double thePt = this->pt();
145 const double thePz = this->pz();
146
147 //DR from Frank Paige
148 // if negative pt point in the opposite direction
149 // BUT eta and phi still the same !!!
150
151 const double eSign = (thePt >= 0.) ? +1. : -1.;
152 return eSign * std::sqrt( thePt*thePt + thePz*thePz + theMass*theMass);
153}
154
155inline double P4BasePtEtaPhiM::et() const
156{
157 return this->e()*this->sinTh();
158}
159
160inline double P4BasePtEtaPhiM::iPt() const
161{
162 return 1./this->pt();
163}
164
165inline double P4BasePtEtaPhiM::rapidity() const
166 {
167 const double theE=this->e();
168 const double thePz=this->pz();
169 return 0.5*std::log((theE+thePz)/(theE-thePz));
170 }
171
172inline double P4BasePtEtaPhiM::cosPhi() const
173{
174 return std::cos(this->phi());
175}
176
177inline double P4BasePtEtaPhiM::sinPhi() const
178{
179 return std::sin(this->phi());
180}
181
182
183
184inline double P4BasePtEtaPhiM::cosTh() const
185{
186 return std::tanh(this->eta());
187}
188
189inline double P4BasePtEtaPhiM::sinTh() const
190{
191 // avoid numeric overflow if very large eta
192
193 double aEta=std::abs(this->eta());
194 if ( aEta>710) {
195 aEta=710;
196 }
197
198 return 1./std::cosh(aEta);
199}
200
201inline double P4BasePtEtaPhiM::cotTh() const
202{
203 return std::sinh(this->eta());
204}
205
206inline double P4BasePtEtaPhiM::tanTh() const
207{
208 return 1./std::sinh(this->eta());
209}
210
211// less efficient
212//inline double P4BasePtEtaPhiM::tanTh() const
213//{
214// return std::tan( 2.* std::atan( std::exp( -(this->eta()) ) ) );
215//}
216
217inline CLHEP::HepLorentzVector P4BasePtEtaPhiM::hlv() const
218{
219 //minimize the number of calculation and dereference
220 const double theM = this->m();
221 // note that pt can have negative sign : then it points in opposite direction but eta and phi are still on the same side
222 const double thePt = this->pt();
223
224
225 const double thePx = thePt*this->cosPhi();
226 const double thePy = thePt*this->sinPhi();
227
228 const double thePz = thePt*this->cotTh();
229
230 const double theE=std::sqrt(thePt*thePt+thePz*thePz+theM*theM);
231
232
233 return CLHEP::HepLorentzVector( thePx, thePy, thePz, theE );
234}
235
236inline std::ostream& P4BasePtEtaPhiM::dump( std::ostream& out ) const
237{
238 std::stringstream s;
239 s << "[pt,eta,phi,m] ="
240 << std::right << std::scientific << std::setprecision(8)
241 << std::setw(16) << this->pt()
242 << std::setw(16) << this->eta()
243 << std::setw(16) << this->phi()
244 << std::setw(16) << this->m();
245
246 out << s.str();
247 return out;
248}
249
250#endif
P4BasePtEtaPhiM is a base class for classes with 4-momentum behavior, for which pt,...
double cosPhi() const
double p2() const
virtual ~P4BasePtEtaPhiM()
virtual destructor needed for inheritance
double m2() const
double pz() const
double py() const
double sinPhi() const
std::ostream & dump(std::ostream &out) const
Print I4Momentum content.
double tanTh() const
double cotTh() const
double cosTh() const
virtual double phi() const =0
virtual double m() const =0
CLHEP::HepLorentzVector hlv() const
double e() const
double rapidity() const
virtual double eta() const =0
double px() const
{@ a la I4Momentum -like interface
double iPt() const
virtual double pt() const =0
double et() const
double sinTh() const
double p() const
-event-from-file