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

#include <TruthBornLeptonCollectionMaker.h>

Inheritance diagram for DerivationFramework::TruthBornLeptonCollectionMaker:
Collaboration diagram for DerivationFramework::TruthBornLeptonCollectionMaker:

Public Member Functions

 TruthBornLeptonCollectionMaker (const std::string &t, const std::string &n, const IInterface *p)
 ~TruthBornLeptonCollectionMaker ()
StatusCode initialize ()
virtual StatusCode addBranches (const EventContext &ctx) const

Private Member Functions

bool hasBareDescendent (const xAOD::TruthParticle *p) const
 Helper function for finding bare descendents of born leptons.

Private Attributes

SG::ReadHandleKey< xAOD::TruthParticleContainerm_particlesKey {this, "ParticlesKey", "TruthParticles", "Name of TruthParticle key for input"}
 < Input particle collection key
SG::ReadDecorHandleKey< xAOD::TruthParticleContainerm_originAccessorKey {this, "Input_classifierParticleOrigin", m_particlesKey, "classifierParticleOrigin", "Particle origin decoration"}
SG::ReadDecorHandleKey< xAOD::TruthParticleContainerm_typeAccessorKey {this, "Input_classifierParticleType",m_particlesKey, "classifierParticleType", "Particle type decoration"}
SG::ReadDecorHandleKey< xAOD::TruthParticleContainerm_outcomeAccessorKey {this, "Input_classifierParticleOutCome", m_particlesKey, "classifierParticleOutCome", "Particle outcome decoration"}
SG::ReadDecorHandleKey< xAOD::TruthParticleContainerm_classificationAccessorKey {this, "Input_Classification", m_particlesKey, "Classification", "Classification code decoration"}
 Output particle collection key.
SG::WriteHandleKey< xAOD::TruthParticleContainerm_collectionName {this, "NewCollectionName", "", "Name of TruthParticle key for output"}
SG::WriteDecorHandleKey< xAOD::TruthParticleContainerm_originDecoratorKey {this, "classifierParticleOrigin", m_collectionName, "classifierParticleOrigin", "Particle origin decoration"}
SG::WriteDecorHandleKey< xAOD::TruthParticleContainerm_typeDecoratorKey {this, "classifierParticleType",m_collectionName, "classifierParticleType", "Particle type decoration"}
SG::WriteDecorHandleKey< xAOD::TruthParticleContainerm_outcomeDecoratorKey {this, "classifierParticleOutCome", m_collectionName, "classifierParticleOutCome", "Particle outcome decoration"}
SG::WriteDecorHandleKey< xAOD::TruthParticleContainerm_classificationDecoratorKey {this, "Classification", m_collectionName, "Classification", "Classification code decoration"}
ServiceHandle< StoreGateSvcm_metaStore
 Handle on the metadata store for init.

Detailed Description

Definition at line 31 of file TruthBornLeptonCollectionMaker.h.

Constructor & Destructor Documentation

◆ TruthBornLeptonCollectionMaker()

DerivationFramework::TruthBornLeptonCollectionMaker::TruthBornLeptonCollectionMaker ( const std::string & t,
const std::string & n,
const IInterface * p )

Definition at line 28 of file TruthBornLeptonCollectionMaker.cxx.

31 : base_class(t,n,p)
32 , m_metaStore( "MetaDataStore", n )
33{
34 declareProperty( "MetaDataStore", m_metaStore );
35}
ServiceHandle< StoreGateSvc > m_metaStore
Handle on the metadata store for init.

◆ ~TruthBornLeptonCollectionMaker()

DerivationFramework::TruthBornLeptonCollectionMaker::~TruthBornLeptonCollectionMaker ( )

Definition at line 38 of file TruthBornLeptonCollectionMaker.cxx.

38 {
39}

Member Function Documentation

◆ addBranches()

StatusCode DerivationFramework::TruthBornLeptonCollectionMaker::addBranches ( const EventContext & ctx) const
virtual

Definition at line 76 of file TruthBornLeptonCollectionMaker.cxx.

