ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
TruthParticleID
McParticleEvent
McParticleEvent
TruthParticleMomentum.h
Go to the documentation of this file.
1
2
3
/*
4
Copyright (C) 2002-2026 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
15
// HepMC / CLHEP includes
16
#include "CLHEP/Vector/LorentzVector.h"
17
#include "CLHEP/Units/SystemOfUnits.h"
18
#include "
AtlasHepMC/SimpleVector.h
"
19
#include "
EventKernel/I4Momentum.h
"
20
// STL includes
21
#include <iostream>
22
#include <limits>
23
#include <cmath>
24
// Forward declaration
25
class
I4MomentumError
;
26
27
class
TruthParticleMomentum
28
{
29
31
// Public methods:
33
public
:
34
37
TruthParticleMomentum
();
38
41
TruthParticleMomentum
(
const
TruthParticleMomentum
& rhs );
42
45
TruthParticleMomentum
&
operator=
(
const
TruthParticleMomentum
& rhs );
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
88
I4Momentum::Kind
kind
()
const
{
return
I4Momentum::P4PXPYPZE
; };
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
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
if
(!
m_hlv
)[[
unlikely
]]{
272
std::cout <<
" FATAL ERROR : TruthParticleMomentum::hlv called with m_hlv = nullptr. "
<< std::endl ;
273
std::abort();
274
}
275
return
CLHEP::HepLorentzVector(
m_hlv
->px(),
m_hlv
->py(),
276
m_hlv
->pz(),
m_hlv
->e() );
277
}
278
279
inline
void
TruthParticleMomentum::set4Mom
(
const
I4Momentum
& )
280
{
281
std::cout <<
" FATAL ERROR : TruthParticleMomentum::set4Mom called. Cannot change 4mom "
<< std::endl ;
282
std::abort();
283
284
285
}
286
287
inline
void
TruthParticleMomentum::set4Mom
(
const
I4Momentum
*
const
)
288
{
289
std::cout <<
" FATAL ERROR : TruthParticleMomentum::set4Mom called. Cannot change 4mom "
<< std::endl ;
290
std::abort();
291
292
293
}
294
295
inline
void
TruthParticleMomentum::set4Mom
(
const
CLHEP::HepLorentzVector & )
296
{
297
std::cout <<
" FATAL ERROR : TruthParticleMomentum::set4Mom called. Cannot change 4mom "
<< std::endl ;
298
std::abort();
299
}
300
301
302
303
inline
void
TruthParticleMomentum::set4Mom
(
const
HepMC::FourVector
&
hlv
)
304
{
305
m_hlv
= &
hlv
;
306
}
307
308
#endif
//> MCPARTICLEEVENT_TRUTHPARTICLEMOMENTUM_H
I4Momentum.h
SimpleVector.h
I4MomentumError
Definition
I4MomentumError.h:28
I4Momentum
I4Momentum is an abstract base class providing 4-momentum behavior.
Definition
I4Momentum.h:31
I4Momentum::Kind
Kind
Definition
I4Momentum.h:33
I4Momentum::P4PXPYPZE
@ P4PXPYPZE
Definition
I4Momentum.h:33
TruthParticleMomentum::pt
double pt() const
Definition
TruthParticleMomentum.h:226
TruthParticleMomentum::TruthParticleMomentum
TruthParticleMomentum()
Default constructor:
Definition
TruthParticleMomentum.cxx:28
TruthParticleMomentum::p2
double p2() const
Definition
TruthParticleMomentum.h:170
TruthParticleMomentum::hlv
CLHEP::HepLorentzVector hlv() const
Definition
TruthParticleMomentum.h:269
TruthParticleMomentum::sinPhi
double sinPhi() const
Definition
TruthParticleMomentum.h:244
TruthParticleMomentum::errors
const I4MomentumError * errors() const
Definition
TruthParticleMomentum.h:85
TruthParticleMomentum::operator=
TruthParticleMomentum & operator=(const TruthParticleMomentum &rhs)
Assignment operator:
Definition
TruthParticleMomentum.cxx:38
TruthParticleMomentum::et
double et() const
Definition
TruthParticleMomentum.h:217
TruthParticleMomentum::eta
double eta() const
Definition
TruthParticleMomentum.h:189
TruthParticleMomentum::e
double e() const
Definition
TruthParticleMomentum.h:212
TruthParticleMomentum::kind
I4Momentum::Kind kind() const
Definition
TruthParticleMomentum.h:88
TruthParticleMomentum::cotTh
double cotTh() const
Definition
TruthParticleMomentum.h:264
TruthParticleMomentum::sinTh
double sinTh() const
Definition
TruthParticleMomentum.h:259
TruthParticleMomentum::m2
double m2() const
Definition
TruthParticleMomentum.h:149
TruthParticleMomentum::tanTh
double tanTh() const
Definition
TruthParticleMomentum.h:249
TruthParticleMomentum::cosPhi
double cosPhi() const
Definition
TruthParticleMomentum.h:239
TruthParticleMomentum::m
double m() const
Definition
TruthParticleMomentum.h:143
TruthParticleMomentum::~TruthParticleMomentum
virtual ~TruthParticleMomentum()
Destructor:
Definition
TruthParticleMomentum.cxx:50
TruthParticleMomentum::rapidity
double rapidity() const
Definition
TruthParticleMomentum.h:179
TruthParticleMomentum::phi
double phi() const
Definition
TruthParticleMomentum.h:204
TruthParticleMomentum::cosTh
double cosTh() const
Definition
TruthParticleMomentum.h:254
TruthParticleMomentum::set4Mom
virtual void set4Mom(const I4Momentum *const theI4Mom)
set 4Momentum (will throw exception if cannot be implemented)
Definition
TruthParticleMomentum.h:287
TruthParticleMomentum::py
double py() const
Definition
TruthParticleMomentum.h:133
TruthParticleMomentum::px
double px() const
{@ a la I4Momentum -like interface
Definition
TruthParticleMomentum.h:128
TruthParticleMomentum::pz
double pz() const
Definition
TruthParticleMomentum.h:138
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::p
double p() const
Definition
TruthParticleMomentum.h:165
TruthParticleMomentum::iPt
double iPt() const
Definition
TruthParticleMomentum.h:234
HepMC::FourVector
HepMC3::FourVector FourVector
Definition
SimpleVector.h:11
dump
-event-from-file
unlikely
#define unlikely(x)
Definition
pythonic_coracool.cxx:9
Generated on
for ATLAS Offline Software by
1.17.0