ATLAS Offline Software
Loading...
Searching...
No Matches
DerivationFramework::CollectionMakerHelpers Class Reference

#include <CollectionMakerHelpers.h>

Collaboration diagram for DerivationFramework::CollectionMakerHelpers:

Static Public Member Functions

static int addTruthParticle (const xAOD::TruthParticle &oldPart, xAOD::TruthParticleContainer *partCont, xAOD::TruthVertexContainer *vertCont, std::vector< int > &seenParticles, const int generations, bool includeVertex=true)
 < Helper function to add truth particles to a collection
static int addTruthVertex (const xAOD::TruthVertex &oldVert, xAOD::TruthParticleContainer *partCont, xAOD::TruthVertexContainer *vertCont, std::vector< int > &seenParticles, const int generations)
 Helper function to set up a truth particle based on an old particle.
static xAOD::TruthParticlesetupTruthParticle (const xAOD::TruthParticle &oldPart, xAOD::TruthParticleContainer *partCont)

Detailed Description

Definition at line 20 of file CollectionMakerHelpers.h.

Member Function Documentation

◆ addTruthParticle()

int DerivationFramework::CollectionMakerHelpers::addTruthParticle ( const xAOD::TruthParticle & oldPart,
xAOD::TruthParticleContainer * partCont,
xAOD::TruthVertexContainer * vertCont,
std::vector< int > & seenParticles,
const int generations,
bool includeVertex = true )
static

< Helper function to add truth particles to a collection

Helper function to add truth vertices to a collection

Definition at line 55 of file CollectionMakerHelpers.cxx.

57 {
58 // See if we've seen it - note, could also do this with a unary function on the container itself
59 if (std::find(seenParticles.begin(), seenParticles.end(), HepMC::uniqueID(&oldPart)) != seenParticles.end()){
60 for (size_t p=0;p<partCont->size();++p){
61 // Was it a hit?
62 const xAOD::TruthParticle *theParticle = (*partCont)[p];
63 if (HepMC::is_same_particle(theParticle,&oldPart)) return p;
64 } // Look through the old container
65 } // Found it in the old container
66 // Now we have seen it
67 seenParticles.push_back(HepMC::uniqueID(&oldPart));
68 // Make a nw truth particle
69 xAOD::TruthParticle* xTruthParticle = setupTruthParticle(oldPart,partCont);
70 // Make a link to this particle
71 int myIndex = partCont->size()-1;
72 ElementLink<xAOD::TruthParticleContainer> eltp(*partCont, myIndex);
73 // Decay vertex information
74 if (oldPart.hasDecayVtx() && includeVertex) {
75 int vertIndex = CollectionMakerHelpers::addTruthVertex( *oldPart.decayVtx(), partCont, vertCont, seenParticles, generations);
76 ElementLink<xAOD::TruthVertexContainer> eltv( *vertCont, vertIndex );
77 xTruthParticle->setDecayVtxLink( eltv );
78 (*vertCont)[vertIndex]->addIncomingParticleLink( eltp );
79 }
80 // Return a link to this particle
81 return myIndex;
82}
size_type size() const noexcept
Returns the number of elements in the collection.
static int addTruthVertex(const xAOD::TruthVertex &oldVert, xAOD::TruthParticleContainer *partCont, xAOD::TruthVertexContainer *vertCont, std::vector< int > &seenParticles, const int generations)
Helper function to set up a truth particle based on an old particle.
static xAOD::TruthParticle * setupTruthParticle(const xAOD::TruthParticle &oldPart, xAOD::TruthParticleContainer *partCont)
const TruthVertex_v1 * decayVtx() const
The decay vertex of this particle.
bool hasDecayVtx() const
Check for a decay vertex on this particle.
void setDecayVtxLink(const ElementLink< TruthVertexContainer > &link)
Set the decay vertex of the particle.
int uniqueID(const T &p)
bool is_same_particle(const T1 &p1, const T2 &p2)
Method to establish if two particles in the GenEvent actually represent the same particle.
TruthParticle_v1 TruthParticle
Typedef to implementation.

◆ addTruthVertex()

int DerivationFramework::CollectionMakerHelpers::addTruthVertex ( const xAOD::TruthVertex & oldVert,
xAOD::TruthParticleContainer * partCont,
xAOD::TruthVertexContainer * vertCont,
std::vector< int > & seenParticles,
const int generations )
static

Helper function to set up a truth particle based on an old particle.

Definition at line 25 of file CollectionMakerHelpers.cxx.