77{
78 // Event context
79
80 // Set up for some metadata handling
81 static const bool is_sherpa = [this]() {
82 bool is_sherpa = false;
83 // TODO: needs to be made MT-friendly
84 if (m_metaStore->contains<xAOD::TruthMetaDataContainer>("TruthMetaData")){
85 // Note that I'd like to get this out of metadata in general, but it seems that the
86 // metadata isn't fully available in initialize, and since this is a const function
87 // I can only do the retrieve every event, rather than lazy-initializing, since this
88 // metadata ought not change during a run
89 const xAOD::TruthMetaDataContainer* truthMetaData(nullptr);
90 // Shamelessly stolen from the file meta data tool
91
92 if (m_metaStore->retrieve(truthMetaData).isSuccess() && !truthMetaData->empty()){
93 // Let's just be super sure...
94 const std::string gens = truthMetaData->at(0)->generators();
95 is_sherpa = (gens.find("sherpa")==std::string::npos &&
96 gens.find("Sherpa")==std::string::npos &&
97 gens.find("SHERPA")==std::string::npos) ? false : true;
98 } // Seems to be the only sure way...
99 else {
100 ATH_MSG_WARNING("Found xAODTruthMetaDataContainer empty! Configuring to be NOT Sherpa.");
101 }
102 ATH_MSG_INFO("From metadata configured: Sherpa? " << is_sherpa);
103 }
104 else {
105 ATH_MSG_WARNING("Could not find metadata container in storegate; assuming NOT Sherpa");
106 }
107 return is_sherpa;
108 }();
109
110 // Retrieve truth collections
111 SG::ReadHandle<xAOD::TruthParticleContainer> truthParticles(m_particlesKey,ctx);
112 if (!truthParticles.isValid()) {
113 ATH_MSG_ERROR("Couldn't retrieve TruthParticle collection with name " << m_particlesKey);
114 return StatusCode::FAILURE;
115 }
116
117 // Create the new particle containers and WriteHandles
118 SG::WriteHandle<xAOD::TruthParticleContainer> newParticlesWriteHandle(m_collectionName, ctx);
119 ATH_CHECK(newParticlesWriteHandle.record(std::make_unique<xAOD::TruthParticleContainer>(),
120 std::make_unique<xAOD::TruthParticleAuxContainer>()));
121 ATH_MSG_DEBUG( "Recorded new TruthParticleContainer with key: " << (m_collectionName.key()));
122
123 // Set up decorators
124 SG::WriteDecorHandle<xAOD::TruthParticleContainer, unsigned int > originDecorator(m_originDecoratorKey, ctx);
125 SG::WriteDecorHandle<xAOD::TruthParticleContainer, unsigned int > typeDecorator(m_typeDecoratorKey, ctx);
126 SG::WriteDecorHandle<xAOD::TruthParticleContainer, unsigned int > outcomeDecorator(m_outcomeDecoratorKey, ctx);
127 SG::WriteDecorHandle<xAOD::TruthParticleContainer, unsigned int > classificationDecorator(m_classificationDecoratorKey, ctx);
128
129 SG::ReadDecorHandle<xAOD::TruthParticleContainer, unsigned int > originAccessor(m_originAccessorKey, ctx);
130 SG::ReadDecorHandle<xAOD::TruthParticleContainer, unsigned int > typeAccessor(m_typeAccessorKey, ctx);
131 SG::ReadDecorHandle<xAOD::TruthParticleContainer, unsigned int > outcomeAccessor(m_outcomeAccessorKey, ctx);
132 SG::ReadDecorHandle<xAOD::TruthParticleContainer, unsigned int > classificationAccessor(m_classificationAccessorKey, ctx);
133
134 // add relevant particles to new collection
135 for (unsigned int i=0; i<truthParticles->size(); ++i) {
136 // Grab the particle
137 const xAOD::TruthParticle* theParticle = (*truthParticles)[i];
138 if (!theParticle) continue; // Protection against null pointers
139 if (!theParticle->isLepton()) continue; // Only include leptons!
140
141 if (is_sherpa) {
142 // For Sherpa, skip is not status 11
143 if (MC::isPhysical(theParticle)) continue;
144 // Sherpa may have two sets of status == 11 leptons. Here we take the first set.
145 // To do so, we check the first status == 11 leptons,
146 // check that it has a child a parent barecode corresponding the the lepton's uniqueID
147 // If so, then save this parent uniqueID and skip all status 11 leptons with this parent uniqueID.
148 bool has_parent_of_same_flavour = false;
149 if (theParticle->prodVtx())
150 for (size_t p = 0; p < theParticle->prodVtx()->nIncomingParticles(); ++p){
151 if (theParticle->parent(p)->pdg_id() == theParticle->pdg_id()) has_parent_of_same_flavour = true;
152 }
153 if (has_parent_of_same_flavour) continue;
154 } else {
155 // Some generators, look for leptons coming from vertices with other leptons
156 bool physical = false, has_V = false;
157 if (!MC::isPhysical(theParticle) && theParticle->hasProdVtx()){
158 const xAOD::TruthVertex * prod = theParticle->prodVtx();
159 // Look for other leptons in the production vertex and check if those are physical
160 for (size_t p = 0; p < prod->nOutgoingParticles(); ++p){
161 if (prod->outgoingParticle(p) && prod->outgoingParticle(p)->isLepton() && MC::isPhysical(prod->outgoingParticle(p))){
162 physical = true;
163 break;
164 }
165 }
166 // See if there was a boson going *into* the vertex
167 for (size_t p = 0; p < prod->nIncomingParticles(); ++p){
168 if (prod->incomingParticle(p) && (prod->incomingParticle(p)->isZ() || prod->incomingParticle(p)->isW() || prod->incomingParticle(p)->isHiggs()) ){
169 has_V = true; // Found a vector boson
170 break;
171 }
172 }
173 }
174
175 // Now we have all the information for the special case of V->l(born) l(bare) l(born) l(bare)
176 // AV: The comment above, most likely is related to the case when the event is passed to PHOTOS with an option to keep
177 // the "documentation" particles, i.e. particles before the photon emission.
178 // These particles in PHOTOS are attached to the same vertex, but have different status, e.g. 3.
179 // The momentum conservation, is, of course, violated.
180 if ( !(physical && has_V && !MC::isPhysical(theParticle)) && !MC::Pythia8::isConditionB(theParticle)){
181 // Skip if it has no boson parent, or has no descendent that is a bare lepton
182 if (!hasBareDescendent( theParticle ) ) continue;
183 const xAOD::TruthVertex * prod = theParticle->prodVtx();
184 if (!prod) continue;
185 if (prod->nIncomingParticles() < 1) continue;
186 size_t bad_parent = 0;
187 for (size_t p = 0; p < prod->nIncomingParticles(); ++p){
188 if (!theParticle->parent(p)) { bad_parent++; continue;}
189 if (!theParticle->parent(p)->isZ() && !theParticle->parent(p)->isW() && !theParticle->parent(p)->isHiggs()) bad_parent++;
190 }
191 if (bad_parent != 0) continue;
192
193 }
194 } // End of treatment for generators that are not Sherpa
195
196 // Add this particle to the new collection
197 xAOD::TruthParticle* xTruthParticle = new xAOD::TruthParticle();
198 newParticlesWriteHandle->push_back( xTruthParticle );
199 // Fill with numerical content
200 *xTruthParticle=*theParticle;
201 // Copy over the decorations if they are available
202 typeDecorator(*xTruthParticle) = typeAccessor(*theParticle);
203 originDecorator(*xTruthParticle) = originAccessor(*theParticle);
204 outcomeDecorator(*xTruthParticle) = outcomeAccessor(*theParticle);
205 classificationDecorator(*xTruthParticle) = classificationAccessor(*theParticle);
206 } // Loop over all particles
207
208 return StatusCode::SUCCESS;
209}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_particlesKey
< Input particle collection key
bool hasBareDescendent(const xAOD::TruthParticle *p) const
Helper function for finding bare descendents of born leptons.
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_originDecoratorKey
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_typeDecoratorKey
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_classificationAccessorKey
Output particle collection key.
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_outcomeAccessorKey
SG::WriteHandleKey< xAOD::TruthParticleContainer > m_collectionName
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_outcomeDecoratorKey
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_originAccessorKey
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_typeAccessorKey
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_classificationDecoratorKey
int pdg_id() const
PDG ID code.
const TruthParticle_v1 * parent(size_t i) const
Retrieve the i-th mother (TruthParticle) of this TruthParticle.
bool hasProdVtx() const
Check for a production vertex on this particle.
bool isLepton() const
Whether the particle is a lepton.
bool isW() const
Check if this particle is a W boson.
const TruthVertex_v1 * prodVtx() const
The production vertex of this particle.
bool isZ() const
Check if this particle is a Z boson.
bool isHiggs() const
Check if this particle is a Higgs boson.
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 isConditionB(const T &p)
bool isPhysical(const T &p)
Identify if the particle is physical, i.e. is stable or decayed.
TruthMetaDataContainer_v1 TruthMetaDataContainer
Declare the latest version of the truth vertex container.
TruthVertex_v1 TruthVertex
Typedef to implementation.
Definition TruthVertex.h:15
TruthParticle_v1 TruthParticle
Typedef to implementation.

