77{
78
79
80
81 static const bool is_sherpa = [this]() {
82 bool is_sherpa = false;
83
85
86
87
88
90
91
92 if (
m_metaStore->retrieve(truthMetaData).isSuccess() && !truthMetaData->empty()){
93
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 }
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
111 SG::ReadHandle<xAOD::TruthParticleContainer> truthParticles(
m_particlesKey,ctx);
112 if (!truthParticles.isValid()) {
114 return StatusCode::FAILURE;
115 }
116
117
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>()));
122
123
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);
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);
133
134
135 for (
unsigned int i=0;
i<truthParticles->size(); ++
i) {
136
138 if (!theParticle) continue;
139 if (!theParticle->
isLepton())
continue;
140
141 if (is_sherpa) {
142
144
145
146
147
148 bool has_parent_of_same_flavour = false;
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
156 bool physical = false, has_V = false;
159
162 physical = true;
163 break;
164 }
165 }
166
169 has_V = true;
170 break;
171 }
172 }
173 }
174
175
176
177
178
179
181
184 if (!prod) continue;
186 size_t bad_parent = 0;
188 if (!theParticle->
parent(p)) { bad_parent++;
continue;}
190 }
191 if (bad_parent != 0) continue;
192
193 }
194 }
195
196
198 newParticlesWriteHandle->push_back( xTruthParticle );
199
200 *xTruthParticle=*theParticle;
201
202 typeDecorator(*xTruthParticle) = typeAccessor(*theParticle);
203 originDecorator(*xTruthParticle) = originAccessor(*theParticle);
204 outcomeDecorator(*xTruthParticle) = outcomeAccessor(*theParticle);
205 classificationDecorator(*xTruthParticle) = classificationAccessor(*theParticle);
206 }
207
208 return StatusCode::SUCCESS;
209}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(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.
TruthParticle_v1 TruthParticle
Typedef to implementation.