From 2ce6bff4f5b1031dba50c1be02f1e5f733dd2f70 Mon Sep 17 00:00:00 2001 From: Andrii Verbytskyi <averbyts@cern.ch> Date: Wed, 23 Dec 2020 22:24:11 +0100 Subject: [PATCH] More migration --- .../D2PDMaker/src/D2PDParticleCombiner.cxx | 31 ++++++++----- .../src/GenVertexFillerTool.cxx | 2 +- .../TruthD3PDMaker/src/JetFullTruthTag.cxx | 29 ++++++------ .../src/SpclMcValidationTool.cxx | 2 +- .../iPatInterfaces/ITruthParameters.h | 4 +- .../iPatTruthTrajectory/TruthParameters.h | 12 ++--- .../src/TruthParameters.cxx | 46 +++++++++---------- 7 files changed, 66 insertions(+), 60 deletions(-) diff --git a/PhysicsAnalysis/D2PDMaker/src/D2PDParticleCombiner.cxx b/PhysicsAnalysis/D2PDMaker/src/D2PDParticleCombiner.cxx index b4cab570b04..a4425d30e16 100644 --- a/PhysicsAnalysis/D2PDMaker/src/D2PDParticleCombiner.cxx +++ b/PhysicsAnalysis/D2PDMaker/src/D2PDParticleCombiner.cxx @@ -1385,13 +1385,13 @@ bool D2PDParticleCombiner::mcTruthSelections( const CompositeParticle* compPart { // Get the GenParticle from the TruthParticle const TruthParticle* part = (*partItr); - const HepMC::GenParticle* genPart = part->genParticle(); + auto genPart = part->genParticle(); const int pdgID = genPart->pdg_id(); // Now, get the origin of this generated particle McEventCollection::const_iterator mcEventItr = m_mcEventColl->begin(); - const int primaryBarcode = genPart->barcode()%1000000; - const HepMC::GenParticle* primaryPart = (*mcEventItr)->barcode_to_particle(primaryBarcode); + const int primaryBarcode = HepMC::barcode(genPart)%1000000; + auto primaryPart = HepMC::barcode_to_particle((*mcEventItr),primaryBarcode); // Check that we really have the primaryPart if ( !primaryPart ) @@ -1401,7 +1401,7 @@ bool D2PDParticleCombiner::mcTruthSelections( const CompositeParticle* compPart } // Now get the production vertex - const HepMC::GenVertex* prodVert = primaryPart->production_vertex(); + auto prodVert = primaryPart->production_vertex(); if ( !prodVert ) { ATH_MSG_WARNING ( "Could not get the ProductionVertex... skipping!" ); @@ -1409,7 +1409,11 @@ bool D2PDParticleCombiner::mcTruthSelections( const CompositeParticle* compPart } // Check that we have only one mother +#ifdef HEPMC3 + if ( prodVert->particles_in().size() > 1 ) +#else if ( prodVert->particles_in_size() > 1 ) +#endif { ATH_MSG_WARNING ( "The ProductionVertex has more than one incomming particles... skipping!" ); return true; @@ -1418,21 +1422,24 @@ bool D2PDParticleCombiner::mcTruthSelections( const CompositeParticle* compPart // Loop over the mother particles // Make sure that we ignore bremsstrahlung and decays into itself - const HepMC::GenVertex* originVert = prodVert ; - //const HepMC::GenVertex* tmpVert(0); + auto originVert = prodVert; int originPdgID = pdgID; int originBarcode(0); int counter(0); do { ++counter; +#ifdef HEPMC3 + for ( auto mother: originVert->particles_in()) { +#else HepMC::GenVertex::particles_in_const_iterator motherItr = originVert->particles_in_const_begin(); HepMC::GenVertex::particles_in_const_iterator motherItrEnd = originVert->particles_in_const_end(); - for ( ; motherItr != motherItrEnd; ++motherItr ) - { - originPdgID = (*motherItr)->pdg_id(); - originVert = (*motherItr)->production_vertex(); - originBarcode = (*motherItr)->barcode(); + for ( ; motherItr != motherItrEnd; ++motherItr ) { + auto mother=*motherItr; +#endif + originPdgID = mother->pdg_id(); + originVert = mother->production_vertex(); + originBarcode = HepMC::barcode(mother); } // Protect against infinite loop @@ -1441,7 +1448,7 @@ bool D2PDParticleCombiner::mcTruthSelections( const CompositeParticle* compPart ATH_MSG_WARNING ( "Stuck in an infinite while loop... breaking out!" ); break; } - } while ( abs(originPdgID) == abs(pdgID) && originVert != 0 ); + } while ( std::abs(originPdgID) == std::abs(pdgID) && originVert ); // Attach the PDG_ID and barcode of the origin particle to the vectors pdgIDList.push_back( originPdgID ); diff --git a/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenVertexFillerTool.cxx b/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenVertexFillerTool.cxx index 453e1dc2558..852510d4147 100644 --- a/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenVertexFillerTool.cxx +++ b/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenVertexFillerTool.cxx @@ -67,7 +67,7 @@ StatusCode GenVertexFillerTool::fill (const HepMC::GenVertex& p) *m_x = pos.x(); *m_y = pos.y(); *m_z = pos.z(); - *m_barcode = p.barcode(); + *m_barcode = HepMC::barcode(p); if (m_do_id) *m_id = p.id(); return StatusCode::SUCCESS; diff --git a/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/JetFullTruthTag.cxx b/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/JetFullTruthTag.cxx index 71d853c66ec..3d01e45b521 100644 --- a/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/JetFullTruthTag.cxx +++ b/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/JetFullTruthTag.cxx @@ -63,36 +63,35 @@ StatusCode JetFullTruthTag::fill (const Jet& p) // We have an McEventCollection for (McEventCollection::const_iterator currentGenEventIter = mcCollection->begin(); currentGenEventIter!=mcCollection->end(); ++currentGenEventIter) { - for (HepMC::GenEvent::particle_const_iterator currentGenParticleIter= (*currentGenEventIter)->particles_begin(); - currentGenParticleIter!= (*currentGenEventIter)->particles_end(); ++currentGenParticleIter) { + for (auto currentGenParticle: *(*currentGenEventIter)) { // Grab the PDGID, used both for partons and hadrons - pdgid = (*currentGenParticleIter)->pdg_id(); + pdgid = currentGenParticle->pdg_id(); // Parton labeling section... - if((*currentGenParticleIter)->momentum().e()>=Emax && (*currentGenParticleIter)->momentum().perp()>m_min_parton_pt){ - if( abs(pdgid)<=21 && // Should be a parton - abs(pdgid)!=6 && // Should not be a top - (abs(pdgid)==15 || abs(pdgid)<=10 || abs(pdgid)>16) && // Not a lepton - abs(pdgid)!=0){ // not an unrecognized thingy + if(currentGenParticle->momentum().e()>=Emax && currentGenParticle->momentum().perp()>m_min_parton_pt){ + if( std::abs(pdgid)<=21 && // Should be a parton + std::abs(pdgid)!=6 && // Should not be a top + (std::abs(pdgid)==15 || std::abs(pdgid)<=10 || std::abs(pdgid)>16) && // Not a lepton + std::abs(pdgid)!=0){ // not an unrecognized thingy - dR2 = std::pow( std::acos( std::cos( p.phi() - (*currentGenParticleIter)->momentum().phi() ) ) , 2 ); - dR2 += std::pow( p.eta()-(*currentGenParticleIter)->momentum().eta() , 2 ); + dR2 = std::pow( std::acos( std::cos( p.phi() - currentGenParticle->momentum().phi() ) ) , 2 ); + dR2 += std::pow( p.eta()-currentGenParticle->momentum().eta() , 2 ); if(dR2<=m_partonMatch_dr*m_partonMatch_dr){ // We have a winner - Emax=(*currentGenParticleIter)->momentum().e(); - *m_partonFlavor = (*currentGenParticleIter)->pdg_id(); + Emax=currentGenParticle->momentum().e(); + *m_partonFlavor = currentGenParticle->pdg_id(); *m_partonDR = static_cast<float> (dR2); } // Outside of dR } // Wrong PDG ID } // Low energy // Hadron labeling section - if ((HepPID::isHadron (pdgid) || abs(pdgid)==15) && ((*currentGenParticleIter)->momentum().perp()>m_min_hadron_pt)){ + if ((HepPID::isHadron (pdgid) || std::abs(pdgid)==15) && (currentGenParticle->momentum().perp()>m_min_hadron_pt)){ // Check on DR match - dR2 = std::pow( std::acos( std::cos( p.phi() - (*currentGenParticleIter)->momentum().phi() ) ) , 2 ); - dR2 += std::pow( p.eta()-(*currentGenParticleIter)->momentum().eta() , 2 ); + dR2 = std::pow( std::acos( std::cos( p.phi() - currentGenParticle->momentum().phi() ) ) , 2 ); + dR2 += std::pow( p.eta()-currentGenParticle->momentum().eta() , 2 ); if( dR2<=m_hadronMatch_dr*m_hadronMatch_dr ){ // Strict ordering bottom up - 0 -> tau -> c -> b diff --git a/PhysicsAnalysis/TruthParticleID/McParticleTools/src/SpclMcValidationTool.cxx b/PhysicsAnalysis/TruthParticleID/McParticleTools/src/SpclMcValidationTool.cxx index 2bf794a86ec..f75434c6f5d 100755 --- a/PhysicsAnalysis/TruthParticleID/McParticleTools/src/SpclMcValidationTool.cxx +++ b/PhysicsAnalysis/TruthParticleID/McParticleTools/src/SpclMcValidationTool.cxx @@ -160,7 +160,7 @@ SpclMcValidationTool::executeTool( const McEventCollection* mcEvents, const TruthParticle * mc = *itrPart; auto hepMc = mc->genParticle(); - if ( hepMc->momentum() != mc->hlv() ) { + if ( hepMc->momentum() != HepMC::FourVector(mc->hlv().x(),mc->hlv().y(),mc->hlv().z(),mc->hlv().t()) ) { ATH_MSG_ERROR("TruthParticle and GenParticle-link don't have same 4-mom !!"); return StatusCode::FAILURE; } diff --git a/Reconstruction/iPat/iPatInterfaces/iPatInterfaces/ITruthParameters.h b/Reconstruction/iPat/iPatInterfaces/iPatInterfaces/ITruthParameters.h index 234ef43245c..6581ddaab17 100755 --- a/Reconstruction/iPat/iPatInterfaces/iPatInterfaces/ITruthParameters.h +++ b/Reconstruction/iPat/iPatInterfaces/iPatInterfaces/ITruthParameters.h @@ -44,7 +44,7 @@ public: /**ITruthParameters interface: obtain PerigeeParameters corresponding to a simulated particle from a HepMC GenParticle */ - virtual const PerigeeParameters* perigeeParameters(const HepMC::GenParticle& particle, + virtual const PerigeeParameters* perigeeParameters(HepMC::ConstGenParticlePtr particle, const Amg::Vector3D& vertex) = 0; /**ITruthParameters interface: @@ -53,7 +53,7 @@ public: /**ITruthParameters interface: obtain TrackParameters corresponding to a simulated particle from a HepMC GenParticle */ - virtual const TrackParameters* trackParameters(const HepMC::GenParticle& particle) = 0; + virtual const TrackParameters* trackParameters(HepMC::ConstGenParticlePtr particle) = 0; }; #endif // IPATINTERFACES_ITRUTHPARAMETERS_H diff --git a/Reconstruction/iPat/iPatTruthTrajectory/iPatTruthTrajectory/TruthParameters.h b/Reconstruction/iPat/iPatTruthTrajectory/iPatTruthTrajectory/TruthParameters.h index 963db93f57d..2fd6367c4ce 100755 --- a/Reconstruction/iPat/iPatTruthTrajectory/iPatTruthTrajectory/TruthParameters.h +++ b/Reconstruction/iPat/iPatTruthTrajectory/iPatTruthTrajectory/TruthParameters.h @@ -10,7 +10,7 @@ #ifndef IPATTRUTHTRAJECTORY_TRUTHPARAMETERS_H #define IPATTRUTHTRAJECTORY_TRUTHPARAMETERS_H -//<<<<<< INCLUDES >>>>>> +//INCLUDES #include "AthenaBaseComps/AthAlgTool.h" #include "AtlasHepMC/GenParticle.h" @@ -20,7 +20,7 @@ #include "iPatInterfaces/ITruthParameters.h" #include "iPatTrackParameters/PerigeeParameters.h" -//<<<<<< CLASS DECLARATIONS >>>>>> +//CLASS DECLARATIONS class ITruthSelector; namespace Trk { class IIntersector; } @@ -39,14 +39,14 @@ public: StatusCode finalize(); const PerigeeParameters* perigeeParameters(int barcode, const Amg::Vector3D& vertex); - const PerigeeParameters* perigeeParameters(const HepMC::GenParticle& particle, + const PerigeeParameters* perigeeParameters(HepMC::ConstGenParticlePtr particle, const Amg::Vector3D& vertex); const TrackParameters* trackParameters(int barcode); - const TrackParameters* trackParameters(const HepMC::GenParticle& particle); + const TrackParameters* trackParameters(HepMC::ConstGenParticlePtr particle); private: - const HepMC::GenParticle* findParticle(int barcode); - void trackFromParticle(const HepMC::GenParticle& particle); + HepMC::ConstGenParticlePtr findParticle(int barcode); + void trackFromParticle(HepMC::ConstGenParticlePtr particle); // configuration: tools etc diff --git a/Reconstruction/iPat/iPatTruthTrajectory/src/TruthParameters.cxx b/Reconstruction/iPat/iPatTruthTrajectory/src/TruthParameters.cxx index 46396ea1d7f..f7f25e06724 100755 --- a/Reconstruction/iPat/iPatTruthTrajectory/src/TruthParameters.cxx +++ b/Reconstruction/iPat/iPatTruthTrajectory/src/TruthParameters.cxx @@ -7,7 +7,7 @@ particle, either from its barcode or from a HepMC GenParticle. ***************************************************************************/ -//<<<<<< INCLUDES >>>>>> +//INCLUDES #include <cmath> #include "GaudiKernel/IPartPropSvc.h" @@ -17,7 +17,7 @@ #include "GenInterfaces/ITruthSelector.h" #include "iPatTruthTrajectory/TruthParameters.h" -//<<<<<< CLASS STRUCTURE INITIALIZATION >>>>>> +//CLASS STRUCTURE INITIALIZATION TruthParameters::TruthParameters (const std::string& type, const std::string& name, @@ -39,11 +39,11 @@ TruthParameters::~TruthParameters (void) //<<<<<< PRIVATE MEMBER FUNCTION DEFINITIONS>>>>>> -const HepMC::GenParticle* +HepMC::ConstGenParticlePtr TruthParameters::findParticle (int barCode) { // protect against real data, fakes ... - const HepMC::GenParticle* particle = 0; + HepMC::ConstGenParticlePtr particle{nullptr}; if (barCode == 0) return particle; // retrieve McEventCollection (from truthSelector to give G3/4 simulation independence) @@ -56,26 +56,26 @@ TruthParameters::findParticle (int barCode) } void -TruthParameters::trackFromParticle(const HepMC::GenParticle& particle) +TruthParameters::trackFromParticle(HepMC::ConstGenParticlePtr particle) { // protect against missing production_vertex - if (! particle.production_vertex()) return; + if (! particle->production_vertex()) return; // ensure known particle m_intersection = 0; - int pdgCode = particle.pdg_id(); + int pdgCode = particle->pdg_id(); if (! m_particleDataTable->particle(std::abs(pdgCode))) return; // fill intersection, qOverP - Amg::Vector3D position( particle.production_vertex()->position().x(), - particle.production_vertex()->position().y(), - particle.production_vertex()->position().z()); - m_qOverP = 1./std::sqrt(particle.momentum().px()*particle.momentum().px() + - particle.momentum().py()*particle.momentum().py() + - particle.momentum().pz()*particle.momentum().pz()); - Amg::Vector3D direction( m_qOverP*particle.momentum().px(), - m_qOverP*particle.momentum().py(), - m_qOverP*particle.momentum().pz()); + Amg::Vector3D position( particle->production_vertex()->position().x(), + particle->production_vertex()->position().y(), + particle->production_vertex()->position().z()); + m_qOverP = 1./std::sqrt(particle->momentum().px()*particle->momentum().px() + + particle->momentum().py()*particle->momentum().py() + + particle->momentum().pz()*particle->momentum().pz()); + Amg::Vector3D direction( m_qOverP*particle->momentum().px(), + m_qOverP*particle->momentum().py(), + m_qOverP*particle->momentum().pz()); m_intersection = new Trk::TrackSurfaceIntersection(position,direction,0.); // fill trackParameters @@ -94,7 +94,7 @@ TruthParameters::trackFromParticle(const HepMC::GenParticle& particle) m_trackParameters.fill(position,cosPhi,sinPhi,sinThetaInv*cosTheta,sinThetaInv*m_qOverP); } -//<<<<<< PUBLIC MEMBER FUNCTION DEFINITIONS >>>>>> +// PUBLIC MEMBER FUNCTION DEFINITIONS StatusCode TruthParameters::initialize() @@ -143,9 +143,9 @@ TruthParameters::finalize() const PerigeeParameters* TruthParameters::perigeeParameters (int barCode, const Amg::Vector3D& vertex) { - const HepMC::GenParticle* particle = findParticle(barCode); + auto particle = findParticle(barCode); if (! particle) return 0; - trackFromParticle(*particle); + trackFromParticle(particle); if (! m_intersection) return 0; Trk::PerigeeSurface surface(vertex); @@ -181,7 +181,7 @@ TruthParameters::perigeeParameters (int barCode, const Amg::Vector3D& vertex) } const PerigeeParameters* -TruthParameters::perigeeParameters (const HepMC::GenParticle& particle, const Amg::Vector3D& vertex) +TruthParameters::perigeeParameters (HepMC::ConstGenParticlePtr particle, const Amg::Vector3D& vertex) { trackFromParticle(particle); if (! m_intersection) return 0; @@ -220,16 +220,16 @@ TruthParameters::perigeeParameters (const HepMC::GenParticle& particle, const Am const TrackParameters* TruthParameters::trackParameters (int barCode) { - const HepMC::GenParticle* particle = findParticle(barCode); + auto particle = findParticle(barCode); if (! particle) return 0; - trackFromParticle(*particle); + trackFromParticle(particle); if (! m_intersection) return 0; delete m_intersection; return &m_trackParameters; } const TrackParameters* -TruthParameters::trackParameters (const HepMC::GenParticle& particle) +TruthParameters::trackParameters (HepMC::ConstGenParticlePtr particle) { trackFromParticle(particle); if (! m_intersection) return 0; -- GitLab