◆ hasBareDescendent()

bool DerivationFramework::TruthBornLeptonCollectionMaker::hasBareDescendent ( const xAOD::TruthParticle * p) const
private

Helper function for finding bare descendents of born leptons.

Definition at line 212 of file TruthBornLeptonCollectionMaker.cxx.

213{
214 // Null pointer check
215 if (!p) return false;
216 // If we hit a bare descendent, then we're a winnner
217 if (p->isLepton() && MC::isStable(p) ) return true;
218 // Otherwise look through all the children
219 for (size_t c=0;c<p->nChildren();++c){
220 if (!p->child(c)) continue; // Null pointer protection
221 if (p->pdgId()!=p->child(c)->pdgId()) continue; // Different particle child
222 if (hasBareDescendent( p->child(c) )) return true;
223 }
224 // No luck -- this branch is a dead end
225 return false;
226}
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.

◆ initialize()

StatusCode DerivationFramework::TruthBornLeptonCollectionMaker::initialize ( )

Definition at line 42 of file TruthBornLeptonCollectionMaker.cxx.

43{
44 ATH_MSG_VERBOSE("initialize() ...");
45
46 // Input truth particles
47 ATH_CHECK( m_particlesKey.initialize() );
48 ATH_MSG_INFO("Using " << m_particlesKey.key() << " as the input truth container key");
49
50 // ReadDecorHandleKeys
51 ATH_CHECK(m_originAccessorKey.initialize());
52 ATH_CHECK(m_typeAccessorKey.initialize());
53 ATH_CHECK(m_outcomeAccessorKey.initialize());
55
56 // Output truth particles
57 if (m_collectionName.empty()) {
58 ATH_MSG_FATAL("No key provided for the new truth particle collection");
59 return StatusCode::FAILURE;
60 } else {ATH_MSG_INFO("New truth particle collection key: " << m_collectionName.key() );}
61 ATH_CHECK( m_collectionName.initialize());
62
63 // Decoration keys - FIXME we should not need to use WriteDecorHandleKeys here.
64 ATH_CHECK(m_originDecoratorKey.initialize());
65 ATH_CHECK(m_typeDecoratorKey.initialize());
66 ATH_CHECK(m_outcomeDecoratorKey.initialize());
68
69 // TODO: needs to be made MT-friendly
70 ATH_CHECK( m_metaStore.retrieve() );
71
72 return StatusCode::SUCCESS;
73}
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)

