ATLAS Offline Software
TruthParticleMomentum.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 // TruthParticleMomentum.h
8 // Header file for class TruthParticleMomentum
9 // Author: S.Binet<binet@cern.ch>
11 #ifndef MCPARTICLEEVENT_TRUTHPARTICLEMOMENTUM_H
12 #define MCPARTICLEEVENT_TRUTHPARTICLEMOMENTUM_H
13 
14 // STL includes
15 #include <iosfwd>
16 #include <limits>
17 
18 // HepMC / CLHEP includes
19 #include "CLHEP/Vector/LorentzVector.h"
20 #include "CLHEP/Units/SystemOfUnits.h"
22 #include "EventKernel/I4Momentum.h"
23 
24 // Forward declaration
25 class I4MomentumError;
26 
28 {
29 
31  // Public methods:
33  public:
34 
38 
42 
46 
49  TruthParticleMomentum( const HepMC::FourVector& hlv );
50 
53  virtual ~TruthParticleMomentum();
54 
56  // Const methods:
58 
62  double px() const;
63  double py() const;
64  double pz() const;
65  double m() const;
66  double m2() const;
67  double p() const;
68  double p2() const;
69  double rapidity() const;
70  double eta() const;
71  double phi() const;
72  double e() const;
73  double et() const;
74  double pt() const;
75  double iPt() const;
76  double sinPhi() const;
77  double cosPhi() const;
78  double tanTh() const;
79  double cotTh() const;
80  double cosTh() const;
81  double sinTh() const;
82  CLHEP::HepLorentzVector hlv() const;
83 
84  // Truth particles never have errors
85  const I4MomentumError* errors() const {return 0;}
86 
87  // underlying 4 vector is of type HepLorentzVector, so of P4PxPyPzE style
89 
90 
91 
92 
94  std::ostream& dump( std::ostream& out ) const;
95 
99  // Non-const methods:
102 
103  virtual void set4Mom (const I4Momentum * const theI4Mom ) ;
104 
106  virtual void set4Mom (const I4Momentum & theI4Mom);
107 
109  virtual void set4Mom (const CLHEP::HepLorentzVector & theHlv ) ;
110 
112  void set4Mom( const HepMC::FourVector& hlv );
113 
115  // Private data:
117  private:
118 
121  const HepMC::FourVector * m_hlv;
122 };
123 
125 // Inline methods:
127 
128 inline double TruthParticleMomentum::px() const
129 {
130  return m_hlv ? m_hlv->px() : 0.*CLHEP::GeV;
131 }
132 
133 inline double TruthParticleMomentum::py() const
134 {
135  return m_hlv ? m_hlv->py() : 0.*CLHEP::GeV;
136 }
137 
138 inline double TruthParticleMomentum::pz() const
139 {
140  return m_hlv ? m_hlv->pz() : 0.*CLHEP::GeV;
141 }
142 
143 inline double TruthParticleMomentum::m() const
144 {
145  const double m2 = this->m2();
146  return m2 < 0. ? -std::sqrt(-m2) : std::sqrt(m2);
147 }
148 
149 inline double TruthParticleMomentum::m2() const
150 {
151  const double thePx = this->px();
152  const double thePy = this->py();
153  const double thePz = this->pz();
154  const double theE = this->e();
155 
156  const double theM2=
157  theE*theE - ( thePx*thePx +
158  thePy*thePy +
159  thePz*thePz );
160 
161  return theM2;
162 
163 }
164 
165 inline double TruthParticleMomentum::p() const
166 {
167  return std::sqrt( this->p2() );
168 }
169 
170 inline double TruthParticleMomentum::p2() const
171 {
172  const double px = this->px();
173  const double py = this->py();
174  const double pz = this->pz();
175 
176  return px*px + py*py + pz*pz;
177 }
178 
179 inline double TruthParticleMomentum::rapidity() const
180 {
181  const double e =this->e();
182  const double pz=this->pz();
183  if (e==0.0) return 0.0;
184  if (e==+pz) return +std::numeric_limits<double>::infinity();
185  if (e==-pz) return -std::numeric_limits<double>::infinity();
186  return 0.5*std::log((e+pz)/(e-pz));
187 }
188 
189 inline double TruthParticleMomentum::eta() const
190 {
191  const double px=this->px();
192  const double py=this->py();
193  const double pz=this->pz();
194  // FIXME: should we use a more underflow-friendly formula:
195  // sqrt(a**2 + b**2)
196  // => y.sqrt(1+(x/y)**2) where y=max(|a|,|b|) and x=min(|a|,|b|)
197  const double p =std::sqrt (px*px + py*py + pz*pz);
198  if (p==0.0) return 0.0;
199  if (p==+pz) return +std::numeric_limits<double>::infinity();
200  if (p==-pz) return -std::numeric_limits<double>::infinity();
201  return 0.5*log((p+pz)/(p-pz));
202 }
203 
204 inline double TruthParticleMomentum::phi() const
205 {
206  const double thePx = this->px();
207  const double thePy = this->py();
208  return thePx == 0.0 && thePy == 0.0 ? 0.0 : std::atan2(thePy,thePx);
209 }
210 
211 
212 inline double TruthParticleMomentum::e() const
213 {
214  return m_hlv ? m_hlv->e() : 0.*CLHEP::GeV;
215 }
216 
217 inline double TruthParticleMomentum::et() const
218 {
219  //to be improved
220  const double theE = this->e();
221  const double theSinTh = this->sinTh();
222 
223  return theE*theSinTh;
224 }
225 
226 inline double TruthParticleMomentum::pt() const
227 {
228  const double thePx = this->px();
229  const double thePy = this->py();
230 
231  return std::sqrt(thePx*thePx+thePy*thePy);
232 }
233 
234 inline double TruthParticleMomentum::iPt() const
235 {
236  return 1./this->pt();
237 }
238 
239 inline double TruthParticleMomentum::cosPhi() const
240 {
241  return this->px()/this->pt();
242 }
243 
244 inline double TruthParticleMomentum::sinPhi() const
245 {
246  return this->py()/this->pt();
247 }
248 
249 inline double TruthParticleMomentum::tanTh() const
250 {
251  return this->pt()/this->pz();
252 }
253 
254 inline double TruthParticleMomentum::cosTh() const
255 {
256  return this->pz()/this->p();
257 }
258 
259 inline double TruthParticleMomentum::sinTh() const
260 {
261  return this->pt()/this->p();
262 }
263 
264 inline double TruthParticleMomentum::cotTh() const
265 {
266  return this->pz()/this->pt();
267 }
268 
269 inline CLHEP::HepLorentzVector TruthParticleMomentum::hlv() const
270 {
271  return CLHEP::HepLorentzVector(m_hlv->px(), m_hlv->py(),
272  m_hlv->pz(), m_hlv->e() );
273 }
274 
276 {
277  std::cout << " FATAL ERROR : TruthParticleMomentum::set4Mom called. Cannot change 4mom " << std::endl ;
278  std::abort();
279 
280 
281 }
282 
283 inline void TruthParticleMomentum::set4Mom(const I4Momentum * const )
284 {
285  std::cout << " FATAL ERROR : TruthParticleMomentum::set4Mom called. Cannot change 4mom " << std::endl ;
286  std::abort();
287 
288 
289 }
290 
291 inline void TruthParticleMomentum::set4Mom(const CLHEP::HepLorentzVector & )
292 {
293  std::cout << " FATAL ERROR : TruthParticleMomentum::set4Mom called. Cannot change 4mom " << std::endl ;
294  std::abort();
295 }
296 
297 
298 
299 inline void TruthParticleMomentum::set4Mom( const HepMC::FourVector& hlv )
300 {
301  m_hlv = &hlv;
302 }
303 
304 #endif //> MCPARTICLEEVENT_TRUTHPARTICLEMOMENTUM_H
TruthParticleMomentum::hlv
CLHEP::HepLorentzVector hlv() const
Definition: TruthParticleMomentum.h:269
I4Momentum
Definition: I4Momentum.h:31
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
TruthParticleMomentum::set4Mom
virtual void set4Mom(const I4Momentum *const theI4Mom)
set 4Momentum (will throw exception if cannot be implemented)
Definition: TruthParticleMomentum.h:283
TruthParticleMomentum::cotTh
double cotTh() const
Definition: TruthParticleMomentum.h:264
TruthParticleMomentum::~TruthParticleMomentum
virtual ~TruthParticleMomentum()
Destructor:
Definition: TruthParticleMomentum.cxx:50
TruthParticleMomentum
Definition: TruthParticleMomentum.h:28
TruthParticleMomentum::TruthParticleMomentum
TruthParticleMomentum()
Default constructor:
Definition: TruthParticleMomentum.cxx:28
TruthParticleMomentum::m
double m() const
Definition: TruthParticleMomentum.h:143
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
TruthParticleMomentum::eta
double eta() const
Definition: TruthParticleMomentum.h:189
TruthParticleMomentum::px
double px() const
{@ a la I4Momentum -like interface
Definition: TruthParticleMomentum.h:128
I4Momentum.h
TruthParticleMomentum::operator=
TruthParticleMomentum & operator=(const TruthParticleMomentum &rhs)
Assignment operator:
Definition: TruthParticleMomentum.cxx:38
I4Momentum::Kind
Kind
Definition: I4Momentum.h:33
TruthParticleMomentum::phi
double phi() const
Definition: TruthParticleMomentum.h:204
SimpleVector.h
TruthParticleMomentum::py
double py() const
Definition: TruthParticleMomentum.h:133
TruthParticleMomentum::p
double p() const
Definition: TruthParticleMomentum.h:165
TruthParticleMomentum::tanTh
double tanTh() const
Definition: TruthParticleMomentum.h:249
I4MomentumError
Definition: I4MomentumError.h:28
TruthParticleMomentum::m_hlv
const HepMC::FourVector * m_hlv
The CLHEP::LorentzVector we are proxying (from the HepMC::GenParticle which is also being proxied)
Definition: TruthParticleMomentum.h:121
TruthParticleMomentum::rapidity
double rapidity() const
Definition: TruthParticleMomentum.h:179
TruthParticleMomentum::pt
double pt() const
Definition: TruthParticleMomentum.h:226
TruthParticleMomentum::e
double e() const
Definition: TruthParticleMomentum.h:212
TruthParticleMomentum::m2
double m2() const
Definition: TruthParticleMomentum.h:149
TruthParticleMomentum::iPt
double iPt() const
Definition: TruthParticleMomentum.h:234
TruthParticleMomentum::p2
double p2() const
Definition: TruthParticleMomentum.h:170
TruthParticleMomentum::kind
I4Momentum::Kind kind() const
Definition: TruthParticleMomentum.h:88
TruthParticleMomentum::et
double et() const
Definition: TruthParticleMomentum.h:217
TruthParticleMomentum::sinTh
double sinTh() const
Definition: TruthParticleMomentum.h:259
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
TruthParticleMomentum::cosTh
double cosTh() const
Definition: TruthParticleMomentum.h:254
TruthParticleMomentum::pz
double pz() const
Definition: TruthParticleMomentum.h:138
TruthParticleMomentum::dump
std::ostream & dump(std::ostream &out) const
Print I4Momentum content.
Definition: TruthParticleMomentum.cxx:57
TruthParticleMomentum::errors
const I4MomentumError * errors() const
Definition: TruthParticleMomentum.h:85
TruthParticleMomentum::cosPhi
double cosPhi() const
Definition: TruthParticleMomentum.h:239
TruthParticleMomentum::sinPhi
double sinPhi() const
Definition: TruthParticleMomentum.h:244
I4Momentum::P4PXPYPZE
@ P4PXPYPZE
Definition: I4Momentum.h:33