diff --git a/Simulation/ISF/ISF_Fatras/ISF_FatrasRecoTools/ISF_FatrasRecoTools/PRD_PlanarTruthTrajectoryBuilder.h b/Simulation/ISF/ISF_Fatras/ISF_FatrasRecoTools/ISF_FatrasRecoTools/PRD_PlanarTruthTrajectoryBuilder.h index e8446ed274db22945a1eedec452861e89202d0a4..3c7d364d17aed3d3df58ddb6b879a4ed58c48ffe 100644 --- a/Simulation/ISF/ISF_Fatras/ISF_FatrasRecoTools/ISF_FatrasRecoTools/PRD_PlanarTruthTrajectoryBuilder.h +++ b/Simulation/ISF/ISF_Fatras/ISF_FatrasRecoTools/ISF_FatrasRecoTools/PRD_PlanarTruthTrajectoryBuilder.h @@ -59,7 +59,7 @@ namespace iFatras { StatusCode finalize(); /** return a vector of PrepRawData trajectories - uses internal cache**/ - const std::map< const HepMC::GenParticle*, Trk::PRD_TruthTrajectory >& truthTrajectories() const; + const std::vector< Trk::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(); @@ -85,6 +85,7 @@ namespace iFatras { //!< Track geantinos or not bool m_geantinos; //!< the cache for the return (cleared by Incident) + mutable std::vector< Trk::PRD_TruthTrajectory > m_prdTruthTrajectories; mutable std::map< const HepMC::GenParticle*, Trk::PRD_TruthTrajectory > m_gpPrdTruthTrajectories; }; diff --git a/Simulation/ISF/ISF_Fatras/ISF_FatrasRecoTools/src/PRD_PlanarTruthTrajectoryBuilder.cxx b/Simulation/ISF/ISF_Fatras/ISF_FatrasRecoTools/src/PRD_PlanarTruthTrajectoryBuilder.cxx index 7098d7f564a30cc6cbb796c16f07a1d742fbd2f6..4644eab89b5f000fd2cd71c3f5f107a9768a9f0a 100644 --- a/Simulation/ISF/ISF_Fatras/ISF_FatrasRecoTools/src/PRD_PlanarTruthTrajectoryBuilder.cxx +++ b/Simulation/ISF/ISF_Fatras/ISF_FatrasRecoTools/src/PRD_PlanarTruthTrajectoryBuilder.cxx @@ -73,6 +73,7 @@ StatusCode iFatras::PRD_PlanarTruthTrajectoryBuilder::refreshEvent() { ATH_MSG_VERBOSE("Calling refreshEvent() to reset cache and retrieve collections"); // clear the cache & reserve + m_prdTruthTrajectories.clear(); m_gpPrdTruthTrajectories.clear(); m_prdPlanarMultiTruthCollections.clear(); m_prdPlanarMultiTruthCollections.reserve(m_prdPlanarMultiTruthCollectionNames.size()); @@ -105,12 +106,13 @@ StatusCode iFatras::PRD_PlanarTruthTrajectoryBuilder::refreshEvent() { } -const std::map< const HepMC::GenParticle*, Trk::PRD_TruthTrajectory >& iFatras::PRD_PlanarTruthTrajectoryBuilder::truthTrajectories() const { +const std::vector< Trk::PRD_TruthTrajectory >& iFatras::PRD_PlanarTruthTrajectoryBuilder::truthTrajectories() const { // ndof size_t ndofTotal = 0; size_t ndof = 0; // PART 1 for Planar clusters-------------------------------------------------------------------------------------------------------- + std::vector<const HepMC::GenParticle*> vecGP; //vector storing the initial order of GenParticles // loop over the PRD_MultiTruthCollection, search for the PRD and create (if necessary and entry in the return map) std::vector<const PRD_MultiTruthCollection*>::const_iterator pmtPlanarCollIter = m_prdPlanarMultiTruthCollections.begin(); std::vector<const PRD_MultiTruthCollection*>::const_iterator pmtPlanarCollIterE = m_prdPlanarMultiTruthCollections.end(); @@ -149,6 +151,7 @@ const std::map< const HepMC::GenParticle*, Trk::PRD_TruthTrajectory >& iFatras:: newPrdTruthTrajectory.genParticle = curGenP; // fill into map m_gpPrdTruthTrajectories[curGenP] = newPrdTruthTrajectory; + if (std::find(vecGP.begin(),vecGP.end(),curGenP)==vecGP.end()) vecGP.push_back(curGenP); ndofTotal = ndof; } else { // this PRD_TruthTrajectory already exists @@ -162,28 +165,36 @@ const std::map< const HepMC::GenParticle*, Trk::PRD_TruthTrajectory >& iFatras:: } } + //Create the output vector of Trk::PRD_TruthTrajectory ordered like the input GenParticles + for (auto gp : vecGP) { + std::map< const HepMC::GenParticle*, Trk::PRD_TruthTrajectory >::iterator prdTrajIter = m_gpPrdTruthTrajectories.find(gp); + if ( prdTrajIter != m_gpPrdTruthTrajectories.end() ) + m_prdTruthTrajectories.push_back(prdTrajIter->second); + } + // PART 2 -------------------------------------------------------------------------------------------------------- // loop through the provided list of manipulators ( sorter is included ) - std::map< const HepMC::GenParticle*, Trk::PRD_TruthTrajectory >::iterator prdTruthTrajIter = m_gpPrdTruthTrajectories.begin(); - std::map< const HepMC::GenParticle*, Trk::PRD_TruthTrajectory >::iterator prdTruthTrajIterE = m_gpPrdTruthTrajectories.end(); + std::vector< Trk::PRD_TruthTrajectory >::iterator prdTruthTrajIter = m_prdTruthTrajectories.begin(); + std::vector< Trk::PRD_TruthTrajectory >::iterator prdTruthTrajIterE = m_prdTruthTrajectories.end(); for ( ; prdTruthTrajIter != prdTruthTrajIterE; ++prdTruthTrajIter ){ //std::cout << "sorting, barcode: " << prdTruthTrajIter->first->barcode() << std::endl; if ( m_prdTruthTrajectoryManipulators.size() ){ ToolHandleArray<Trk::IPRD_TruthTrajectoryManipulator>::const_iterator prdTTMIter = m_prdTruthTrajectoryManipulators.begin(); ToolHandleArray<Trk::IPRD_TruthTrajectoryManipulator>::const_iterator prdTTMIterE = m_prdTruthTrajectoryManipulators.end(); for ( ; prdTTMIter != prdTTMIterE; ++prdTTMIter ){ - if ((*prdTTMIter)->manipulateTruthTrajectory((*prdTruthTrajIter).second)) + if ((*prdTTMIter)->manipulateTruthTrajectory(*prdTruthTrajIter)) ATH_MSG_VERBOSE("PRD truth trajectory got manipulated by: " << (*prdTTMIter).name() ); } } } // return the truth trajectories and leave it to the TruthTrack creation to proceed further - return m_gpPrdTruthTrajectories; + return m_prdTruthTrajectories; } StatusCode iFatras::PRD_PlanarTruthTrajectoryBuilder::finalize() { // clear the cache a last time + m_prdTruthTrajectories.clear(); m_gpPrdTruthTrajectories.clear(); //m_prdPlanarMultiTruthCollections.clear(); ATH_MSG_VERBOSE("Finalizing ..."); diff --git a/Tracking/TrkTruthTracks/TrkTruthTrackAlgs/src/TruthTrackCreation.cxx b/Tracking/TrkTruthTracks/TrkTruthTrackAlgs/src/TruthTrackCreation.cxx index 3842e46fc46c5e5d47eb94e75c0ae321fd25215d..6d4615974cef921b26c65b8ce141975b06ab85bc 100644 --- a/Tracking/TrkTruthTracks/TrkTruthTrackAlgs/src/TruthTrackCreation.cxx +++ b/Tracking/TrkTruthTracks/TrkTruthTrackAlgs/src/TruthTrackCreation.cxx @@ -119,13 +119,13 @@ StatusCode Trk::TruthTrackCreation::execute() // ----------------------------------- main loop ------------------------------------------------------------------ // get the PRD truth trajectories - const std::map< const HepMC::GenParticle*, PRD_TruthTrajectory >& truthTraj = + const std::vector< PRD_TruthTrajectory >& truthTraj = m_prdTruthTrajectoryBuilder->truthTrajectories(); // some screen output ATH_MSG_VERBOSE("PRD_TruthTrajectoryBuilder delivered " << truthTraj.size() << " PRD truth trajectories, starting track creation."); // loop over truth trajectories and create track - std::map< const HepMC::GenParticle*, PRD_TruthTrajectory >::const_iterator ttIter = truthTraj.begin(); - std::map< const HepMC::GenParticle*, PRD_TruthTrajectory >::const_iterator ttIterE = truthTraj.end(); + std::vector< PRD_TruthTrajectory >::const_iterator ttIter = truthTraj.begin(); + std::vector< PRD_TruthTrajectory >::const_iterator ttIterE = truthTraj.end(); for ( ; ttIter != ttIterE; ++ttIter){ // run through the selector chain if (m_prdTruthTrajectorySelectors.size()){ @@ -133,7 +133,7 @@ StatusCode Trk::TruthTrackCreation::execute() ToolHandleArray<Trk::IPRD_TruthTrajectorySelector>::const_iterator prdTTSelIterE = m_prdTruthTrajectorySelectors.end(); bool passed = true; for ( ; prdTTSelIter != prdTTSelIterE && passed; ++prdTTSelIter ){ - if (!(*prdTTSelIter)->pass((*ttIter).second)){ + if (!(*prdTTSelIter)->pass(*ttIter)){ ATH_MSG_VERBOSE("PRD truth trajectory did not pass the selection cuts. Skipping ... "); passed = false; } @@ -142,12 +142,12 @@ StatusCode Trk::TruthTrackCreation::execute() if (!passed) continue; } // create the truth track - Trk::Track* truthTrack = m_truthTrackBuilder->createTrack(ttIter->second,outputSegmentCollection); + Trk::Track* truthTrack = m_truthTrackBuilder->createTrack(*ttIter,outputSegmentCollection); if (!truthTrack){ - ATH_MSG_VERBOSE("Track creation for PRD truth trajectory with size " << (*ttIter).second.prds.size() << " failed. Skipping ..."); + ATH_MSG_VERBOSE("Track creation for PRD truth trajectory with size " << (*ttIter).prds.size() << " failed. Skipping ..."); continue; } - ATH_MSG_VERBOSE("Track creation for PRD truth trajectory with size " << (*ttIter).second.prds.size() << " successful."); + ATH_MSG_VERBOSE("Track creation for PRD truth trajectory with size " << (*ttIter).prds.size() << " successful."); // If configured : update the track summary if (!m_trackSummaryTool.empty()){ ATH_MSG_VERBOSE("Updating the TrackSummary."); diff --git a/Tracking/TrkTruthTracks/TrkTruthTrackInterfaces/TrkTruthTrackInterfaces/IPRD_TruthTrajectoryBuilder.h b/Tracking/TrkTruthTracks/TrkTruthTrackInterfaces/TrkTruthTrackInterfaces/IPRD_TruthTrajectoryBuilder.h index e936239d168ecc74701d0435408d616dd8e63fac..ceee17c5bf53a32326bb4c2322bba9111f41fb0a 100644 --- a/Tracking/TrkTruthTracks/TrkTruthTrackInterfaces/TrkTruthTrackInterfaces/IPRD_TruthTrajectoryBuilder.h +++ b/Tracking/TrkTruthTracks/TrkTruthTrackInterfaces/TrkTruthTrackInterfaces/IPRD_TruthTrajectoryBuilder.h @@ -40,7 +40,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::vector< 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; @@ -49,4 +49,4 @@ namespace Trk { } // end of namespace -#endif // TRK_TRKTRUTHTRACKS_IPRD_TRUTHTRAJECTORYBUILDER_H \ No newline at end of file +#endif // TRK_TRKTRUTHTRACKS_IPRD_TRUTHTRAJECTORYBUILDER_H diff --git a/Tracking/TrkTruthTracks/TrkTruthTrackTools/src/PRD_TruthTrajectoryBuilder.cxx b/Tracking/TrkTruthTracks/TrkTruthTrackTools/src/PRD_TruthTrajectoryBuilder.cxx index 8446fc54011a3b2d59e53c9b1d870901a693177d..90285afd654a1b7786463334bd7bead532b3345f 100644 --- a/Tracking/TrkTruthTracks/TrkTruthTrackTools/src/PRD_TruthTrajectoryBuilder.cxx +++ b/Tracking/TrkTruthTracks/TrkTruthTrackTools/src/PRD_TruthTrajectoryBuilder.cxx @@ -75,6 +75,7 @@ StatusCode Trk::PRD_TruthTrajectoryBuilder::refreshEvent() { ATH_MSG_VERBOSE("Calling refreshEvent() to reset cache and retrieve collections"); // clear the cache & reserve + m_prdTruthTrajectories.clear(); m_gpPrdTruthTrajectories.clear(); m_prdMultiTruthCollections.clear(); m_prdMultiTruthCollections.reserve(m_prdMultiTruthCollectionNames.size()); @@ -105,11 +106,12 @@ StatusCode Trk::PRD_TruthTrajectoryBuilder::refreshEvent() { } -const std::map< const HepMC::GenParticle*, Trk::PRD_TruthTrajectory >& Trk::PRD_TruthTrajectoryBuilder::truthTrajectories() const { +const std::vector< Trk::PRD_TruthTrajectory >& Trk::PRD_TruthTrajectoryBuilder::truthTrajectories() const { // ndof size_t ndofTotal = 0; size_t ndof = 0; // PART 1 -------------------------------------------------------------------------------------------------------- + std::vector<const HepMC::GenParticle*> vecGP; //vector storing the initial order of GenParticles // loop over the PRD_MultiTruthCollection, search for the PRD and create (if necessary and entry in the return map) std::vector<const PRD_MultiTruthCollection*>::const_iterator pmtCollIter = m_prdMultiTruthCollections.begin(); std::vector<const PRD_MultiTruthCollection*>::const_iterator pmtCollIterE = m_prdMultiTruthCollections.end(); @@ -141,6 +143,7 @@ const std::map< const HepMC::GenParticle*, Trk::PRD_TruthTrajectory >& Trk::PRD_ newPrdTruthTrajectory.genParticle = curGenP; // fill into map m_gpPrdTruthTrajectories[curGenP] = newPrdTruthTrajectory; + if (std::find(vecGP.begin(),vecGP.end(),curGenP)==vecGP.end()) vecGP.push_back(curGenP); ndofTotal = ndof; } else { // this PRD_TruthTrajectory already exists @@ -153,23 +156,31 @@ const std::map< const HepMC::GenParticle*, Trk::PRD_TruthTrajectory >& Trk::PRD_ } } } + + //Create the output vector of Trk::PRD_TruthTrajectory ordered like the input GenParticles + for (auto gp : vecGP) { + std::map< const HepMC::GenParticle*, Trk::PRD_TruthTrajectory >::iterator prdTrajIter = m_gpPrdTruthTrajectories.find(gp); + if ( prdTrajIter != m_gpPrdTruthTrajectories.end() ) + m_prdTruthTrajectories.push_back(prdTrajIter->second); + } + // 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(); + std::vector< PRD_TruthTrajectory >::iterator prdTruthTrajIter = m_prdTruthTrajectories.begin(); + std::vector< PRD_TruthTrajectory >::iterator prdTruthTrajIterE = m_prdTruthTrajectories.end(); for ( ; prdTruthTrajIter != prdTruthTrajIterE; ++prdTruthTrajIter ){ //std::cout << "sorting, barcode: " << prdTruthTrajIter->first->barcode() << std::endl; if ( m_prdTruthTrajectoryManipulators.size() ){ ToolHandleArray<IPRD_TruthTrajectoryManipulator>::const_iterator prdTTMIter = m_prdTruthTrajectoryManipulators.begin(); ToolHandleArray<IPRD_TruthTrajectoryManipulator>::const_iterator prdTTMIterE = m_prdTruthTrajectoryManipulators.end(); for ( ; prdTTMIter != prdTTMIterE; ++prdTTMIter ){ - if ((*prdTTMIter)->manipulateTruthTrajectory((*prdTruthTrajIter).second)) + if ((*prdTTMIter)->manipulateTruthTrajectory(*prdTruthTrajIter)) ATH_MSG_VERBOSE("PRD truth trajectory got manipulated by: " << (*prdTTMIter).name() ); } } } // return the truth trajectories and leave it to the TruthTrack creation to proceed further - return m_gpPrdTruthTrajectories; + return m_prdTruthTrajectories; } StatusCode Trk::PRD_TruthTrajectoryBuilder::finalize() diff --git a/Tracking/TrkTruthTracks/TrkTruthTrackTools/src/PRD_TruthTrajectoryBuilder.h b/Tracking/TrkTruthTracks/TrkTruthTrackTools/src/PRD_TruthTrajectoryBuilder.h index e7caa296d457919d9f015f6cdf12d576c2362fcc..7fc823b341748ff2c88df6685050b088276f070b 100644 --- a/Tracking/TrkTruthTracks/TrkTruthTrackTools/src/PRD_TruthTrajectoryBuilder.h +++ b/Tracking/TrkTruthTracks/TrkTruthTrackTools/src/PRD_TruthTrajectoryBuilder.h @@ -55,7 +55,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::vector< 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(); @@ -73,6 +73,7 @@ namespace Trk { double m_minPt; //!< minimum pT to be even considered bool m_geantinos; //!< Track geantinos or not + mutable std::vector< PRD_TruthTrajectory > m_prdTruthTrajectories; //!< the cache for the return (cleared by Incident) mutable std::map< const HepMC::GenParticle*, PRD_TruthTrajectory > m_gpPrdTruthTrajectories; //!< the cache for the return (cleared by Incident) };