Function executing the algorithm.
111 {
112
114 ATH_CHECK(truthLinkVec.record(std::make_unique<xAODTruthParticleLinkVector>()));
115
116
118
119 if (!mcColl.isValid()) {
121 return StatusCode::FAILURE;
122 } else {
124 }
125
126
127
128
129
131 ATH_CHECK(xTruthEventContainer.record(std::make_unique<xAOD::TruthEventContainer>(),
132 std::make_unique<xAOD::TruthEventAuxContainer>()));
134
135
136 SG::WriteHandle<xAOD::TruthPileupEventContainer> xTruthPileupEventContainer;
139 ATH_CHECK(xTruthPileupEventContainer.
record(std::make_unique<xAOD::TruthPileupEventContainer>(),
140 std::make_unique<xAOD::TruthPileupEventAuxContainer>()));
142 }
143
144
146 ATH_CHECK(xTruthParticleContainer.record(std::make_unique<xAOD::TruthParticleContainer>(),
147 std::make_unique<xAOD::TruthParticleAuxContainer>()));
149
151 ATH_CHECK(xTruthVertexContainer.record(std::make_unique<xAOD::TruthVertexContainer>(),
152 std::make_unique<xAOD::TruthVertexAuxContainer>()));
154
155
156 bool hadLHERecord = false;
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189 ATH_MSG_DEBUG(
"Number of GenEvents in this Athena event = " << mcColl->size());
190 bool newAttributesPresent(false);
191 for (unsigned int cntr = 0; cntr < mcColl->size(); ++cntr) {
193 bool isSignalProcess(false);
194 if (cntr==0) {
195 isSignalProcess=true;
197 if (bunchCrossingTime) {
198 newAttributesPresent = true;
200 }
201 else {
203 }
204 }
205 if (cntr>0) {
206
208 isSignalProcess=false;
210 if (bunchCrossingTime) {
211
212
214
215 continue;
216 }
217 }
218 else {
219
220
221
222
224 if (newAttributesPresent) {
225
226
228 continue;
229 }
230
231
232 break;
233 }
234 }
235 }
236
239
240
241 if (isSignalProcess) {
242 xTruthEvent = xTruthEventContainer->push_back( std::make_unique<xAOD::TruthEvent>() );
243
247
249
251 SG::ReadHandle<xAOD::EventInfo> evtInfo (
m_evtInfo,ctx);
252 if (evtInfo.isValid()) {
255 }
256 else {
258 return StatusCode::FAILURE;
259 }
260
262 }
263
265 for (
const double& w : genEvt->weights())
weights.push_back((
float)(w));
266
267
269
270
271 auto const hiInfo = genEvt->heavy_ion();
272 if (hiInfo) {
273
287
288
289 }
290
291
292
293 auto const pdfInfo = genEvt->pdf_info();
294 if (pdfInfo) {
299
305 }
306
307
308 auto lhe_record_attribute = genEvt->attribute<HepMC::ShortEventAttribute>(
HepMCStr::LHERecord);
309
311 hadLHERecord=true;
312
314 ATH_CHECK(xTruthLHEParticleContainer.record(std::make_unique<xAOD::TruthParticleContainer>(),
315 std::make_unique<xAOD::TruthParticleAuxContainer>()));
317
318 for (int nPart=0;nPart<lhe_record_attribute->NUP;++nPart) {
319
321
322 xTruthLHEParticleContainer->push_back( xTruthParticle );
323
324 xTruthParticle->
setPdgId( lhe_record_attribute->IDUP[nPart] );
325 xTruthParticle->
setUid( nPart+1 );
326 xTruthParticle->
setStatus( lhe_record_attribute->ISTUP[nPart] );
327 xTruthParticle->
setPx( lhe_record_attribute->PUP[nPart][0] );
328 xTruthParticle->
setPy( lhe_record_attribute->PUP[nPart][1] );
329 xTruthParticle->
setPz( lhe_record_attribute->PUP[nPart][2] );
330 xTruthParticle->
setE( lhe_record_attribute->PUP[nPart][3] );
331 xTruthParticle->
setM( lhe_record_attribute->PUP[nPart][4] );
332 }
333 }
334 else if (hadLHERecord){
335 ATH_MSG_WARNING(
"Truth record appeared to have two LHE records; this should not be possible");
336 }
337 }else{
338 xTruthPileupEvent = xTruthPileupEventContainer->push_back( std::make_unique<xAOD::TruthPileupEvent>() );
339 }
340
341
342
343
344
346 VertexMap::iterator mapItr;
347 vector<HepMC::ConstGenVertexPtr> vertices;
348
349
350
352 if (disconnectedSignalProcessVtx) {
353 if (disconnectedSignalProcessVtx->particles_in_size() == 0 && disconnectedSignalProcessVtx->particles_out_size() == 0 ) {
354
355 vertices.push_back (std::move(disconnectedSignalProcessVtx));
356 }
357 } else {
358 ATH_MSG_WARNING(
"Signal process vertex pointer not valid in HepMC Collection for GenEvent #" << cntr <<
" / " << mcColl->size());
359 }
360
361
362 pair<HepMC::ConstGenParticlePtr,HepMC::ConstGenParticlePtr> beamParticles;
363 bool genEvt_valid_beam_particles=false;
364 auto beamParticles_vec = genEvt->beams();
365 genEvt_valid_beam_particles=(beamParticles_vec.size()>1);
366 if (genEvt_valid_beam_particles){beamParticles.first=beamParticles_vec[0]; beamParticles.second=beamParticles_vec[1]; }
367
369 if (!bcmapatt) {
370 ATH_MSG_ERROR(
"TruthParticleCnvTool.cxx: Event does not contain barcodes attribute");
371 return StatusCode::FAILURE;
372 }
373 std::map<int, HepMC3::ConstGenParticlePtr> bcmap = bcmapatt->barcode_to_particle_map();
374 xTruthParticleContainer->reserve(bcmap.size());
375 for (const auto &[genPartBarcode,part]: bcmap) {
377
379
380 xTruthParticleContainer->push_back( xTruthParticle );
382
383 const ElementLink<xAOD::TruthParticleContainer> eltp(*xTruthParticleContainer, xTruthParticleContainer->size()-1);
386
387
390
391
392 if (genEvt_valid_beam_particles) {
393 if (isSignalProcess) {
396 }
397 }
398
399 auto productionVertex =
part->production_vertex();
400
401
402
403 if (productionVertex && productionVertex->parent_event() != nullptr) {
405 if (
parts.incoming.empty() &&
parts.outgoing.empty())
406 vertices.push_back (std::move(productionVertex));
407 parts.outgoingEL.push_back(eltp);
408 parts.outgoing.push_back(xTruthParticle);
409 }
410
411
412
413
414 auto decayVertex =
part->end_vertex();
415 if (decayVertex) {
417 if (
parts.incoming.empty() &&
parts.outgoing.empty())
418 vertices.push_back (std::move(decayVertex));
419 parts.incomingEL.push_back(eltp);
420 parts.incoming.push_back(xTruthParticle);
421 }
422
423 }
424
425
427 xTruthVertexContainer->reserve(vertices.size());
428 for (const auto& vertex : vertices) {
430
432
433 xTruthVertexContainer->push_back( xTruthVertex );
435
437
441
443
445
447
449 }
450
451 }
452
453
454 std::stable_sort(truthLinkVec->begin(), truthLinkVec->end(), SortTruthParticleLink());
455 ATH_MSG_VERBOSE(
"Summarizing truth link size: " << truthLinkVec->size() );
456
457 return StatusCode::SUCCESS;
458 }
#define ATH_CHECK
Evaluate an expression and check for errors.
ElementLink()
Default constructor.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
SG::WriteHandleKey< xAOD::TruthVertexContainer > m_xaodTruthVertexContainerKey
MetadataFields m_metaFields
Gaudi::Property< bool > m_doAllPileUp
Pile-up options.
SG::WriteHandleKey< xAOD::TruthParticleContainer > m_lheTruthParticleContainerKey
SG::WriteHandleKey< xAODTruthParticleLinkVector > m_truthLinkContainerKey
SG::ReadHandleKey< McEventCollection > m_aodContainerKey
The key of the input AOD truth container.
static void fillVertex(xAOD::TruthVertex *tv, const HepMC::ConstGenVertexPtr &gv)
These functions do not set up ELs, just the other variables.
SG::WriteHandleKey< xAOD::TruthParticleContainer > m_xaodTruthParticleContainerKey
Gaudi::Property< bool > m_writeMetaData
option to disable writing of metadata (e.g. if running a filter on xAOD in generators)
std::map< HepMC::ConstGenVertexPtr, VertexParticles > VertexMap
Convenience handle for a map of vtx ptrs -> connected particles.
SG::ReadHandleKey< xAOD::EventInfo > m_evtInfo
Event Info.
Gaudi::Property< bool > m_doInTimePileUp
static void fillParticle(xAOD::TruthParticle *tp, const HepMC::ConstGenParticlePtr &gp)
SG::WriteHandleKey< xAOD::TruthEventContainer > m_xaodTruthEventContainerKey
The key for the output xAOD truth containers.
SG::WriteHandleKey< xAOD::TruthPileupEventContainer > m_xaodTruthPUEventContainerKey
void addTruthVertexLink(const TruthVertexLink_t &vlink)
Add one truth vertex.
void addTruthParticleLink(const TruthParticleLink_t &plink)
Add one truth particle.
void setWeights(const std::vector< float > &weights)
Set the event weights.
void setSignalProcessVertexLink(const TruthVertexLink_t &link)
Set pointer to a vertex representing the primary beam interaction point.
void setCrossSectionError(float value)
Set the cross-section error.
void setCrossSection(float value)
Set the cross-section.
bool setHeavyIonParameter(int value, HIParam parameter)
Set an integer HI parameter.
bool setPdfInfoParameter(int value, PdfParam parameter)
Set an integer PDF info parameter.
@ NWOUNDEDNWOUNDEDCOLLISIONS
[int]
@ NNWOUNDEDCOLLISIONS
[int]
@ NWOUNDEDNCOLLISIONS
[int]
void setBeamParticle1Link(const TruthParticleLink_t &pcl1)
Set one incoming beam particle.
void setBeamParticle2Link(const TruthParticleLink_t &pcl2)
Set one incoming beam particle.
void setPy(float value)
Set the y component of the particle's momentum.
void setUid(int value)
Set unique ID.
void setM(float value)
Also store the mass.
void setE(float value)
Set the energy of the particle.
void setPz(float value)
Set the z 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.
void setOutgoingParticleLinks(const TPLinks_t &links)
Set all the outgoing particles.
void setIncomingParticleLinks(const TPLinks_t &links)
Set all the incoming particles.
const std::string weights
const std::string BunchCrossingTime
const std::string barcodes
const std::string LHERecord
ConstGenVertexPtr signal_process_vertex(const GenEvent *e)
HepMC3::GenEvent GenEvent
void stable_sort(DataModel_detail::iterator< DVL > beg, DataModel_detail::iterator< DVL > end)
Specialization of stable_sort for DataVector/List.
TruthVertex_v1 TruthVertex
Typedef to implementation.
TruthEvent_v1 TruthEvent
Typedef to implementation.
TruthParticle_v1 TruthParticle
Typedef to implementation.
TruthPileupEvent_v1 TruthPileupEvent
Typedef to implementation.
Type for tracking particles connected to a single vertex.
bool isSeparatorGenEvent(const HepMC::GenEvent *genEvt)
std::pair< HepMcParticleLink, ElementLink< xAOD::TruthParticleContainer > > xAODTruthParticleLink