diff --git a/Tracking/TrkValidation/TrkValTools/src/InDetPrimaryConversionSelector.cxx b/Tracking/TrkValidation/TrkValTools/src/InDetPrimaryConversionSelector.cxx index 26e8b3a1552558fc7751a711ca8e6d207bc82371..768c58a4fc206996182bb356d0e63b2a750b7a2d 100644 --- a/Tracking/TrkValidation/TrkValTools/src/InDetPrimaryConversionSelector.cxx +++ b/Tracking/TrkValidation/TrkValTools/src/InDetPrimaryConversionSelector.cxx @@ -59,61 +59,61 @@ StatusCode Trk::InDetPrimaryConversionSelector::finalize() { return StatusCode::SUCCESS; } -std::vector<const HepMC::GenParticle*>* +std::vector<HepMC::ConstGenParticlePtr>* Trk::InDetPrimaryConversionSelector::selectGenSignal (const McEventCollection* SimTracks) const { if (! SimTracks) return NULL; - std::vector<const HepMC::GenParticle *>* genSignal = - new std::vector<const HepMC::GenParticle *>; - + std::vector<HepMC::ConstGenParticlePtr>* genSignal = + new std::vector<HepMC::ConstGenParticlePtr>; // pile-up: vector of MCEC has more than one entry DataVector<HepMC::GenEvent>::const_iterator itCollision = SimTracks->begin(); for( ; itCollision != SimTracks->end(); ++itCollision ) { const HepMC::GenEvent* genEvent = *itCollision; - HepMC::GenParticle * particle = NULL; - for (HepMC::GenEvent::particle_const_iterator it = genEvent->particles_begin(); - it != genEvent->particles_end(); ++it) { - - particle = *it; + for (auto particle: *genEvent) { // 1) require stable particle from generation or simulation if ((particle->status()%1000) != 1 ) continue; - if(particle->production_vertex() == NULL) { + if(!particle->production_vertex()) { ATH_MSG_WARNING ("GenParticle without production vertex - simulation corrupt? "); - ATH_MSG_DEBUG ("It's this one: " << *particle); + ATH_MSG_DEBUG ("It's this one: " << particle); continue; } else { // 2) require track inside ID - relaxed definition including decays of neutrals (secondaries) - if ( fabs(particle->production_vertex()->position().perp()) > m_maxRStartAll || - fabs(particle->production_vertex()->position().z()) > m_maxZStartAll ) continue; + if ( std::fabs(particle->production_vertex()->position().perp()) > m_maxRStartAll || + std::fabs(particle->production_vertex()->position().z()) > m_maxZStartAll ) continue; int pdgCode = particle->pdg_id(); - if (abs(pdgCode) > 1000000000 ) continue; // ignore nuclei from hadronic interactions + if (std::abs(pdgCode) > 1000000000 ) continue; // ignore nuclei from hadronic interactions const HepPDT::ParticleData* pd = m_particleDataTable->particle(abs(pdgCode)); if (!pd) { // nuclei excluded, still problems with a given type? - ATH_MSG_INFO ("Could not get particle data for particle with pdgCode="<<pdgCode<< ", status=" << particle->status() << ", barcode=" << particle->barcode()); - ATH_MSG_INFO ("GenParticle= " << *particle); + ATH_MSG_INFO ("Could not get particle data for particle with pdgCode="<<pdgCode<< ", status=" << particle->status() << ", barcode=" << HepMC::barcode(particle)); + ATH_MSG_INFO ("GenParticle= " << particle); continue; } - ATH_MSG_DEBUG ("found particle = " << *particle); + ATH_MSG_DEBUG ("found particle = " << particle); // assume for the moment we're only running over single gamma MC files ... - HepMC::GenVertex* prodVertex( particle->production_vertex()); - if ( abs(pdgCode) == 11 ) { + auto prodVertex = particle->production_vertex(); + if ( std::abs(pdgCode) == 11 ) { ATH_MSG_DEBUG ("Electron/Positron detected -- checking for production process ..."); - HepMC::GenVertex::particles_in_const_iterator inParticle = prodVertex->particles_in_const_begin(); - HepMC::GenVertex::particles_out_const_iterator inParticleEnd = prodVertex->particles_in_const_end(); - for ( ; inParticle != inParticleEnd; ++inParticle) { - ATH_MSG_DEBUG(" --> checking morther: " << *(*inParticle) ); - if ( abs((*inParticle)->pdg_id()) == 22 || abs((*inParticle)->pdg_id()) == 11 ){ - if (fabs(particle->momentum().perp()) > m_minPt && fabs(particle->momentum().pseudoRapidity()) < m_maxEta ) { +#ifdef HEPMC3 + for ( auto inParticle: prodVertex->particles_in()) { +#else + HepMC::GenVertex::particles_in_const_iterator ItinParticle = prodVertex->particles_in_const_begin(); + HepMC::GenVertex::particles_out_const_iterator ItinParticleEnd = prodVertex->particles_in_const_end(); + for ( ; ItinParticle != ItinParticleEnd; ++ItinParticle) { + auto inParticle=*ItinParticle; +#endif + ATH_MSG_DEBUG(" --> checking morther: " << inParticle ); + if ( std::abs(inParticle->pdg_id()) == 22 || std::abs(inParticle->pdg_id()) == 11 ){ + if (std::fabs(particle->momentum().perp()) > m_minPt && std::fabs(particle->momentum().pseudoRapidity()) < m_maxEta ) { genSignal->push_back(particle); ATH_MSG_DEBUG ("Selected this electron/positron!"); break; diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisUtils/TrigInDetAnalysisUtils/TrigTrackSelector.h b/Trigger/TrigAnalysis/TrigInDetAnalysisUtils/TrigInDetAnalysisUtils/TrigTrackSelector.h index 09a6a6f20557963f5d378a0e1746aadf5a11addf..422a582703ea0e734c3124b71f1a145500a88f72 100644 --- a/Trigger/TrigAnalysis/TrigInDetAnalysisUtils/TrigInDetAnalysisUtils/TrigTrackSelector.h +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisUtils/TrigInDetAnalysisUtils/TrigTrackSelector.h @@ -104,7 +104,7 @@ public: void selectTracks( const xAOD::TruthParticleContainer* truthtracks ); - bool selectTrack( const HepMC::GenParticle* track ); + bool selectTrack( HepMC::ConstGenParticlePtr track ); // add a TruthParticle @@ -117,7 +117,7 @@ public: // make a TIDA::Track from a GenParticle - TIDA::Track* makeTrack( const HepMC::GenParticle* track ); + TIDA::Track* makeTrack( HepMC::ConstGenParticlePtr track ); // make a TIDA::Track from a TruthParticle TIDA::Track* makeTrack( const TruthParticle* track, unsigned long tid=0 ); diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisUtils/src/TrigTrackSelector.cxx b/Trigger/TrigAnalysis/TrigInDetAnalysisUtils/src/TrigTrackSelector.cxx index 66c02cad6d9fd84ba62811330911ba4cd2db9db4..450b0d6cd62b1f12d34065cc527f8825780d3dd1 100644 --- a/Trigger/TrigAnalysis/TrigInDetAnalysisUtils/src/TrigTrackSelector.cxx +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisUtils/src/TrigTrackSelector.cxx @@ -298,13 +298,18 @@ void TrigTrackSelector::selectTracks( const xAOD::TruthParticleContainer* trutht // add a TruthParticle from a GenParticle - easy, bet it doesn't work -bool TrigTrackSelector::selectTrack( const HepMC::GenParticle* track ) { +bool TrigTrackSelector::selectTrack( HepMC::ConstGenParticlePtr track ) { /// not a "final state" particle if ( track->status() != 1 ) return false; /// set this so can use it as the identifier - don't forget to reset!! +//AV Using memory to get some value is not a good idea. This is not a repruducible/portable way, but I leave it as is. +#ifdef HEPMC3 + m_id = (unsigned long)(track.get()); +#else m_id = (unsigned long)track; +#endif bool sel; sel = selectTrack( TruthParticle(track) ); m_id = 0; @@ -476,8 +481,13 @@ bool TrigTrackSelector::selectTrack( const xAOD::TruthParticle* track ) { // make a TIDA::Track from a GenParticle -TIDA::Track* TrigTrackSelector::makeTrack( const HepMC::GenParticle* track ) { +TIDA::Track* TrigTrackSelector::makeTrack(HepMC::ConstGenParticlePtr track ) { +//AV Using memory to get some value is not a good idea. This is not a repruducible/portable way, but I leave it as is. +#ifdef HEPMC3 + unsigned long id = (unsigned long)(track.get()); +#else unsigned long id = (unsigned long)track; +#endif TruthParticle t = TruthParticle(track); return makeTrack( &t, id ); } diff --git a/graphics/VP1/VP1Systems/VP1TrackSystems/VP1TrackSystems/AscObj_TruthPoint.h b/graphics/VP1/VP1Systems/VP1TrackSystems/VP1TrackSystems/AscObj_TruthPoint.h index c18c7be39ab4dc00bc6f296b97e8499dbd191031..7d75aa7e58dd6e08fa89abc91c152d8ebc97a803 100644 --- a/graphics/VP1/VP1Systems/VP1TrackSystems/VP1TrackSystems/AscObj_TruthPoint.h +++ b/graphics/VP1/VP1Systems/VP1TrackSystems/VP1TrackSystems/AscObj_TruthPoint.h @@ -27,7 +27,7 @@ class SimHitHandleBase; class AscObj_TruthPoint : public AssociatedObjectHandleBase { public: - AscObj_TruthPoint( TrackHandleBase*, const HepMC::GenVertex * v, const HepMC::GenParticle * p ); + AscObj_TruthPoint( TrackHandleBase*, HepMC::ConstGenVertexPtr v, HepMC::ConstGenParticlePtr p ); AscObj_TruthPoint( TrackHandleBase*, SimHitHandleBase* ); virtual ~AscObj_TruthPoint(); diff --git a/graphics/VP1/VP1Systems/VP1TrackSystems/src/AscObj_TruthPoint.cxx b/graphics/VP1/VP1Systems/VP1TrackSystems/src/AscObj_TruthPoint.cxx index 9372689c3f0e830631a87c6b71c1c861fe5f06e6..04d581cbed4c2063f00211779d2684cd9e581787 100644 --- a/graphics/VP1/VP1Systems/VP1TrackSystems/src/AscObj_TruthPoint.cxx +++ b/graphics/VP1/VP1Systems/VP1TrackSystems/src/AscObj_TruthPoint.cxx @@ -36,18 +36,18 @@ //____________________________________________________________________ class AscObj_TruthPoint::Imp { public: - Imp(const HepMC::GenVertex * v, const HepMC::GenParticle * p) - : genVertex(v), genParticle(p), simhit(0) {} + Imp(HepMC::ConstGenVertexPtr v, HepMC::ConstGenParticlePtr p) + : genVertex(v), genParticle(p), simhit(nullptr) {} Imp(SimHitHandleBase*s) - : genVertex(0), genParticle(0), simhit(s) {} - const HepMC::GenVertex * genVertex; - const HepMC::GenParticle * genParticle; + : genVertex(nullptr), genParticle(nullptr), simhit(s) {} + HepMC::ConstGenVertexPtr genVertex; + HepMC::ConstGenParticlePtr genParticle; SimHitHandleBase * simhit; }; //____________________________________________________________________ -AscObj_TruthPoint::AscObj_TruthPoint(TrackHandleBase*th, const HepMC::GenVertex * v, const HepMC::GenParticle * p) +AscObj_TruthPoint::AscObj_TruthPoint(TrackHandleBase*th, HepMC::ConstGenVertexPtr v, HepMC::ConstGenParticlePtr p) : AssociatedObjectHandleBase(th), m_d(new Imp(v,p)) { } diff --git a/graphics/VP1/VP1Systems/VP1TrackSystems/src/TrackHandle_TruthTrack.cxx b/graphics/VP1/VP1Systems/VP1TrackSystems/src/TrackHandle_TruthTrack.cxx index 1416ea225bfa6a2666bdbfa46b18d5c0e4cc0b3d..0ba886b7445136788bd8b261d8de251e8bb1b238 100644 --- a/graphics/VP1/VP1Systems/VP1TrackSystems/src/TrackHandle_TruthTrack.cxx +++ b/graphics/VP1/VP1Systems/VP1TrackSystems/src/TrackHandle_TruthTrack.cxx @@ -28,18 +28,18 @@ class TrackHandle_TruthTrack::Imp { public: Imp(TrackHandle_TruthTrack * tc, - const SimBarCode& sbc,const SimHitList& shl,const HepMC::GenParticle* p) + const SimBarCode& sbc,const SimHitList& shl,HepMC::ConstGenParticlePtr p) : theclass(tc), simBarCode(sbc), simHitList(shl), genParticle(p), ascObjVis(false), ascObjs(0), - trkTrack(0) {} + trkTrack(nullptr) {} TrackHandle_TruthTrack * theclass; SimBarCode simBarCode; SimHitList simHitList; - const HepMC::GenParticle* genParticle; + HepMC::ConstGenParticlePtr genParticle; bool ascObjVis; std::vector<AscObj_TruthPoint*> * ascObjs; @@ -47,11 +47,11 @@ public: const Trk::Track * trkTrack; void ensureInitTrkTracks(); - static Trk::Perigee * createTrkPerigeeFromProdVertex(const HepMC::GenParticle * p, const double& charge ) + static Trk::Perigee * createTrkPerigeeFromProdVertex(HepMC::ConstGenParticlePtr p, const double& charge ) { if (!p) return 0;//Fixme: message! - const HepMC::GenVertex * v = p->production_vertex(); + auto v = p->production_vertex(); if (!v) return 0;//Fixme: message! Amg::Vector3D mom(p->momentum().px(),p->momentum().py(),p->momentum().pz()); @@ -62,11 +62,11 @@ public: return new Trk::Perigee(0.,0.,mom.phi(), mom.theta(), charge/absmom, pos); } - static Trk::TrackParameters * createTrkParamFromDecayVertex(const HepMC::GenParticle * p, const double& charge ) + static Trk::TrackParameters * createTrkParamFromDecayVertex(HepMC::ConstGenParticlePtr p, const double& charge ) { if (!p) return 0;//Fixme: message! - const HepMC::GenVertex * v = p->end_vertex(); + auto v = p->end_vertex(); if (!v) return 0;//Fixme: message! Amg::Vector3D mom(p->momentum().px(),p->momentum().py(),p->momentum().pz()); @@ -125,7 +125,7 @@ public: TrackHandle_TruthTrack::TrackHandle_TruthTrack( TrackCollHandleBase* ch, const SimBarCode& simBarCode, const SimHitList& simHitList, - const HepMC::GenParticle* genPart ) + HepMC::ConstGenParticlePtr genPart ) : TrackHandleBase(ch), m_d(new Imp(this,simBarCode,simHitList,genPart)) { if (VP1Msg::verbose()) { @@ -262,7 +262,7 @@ bool TrackHandle_TruthTrack::hasVertexAtIR(const double& rmaxsq, const double& z { if (!m_d->genParticle) return false; - const HepMC::GenVertex * v = m_d->genParticle->production_vertex(); + auto v = m_d->genParticle->production_vertex(); if (!v) return false; @@ -308,8 +308,12 @@ void TrackHandle_TruthTrack::Imp::ensureInitAscObjs() if (ascObjs) return; ascObjs = new std::vector<AscObj_TruthPoint*>; - const HepMC::GenVertex * vprod = genParticle ? genParticle->production_vertex() : 0; - const HepMC::GenVertex * vend = genParticle ? genParticle->end_vertex() : 0; + HepMC::ConstGenVertexPtr vprod{nullptr}; + HepMC::ConstGenVertexPtr vend{nullptr}; + if (genParticle) { + vprod=genParticle->production_vertex(); + vend=genParticle->end_vertex(); + } ascObjs->reserve((vprod?1:0)+(vend?1:simHitList.size())); if (vprod) ascObjs->push_back(new AscObj_TruthPoint(theclass,vprod,genParticle));