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#ifdef HEPMC3
157 bool hadLHERecord = false;
158#endif
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
190
191 ATH_MSG_DEBUG(
"Number of GenEvents in this Athena event = " << mcColl->size());
192#ifdef HEPMC3
193 bool newAttributesPresent(false);
194#endif
195 for (unsigned int cntr = 0; cntr < mcColl->size(); ++cntr) {
196 const HepMC::GenEvent* genEvt = (*mcColl)[cntr];
197 bool isSignalProcess(false);
198 if (cntr==0) {
199 isSignalProcess=true;
200#ifdef HEPMC3
201 auto bunchCrossingTime = genEvt->attribute<HepMC3::IntAttribute>("BunchCrossingTime");
202 if (bunchCrossingTime) {
203 newAttributesPresent = true;
205 }
206 else {
208 }
209#else
211#endif
212 }
213 if (cntr>0) {
214
216 isSignalProcess=false;
217#ifdef HEPMC3
218 auto bunchCrossingTime = genEvt->attribute<HepMC3::IntAttribute>("BunchCrossingTime");
219 if (bunchCrossingTime) {
220
221
223
224 continue;
225 }
226 }
227 else {
228
229
230
231
233 if (newAttributesPresent) {
234
235
237 continue;
238 }
239
240
241 break;
242 }
243 }
244#else
245
246
247
248
250
251
252 break;
253 }
254#endif
255 }
256
259
260
261 if (isSignalProcess) {
262 xTruthEvent = xTruthEventContainer->push_back( std::make_unique<xAOD::TruthEvent>() );
263
265#ifdef HEPMC3
268#else
271#endif
272
274
276 SG::ReadHandle<xAOD::EventInfo> evtInfo (
m_evtInfo,ctx);
277 if (evtInfo.isValid()) {
280 }
281 else {
283 return StatusCode::FAILURE;
284 }
285
287 }
288
289 vector<float> weights;
290 for (const double& w : genEvt->weights()) weights.push_back((float)(w));
291
292
294
295
296 auto const hiInfo = genEvt->heavy_ion();
297 if (hiInfo) {
298#ifdef HEPMC3
299
313#else
327#endif
328
329
330 }
331
332
333
334 auto const pdfInfo = genEvt->pdf_info();
335 if (pdfInfo) {
336#ifdef HEPMC3
341
347#else
352
358#endif
359 }
360
361
362#ifdef HEPMC3
363 auto lhe_record_attribute = genEvt->attribute<HepMC::ShortEventAttribute>("LHERecord");
364
366 hadLHERecord=true;
367
369 ATH_CHECK(xTruthLHEParticleContainer.record(std::make_unique<xAOD::TruthParticleContainer>(),
370 std::make_unique<xAOD::TruthParticleAuxContainer>()));
372
373 for (int nPart=0;nPart<lhe_record_attribute->NUP;++nPart) {
374
376
377 xTruthLHEParticleContainer->push_back( xTruthParticle );
378
379 xTruthParticle->
setPdgId( lhe_record_attribute->IDUP[nPart] );
380 xTruthParticle->
setUid( nPart+1 );
381 xTruthParticle->
setStatus( lhe_record_attribute->ISTUP[nPart] );
382 xTruthParticle->
setPx( lhe_record_attribute->PUP[nPart][0] );
383 xTruthParticle->
setPy( lhe_record_attribute->PUP[nPart][1] );
384 xTruthParticle->
setPz( lhe_record_attribute->PUP[nPart][2] );
385 xTruthParticle->
setE( lhe_record_attribute->PUP[nPart][3] );
386 xTruthParticle->
setM( lhe_record_attribute->PUP[nPart][4] );
387 }
388 }
389 else if (hadLHERecord){
390 ATH_MSG_WARNING(
"Truth record appeared to have two LHE records; this should not be possible");
391 }
392#else
394 ATH_MSG_WARNING(
"HEPMC2 does not support LHE truth record storage. Skipping.");
395 }
396#endif
397 }else{
398 xTruthPileupEvent = xTruthPileupEventContainer->push_back( std::make_unique<xAOD::TruthPileupEvent>() );
399 }
400
401
402
403
404
406 VertexMap::iterator mapItr;
407 vector<HepMC::ConstGenVertexPtr> vertices;
408
409
410
412 if (disconnectedSignalProcessVtx) {
413 if (disconnectedSignalProcessVtx->particles_in_size() == 0 && disconnectedSignalProcessVtx->particles_out_size() == 0 ) {
414
415 vertices.push_back (std::move(disconnectedSignalProcessVtx));
416 }
417 } else {
418 ATH_MSG_WARNING(
"Signal process vertex pointer not valid in HepMC Collection for GenEvent #" << cntr <<
" / " << mcColl->size());
419 }
420
421
422 pair<HepMC::ConstGenParticlePtr,HepMC::ConstGenParticlePtr> beamParticles;
423 bool genEvt_valid_beam_particles=false;
424#ifdef HEPMC3
425 auto beamParticles_vec = genEvt->beams();
426 genEvt_valid_beam_particles=(beamParticles_vec.size()>1);
427 if (genEvt_valid_beam_particles){beamParticles.first=beamParticles_vec[0]; beamParticles.second=beamParticles_vec[1]; }
428
429 auto bcmapatt = genEvt->attribute<HepMC::GenEventBarcodes>("barcodes");
430 if (!bcmapatt) {
431 ATH_MSG_ERROR(
"TruthParticleCnvTool.cxx: Event does not contain barcodes attribute");
432 return StatusCode::FAILURE;
433 }
434 std::map<int, HepMC3::ConstGenParticlePtr> bcmap = bcmapatt->barcode_to_particle_map();
435 xTruthParticleContainer->reserve(bcmap.size());
436 for (const auto &[genPartBarcode,part]: bcmap) {
437#else
438 genEvt_valid_beam_particles=genEvt->valid_beam_particles();
439 if ( genEvt_valid_beam_particles ) beamParticles = genEvt->beam_particles();
440 xTruthParticleContainer->reserve(genEvt->particles_size());
441 for (auto part: *genEvt) {
442#endif
444
446
447 xTruthParticleContainer->push_back( xTruthParticle );
449
450 const ElementLink<xAOD::TruthParticleContainer> eltp(*xTruthParticleContainer, xTruthParticleContainer->size()-1);
453
454
457
458
459 if (genEvt_valid_beam_particles) {
460 if (isSignalProcess) {
463 }
464 }
465
466 auto productionVertex =
part->production_vertex();
467
468
469
470 if (productionVertex && productionVertex->parent_event() != nullptr) {
472 if (
parts.incoming.empty() &&
parts.outgoing.empty())
473 vertices.push_back (std::move(productionVertex));
474 parts.outgoingEL.push_back(eltp);
475 parts.outgoing.push_back(xTruthParticle);
476 }
477
478
479
480
481 auto decayVertex =
part->end_vertex();
482 if (decayVertex) {
484 if (
parts.incoming.empty() &&
parts.outgoing.empty())
485 vertices.push_back (std::move(decayVertex));
486 parts.incomingEL.push_back(eltp);
487 parts.incoming.push_back(xTruthParticle);
488 }
489
490 }
491
492
494 xTruthVertexContainer->reserve(vertices.size());
495 for (const auto& vertex : vertices) {
497
499
500 xTruthVertexContainer->push_back( xTruthVertex );
502
503 ElementLink<xAOD::TruthVertexContainer> eltv(*xTruthVertexContainer, xTruthVertexContainer->size()-1);
504
508
510
512
514
516 }
517
518 }
519
520
521 std::stable_sort(truthLinkVec->begin(), truthLinkVec->end(), SortTruthParticleLink());
522 ATH_MSG_VERBOSE(
"Summarizing truth link size: " << truthLinkVec->size() );
523
524 return StatusCode::SUCCESS;
525 }
#define ATH_CHECK
Evaluate an expression and check for errors.
#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.
GenVertex * signal_process_vertex(const GenEvent *e)
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