ATLAS Offline Software
P4BasePxPyPzE.h
Go to the documentation of this file.
1 
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 
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 
74  // Non-const methods:
77 
79  // Protected data:
81  private:
82 
83 };
84 
86 // Inline methods:
88 
90 {}
91 
92 inline double P4BasePxPyPzE::m() const
93 {
94  const double m2 = this->m2();
95  return m2 < 0. ? -std::sqrt(-m2) : std::sqrt(m2);
96 }
97 
98 inline 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 
109 inline double P4BasePxPyPzE::p() const
110 {
111  return std::sqrt( this->p2() );
112 }
113 
114 inline 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 
123 inline 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 
138 inline double P4BasePxPyPzE::cosPhi() const
139 {
140  if ( this->px() == 0 && this->py() ==0 )
141  return 0;
142  return this->px()/this->pt();
143 }
144 
145 inline double P4BasePxPyPzE::sinPhi() const
146 {
147  if ( this->px() == 0 && this->py() ==0 )
148  return 0;
149  return this->py()/this->pt();
150 }
151 
152 inline 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 
162 inline double P4BasePxPyPzE::et() const
163 {
164  if ( this->e() == 0 )
165  return 0;
166  return this->e()*this->sinTh();
167 }
168 
169 inline 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 
177 inline 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 
185 inline 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 
195 inline double P4BasePxPyPzE::cosTh() const
196 {
197  if ( this->p() == 0 ) return 0;
198  return this->pz()/this->p();
199 }
200 
201 inline double P4BasePxPyPzE::sinTh() const
202 {
203  if ( this->p() == 0 ) return 0;
204  return this->pt()/this->p();
205 }
206 
207 inline double P4BasePxPyPzE::tanTh() const
208 {
209  if ( this->pz() == 0 ) return 0;
210  return this->pt()/this->pz();
211 }
212 
213 inline double P4BasePxPyPzE::cotTh() const
214 {
215  if ( this->pt() == 0 ) return 0;
216  return this->pz()/this->pt();
217 }
218 
219 inline CLHEP::HepLorentzVector P4BasePxPyPzE::hlv() const
220 {
221  return CLHEP::HepLorentzVector(this->px(),this->py(),this->pz(),this->e());
222 }
223 
224 inline 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
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
P4BasePxPyPzE::~P4BasePxPyPzE
virtual ~P4BasePxPyPzE()
Destructor:
Definition: P4BasePxPyPzE.h:89
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
P4BasePxPyPzE::tanTh
double tanTh() const
Definition: P4BasePxPyPzE.h:207
P4BasePxPyPzE::hlv
CLHEP::HepLorentzVector hlv() const
Definition: P4BasePxPyPzE.h:219
P4BasePxPyPzE::p
double p() const
Definition: P4BasePxPyPzE.h:109
P4BasePxPyPzE::pz
virtual double pz() const =0
P4BasePxPyPzE::phi
double phi() const
Definition: P4BasePxPyPzE.h:152
P4BasePxPyPzE::rapidity
double rapidity() const
Definition: P4BasePxPyPzE.h:185
P4BasePxPyPzE::sinTh
double sinTh() const
Definition: P4BasePxPyPzE.h:201
P4BasePxPyPzE::sinPhi
double sinPhi() const
Definition: P4BasePxPyPzE.h:145
P4BasePxPyPzE::et
double et() const
Definition: P4BasePxPyPzE.h:162
P4BasePxPyPzE::iPt
double iPt() const
Definition: P4BasePxPyPzE.h:177
P4BasePxPyPzE::p2
double p2() const
Definition: P4BasePxPyPzE.h:114
P4BasePxPyPzE::pt
double pt() const
Definition: P4BasePxPyPzE.h:169
P4BasePxPyPzE::cosPhi
double cosPhi() const
Definition: P4BasePxPyPzE.h:138
P4BasePxPyPzE::cotTh
double cotTh() const
Definition: P4BasePxPyPzE.h:213
P4BasePxPyPzE
Definition: P4BasePxPyPzE.h:28
P4BasePxPyPzE::m2
double m2() const
Definition: P4BasePxPyPzE.h:98
P4BasePxPyPzE::m
double m() const
Definition: P4BasePxPyPzE.h:92
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
P4BasePxPyPzE::py
virtual double py() const =0
P4BasePxPyPzE::cosTh
double cosTh() const
Definition: P4BasePxPyPzE.h:195
P4BasePxPyPzE::dump
std::ostream & dump(std::ostream &out) const
Print I4Momentum content.
Definition: P4BasePxPyPzE.h:224
P4BasePxPyPzE::e
virtual double e() const =0
P4BasePxPyPzE::eta
double eta() const
Definition: P4BasePxPyPzE.h:123
P4BasePxPyPzE::px
virtual double px() const =0
{@ a la I4Momentum -like interface