diff --git a/Tracking/TrkTools/TrkToolInterfaces/TrkToolInterfaces/ITruthToTrack.h b/Tracking/TrkTools/TrkToolInterfaces/TrkToolInterfaces/ITruthToTrack.h index ff2438d11c26c3bfb67a77c661bd0f8eba823351..2e0801ba13a2cfc9328bf94593425365eabe9026 100644 --- a/Tracking/TrkTools/TrkToolInterfaces/TrkToolInterfaces/ITruthToTrack.h +++ b/Tracking/TrkTools/TrkToolInterfaces/TrkToolInterfaces/ITruthToTrack.h @@ -51,7 +51,7 @@ namespace Trk { * object. (Wrapping it into a smart pointer may be the most * convenient way to make sure the memory is freed.) */ - virtual const Trk::TrackParameters* makeProdVertexParameters(const HepMC::GenParticle* part) const = 0; + virtual const Trk::TrackParameters* makeProdVertexParameters(HepMC::ConstGenParticlePtr part) const = 0; virtual const Trk::TrackParameters* makeProdVertexParameters(const xAOD::TruthParticle* part) const = 0; /** This function extrapolates track to the perigee, and returns @@ -61,7 +61,7 @@ namespace Trk { * operator new. The caller is responsible for deletion of the * object. */ - virtual const Trk::TrackParameters* makePerigeeParameters(const HepMC::GenParticle* part) const = 0; + virtual const Trk::TrackParameters* makePerigeeParameters(HepMC::ConstGenParticlePtr part) const = 0; virtual const Trk::TrackParameters* makePerigeeParameters(const xAOD::TruthParticle* part) const = 0; }; diff --git a/Tracking/TrkTools/TrkToolInterfaces/TrkToolInterfaces/ITruthTrajectoryBuilder.h b/Tracking/TrkTools/TrkToolInterfaces/TrkToolInterfaces/ITruthTrajectoryBuilder.h index 61e708ffe730eb9a70a435936e12d8ac139059b4..b67b81d0c43d85216fcf404bb4a09a483a980364 100644 --- a/Tracking/TrkTools/TrkToolInterfaces/TrkToolInterfaces/ITruthTrajectoryBuilder.h +++ b/Tracking/TrkTools/TrkToolInterfaces/TrkToolInterfaces/ITruthTrajectoryBuilder.h @@ -29,13 +29,13 @@ namespace Trk { /** Build a TruthTrajectory this particle belongs to. * The result may be an empty TruthTrajectory (in case input did not pass the cuts). */ - virtual void buildTruthTrajectory(TruthTrajectory *result, const HepMC::GenParticle *input) const = 0; + virtual void buildTruthTrajectory(TruthTrajectory *result, HepMC::ConstGenParticlePtr input) const = 0; /** Previous particle on the truth trajectory or 0 */ - virtual const HepMC::GenParticle *getMother(const HepMC::GenParticle *part) const = 0; + virtual HepMC::ConstGenParticlePtr getMother(HepMC::ConstGenParticlePtr part) const = 0; /** Next particle on the truth trajectory or 0 */ - virtual const HepMC::GenParticle *getDaughter(const HepMC::GenParticle *part) const = 0; + virtual HepMC::ConstGenParticlePtr getDaughter(HepMC::ConstGenParticlePtr part) const = 0; }; } // namespace Trk diff --git a/Tracking/TrkTools/TrkTruthCreatorTools/src/DecayInFlyTruthTrajectoryBuilder.cxx b/Tracking/TrkTools/TrkTruthCreatorTools/src/DecayInFlyTruthTrajectoryBuilder.cxx index 9e25de02879fa589d7d07209f5d99d36d73505c4..6752fe0d1b6a73086382770d40aaf903573d5b5a 100644 --- a/Tracking/TrkTools/TrkTruthCreatorTools/src/DecayInFlyTruthTrajectoryBuilder.cxx +++ b/Tracking/TrkTools/TrkTruthCreatorTools/src/DecayInFlyTruthTrajectoryBuilder.cxx @@ -71,34 +71,32 @@ buildTruthTrajectory(TruthTrajectory *result, HepMC::ConstGenParticlePtr input) DecayInFlyTruthTrajectoryBuilder::MotherDaughter DecayInFlyTruthTrajectoryBuilder::truthTrajectoryCuts(HepMC::ConstGenVertexPtr vtx) const { - HepMC::GenParticlePtr mother{nullptr}; - HepMC::GenParticlePtr daughter{nullptr}; - // only truth vertices with 1 incoming particle + HepMC::ConstGenParticlePtr mother{nullptr}; + HepMC::ConstGenParticlePtr daughter{nullptr}; + // only truth vertices with 1 incoming particle + // Restrict to quasi-elastic processes (e.g. brems, delta-rays, pi->pi+Delta). + // + // Require not more than 2 outgoing particles. Note that + // delta-rays for primary==electron is a special case, because we have two + // outgoing particles with the same PDG id. The "correct" one + // is that with the higher energy (NOT pt). + // + // allow 1 outgoing to cover possible vertexes from interaction in detector material #ifdef HEPMC3 - if(vtx && (vtx->particles_in().size() == 1)) { + if(vtx && (vtx->particles_in().size() == 1) && (vtx->particles_out().size() <= 2) ) { mother = vtx->particles_in().front(); #else - if(vtx && (vtx->particles_in_size() == 1)) { + if(vtx && (vtx->particles_in_size() == 1) && (vtx->particles_out_size() <= 2) ) { mother = *vtx->particles_in_const_begin(); #endif // Allow status code 1 and 2. E.g. a pion that produced a long track can decay outside of InDet and have status==2. if( mother && (mother->status() < 3) ) { - - // Restrict to quasi-elastic processes (e.g. brems, delta-rays, pi->pi+Delta). - // - // Require not more than 2 outgoing particles. Note that - // delta-rays for primary==electron is a special case, because we have two - // outgoing particles with the same PDG id. The "correct" one - // is that with the higher energy (NOT pt). - // - // allow 1 outgoing to cover possible vertexes from interaction in detector material - if (vtx->particles_out_size() <= 2) { int num_passed_cuts = 0; - HepMC::GenParticlePtr passed_cuts{nullptr}; - for(HepMC::GenParticlePtr candidate: *vtx){ + HepMC::ConstGenParticlePtr passed_cuts{nullptr}; + for(HepMC::ConstGenParticlePtr candidate: *vtx){ if(candidate->pdg_id() == mother->pdg_id()) { if(passed_cuts && (mother->pdg_id() == 11)) { // second negative electron is a special case @@ -121,8 +119,6 @@ DecayInFlyTruthTrajectoryBuilder::truthTrajectoryCuts(HepMC::ConstGenVertexPtr v if(num_passed_cuts==1) { // disallow hadronic pi->N*pi etc. daughter = passed_cuts; } - - } // if (vtx->particles_out_size() <= 2) } // if( mother && (mother->status() == 1) ) } diff --git a/Tracking/TrkTools/TrkTruthCreatorTools/src/DetailedTrackTruthBuilder.cxx b/Tracking/TrkTools/TrkTruthCreatorTools/src/DetailedTrackTruthBuilder.cxx index e560005102d3c15c47fc65608d53cfdb865f4dab..04e2724ff88ce47df8cfa86cb09da857d20beca7 100755 --- a/Tracking/TrkTools/TrkTruthCreatorTools/src/DetailedTrackTruthBuilder.cxx +++ b/Tracking/TrkTools/TrkTruthCreatorTools/src/DetailedTrackTruthBuilder.cxx @@ -165,7 +165,7 @@ buildDetailedTrackTruth(DetailedTrackTruthCollection *output, const TruthTrajectory& t = i->second.trajectory(); msg(MSG::VERBOSE)<<"Particles on the trajectory:\n"; for(unsigned k=0; k<t.size(); ++k) { - msg(MSG::VERBOSE)<<*t[k]<<"\n"; + msg(MSG::VERBOSE)<<t[k]<<"\n"; } msg(MSG::VERBOSE)<<"\n"<<endmsg; } @@ -353,12 +353,12 @@ void DetailedTrackTruthBuilder::addTrack(DetailedTrackTruthCollection *output, while(!seeds.empty()) { HepMcParticleLink link = *seeds.begin(); Sprout current_sprout; - std::queue<const HepMC::GenParticle*> tmp; + std::queue<HepMC::ConstGenParticlePtr> tmp; ExtendedEventIndex eventIndex(link, proxy); const HepMC::GenParticle *current = link.cptr(); do { - HepMcParticleLink curlink( eventIndex.makeLink(current->barcode(), proxy)); + HepMcParticleLink curlink( eventIndex.makeLink(HepMC::barcode(current), proxy)); // remove the current particle from the list of particles to consider (if it is still there) seeds.erase(curlink); @@ -410,7 +410,7 @@ void DetailedTrackTruthBuilder::addTrack(DetailedTrackTruthCollection *output, // This may add only hits that are *not* on the current track. // Thus no need to update stats track and stats common. - const HepMC::GenParticle* current = *s->second.begin(); + auto current = *s->second.begin(); while( (current = m_truthTrajBuilder->getDaughter(current)) ) { s->second.push_front(current); } diff --git a/Tracking/TrkTruthTracks/TrkTruthTrackInterfaces/TrkTruthTrackInterfaces/IPRD_TruthTrajectoryBuilder.h b/Tracking/TrkTruthTracks/TrkTruthTrackInterfaces/TrkTruthTrackInterfaces/IPRD_TruthTrajectoryBuilder.h index 309d14623515dc70d45915a2e352ff3a53dfc5f3..58365fe2213370bbc6ecbf7fcab59b5ccf588974 100644 --- a/Tracking/TrkTruthTracks/TrkTruthTrackInterfaces/TrkTruthTrackInterfaces/IPRD_TruthTrajectoryBuilder.h +++ b/Tracking/TrkTruthTracks/TrkTruthTrackInterfaces/TrkTruthTrackInterfaces/IPRD_TruthTrajectoryBuilder.h @@ -38,7 +38,7 @@ namespace Trk { static const InterfaceID& interfaceID() { return IID_IPRD_TruthTrajectoryBuilder; } /** return a vector of PrepRawData trajectories - uses internal cache**/ - virtual const std::map< const HepMC::GenParticle*, PRD_TruthTrajectory >& truthTrajectories() const = 0; + virtual const std::map< HepMC::ConstGenParticlePtr, PRD_TruthTrajectory >& truthTrajectories() const = 0; /** Event refresh - can't be an IIncident, because it has to run after PRD creation and PRD truth creation */ virtual StatusCode refreshEvent() = 0; diff --git a/Tracking/TrkTruthTracks/TrkTruthTrackInterfaces/TrkTruthTrackInterfaces/PRD_TruthTrajectory.h b/Tracking/TrkTruthTracks/TrkTruthTrackInterfaces/TrkTruthTrackInterfaces/PRD_TruthTrajectory.h index 21ff251f2e43dd3129747a08aa3ed830668a7b0f..2d3a9df02060a658c868595598f4fd0bfacf4c3e 100644 --- a/Tracking/TrkTruthTracks/TrkTruthTrackInterfaces/TrkTruthTrackInterfaces/PRD_TruthTrajectory.h +++ b/Tracking/TrkTruthTracks/TrkTruthTrackInterfaces/TrkTruthTrackInterfaces/PRD_TruthTrajectory.h @@ -28,7 +28,7 @@ namespace Trk { /** public members */ std::vector<const Trk::PrepRawData* > prds; - const HepMC::GenParticle* genParticle; + HepMC::ConstGenParticlePtr genParticle; size_t nDoF; /** defualt constructor */ @@ -39,7 +39,7 @@ namespace Trk { /** fast constructor */ PRD_TruthTrajectory( const std::vector<const Trk::PrepRawData* >& prdVec, - const HepMC::GenParticle* gP = 0, + HepMC::ConstGenParticlePtr gP = nullptr, size_t numberOfDegreesOfFreedom = 0) : prds(prdVec), genParticle(gP), diff --git a/Tracking/TrkTruthTracks/TrkTruthTrackTools/src/PRD_TruthTrajectoryBuilder.cxx b/Tracking/TrkTruthTracks/TrkTruthTrackTools/src/PRD_TruthTrajectoryBuilder.cxx index 7b60f9c4c5d8753febe9c5c73af442944d4b9255..628c472caefaa02c3d55093692e67009b69c79e7 100644 --- a/Tracking/TrkTruthTracks/TrkTruthTrackTools/src/PRD_TruthTrajectoryBuilder.cxx +++ b/Tracking/TrkTruthTracks/TrkTruthTrackTools/src/PRD_TruthTrajectoryBuilder.cxx @@ -97,7 +97,7 @@ StatusCode Trk::PRD_TruthTrajectoryBuilder::refreshEvent() { } -const std::map< const HepMC::GenParticle*, Trk::PRD_TruthTrajectory >& Trk::PRD_TruthTrajectoryBuilder::truthTrajectories() const { +const std::map<HepMC::ConstGenParticlePtr, Trk::PRD_TruthTrajectory >& Trk::PRD_TruthTrajectoryBuilder::truthTrajectories() const { // ndof size_t ndofTotal = 0; size_t ndof = 0; @@ -111,7 +111,7 @@ const std::map< const HepMC::GenParticle*, Trk::PRD_TruthTrajectory >& Trk::PRD_ PRD_MultiTruthCollection::const_iterator prdMtCIterE = (*pmtCollIter)->end(); for ( ; prdMtCIter != prdMtCIterE; ++ prdMtCIter ){ // check if entry exists and if - const HepMC::GenParticle* curGenP = (*prdMtCIter).second; + auto curGenP = (*prdMtCIter).second; Identifier curIdentifier = (*prdMtCIter).first; // apply the min pT cut if ( curGenP->momentum().perp() < m_minPt ) continue; @@ -123,7 +123,7 @@ const std::map< const HepMC::GenParticle*, Trk::PRD_TruthTrajectory >& Trk::PRD_ // stuff it into the trajectory if you found a PRD if (prd){ // try to find the entry for this GenParticle - std::map< const HepMC::GenParticle*, PRD_TruthTrajectory >::iterator prdTrajIter = m_gpPrdTruthTrajectories.find(curGenP); + auto prdTrajIter = m_gpPrdTruthTrajectories.find(curGenP); if ( prdTrajIter == m_gpPrdTruthTrajectories.end() ){ // first PRD associated to this: create PRD_TruthTrajectory object Trk::PRD_TruthTrajectory newPrdTruthTrajectory; @@ -147,8 +147,8 @@ const std::map< const HepMC::GenParticle*, Trk::PRD_TruthTrajectory >& Trk::PRD_ } // PART 2 -------------------------------------------------------------------------------------------------------- // loop through the provided list of manipulators ( sorter is included ) - std::map< const HepMC::GenParticle*, PRD_TruthTrajectory >::iterator prdTruthTrajIter = m_gpPrdTruthTrajectories.begin(); - std::map< const HepMC::GenParticle*, PRD_TruthTrajectory >::iterator prdTruthTrajIterE = m_gpPrdTruthTrajectories.end(); + auto prdTruthTrajIter = m_gpPrdTruthTrajectories.begin(); + auto prdTruthTrajIterE = m_gpPrdTruthTrajectories.end(); for ( ; prdTruthTrajIter != prdTruthTrajIterE; ++prdTruthTrajIter ){ //std::cout << "sorting, barcode: " << prdTruthTrajIter->first->barcode() << std::endl; if ( m_prdTruthTrajectoryManipulators.size() ){ diff --git a/Tracking/TrkTruthTracks/TrkTruthTrackTools/src/PRD_TruthTrajectoryBuilder.h b/Tracking/TrkTruthTracks/TrkTruthTrackTools/src/PRD_TruthTrajectoryBuilder.h index 3199d6c9ed38d7c6ef22da7037ba8be0badc7f4f..6112ea9f8370335480e1159fdd42d94f4b5d20e1 100644 --- a/Tracking/TrkTruthTracks/TrkTruthTrackTools/src/PRD_TruthTrajectoryBuilder.h +++ b/Tracking/TrkTruthTracks/TrkTruthTrackTools/src/PRD_TruthTrajectoryBuilder.h @@ -53,7 +53,7 @@ namespace Trk { StatusCode finalize(); /** return a vector of PrepRawData trajectories - uses internal cache**/ - const std::map< const HepMC::GenParticle*, PRD_TruthTrajectory >& truthTrajectories() const; + const std::map< HepMC::ConstGenParticlePtr, PRD_TruthTrajectory >& truthTrajectories() const; /** Event refresh - can't be an IIncident, because it has to run after PRD creation and PRD truth creation */ StatusCode refreshEvent(); @@ -71,7 +71,7 @@ namespace Trk { Gaudi::Property<double> m_minPt {this,"MinimumPt",400.,"minimum pT to be even considered"}; Gaudi::Property<bool> m_geantinos {this,"Geantinos",false,"Track geantinos or not"}; - mutable std::map< const HepMC::GenParticle*, PRD_TruthTrajectory > m_gpPrdTruthTrajectories; //!< the cache for the return (cleared by Incident) + mutable std::map< HepMC::ConstGenParticlePtr, PRD_TruthTrajectory > m_gpPrdTruthTrajectories; //!< the cache for the return (cleared by Incident) }; diff --git a/Tracking/TrkTruthTracks/TrkTruthTrackTools/src/TruthTrackBuilder.cxx b/Tracking/TrkTruthTracks/TrkTruthTrackTools/src/TruthTrackBuilder.cxx index 1940d483abe38acde00dfa9fac5bbdf5ed0def2d..bda9841b728f682f5bd609f57985ca033fcab1db 100644 --- a/Tracking/TrkTruthTracks/TrkTruthTrackTools/src/TruthTrackBuilder.cxx +++ b/Tracking/TrkTruthTracks/TrkTruthTrackTools/src/TruthTrackBuilder.cxx @@ -130,7 +130,7 @@ Trk::Track* Trk::TruthTrackBuilder::createTrack(const PRD_TruthTrajectory& prdTr ATH_MSG_VERBOSE("The PRD Truth trajectory contains " << prdTraj.prds.size() << " PRDs."); // get the associated GenParticle - const HepMC::GenParticle* genPart = prdTraj.genParticle; + auto genPart = prdTraj.genParticle; if (!genPart) { ATH_MSG_WARNING("No GenParticle associated to this PRD_TruthTrajectory. Ignoring track creation."); return 0; diff --git a/Tracking/TrkValidation/TrkValAlgs/TrkValAlgs/TrackValidationNtupleWriter.h b/Tracking/TrkValidation/TrkValAlgs/TrkValAlgs/TrackValidationNtupleWriter.h index b5fe26995e4d217a39997ba7531c8584abfe75c0..98e06ad91b6e7c9d0bc09fea08d34bfe6a6b2c50 100644 --- a/Tracking/TrkValidation/TrkValAlgs/TrkValAlgs/TrackValidationNtupleWriter.h +++ b/Tracking/TrkValidation/TrkValAlgs/TrkValAlgs/TrackValidationNtupleWriter.h @@ -96,7 +96,7 @@ protected: bool m_doTruth; //!< Switch to turn on / off truth bool m_doTrackParticle; //! Switch to turn on/pff recording track particle trees into Ntuple - const HepMC::GenParticle* m_visibleParticleWithoutTruth; //!< cludge to treat G4's "fake fakes" + HepMC::GenParticlePtr m_visibleParticleWithoutTruth; //!< cludge to treat G4's "fake fakes" std::vector<unsigned int> m_nTrackTreeRecords; std::vector<TTree*> m_trees; //!< Pointer to the NTuple trees (one for each input track collection) TTree* m_eventLinkTree; //!< pointer to event-wise ntuple trees (one for all input track collections + truth) diff --git a/Tracking/TrkValidation/TrkValAlgs/src/RecMomentumQualityValidation.cxx b/Tracking/TrkValidation/TrkValAlgs/src/RecMomentumQualityValidation.cxx index 6b6d9248f5e57bb4e1b122ba8f078fe6b1438938..9e37c70845e06b7bed5f0c87947a3954c6bf2e8f 100644 --- a/Tracking/TrkValidation/TrkValAlgs/src/RecMomentumQualityValidation.cxx +++ b/Tracking/TrkValidation/TrkValAlgs/src/RecMomentumQualityValidation.cxx @@ -135,7 +135,7 @@ StatusCode Trk::RecMomentumQualityValidation::execute() // find matching truth particle const TrackTruth* trackTruth = 0; - const HepMC::GenParticle* genParticle = 0; + HepMC::ConstGenParticlePtr genParticle{nullptr}; TrackTruthCollection::const_iterator truthIterator = trackTruthCollection->find( trackIterator - (*trackCollection).begin() ); if ( truthIterator == trackTruthCollection->end() ){ diff --git a/Tracking/TrkValidation/TrkValAlgs/src/TrackValidationNtupleWriter.cxx b/Tracking/TrkValidation/TrkValAlgs/src/TrackValidationNtupleWriter.cxx index d24e097589807a0d3a9daac874f4d3879ceb6f05..7ebe04335e8ef9c62bcd553ed5aee2ffe5f405af 100644 --- a/Tracking/TrkValidation/TrkValAlgs/src/TrackValidationNtupleWriter.cxx +++ b/Tracking/TrkValidation/TrkValAlgs/src/TrackValidationNtupleWriter.cxx @@ -219,7 +219,7 @@ StatusCode Trk::TrackValidationNtupleWriter::initialize() { sc = m_truthNtupleTool->initBranches(m_trackTruthClassifiers, include_jets, m_inputTrackCollection); if (sc.isFailure()) return sc; - m_visibleParticleWithoutTruth = new HepMC::GenParticle(HepLorentzVector(), 0); + m_visibleParticleWithoutTruth = HepMC::newGenParticlePtr(HepMC::FourVector(), 0); } // if truth is activated @@ -332,7 +332,7 @@ StatusCode Trk::TrackValidationNtupleWriter::execute() { unsigned int nTruthTreeRecordsAtCurrentEvent = 0; std::vector<Trk::ValidationTrackTruthData> truthData; - std::vector<const HepMC::GenParticle*>* selecParticles = 0; + std::vector<HepMC::ConstGenParticlePtr>* selecParticles = nullptr; //std::vector<const Trk::TrackParameters*> extrapolatedTruthPerigees; //std::vector<std::vector<unsigned int> > classifications; std::vector< Trk::GenParticleJet >* genParticleJets = 0; @@ -377,7 +377,7 @@ StatusCode Trk::TrackValidationNtupleWriter::execute() { if ( genParticle->production_vertex() ) { generatedTrackPerigee = m_truthToTrack->makePerigeeParameters( genParticle ); - if (generatedTrackPerigee == NULL && genParticle->barcode() > 1000000 ) { + if (generatedTrackPerigee == NULL && HepMC::barcode(genParticle) > 1000000 ) { ATH_MSG_DEBUG ("No perigee available for interacting truth particle." <<" -> This is OK for particles from the TrackRecord, but probably" <<" a bug for production vertex particles."); @@ -389,7 +389,7 @@ StatusCode Trk::TrackValidationNtupleWriter::execute() { partData.classifications.reserve(m_trackTruthClassifiers.size()); for (unsigned int toolIndex = 0 ; toolIndex < m_trackTruthClassifiers.size(); ++toolIndex ) { - partData.classifications.push_back(m_trackTruthClassifiers[toolIndex]->classify(*genParticle)); + partData.classifications.push_back(m_trackTruthClassifiers[toolIndex]->classify(genParticle)); } // resize the truth to track vectors to the number of input track collections: partData.truthToTrackIndices.resize(m_inputTrackCollection.size()); @@ -594,7 +594,7 @@ StatusCode Trk::TrackValidationNtupleWriter::writeTrackData(unsigned int trackCo if (m_doTruth){ // find matching truth particle const TrackTruth* trackTruth = 0; - const HepMC::GenParticle* genParticle = 0; + HepMC::ConstGenParticlePtr genParticle{nullptr}; TrackTruthCollection::const_iterator truthIterator = trackTruthCollection->find( trackIterator - (*tracks).begin() ); if ( truthIterator == trackTruthCollection->end() ){ ATH_MSG_DEBUG ("No matching truth particle found for track"); diff --git a/Tracking/TrkValidation/TrkValInterfaces/TrkValInterfaces/IGenParticleJetFinder.h b/Tracking/TrkValidation/TrkValInterfaces/TrkValInterfaces/IGenParticleJetFinder.h index fde30d484a15d4eae8a98ffd6076812fb75f75a6..b16a3ab46f3cd913d025816a6b43ca4a7d291c06 100644 --- a/Tracking/TrkValidation/TrkValInterfaces/TrkValInterfaces/IGenParticleJetFinder.h +++ b/Tracking/TrkValidation/TrkValInterfaces/TrkValInterfaces/IGenParticleJetFinder.h @@ -47,7 +47,7 @@ class IGenParticleJetFinder : virtual public IAlgTool { This method is a factory, i.e. vector ownership is given back and on failure condition returns NULL. */ virtual std::vector< Trk::GenParticleJet >* jetMCFinder - (std::vector <const HepMC::GenParticle *>& ) const=0; + (std::vector <HepMC::ConstGenParticlePtr>& ) const=0; }; diff --git a/Tracking/TrkValidation/TrkValInterfaces/TrkValInterfaces/IGenParticleSelector.h b/Tracking/TrkValidation/TrkValInterfaces/TrkValInterfaces/IGenParticleSelector.h index 0e58912b073fef1eaf5768fab0b5e74f0144cf9e..ac8d6b138ee49476ea77a7ee7a8f76f287db502b 100644 --- a/Tracking/TrkValidation/TrkValInterfaces/TrkValInterfaces/IGenParticleSelector.h +++ b/Tracking/TrkValidation/TrkValInterfaces/TrkValInterfaces/IGenParticleSelector.h @@ -33,7 +33,7 @@ class IGenParticleSelector : virtual public IAlgTool { static const InterfaceID& interfaceID(); /** explain */ - virtual std::vector<const HepMC::GenParticle *>* + virtual std::vector<HepMC::ConstGenParticlePtr>* selectGenSignal (const McEventCollection*) const=0; }; diff --git a/Tracking/TrkValidation/TrkValInterfaces/TrkValInterfaces/ITrackTruthClassifier.h b/Tracking/TrkValidation/TrkValInterfaces/TrkValInterfaces/ITrackTruthClassifier.h index 56af45805d4908631248bcf821940a35cc15f72e..c557707b4470598e37cbd1be70f552b56d4d0b07 100644 --- a/Tracking/TrkValidation/TrkValInterfaces/TrkValInterfaces/ITrackTruthClassifier.h +++ b/Tracking/TrkValidation/TrkValInterfaces/TrkValInterfaces/ITrackTruthClassifier.h @@ -33,9 +33,9 @@ class ITrackTruthClassifier : virtual public IAlgTool { /** explain */ virtual void initClassification(const McEventCollection&, - const std::vector<const HepMC::GenParticle *>*) const=0; + const std::vector<HepMC::ConstGenParticlePtr>*) const=0; - virtual unsigned int classify(const HepMC::GenParticle&) const = 0; + virtual unsigned int classify(HepMC::ConstGenParticlePtr) const = 0; virtual std::string nameOfClassifier() const = 0; diff --git a/Tracking/TrkValidation/TrkValTools/TrkValTools/PrimaryTruthClassifier.h b/Tracking/TrkValidation/TrkValTools/TrkValTools/PrimaryTruthClassifier.h index 496e2a09b8d731a26b207b1bac57f719ce27d894..c3eaf26f51fe65482bef104106a649cd2bcb0271 100644 --- a/Tracking/TrkValidation/TrkValTools/TrkValTools/PrimaryTruthClassifier.h +++ b/Tracking/TrkValidation/TrkValTools/TrkValTools/PrimaryTruthClassifier.h @@ -18,6 +18,7 @@ #include "TrkValEvent/TruthClassificationDefs.h" #include "AtlasHepMC/GenParticle.h" +#include "AtlasHepMC/SimpleVector.h" namespace Trk { @@ -40,9 +41,9 @@ namespace Trk { /** explain */ virtual void initClassification(const McEventCollection&, - const std::vector<const HepMC::GenParticle *>*) const; + const std::vector<HepMC::ConstGenParticlePtr>*) const; - virtual unsigned int classify(const HepMC::GenParticle&) const; + virtual unsigned int classify(HepMC::ConstGenParticlePtr) const; virtual std::string nameOfClassifier() const; diff --git a/Tracking/TrkValidation/TrkValTools/src/PrimaryTruthClassifier.cxx b/Tracking/TrkValidation/TrkValTools/src/PrimaryTruthClassifier.cxx index bd344c64e57067554318fcfd02eb0fcffc5a2dae..01c8f65d5657651eef274a69af00fb87f0d0351e 100644 --- a/Tracking/TrkValidation/TrkValTools/src/PrimaryTruthClassifier.cxx +++ b/Tracking/TrkValidation/TrkValTools/src/PrimaryTruthClassifier.cxx @@ -53,7 +53,7 @@ StatusCode Trk::PrimaryTruthClassifier::finalize() { void Trk::PrimaryTruthClassifier::initClassification (const McEventCollection& /*SimTracks*/, - const std::vector<const HepMC::GenParticle *>* /*genSignal*/) const { + const std::vector<HepMC::ConstGenParticlePtr>* /*genSignal*/) const { // nothing to prepare as local data at start of collection analysis return; @@ -62,7 +62,7 @@ void Trk::PrimaryTruthClassifier::initClassification ////////////////////////////////////////// // classification from InDetRecStatistics ////////////////////////////////////////// -unsigned int Trk::PrimaryTruthClassifier::classify(const HepMC::GenParticle& genParticle) const { +unsigned int Trk::PrimaryTruthClassifier::classify(HepMC::ConstGenParticlePtr genParticle) const { /* note on using HepMC::FourVector/3Vector against HepGeom::Point3D<double>: The versions from HepMC2 do not know @@ -74,17 +74,17 @@ unsigned int Trk::PrimaryTruthClassifier::classify(const HepMC::GenParticle& gen bool secondary=false; bool truncated=false; - if (genParticle.production_vertex()) { - HepMC::FourVector startVertex = genParticle.production_vertex()->position(); + if (genParticle->production_vertex()) { + HepMC::FourVector startVertex = genParticle->production_vertex()->position(); // primary vertex inside innermost layer? if ( fabs(startVertex.perp()) < m_maxRStartPrimary && fabs(startVertex.z()) < m_maxZStartPrimary) { - if (genParticle.end_vertex() == 0) { + if (genParticle->end_vertex() == 0) { primary=true; } else { - HepMC::FourVector endVertex = genParticle.end_vertex()->position(); + HepMC::FourVector endVertex = genParticle->end_vertex()->position(); if ( endVertex.perp() > m_minREndPrimary || fabs(startVertex.z()) > m_minZEndPrimary) primary=true; else truncated = true; @@ -93,10 +93,10 @@ unsigned int Trk::PrimaryTruthClassifier::classify(const HepMC::GenParticle& gen else if ( startVertex.perp() < m_maxRStartSecondary && fabs(startVertex.z()) < m_maxZStartSecondary) { - if (genParticle.end_vertex() == 0) { + if (genParticle->end_vertex() == 0) { secondary=true; } else { - HepMC::FourVector endVertex = genParticle.end_vertex()->position(); + HepMC::FourVector endVertex = genParticle->end_vertex()->position(); if (endVertex.perp() > m_minREndSecondary || fabs(endVertex.z()) > m_minZEndSecondary) { secondary=true; @@ -108,8 +108,7 @@ unsigned int Trk::PrimaryTruthClassifier::classify(const HepMC::GenParticle& gen if (truncated) return Trk::TruthClassification::Truncated; if (secondary) return Trk::TruthClassification::Secondary; if (primary) return Trk::TruthClassification::Primary; - ATH_MSG_DEBUG ( "Could not classify this particle: " - << genParticle ); + ATH_MSG_DEBUG ( "Could not classify this particle: " << genParticle ); return Trk::TruthClassification::OutsideClassification; } diff --git a/Tracking/TrkValidation/TrkVertexFitterValidationUtils/src/TrkPriVxPurityTool.cxx b/Tracking/TrkValidation/TrkVertexFitterValidationUtils/src/TrkPriVxPurityTool.cxx index b0effec98c423cf4b5e65be44ff9108ef912bbe8..9a9d2eb64510eb8f5ecc197099a56e8900f46d8e 100755 --- a/Tracking/TrkValidation/TrkVertexFitterValidationUtils/src/TrkPriVxPurityTool.cxx +++ b/Tracking/TrkValidation/TrkVertexFitterValidationUtils/src/TrkPriVxPurityTool.cxx @@ -79,36 +79,47 @@ namespace Trk { //getting the signal event itself McEventCollection::const_iterator it = mcCollection->begin(); const HepMC::GenEvent* genEvent= ( *it ); +#ifdef HEPMC3 + if( genEvent->vertices().empty() ) { + ATH_MSG_DEBUG( "No vertices found in first GenEvent" ); + return 0; + } + auto pv = genEvent->vertices()[0]; +#else // std::cout<<"The ID of the first event of the collection: "<<genEvent->event_number()<<std::endl; if( genEvent->vertices_empty() ) { ATH_MSG_DEBUG( "No vertices found in first GenEvent" ); return 0; } + auto pv = *(genEvent->vertices_begin()); +#endif //analysing the MC event to create PV candidate //first finding the vertex of primary pp interaction - HepMC::GenEvent::vertex_const_iterator pv = genEvent->vertices_begin(); //and storing its position - CLHEP::HepLorentzVector pv_pos ( ( *pv )->position().x(), - ( *pv )->position().y(), - ( *pv )->position().z(), - ( *pv )->position().t() ); + CLHEP::HepLorentzVector pv_pos ( pv ->position().x(), + pv ->position().y(), + pv ->position().z(), + pv ->position().t() ); double pv_r = pv_pos.perp(); double pv_z = pv_pos.z(); // storing all the ids of vertices reasonably close to the primary one. // here the region of interest is selected. - std::map<int,HepMC::GenVertex *> vertex_ids; - - for ( HepMC::GenEvent::vertex_const_iterator i = genEvent->vertices_begin(); - i != genEvent->vertices_end() ;++i ) { - CLHEP::HepLorentzVector lv_pos ( ( *i )->position().x(), - ( *i )->position().y(), - ( *i )->position().z(), - ( *i )->position().t() ); - if ( fabs ( lv_pos.perp() - pv_r ) <m_r_tol && fabs ( lv_pos.z() - pv_z ) <m_z_tol ) { - vertex_ids[ ( *i )->barcode() ]= ( *i ); + std::map<int,HepMC::ConstGenVertexPtr> vertex_ids; +#ifdef HEPMC3 + for (auto vtx: genEvent->vertices()){ +#else + for ( HepMC::GenEvent::vertex_const_iterator i = genEvent->vertices_begin(); i != genEvent->vertices_end() ;++i ) { + auto vtx=*i; +#endif + CLHEP::HepLorentzVector lv_pos ( vtx->position().x(), + vtx->position().y(), + vtx->position().z(), + vtx->position().t() ); + if ( std::abs ( lv_pos.perp() - pv_r ) <m_r_tol && std::abs ( lv_pos.z() - pv_z ) <m_z_tol ) { + vertex_ids[ HepMC::barcode(vtx) ]= vtx; }//end of accepted vertices check }//end of loop over all the vertices @@ -128,7 +139,6 @@ namespace Trk { //looping over the tracks to find those matched to the GenParticle originating from signal PV std::vector<Trk::VxTrackAtVertex *>::const_iterator vt = tracks->begin(); std::vector<Trk::VxTrackAtVertex *>::const_iterator ve = tracks->end(); -// unsigned int total_size = 0; unsigned int n_failed = 0; std::vector<double> in_weights ( 0 ); std::vector<double> out_weights ( 0 ); @@ -147,7 +157,6 @@ namespace Trk { // get to the original track particle LinkToTrackParticleBase * tr_part = dynamic_cast< LinkToTrackParticleBase * > ( origLink ); if ( tr_part !=0 && tr_part->isValid()) { -// ++total_size; std::map< Rec::TrackParticleTruthKey, TrackParticleTruth>::const_iterator ttItr = trackParticleTruthCollection->end(); @@ -166,22 +175,22 @@ namespace Trk { if (ttItr != trackParticleTruthCollection->end() ) { const HepMcParticleLink& particleLink = ttItr->second.particleLink(); - const HepMC::GenParticle* genParticle = particleLink.cptr(); + HepMC::ConstGenParticlePtr genParticle = particleLink.cptr(); - if(genParticle !=0) { - HepMC::GenEvent * tpEvent = genParticle->parent_event(); + if(genParticle) { + auto tpEvent = genParticle->parent_event(); if(tpEvent==genEvent) { - const HepMC::GenVertex * pVertex(0); - if (genParticle!=0) pVertex = genParticle->production_vertex(); - if ( pVertex != 0 ) { + HepMC::ConstGenVertexPtr pVertex{nullptr}; + if (genParticle) pVertex = genParticle->production_vertex(); + if ( pVertex) { int link_pid = genParticle->pdg_id(); bool primary_track = false; bool secondary_track = false; //loop over the particles until decision is really taken do { - int tvrt_code = pVertex->barcode(); - std::map<int, HepMC::GenVertex *>::const_iterator idf_res = vertex_ids.find ( tvrt_code ); + int tvrt_code = HepMC::barcode(pVertex); + auto idf_res = vertex_ids.find ( tvrt_code ); //for the HepMcParticle Link, the signal event has an index 0. // tagging on it @@ -193,11 +202,19 @@ namespace Trk { //this vertex is not from the central region. //checking whether it is a bremsstrahlung //if so, propagating track to its origin, otherwise rejecting it completely. +#ifdef HEPMC3 + if ( pVertex->particles_in().size() == 1 ) { +#else if ( pVertex->particles_in_size() == 1 ) { +#endif // one mother particle: is it a brem of some kind? - HepMC::GenVertex::particles_in_const_iterator inp = pVertex->particles_in_const_begin() ; - HepMC::GenVertex * tmpVertex_loc = ( *inp )->production_vertex(); - if ( ( *inp )->pdg_id() == link_pid && tmpVertex_loc) { +#ifdef HEPMC3 + auto inp = pVertex->particles_in()[0] ; +#else + auto inp =*(pVertex->particles_in_const_begin()) ; +#endif + auto tmpVertex_loc = inp ->production_vertex(); + if ( inp ->pdg_id() == link_pid && tmpVertex_loc) { // seems like a brem (this can be generator/simulation dependent unfortunately) // continue iterating pVertex = tmpVertex_loc;