27 {
28 // Make a new vertex and add it to the container
29 xAOD::TruthVertex* xTruthVertex = new xAOD::TruthVertex();
30 vertCont->push_back( xTruthVertex );
31 // Get a link to this vertex -- will be used to set production vertices on all the next particles
32 int myIndex = vertCont->size()-1;
33 ElementLink<xAOD::TruthVertexContainer> eltv(*vertCont, myIndex);
34 // Set properties
35 xTruthVertex->setStatus(HepMC::status(oldVert));
36 xTruthVertex->setUid(HepMC::uniqueID(oldVert));
37 xTruthVertex->setX(oldVert.x());
38 xTruthVertex->setY(oldVert.y());
39 xTruthVertex->setZ(oldVert.z());
40 xTruthVertex->setT(oldVert.t());
41 // If we are done, then stop here
42 if (generations==0) return myIndex;
43 // Add all the outgoing particles
44 for (size_t n=0;n<oldVert.nOutgoingParticles();++n){
45 if (!oldVert.outgoingParticle(n)) continue; // Just in case we removed some truth particles, e.g. G4 decays
46 int partIndex = CollectionMakerHelpers::addTruthParticle( *oldVert.outgoingParticle(n), partCont, vertCont, seenParticles, generations-1);
47 ElementLink<xAOD::TruthParticleContainer> eltp( *partCont, partIndex);
48 xTruthVertex->addOutgoingParticleLink( eltp );
49 (*partCont)[partIndex]->setProdVtxLink( eltv );
50 }
51 // Return a link to this vertex
52 return myIndex;
53}
value_type push_back(value_type pElem)
Add an element to the end of the collection.
static int addTruthParticle(const xAOD::TruthParticle &oldPart, xAOD::TruthParticleContainer *partCont, xAOD::TruthVertexContainer *vertCont, std::vector< int > &seenParticles, const int generations, bool includeVertex=true)
< Helper function to add truth particles to a collection
const TruthParticle_v1 * outgoingParticle(size_t index) const
Get one of the outgoing particles.
void addOutgoingParticleLink(const TPLink_t &link)
Add one outgoing particle.
float z() const
Vertex longitudinal distance along the beam line form the origin.
void setStatus(int value)
Set the vertex status.
void setZ(float value)
Set the vertex's longitudinal distance from the origin.
float y() const
Vertex y displacement.
void setUid(int value)
Set the vertex unique ID.
float t() const
Vertex time.
size_t nOutgoingParticles() const
Get the number of outgoing particles.
void setT(float value)
Set the vertex time.
float x() const
Vertex x displacement.
void setX(float value)
Set the x displacement of the vertex.
void setY(float value)
Set the y displacement of the vertex.
int status(const T &p)
TruthVertex_v1 TruthVertex
Typedef to implementation.
Definition TruthVertex.h:15

◆ setupTruthParticle()

xAOD::TruthParticle * DerivationFramework::CollectionMakerHelpers::setupTruthParticle ( const xAOD::TruthParticle & oldPart,
xAOD::TruthParticleContainer * partCont )
static

Definition at line 84 of file CollectionMakerHelpers.cxx.

84 {
85 // Set up decorators
86 const static SG::Decorator< unsigned int > originDecorator("classifierParticleOrigin");
87 const static SG::Decorator< unsigned int > typeDecorator("classifierParticleType");
88 const static SG::Decorator< unsigned int > outcomeDecorator("classifierParticleOutCome");
89 const static SG::Decorator< int > motherIDDecorator("motherID");
90 const static SG::Decorator< int > daughterIDDecorator("daughterID");
91
92 static const SG::ConstAccessor<unsigned int> classifierParticleTypeAcc("classifierParticleType");
93 static const SG::ConstAccessor<unsigned int> classifierParticleOriginAcc("classifierParticleOrigin");
94 static const SG::ConstAccessor<unsigned int> classifierParticleOutComeAcc("classifierParticleOutCome");
95
96 // Make a truth particle and add it to the container
97 xAOD::TruthParticle* xTruthParticle = new xAOD::TruthParticle();
98 partCont->push_back( xTruthParticle );
99 // Fill with numerical content
100 xTruthParticle->setPdgId(oldPart.pdgId());
101 xTruthParticle->setUid(HepMC::uniqueID(&oldPart));
102 xTruthParticle->setStatus(oldPart.status());
103 xTruthParticle->setM(oldPart.m());
104 xTruthParticle->setPx(oldPart.px());
105 xTruthParticle->setPy(oldPart.py());
106 xTruthParticle->setPz(oldPart.pz());
107 xTruthParticle->setE(oldPart.e());
108 // Copy over the polarization information if it's there
109 if (oldPart.polarization().valid()){
112 }
113 // Copy over the decorations if they are available
114 typeDecorator(*xTruthParticle) = classifierParticleTypeAcc.withDefault(oldPart, 0);
115 originDecorator(*xTruthParticle) = classifierParticleOriginAcc.withDefault(oldPart, 0);
116 outcomeDecorator(*xTruthParticle) = classifierParticleOutComeAcc.withDefault(oldPart, 0);
117 return xTruthParticle;
118}
void setPy(float value)
Set the y component of the particle's momentum.
int status() const
Status code.
void setUid(int value)
Set unique ID.
void setM(float value)
Also store the mass.
virtual double m() const override final
The mass of the particle.
void setE(float value)
Set the energy of the particle.
int pdgId() const
PDG ID code.
Polarization polarization() const
Retrieve a full Polarization with a single call.
void setPz(float value)
Set the z component of the particle's momentum.
float px() const
The x component of the particle's momentum.
virtual double e() const override final
The total energy of the particle.
bool setPolarizationParameter(float value, PolParam parameter)
Set method for polarization parameter values.
float py() const
The y component of the particle's momentum.
void setStatus(int value)
Set status code.
void setPdgId(int pid)
Set PDG ID code.
void setPx(float value)
Set the x component of the particle's momentum.
bool polarizationParameter(float &value, PolParam parameter) const
Accessor for polarization parameters.
float pz() const
The z component of the particle's momentum.
@ polarizationPhi
Polarization in ( )
@ polarizationTheta
Polarization in ( )
bool valid() const
Check if the stored values are valid.

The documentation for this class was generated from the following files: