114 ATH_CHECK(truthLinkVec.
record(std::make_unique<xAODTruthParticleLinkVector>()));
121 return StatusCode::FAILURE;
131 ATH_CHECK(xTruthEventContainer.
record(std::make_unique<xAOD::TruthEventContainer>(),
132 std::make_unique<xAOD::TruthEventAuxContainer>()));
139 ATH_CHECK(xTruthPileupEventContainer.
record(std::make_unique<xAOD::TruthPileupEventContainer>(),
140 std::make_unique<xAOD::TruthPileupEventAuxContainer>()));
146 ATH_CHECK(xTruthParticleContainer.
record(std::make_unique<xAOD::TruthParticleContainer>(),
147 std::make_unique<xAOD::TruthParticleAuxContainer>()));
151 ATH_CHECK(xTruthVertexContainer.
record(std::make_unique<xAOD::TruthVertexContainer>(),
152 std::make_unique<xAOD::TruthVertexAuxContainer>()));
157 bool hadLHERecord =
false;
191 ATH_MSG_DEBUG(
"Number of GenEvents in this Athena event = " << mcColl->size());
193 bool newAttributesPresent(
false);
195 for (
unsigned int cntr = 0; cntr < mcColl->size(); ++cntr) {
196 const HepMC::GenEvent* genEvt = (*mcColl)[cntr];
197 bool isSignalProcess(
false);
199 isSignalProcess=
true;
201 auto bunchCrossingTime = genEvt->attribute<HepMC3::IntAttribute>(
"BunchCrossingTime");
202 if (bunchCrossingTime) {
203 newAttributesPresent =
true;
216 isSignalProcess=
false;
218 auto bunchCrossingTime = genEvt->attribute<HepMC3::IntAttribute>(
"BunchCrossingTime");
219 if (bunchCrossingTime) {
233 if (newAttributesPresent) {
261 if (isSignalProcess) {
262 xTruthEvent = xTruthEventContainer->push_back( std::make_unique<xAOD::TruthEvent>() );
264 auto crossSection = genEvt->cross_section();
266 xTruthEvent->
setCrossSection(crossSection ? (
float)crossSection->xsec() : -1);
269 xTruthEvent->
setCrossSection(crossSection ? (
float)crossSection->cross_section() : -1);
270 xTruthEvent->
setCrossSectionError(crossSection ? (
float)crossSection->cross_section_error() : -1);
275 uint32_t mcChannelNumber = 0;
278 mcChannelNumber = evtInfo->mcChannelNumber();
279 if (mcChannelNumber==0) mcChannelNumber = evtInfo->runNumber();
283 return StatusCode::FAILURE;
290 for (
const double& w : genEvt->weights())
weights.push_back((
float)(w));
296 auto const hiInfo = genEvt->heavy_ion();
334 auto const pdfInfo = genEvt->pdf_info();
363 auto lhe_record_attribute = genEvt->attribute<HepMC::ShortEventAttribute>(
"LHERecord");
369 ATH_CHECK(xTruthLHEParticleContainer.
record(std::make_unique<xAOD::TruthParticleContainer>(),
370 std::make_unique<xAOD::TruthParticleAuxContainer>()));
373 for (
int nPart=0;nPart<lhe_record_attribute->NUP;++nPart) {
377 xTruthLHEParticleContainer->push_back( xTruthParticle );
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] );
389 else if (hadLHERecord){
390 ATH_MSG_WARNING(
"Truth record appeared to have two LHE records; this should not be possible");
394 ATH_MSG_WARNING(
"HEPMC2 does not support LHE truth record storage. Skipping.");
398 xTruthPileupEvent = xTruthPileupEventContainer->push_back( std::make_unique<xAOD::TruthPileupEvent>() );
406 VertexMap::iterator mapItr;
407 vector<HepMC::ConstGenVertexPtr> vertices;
412 if (disconnectedSignalProcessVtx) {
413 if (disconnectedSignalProcessVtx->particles_in_size() == 0 && disconnectedSignalProcessVtx->particles_out_size() == 0 ) {
415 vertices.push_back (std::move(disconnectedSignalProcessVtx));
418 ATH_MSG_WARNING(
"Signal process vertex pointer not valid in HepMC Collection for GenEvent #" << cntr <<
" / " << mcColl->size());
422 pair<HepMC::ConstGenParticlePtr,HepMC::ConstGenParticlePtr> beamParticles;
423 bool genEvt_valid_beam_particles=
false;
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]; }
429 auto bcmapatt = genEvt->attribute<HepMC::GenEventBarcodes>(
"barcodes");
431 ATH_MSG_ERROR(
"TruthParticleCnvTool.cxx: Event does not contain barcodes attribute");
432 return StatusCode::FAILURE;
434 std::map<int, HepMC3::ConstGenParticlePtr> bcmap = bcmapatt->barcode_to_particle_map();
435 xTruthParticleContainer->reserve(bcmap.size());
436 for (
const auto &[genPartBarcode,part]: bcmap) {
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) {
447 xTruthParticleContainer->push_back( xTruthParticle );
459 if (genEvt_valid_beam_particles) {
460 if (isSignalProcess) {
466 auto productionVertex = part->production_vertex();
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);
481 auto decayVertex = part->end_vertex();
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);
494 xTruthVertexContainer->reserve(vertices.size());
495 for (
const auto& vertex : vertices) {
496 const auto& parts = vertexMap[vertex];
500 xTruthVertexContainer->push_back( xTruthVertex );
522 ATH_MSG_VERBOSE(
"Summarizing truth link size: " << truthLinkVec->size() );
524 return StatusCode::SUCCESS;
std::pair< HepMcParticleLink, ElementLink< xAOD::TruthParticleContainer > > xAODTruthParticleLink