ATLAS Offline Software
Loading...
Searching...
No Matches
P4BasePxPyPzE.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// P4BasePxPyPzE.h
8// Header file for class P4::Base::PxPyPzE
9// Author: S.Binet<binet@cern.ch>
11#ifndef FOURMOM_P4BASEPXPYPZE_H
12#define FOURMOM_P4BASEPXPYPZE_H
13
14// STL includes
15#include <cmath>
16#include <limits>
17#include <sstream>
18#include <ostream>
19#include <iomanip>
20
21// CLHEP includes
22#include "CLHEP/Vector/LorentzVector.h"
23#include "CLHEP/Units/SystemOfUnits.h"
24
25// Forward declaration
26
28{
29
31 // Public methods:
33 public:
34
37 virtual ~P4BasePxPyPzE();
38
40 // Const methods:
42
45
46 virtual double px() const = 0;
47 virtual double py() const = 0;
48 virtual double pz() const = 0;
49 double m() const;
50 double m2() const;
51 double p() const;
52 double p2() const;
53 double eta() const ;
54 double rapidity() const ;
55 double phi() const ;
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 cotTh() const;
64 double cosTh() const;
65 double sinTh() const;
66 CLHEP::HepLorentzVector hlv() const;
67
69 std::ostream& dump( std::ostream& out ) const;
70
73
75 // Non-const methods:
77
79 // Protected data:
81 private:
82
83};
84
86// Inline methods:
88
91
92inline double P4BasePxPyPzE::m() const
93{
94 const double m2 = this->m2();
95 return m2 < 0. ? -std::sqrt(-m2) : std::sqrt(m2);
96}
97
98inline double P4BasePxPyPzE::m2() const
99{
100 const double px = this->px();
101 const double py = this->py();
102 const double pz = this->pz();
103 const double e = this->e();
104
105 const double m2 = e*e - ( px*px + py*py + pz*pz );
106 return m2;
107}
108
109inline double P4BasePxPyPzE::p() const
110{
111 return std::sqrt( this->p2() );
112}
113
114inline double P4BasePxPyPzE::p2() const
115{
116 const double px = this->px();
117 const double py = this->py();
118 const double pz = this->pz();
119
120 return px*px + py*py + pz*pz;
121}
122
123inline double P4BasePxPyPzE::eta() const
124{
125 const double px=this->px();
126 const double py=this->py();
127 const double pz=this->pz();
128 // FIXME: should we use a more underflow-friendly formula:
129 // sqrt(a**2 + b**2)
130 // => y.sqrt(1+(x/y)**2) where y=max(|a|,|b|) and x=min(|a|,|b|)
131 const double p =std::sqrt (px*px + py*py + pz*pz);
132 if (p==0.0) return 0.0;
133 if (p==+pz) return +std::numeric_limits<double>::infinity();
134 if (p==-pz) return -std::numeric_limits<double>::infinity();
135 return 0.5*log((p+pz)/(p-pz));
136}
137
138inline double P4BasePxPyPzE::cosPhi() const
139{
140 if ( this->px() == 0 && this->py() ==0 )
141 return 0;
142 return this->px()/this->pt();
143}
144
145inline double P4BasePxPyPzE::sinPhi() const
146{
147 if ( this->px() == 0 && this->py() ==0 )
148 return 0;
149 return this->py()/this->pt();
150}
151
152inline double P4BasePxPyPzE::phi() const
153{
154 const double px=this->px();
155 const double py=this->py();
156 // return px == 0.0 && py == 0.0 ? 0.0 : std::atan2(py,px);
157 // AFAIK, atan2 is doing exactly this
158 return std::atan2(py,px);
159}
160
161
162inline double P4BasePxPyPzE::et() const
163{
164 if ( this->e() == 0 )
165 return 0;
166 return this->e()*this->sinTh();
167}
168
169inline double P4BasePxPyPzE::pt() const
170{
171 const double px=this->px();
172 const double py=this->py();
173
174 return std::sqrt(px*px + py*py);
175}
176
177inline double P4BasePxPyPzE::iPt() const
178{
179 const double pt = this->pt();
180 if ( pt == 0 )
181 return std::numeric_limits<double>::infinity();
182 return 1./pt;
183}
184
185inline double P4BasePxPyPzE::rapidity() const
186{
187 const double e =this->e();
188 const double pz=this->pz();
189 if (e==0.0) return 0.0;
190 if (e==+pz) return +std::numeric_limits<double>::infinity();
191 if (e==-pz) return -std::numeric_limits<double>::infinity();
192 return 0.5*std::log((e+pz)/(e-pz));
193}
194
195inline double P4BasePxPyPzE::cosTh() const
196{
197 if ( this->p() == 0 ) return 0;
198 return this->pz()/this->p();
199}
200
201inline double P4BasePxPyPzE::sinTh() const
202{
203 if ( this->p() == 0 ) return 0;
204 return this->pt()/this->p();
205}
206
207inline double P4BasePxPyPzE::tanTh() const
208{
209 if ( this->pz() == 0 ) return 0;
210 return this->pt()/this->pz();
211}
212
213inline double P4BasePxPyPzE::cotTh() const
214{
215 if ( this->pt() == 0 ) return 0;
216 return this->pz()/this->pt();
217}
218
219inline CLHEP::HepLorentzVector P4BasePxPyPzE::hlv() const
220{
221 return CLHEP::HepLorentzVector(this->px(),this->py(),this->pz(),this->e());
222}
223
224inline std::ostream& P4BasePxPyPzE::dump( std::ostream& out ) const
225{
226 std::stringstream s;
227 s << "[px,py,pz,e] ="
228 << std::right << std::scientific << std::setprecision(8)
229 << std::setw(16) << this->px()
230 << std::setw(16) << this->py()
231 << std::setw(16) << this->pz()
232 << std::setw(16) << this->e();
233
234 out << s.str();
235 return out;
236}
237
238#endif //> FOURMOM_P4BASEPXPYPZE_H
double p() const
virtual double pz() const =0
double cosPhi() const
double tanTh() const
double m() const
double eta() const
double sinPhi() const
double sinTh() const
virtual double e() const =0
CLHEP::HepLorentzVector hlv() const
double pt() const
double p2() const
virtual double px() const =0
{@ a la I4Momentum -like interface
double iPt() const
double et() const
virtual ~P4BasePxPyPzE()
Destructor:
virtual double py() const =0
std::ostream & dump(std::ostream &out) const
Print I4Momentum content.
double cosTh() const
double cotTh() const
double m2() const
double phi() const
double rapidity() const
-event-from-file