Member Data Documentation

◆ m_classificationAccessorKey

SG::ReadDecorHandleKey<xAOD::TruthParticleContainer> DerivationFramework::TruthBornLeptonCollectionMaker::m_classificationAccessorKey {this, "Input_Classification", m_particlesKey, "Classification", "Classification code decoration"}
private

Output particle collection key.

Definition at line 48 of file TruthBornLeptonCollectionMaker.h.

49{this, "Input_Classification", m_particlesKey, "Classification", "Classification code decoration"};

◆ m_classificationDecoratorKey

SG::WriteDecorHandleKey<xAOD::TruthParticleContainer> DerivationFramework::TruthBornLeptonCollectionMaker::m_classificationDecoratorKey {this, "Classification", m_collectionName, "Classification", "Classification code decoration"}
private

Definition at line 60 of file TruthBornLeptonCollectionMaker.h.

61{this, "Classification", m_collectionName, "Classification", "Classification code decoration"};

◆ m_collectionName

SG::WriteHandleKey<xAOD::TruthParticleContainer> DerivationFramework::TruthBornLeptonCollectionMaker::m_collectionName {this, "NewCollectionName", "", "Name of TruthParticle key for output"}
private

Definition at line 51 of file TruthBornLeptonCollectionMaker.h.

52{this, "NewCollectionName", "", "Name of TruthParticle key for output"};

