diff --git a/InnerDetector/InDetEventCnv/InDetEventAthenaPool/test/InDetSimDataCollectionCnv_common_test.h b/InnerDetector/InDetEventCnv/InDetEventAthenaPool/test/InDetSimDataCollectionCnv_common_test.h index a517380278106309318e4eeef56806a9b754d04e..806b45cd25edf220d6bb65340a23061f0419c1c9 100644 --- a/InnerDetector/InDetEventCnv/InDetEventAthenaPool/test/InDetSimDataCollectionCnv_common_test.h +++ b/InnerDetector/InDetEventCnv/InDetEventAthenaPool/test/InDetSimDataCollectionCnv_common_test.h @@ -15,6 +15,7 @@ #include "AtlasHepMC/GenEvent.h" #include "AtlasHepMC/GenParticle.h" +#include "AtlasHepMC/Operators.h" #include "GeneratorObjectsTPCnv/initMcEventCollection.h" #include "InDetIdentifier/PixelID.h" #include "IdDictParser/IdDictParser.h" diff --git a/LArCalorimeter/LArDigitization/src/LArHitEMap.cxx b/LArCalorimeter/LArDigitization/src/LArHitEMap.cxx index ad87463246f1f3501641daf0c0c8157b76563ec5..b685dfb7aab466cb5b51edc5405c4bc31d33062a 100644 --- a/LArCalorimeter/LArDigitization/src/LArHitEMap.cxx +++ b/LArCalorimeter/LArDigitization/src/LArHitEMap.cxx @@ -90,15 +90,13 @@ bool LArHitEMap::BuildWindows(const McEventCollection* mcCollptr, McEventCollection::const_iterator itr; // std::cout << " start loop over particles " << std::endl; for (itr = mcCollptr->begin(); itr!=mcCollptr->end(); ++itr) { - HepMC::GenEvent::particle_const_iterator itrPart; - for (itrPart = (*itr)->particles_begin(); itrPart!=(*itr)->particles_end(); ++itrPart ) + for (auto part: *(*itr)) { - HepMC::GenParticle *part=*itrPart; //works only for photons(22) and electrons(11) primary particle from Geant (status>1000) // with pt>5 GeV // GU 20-june-2006 use barcode between 10001 and 20000 to select primary particles //AV2020: not sure if it works - if( (part->pdg_id()==22 || abs(part->pdg_id())==11 || part->pdg_id()==111) - && part->barcode()>10000 && part->barcode()<20000 + if( (part->pdg_id()==22 || std::abs(part->pdg_id())==11 || part->pdg_id()==111) + && HepMC::barcode(part)>10000 && HepMC::barcode(part)<20000 && part->momentum().perp()> ptmin) { // std::cout << "good particle found ! " << part->pdg_id() << std::endl; diff --git a/LArCalorimeter/LArG4/LArG4H6SD/src/RadLenNtuple.cc b/LArCalorimeter/LArG4/LArG4H6SD/src/RadLenNtuple.cc index 3aad0fdc4e9883e41718f80566235238242366dd..1c450b3ff53e0fd0bdd0c80f6a00952dd5982dbe 100644 --- a/LArCalorimeter/LArG4/LArG4H6SD/src/RadLenNtuple.cc +++ b/LArCalorimeter/LArG4/LArG4H6SD/src/RadLenNtuple.cc @@ -39,7 +39,11 @@ namespace G4UA if (m_mcEvtColl.isValid()) { McEventCollection::const_iterator iEvt = m_mcEvtColl->begin(); +#ifdef HEPMC3 + auto p = (*iEvt)->particles().begin(); +#else HepMC::GenEvent::particle_const_iterator p = (*iEvt)->particles_begin(); +#endif m_xcoord = (*p)->production_vertex()->position().x(); } diff --git a/LArCalorimeter/LArG4/LArG4Validation/src/AODReader.cxx b/LArCalorimeter/LArG4/LArG4Validation/src/AODReader.cxx index f639b09fb78dabe77ff64fcbf5093d4ee9a015c1..a7659ba0f597223ea337211f5b425c30b2d3a7ea 100644 --- a/LArCalorimeter/LArG4/LArG4Validation/src/AODReader.cxx +++ b/LArCalorimeter/LArG4/LArG4Validation/src/AODReader.cxx @@ -126,11 +126,11 @@ StatusCode AODReader::execute() ElectronContainer::const_iterator elecItr = elecTES->begin(); ElectronContainer::const_iterator elecItrE = elecTES->end(); - HepMC::GenParticle * trPart = 0; + HepMC::GenParticlePtr trPart{nullptr}; if (mcEvtColl) { McEventCollection::const_iterator mcTrPart = mcEvtColl->begin(); if (mcTrPart != mcEvtColl->end()) { - trPart = (*mcTrPart)->barcode_to_particle(10001); + trPart = HepMC::barcode_to_particle((*mcTrPart),10001); if (!trPart) { msg(MSG::WARNING) << "Not a single particle event. Truth information won't be available" << endmsg; } diff --git a/LArCalorimeter/LArG4/LArG4Validation/src/SingleTrackValidation.cxx b/LArCalorimeter/LArG4/LArG4Validation/src/SingleTrackValidation.cxx index 08f8be0c04d73a7f99da21ecb032be645378fb61..68424cb9602bf522943974c4a4b30f680ebe0f6c 100755 --- a/LArCalorimeter/LArG4/LArG4Validation/src/SingleTrackValidation.cxx +++ b/LArCalorimeter/LArG4/LArG4Validation/src/SingleTrackValidation.cxx @@ -320,7 +320,11 @@ StatusCode SingleTrackValidation::execute() { for (e=mcEvent->begin();e!=mcEvent->end();e++) { // Get just the primary, call it "theParticle" +#ifdef HEPMC3 + HepMC::ConstGenParticlePtr theParticle = (*e)->particles().front(); +#else const HepMC::GenParticle *theParticle= *((**e).particles_begin()); +#endif // Fetch whatever particle properties will be used in the following: const HepPDT::ParticleDataTable * dataTable = m_c->partPropSvc->PDT(); diff --git a/PhysicsAnalysis/TruthParticleID/McParticleEventTPCnv/src/RootTruthParticleCnvTool.cxx b/PhysicsAnalysis/TruthParticleID/McParticleEventTPCnv/src/RootTruthParticleCnvTool.cxx index c9e8e9812c65f480758e21b156bd2d48ab3444b5..98fc6fb64fcbe761f6c1dd1d8ac2d250fc404e1b 100644 --- a/PhysicsAnalysis/TruthParticleID/McParticleEventTPCnv/src/RootTruthParticleCnvTool.cxx +++ b/PhysicsAnalysis/TruthParticleID/McParticleEventTPCnv/src/RootTruthParticleCnvTool.cxx @@ -71,16 +71,16 @@ RootTruthParticleCnvTool::convert(const McEventCollection *mcCollection, container->setGenEvent( mcCollection, genEventIndex ); // reserve enough space for the container so we don't have to relocate it +#ifdef HEPMC3 + container->reserve( evt->particles().size() ); +#else container->reserve( evt->particles_size() ); +#endif /// Create a map to enhance access between GenParticles and TruthParticles TruthParticleContainer::Map_t bcToMcPart; - const HepMC::GenEvent::particle_const_iterator itrEnd = evt->particles_end(); - for ( HepMC::GenEvent::particle_const_iterator itrPart=evt->particles_begin(); - itrPart != itrEnd; - ++itrPart ) { - const HepMC::GenParticle * hepMcPart = (*itrPart); + for ( auto hepMcPart: *evt) { TruthParticle * mcPart = new TruthParticle( hepMcPart, container ); container->push_back( mcPart ); diff --git a/PhysicsAnalysis/TruthParticleID/McParticleTests/src/McAodMcTopAna_solution.cxx b/PhysicsAnalysis/TruthParticleID/McParticleTests/src/McAodMcTopAna_solution.cxx index b2c94b6e12c4311dac4b81029d4864e3875fad57..11402e4f83f6ddbb4287a4315eb98b2ed1079de9 100644 --- a/PhysicsAnalysis/TruthParticleID/McParticleTests/src/McAodMcTopAna_solution.cxx +++ b/PhysicsAnalysis/TruthParticleID/McParticleTests/src/McAodMcTopAna_solution.cxx @@ -210,20 +210,22 @@ StatusCode McTopAnaSolution::doMcTopWb() m_vtxFilter->filterMcEventCollection(mcevt, filteredMcEvt); const HepMC::GenEvent * evtAod = filteredMcEvt->front(); - for ( HepMC::GenEvent::particle_const_iterator itr = evtAod->particles_begin(); - itr != evtAod->particles_end(); - ++itr ) { - ATH_MSG_DEBUG("Part. id: " << (*itr)->pdg_id() << endmsg - << "E= " << (*itr)->momentum().e() - << "\tpx= " << (*itr)->momentum().px()); + for ( auto particle: *evtAod) { + ATH_MSG_DEBUG("Part. id: " << particle->pdg_id() << endmsg + << "E= " << particle->momentum().e() + << "\tpx= " << particle->momentum().px()); // retrieve the decay vertex of the current particle - const HepMC::GenVertex * decayVtx = (*itr)->end_vertex(); + auto decayVtx = particle->end_vertex(); - if (PDG::t == (*itr)->pdg_id() && //> select top + if (PDG::t == particle->pdg_id() && //> select top 0 != decayVtx && //> check that we have a valid vtx pointer +#ifdef HEPMC3 + 2 <= decayVtx->particles_out().size() ) { //> isn't necessary, just to exercize the GenVertex interface +#else 2 <= decayVtx->particles_out_size() ) { //> isn't necessary, just to exercize the GenVertex interface - m_h_mctop_mass->Fill( (*itr)->momentum().m() ); +#endif + m_h_mctop_mass->Fill( particle->momentum().m() ); }//> top }//> end loop over particles @@ -266,8 +268,8 @@ StatusCode McTopAnaSolution::doMcTopWb() // not interested in... Skip it continue; } - const HepMC::GenParticle* hepPart = mc->genParticle(); - const HepMC::GenVertex* vtx = hepPart->end_vertex(); + auto hepPart = mc->genParticle(); + auto vtx = hepPart->end_vertex(); // Get the W boson if ( 0 != vtx && wqqFilter.isAccepted( vtx ) ) {