ATLAS Offline Software
Loading...
Searching...
No Matches
TruthParticleMomentum.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// 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"
23
24// Forward declaration
25class 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
61
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
98
100 // 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
128inline double TruthParticleMomentum::px() const
129{
130 return m_hlv ? m_hlv->px() : 0.*CLHEP::GeV;
131}
132
133inline double TruthParticleMomentum::py() const
134{
135 return m_hlv ? m_hlv->py() : 0.*CLHEP::GeV;
136}
137
138inline double TruthParticleMomentum::pz() const
139{
140 return m_hlv ? m_hlv->pz() : 0.*CLHEP::GeV;
141}
142
143inline double TruthParticleMomentum::m() const
144{
145 const double m2 = this->m2();
146 return m2 < 0. ? -std::sqrt(-m2) : std::sqrt(m2);
147}
148
149inline 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
165inline double TruthParticleMomentum::p() const
166{
167 return std::sqrt( this->p2() );
168}
169
170inline 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
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
189inline 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
204inline 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
212inline double TruthParticleMomentum::e() const
213{
214 return m_hlv ? m_hlv->e() : 0.*CLHEP::GeV;
215}
216
217inline 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
226inline 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
234inline double TruthParticleMomentum::iPt() const
235{
236 return 1./this->pt();
237}
238
239inline double TruthParticleMomentum::cosPhi() const
240{
241 return this->px()/this->pt();
242}
243
244inline double TruthParticleMomentum::sinPhi() const
245{
246 return this->py()/this->pt();
247}
248
249inline double TruthParticleMomentum::tanTh() const
250{
251 return this->pt()/this->pz();
252}
253
254inline double TruthParticleMomentum::cosTh() const
255{
256 return this->pz()/this->p();
257}
258
259inline double TruthParticleMomentum::sinTh() const
260{
261 return this->pt()/this->p();
262}
263
264inline double TruthParticleMomentum::cotTh() const
265{
266 return this->pz()/this->pt();
267}
268
269inline 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
284{
285 std::cout << " FATAL ERROR : TruthParticleMomentum::set4Mom called. Cannot change 4mom " << std::endl ;
286 std::abort();
287
288
289}
290
291inline 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
299inline void TruthParticleMomentum::set4Mom( const HepMC::FourVector& hlv )
300{
301 m_hlv = &hlv;
302}
303
304#endif //> MCPARTICLEEVENT_TRUTHPARTICLEMOMENTUM_H
I4Momentum is an abstract base class providing 4-momentum behavior.
Definition I4Momentum.h:31
TruthParticleMomentum()
Default constructor:
CLHEP::HepLorentzVector hlv() const
const I4MomentumError * errors() const
TruthParticleMomentum & operator=(const TruthParticleMomentum &rhs)
Assignment operator:
I4Momentum::Kind kind() const
virtual ~TruthParticleMomentum()
Destructor:
virtual void set4Mom(const I4Momentum *const theI4Mom)
set 4Momentum (will throw exception if cannot be implemented)
double px() const
{@ a la I4Momentum -like interface
const HepMC::FourVector * m_hlv
The CLHEP::LorentzVector we are proxying (from the HepMC::GenParticle which is also being proxied)
-event-from-file