◆ m_metaStore

ServiceHandle<StoreGateSvc> DerivationFramework::TruthBornLeptonCollectionMaker::m_metaStore
private

Handle on the metadata store for init.

Definition at line 63 of file TruthBornLeptonCollectionMaker.h.

◆ m_originAccessorKey

SG::ReadDecorHandleKey<xAOD::TruthParticleContainer> DerivationFramework::TruthBornLeptonCollectionMaker::m_originAccessorKey {this, "Input_classifierParticleOrigin", m_particlesKey, "classifierParticleOrigin", "Particle origin decoration"}
private

Definition at line 42 of file TruthBornLeptonCollectionMaker.h.

43{this, "Input_classifierParticleOrigin", m_particlesKey, "classifierParticleOrigin", "Particle origin decoration"};

◆ m_originDecoratorKey

SG::WriteDecorHandleKey<xAOD::TruthParticleContainer> DerivationFramework::TruthBornLeptonCollectionMaker::m_originDecoratorKey {this, "classifierParticleOrigin", m_collectionName, "classifierParticleOrigin", "Particle origin decoration"}
private

Definition at line 54 of file TruthBornLeptonCollectionMaker.h.

55{this, "classifierParticleOrigin", m_collectionName, "classifierParticleOrigin", "Particle origin decoration"};

◆ m_outcomeAccessorKey

SG::ReadDecorHandleKey<xAOD::TruthParticleContainer> DerivationFramework::TruthBornLeptonCollectionMaker::m_outcomeAccessorKey {this, "Input_classifierParticleOutCome", m_particlesKey, "classifierParticleOutCome", "Particle outcome decoration"}
private

Definition at line 46 of file TruthBornLeptonCollectionMaker.h.

47{this, "Input_classifierParticleOutCome", m_particlesKey, "classifierParticleOutCome", "Particle outcome decoration"};

◆ m_outcomeDecoratorKey

SG::WriteDecorHandleKey<xAOD::TruthParticleContainer> DerivationFramework::TruthBornLeptonCollectionMaker::m_outcomeDecoratorKey {this, "classifierParticleOutCome", m_collectionName, "classifierParticleOutCome", "Particle outcome decoration"}
private

Definition at line 58 of file TruthBornLeptonCollectionMaker.h.

59{this, "classifierParticleOutCome", m_collectionName, "classifierParticleOutCome", "Particle outcome decoration"};

◆ m_particlesKey

SG::ReadHandleKey<xAOD::TruthParticleContainer> DerivationFramework::TruthBornLeptonCollectionMaker::m_particlesKey {this, "ParticlesKey", "TruthParticles", "Name of TruthParticle key for input"}
private

< Input particle collection key

Definition at line 40 of file TruthBornLeptonCollectionMaker.h.

41{this, "ParticlesKey", "TruthParticles", "Name of TruthParticle key for input"};

◆ m_typeAccessorKey

SG::ReadDecorHandleKey<xAOD::TruthParticleContainer> DerivationFramework::TruthBornLeptonCollectionMaker::m_typeAccessorKey {this, "Input_classifierParticleType",m_particlesKey, "classifierParticleType", "Particle type decoration"}
private

Definition at line 44 of file TruthBornLeptonCollectionMaker.h.

45{this, "Input_classifierParticleType",m_particlesKey, "classifierParticleType", "Particle type decoration"};

◆ m_typeDecoratorKey

SG::WriteDecorHandleKey<xAOD::TruthParticleContainer> DerivationFramework::TruthBornLeptonCollectionMaker::m_typeDecoratorKey {this, "classifierParticleType",m_collectionName, "classifierParticleType", "Particle type decoration"}
private

Definition at line 56 of file TruthBornLeptonCollectionMaker.h.

57{this, "classifierParticleType",m_collectionName, "classifierParticleType", "Particle type decoration"};

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