ATLAS Offline Software
Loading...
Searching...
No Matches
TruthParticle_v1.cxx
Go to the documentation of this file.
1// -*- C++ -*-
2
3/*
4 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
5*/
6
7// $Id: TruthParticle_v1.cxx 690336 2015-08-20 10:54:57Z abuckley $
8
9// System include(s):
10#include <cmath>
11#include <iostream>
12#include <stdexcept>
13
14// Utility include(s):
17
18// xAOD include(s):
20
21// Accessor include:
23
24// Local include(s):
27#include "TruthAccessors_v1.h"
28
29namespace xAOD {
30
35
37 //
38 // Implementation for functions identifying the particle in the MC record
39 //
40
42 setPdgId )
43
44 int TruthParticle_v1::absPdgId() const {
45
46 return std::abs( pdgId() );
47 }
48
49 AUXSTORE_PRIMITIVE_SETTER_AND_GETTER( TruthParticle_v1, int, uid,
50 setUid )
51 AUXSTORE_PRIMITIVE_SETTER_AND_GETTER( TruthParticle_v1, int, status,
52 setStatus )
53
54 //
56
58 //
59 // Implementation of the links to the vertices
60 //
61
62
64 acc_prodVtxLink( "prodVtxLink" );
67 acc_decayVtxLink( "decayVtxLink" );
68
70
71 return ( acc_prodVtxLink.isAvailable( *this ) &&
72 acc_prodVtxLink( *this ).isValid() );
73 }
74
76
77 return hasProdVtx() ? *prodVtxLink() : nullptr;
78 }
79
82 prodVtxLink, setProdVtxLink )
83
85
86 return ( acc_decayVtxLink.isAvailable( *this ) &&
87 acc_decayVtxLink( *this ).isValid() );
88 }
89
91
92 return hasDecayVtx() ? *decayVtxLink() : nullptr;
93 }
94
96 ElementLink< TruthVertexContainer >,
97 decayVtxLink, setDecayVtxLink )
98
99 //
101
103 //
104 // Direct access to parents and children
105 //
106
107 // Accessor for links to parents
109 acc_parentLinks( "parentLinks" );
110 // Accessor for links to children
112 acc_childLinks( "childLinks" );
113 // Note that in some conditions the vertex might be saved in a different collection from
114 // the daughters, causing the vertex to not know how many children or parents the particle has.
115 // An extra test lets us ensure that we avoid this case.
116
118 if (hasProdVtx() && prodVtx()->nIncomingParticles()>0){
119 return prodVtx()->nIncomingParticles();
120 } else if ( acc_parentLinks.isAvailable( *this ) ) {
121 return acc_parentLinks( *this ).size();
122 }
123 return 0;
124 }
125
127 if (hasProdVtx() && prodVtx()->nIncomingParticles()>0){
128 return prodVtx()->incomingParticle( i );
129 } else if ( acc_parentLinks.isAvailable( *this ) && i<acc_parentLinks( *this ).size() ) {
130 return acc_parentLinks( *this )[i].isValid() ? *(acc_parentLinks( *this )[i]) : nullptr;
131 }
132 return nullptr;
133 }
134
136 if (hasDecayVtx() && decayVtx()->nOutgoingParticles()>0){
137 return decayVtx()->nOutgoingParticles();
138 } else if ( acc_childLinks.isAvailable( *this ) ) {
139 return acc_childLinks( *this ).size();
140 }
141 return 0;
142 }
143
144 const TruthParticle_v1* TruthParticle_v1::child( size_t i ) const {
145 if (hasDecayVtx() && decayVtx()->nOutgoingParticles()>0){
146 return decayVtx()->outgoingParticle( i );
147 } else if ( acc_childLinks.isAvailable( *this ) && i<acc_childLinks( *this ).size() ) {
148 return acc_childLinks( *this )[i].isValid() ? *(acc_childLinks( *this )[i]) : nullptr;
149 }
150 return nullptr;
151 }
152
153 //
155
157 //
158 // Implementation of the IParticle interface
159 //
160
161 double TruthParticle_v1::pt() const {
162
163 // Do the calculation by hand:
164 const double localPx = static_cast< double >( px() );
165 const double localPy = static_cast< double >( py() );
166 return std::sqrt( localPx * localPx + localPy * localPy );
167 }
168
169 double TruthParticle_v1::eta() const {
170
171 // Calculate the pseudo-rapidity using TLorentzVector.
172 // Could do something more lightweight later on.
173 return genvecP4().Eta();
174 }
175
176 double TruthParticle_v1::phi() const {
177
178 // Calculate the azimuth angle using TLorentzVector.
179 // Could do something more lightweight later on.
180 return genvecP4().Phi();
181 }
182
185
187
188 return genvecP4().Rapidity();
189 }
190
192 return FourMom_t(px(), py(), pz(), e() );
193 }
194
195 // not very different in this case; just adding for uniformity
199
200 Type::ObjectType TruthParticle_v1::type() const {
201
202 return Type::TruthParticle;
203 }
204
205 //
207
209 //
210 // Implementation of the truth particle specific 4-momentum functions
211 //
212
214
215 return std::abs( eta() );
216 }
217
219
220 return std::abs( rapidity() );
221 }
222
224
226
228
229
230 void TruthParticle_v1::setE( float value ) {
231 static const Accessor< float > acc( "e" );
232 acc( *this ) = value;
233 return;
234 }
235
236 void TruthParticle_v1::setM( float value ) {
237 static const Accessor< float > acc( "m" );
238 acc( *this ) = value;
239 return;
240 }
241
242 //
244
246 //
247 // Implementation of the particle species decoder functions
248 //
249
251#define MC_PID_HELPER( TYPE, FNAME ) \
252 TYPE TruthParticle_v1::FNAME() const { \
253 return MC::FNAME( pdgId() ); \
254 }
255
256
257 MC_PID_HELPER( double, charge )
259
260 MC_PID_HELPER( bool, isCharged )
261 MC_PID_HELPER( bool, isNeutral )
262
263 MC_PID_HELPER( bool, isPhoton )
264 MC_PID_HELPER( bool, isLepton )
267 MC_PID_HELPER( bool, isMuon )
268 MC_PID_HELPER( bool, isTau )
270
271 MC_PID_HELPER( bool, isHadron )
272 MC_PID_HELPER( bool, isMeson )
273 MC_PID_HELPER( bool, isBaryon )
274
276 MC_PID_HELPER( bool, hasCharm )
277 MC_PID_HELPER( bool, hasBottom )
278
282
286
290
294
298
299 MC_PID_HELPER( bool, isQuark )
300 MC_PID_HELPER( bool, isParton )
301 MC_PID_HELPER( bool, isTop )
302 MC_PID_HELPER( bool, isW )
303 MC_PID_HELPER( bool, isZ )
304 MC_PID_HELPER( bool, isHiggs )
307 MC_PID_HELPER( bool, isBSM )
308
309// Forget about this macro:
310#undef MC_PID_HELPER
311 bool TruthParticle_v1::isGenStable() const { return MC::isGenStable(this); };
312 bool TruthParticle_v1::isStable() const { return MC::isStable(this); };
314
315
316
317 //
319
321 //
322 // Implementation of the optional polarization accessors
323 //
324
326 PolParam param ) const {
327
328 // Get the accessor object:
330 if( ! acc ) {
331 // The user asked for a non-existent parameter type. o.O
332 std::cerr << "xAOD::TruthParticle_v1::polarizationParameter ERROR "
333 << "Request for an unknown (" << param << ") polarization "
334 << "parameter type" << std::endl;
335 return false;
336 }
337 // Check if the variable is available:
338 if( ! acc->isAvailable( *this ) ) {
339 // No, it is not.
340 return false;
341 }
342
343 // Read the value:
344 value = ( *acc )( *this );
345 return true;
346 }
347
349 PolParam param ) {
350
351 // Get the accessor object:
353 if( ! acc ) {
354 // The user asked for a non-existent parameter type. o.O
355 std::cerr << "xAOD::TruthParticle_v1::setPolarizationParameter ERROR "
356 << "Request for an unknown (" << param << ") polarization "
357 << "parameter type" << std::endl;
358 return false;
359 }
360
361 // Set the value:
362 ( *acc )( *this ) = value;
363 return true;
364 }
365
367
368 // Get the accessor object:
370 if( ! acc ) {
371 // Throw an exception:
372 throw std::runtime_error( "Unrecognized polarization parameter "
373 "requested" );
374 }
375
376 // Read the value:
377 return ( *acc )( *this );
378 }
379
381
382 // Construct the object:
383 Polarization rtn;
386
387 return rtn;
388 }
389
390 //
392
394
395 if( acc_prodVtxLink.isAvailableWritable( *this ) ) {
396 acc_prodVtxLink( *this ).toPersistent();
397 }
398 if( acc_decayVtxLink.isAvailableWritable( *this ) ) {
400 }
401 return;
402 }
403
404} // namespace xAOD
bool hasStrange(const T &p)
Definition AtlasPID.h:736
bool isBottomBaryon(const T &p)
Definition AtlasPID.h:935
bool isBottomMeson(const T &p)
Definition AtlasPID.h:919
bool isTau(const T &p)
Definition AtlasPID.h:208
bool isElectron(const T &p)
Definition AtlasPID.h:202
bool isChLepton(const T &p)
APID: the fourth generation leptons are leptons.
Definition AtlasPID.h:199
bool isStrangeHadron(const T &p)
Definition AtlasPID.h:910
bool isLepton(const T &p)
APID: the fourth generation leptons are leptons.
Definition AtlasPID.h:189
bool isHiggs(const T &p)
APID: HIGGS boson is only one particle.
Definition AtlasPID.h:390
bool isLightBaryon(const T &p)
Definition AtlasPID.h:931
bool isCharged(const T &p)
Definition AtlasPID.h:1004
bool isHeavyMeson(const T &p)
Definition AtlasPID.h:916
bool isW(const T &p)
Definition AtlasPID.h:382
bool hasBottom(const T &p)
Definition AtlasPID.h:738
bool isLightHadron(const T &p)
Definition AtlasPID.h:908
double charge(const T &p)
Definition AtlasPID.h:997
bool isResonance(const T &p)
Definition AtlasPID.h:400
bool isParton(const T &p)
Definition AtlasPID.h:1103
bool isStrangeBaryon(const T &p)
Definition AtlasPID.h:933
bool hasCharm(const T &p)
Definition AtlasPID.h:737
bool isBottomHadron(const T &p)
Definition AtlasPID.h:912
bool isQuark(const T &p)
PDG rule 2: Quarks and leptons are numbered consecutively starting from 1 and 11 respectively; to do ...
Definition AtlasPID.h:167
bool isMeson(const T &p)
Table 43.1 PDG rule 5a: The numbers specifying the meson’s quark content conform to the convention nq...
Definition AtlasPID.h:244
bool isZ(const T &p)
Definition AtlasPID.h:379
bool isNeutrino(const T &p)
APID: the fourth generation neutrinos are neutrinos.
Definition AtlasPID.h:212
bool isTop(const T &p)
Definition AtlasPID.h:185
bool isCharmBaryon(const T &p)
Definition AtlasPID.h:934
bool isPhoton(const T &p)
Definition AtlasPID.h:376
bool isHeavyBaryon(const T &p)
Definition AtlasPID.h:932
double threeCharge(const T &p)
Definition AtlasPID.h:1003
bool isCharmMeson(const T &p)
Definition AtlasPID.h:918
bool isBaryon(const T &p)
Table 43.2 APID: states with fourth generation quarks are not baryons.
Definition AtlasPID.h:282
bool isCharmHadron(const T &p)
Definition AtlasPID.h:911
bool isHadron(const T &p)
Definition AtlasPID.h:351
bool isMuon(const T &p)
Definition AtlasPID.h:205
bool isLightMeson(const T &p)
Definition AtlasPID.h:915
bool isStrangeMeson(const T &p)
Definition AtlasPID.h:917
bool isHeavyHadron(const T &p)
Definition AtlasPID.h:909
bool isGenSpecific(const T &p)
Main Table for MC internal use 81–100,901–930,998-999,1901–1930,2901–2930, and 3901–3930.
Definition AtlasPID.h:425
bool isBSM(const T &p)
APID: graviton and all Higgs extensions are BSM.
Definition AtlasPID.h:846
bool isNeutral(const T &p)
Definition AtlasPID.h:1085
Base class for elements of a container that can have aux data.
#define AUXSTORE_PRIMITIVE_GETTER_WITH_CAST(CL, PERSTYPE, TRANSTYPE, NAME)
Macro creating a getter function with a type conversion.
#define AUXSTORE_PRIMITIVE_SETTER_AND_GETTER(CL, TYPE, NAME, SETTER)
Macro creating the accessors of primitive auxiliary properties.
#define AUXSTORE_OBJECT_SETTER_AND_GETTER(CL, TYPE, NAME, SETTER)
Macro creating the accessors of complex auxiliary properties.
ATLAS-specific HepMC functions.
#define MC_PID_HELPER(TYPE, FNAME)
Helper macro to implement the functions that rely in functions from MC:: namespace.
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:572
IParticle()=default
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:572
Class describing a truth particle in the MC record.
bool isSimulationParticle() const
Check if this particle was produced during the simulation.
const TruthParticle_v1 * child(size_t i) const
Retrieve the i-th mother (TruthParticle) of this TruthParticle.
double abseta() const
The absolute pseudorapidity ( ) of the particle.
IParticle::FourMom_t FourMom_t
Definition of the 4-momentum type.
double absrapidity() const
The true absolute rapidity ( ) of the particle.
virtual double rapidity() const override final
The true rapidity ( ) of the particle.
void toPersistent()
Function making sure that the object is ready for persistification.
GenVecFourMom_t genvecP4() const
The full 4-momentum of the particle : GenVector form.
void setM(float value)
Also store the mass.
void setE(float value)
Set the energy of the particle.
bool isStable() const
Check if this is a stable particle (generator or simulation produced)
int pdgId() const
PDG ID code.
const ElementLink< TruthVertexContainer > & decayVtxLink() const
The decay vertex link of this particle.
const TruthVertex_v1 * decayVtx() const
The decay vertex of this particle.
TruthParticle_v1()
Default constructor.
const TruthParticle_v1 * parent(size_t i) const
Retrieve the i-th mother (TruthParticle) of this TruthParticle.
Polarization polarization() const
Retrieve a full Polarization with a single call.
int absPdgId() const
Absolute PDG ID code (often useful)
bool hasProdVtx() const
Check for a production vertex on this particle.
virtual Type::ObjectType type() const override final
The type of the object as a simple enumeration.
float px() const
The x component of the particle's momentum.
bool hasDecayVtx() const
Check for a decay vertex on this particle.
virtual double e() const override final
The total energy of the particle.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
bool isGenStable() const
Check if this is generator stable particle.
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > GenVecFourMom_t
Base 4 Momentum type for TruthParticle.
bool setPolarizationParameter(float value, PolParam parameter)
Set method for polarization parameter values.
const TruthVertex_v1 * prodVtx() const
The production vertex of this particle.
float py() const
The y component of the particle's momentum.
size_t nParents() const
Number of parents of this particle.
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
virtual double phi() const override final
The azimuthal angle ( ) of the particle.
size_t nChildren() const
Number of children of this particle.
virtual FourMom_t p4() const override final
The full 4-momentum of the particle.
bool polarizationParameter(float &value, PolParam parameter) const
Accessor for polarization parameters.
float pz() const
The z component of the particle's momentum.
PolParam
Polarization parameter types.
@ polarizationPhi
Polarization in ( )
@ polarizationTheta
Polarization in ( )
const ElementLink< TruthVertexContainer > & prodVtxLink() const
The production vertex link of this particle.
const TruthParticle_v1 * outgoingParticle(size_t index) const
Get one of the outgoing particles.
const TruthParticle_v1 * incomingParticle(size_t index) const
Get one of the incoming particles.
size_t nOutgoingParticles() const
Get the number of outgoing particles.
size_t nIncomingParticles() const
Get the number of incoming particles.
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (TODO update to be s...
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
bool isGenStable(const T &p)
Determine if the particle is stable at the generator (not det-sim) level,.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
const SG::AuxElement::Accessor< float > * polarizationAccessorV1(TruthParticle_v1::PolParam type)
This function holds on to Accessor objects that can be used by each TruthParticle_v1 object at runtim...
static AUXSTORE_OBJECT_SETTER_AND_GETTER(TruthParticle_v1, ElementLink< TruthVertexContainer >, prodVtxLink, setProdVtxLink) bool TruthParticle_v1 const SG::AuxElement::ConstAccessor< std::vector< ElementLink< xAOD::TruthParticleContainer > > > acc_childLinks("childLinks")
TruthVertex_v1 TruthVertex
Typedef to implementation.
Definition TruthVertex.h:15
static const SG::AuxElement::Accessor< ElementLink< IParticleContainer > > acc("originalObjectLink")
Object used for setting/getting the dynamic decoration in question.
static AUXSTORE_PRIMITIVE_SETTER_AND_GETTER(TruthParticle_v1, int, pdgId, setPdgId) int TruthParticle_v1 const SG::AuxElement::Accessor< ElementLink< TruthVertexContainer > > acc_decayVtxLink("decayVtxLink")
Accessor for the decay vertex.
Single container for full polarization information.