diff --git a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Interfaces/ISF_HepMC_Interfaces/IGenParticleFilter.h b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Interfaces/ISF_HepMC_Interfaces/IGenParticleFilter.h index a982785281580ae4db0a0837817e3c4ffcc9cae6..ef30901c0889be01d4a901763cf28b8ff6342f09 100644 --- a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Interfaces/ISF_HepMC_Interfaces/IGenParticleFilter.h +++ b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Interfaces/ISF_HepMC_Interfaces/IGenParticleFilter.h @@ -37,8 +37,13 @@ namespace ISF { /// Creates the InterfaceID and interfaceID() method DeclareInterfaceID(IGenParticleFilter, 1, 0); +#ifdef HEPMC3 + /** Returns a boolean if the particle has passed or not */ + virtual bool pass(HepMC::ConstGenParticlePtr particle) const = 0; +#else /** Returns a boolean if the particle has passed or not */ virtual bool pass(const HepMC::GenParticle& particle) const = 0; +#endif }; diff --git a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleFinalStateFilter.cxx b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleFinalStateFilter.cxx index 7ce0aa81d86ca7ba0ba4b21994e8bc12cc0f5334..954e498d03e153e8f970955ef8ed8c5048259db1 100644 --- a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleFinalStateFilter.cxx +++ b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleFinalStateFilter.cxx @@ -39,6 +39,17 @@ StatusCode ISF::GenParticleFinalStateFilter::initialize() /** returns true if the the particle is considered stable */ +#ifdef HEPMC3 +bool ISF::GenParticleFinalStateFilter::pass(HepMC::ConstGenParticlePtr particle) const +{ + bool passFilter = true; + passFilter &= isFinalState(particle); + passFilter &= (!m_checkGenSimStable) || MC::isSimStable(particle); + passFilter &= (!m_checkGenInteracting) || MC::isSimInteracting(particle); + return passFilter; +} + +#else bool ISF::GenParticleFinalStateFilter::pass(const HepMC::GenParticle& particle) const { bool passFilter = true; @@ -48,6 +59,7 @@ bool ISF::GenParticleFinalStateFilter::pass(const HepMC::GenParticle& particle) return passFilter; } +#endif StatusCode ISF::GenParticleFinalStateFilter::finalize() @@ -57,9 +69,18 @@ StatusCode ISF::GenParticleFinalStateFilter::finalize() } /** checks if the particle is in its final state (no end vertex) */ +#ifdef HEPMC3 +bool ISF::GenParticleFinalStateFilter::isFinalState(HepMC::ConstGenParticlePtr p) const { + // particle is in its final state if both: + // * no end_vertex + // * status==1 + return ( !p->end_vertex() && p->status()==1 ); +} +#else bool ISF::GenParticleFinalStateFilter::isFinalState(const HepMC::GenParticle &p) const { // particle is in its final state if both: // * no end_vertex // * status==1 return ( !p.end_vertex() && p.status()==1 ); } +#endif diff --git a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleFinalStateFilter.h b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleFinalStateFilter.h index 1e6e3dceb61d493ac4a4d48a138e224568724e02..b00e661f55ac82284557c1bbe9d1575687149045 100644 --- a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleFinalStateFilter.h +++ b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleFinalStateFilter.h @@ -42,12 +42,21 @@ namespace ISF { StatusCode initialize(); StatusCode finalize(); +#ifdef HEPMC3 + /** Returns the Particle Stack, should register truth */ + bool pass(HepMC::ConstGenParticlePtr particle) const; + private: + /** checks if the particle is in its final state (no end vertex) */ + bool isFinalState( HepMC::ConstGenParticlePtr p) const; +#else + /** Returns the Particle Stack, should register truth */ bool pass(const HepMC::GenParticle& particle) const; private: /** checks if the particle is in its final state (no end vertex) */ bool isFinalState( const HepMC::GenParticle& p) const; +#endif bool m_checkGenSimStable; //!< boolean switch to check on sim stable bool m_checkGenInteracting; //!< boolean switch to check on gen interacting diff --git a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleGenericFilter.cxx b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleGenericFilter.cxx index f4a54d5845c4ca7d9078e81d47da90a3a465a8ab..efee0b2b74bbc92fdc02c9532837fd07a173a282 100644 --- a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleGenericFilter.cxx +++ b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleGenericFilter.cxx @@ -81,17 +81,29 @@ StatusCode ISF::GenParticleGenericFilter::finalize() /** Returns whether the given particle passes all cuts or not */ +#ifdef HEPMC3 +bool ISF::GenParticleGenericFilter::pass(HepMC::ConstGenParticlePtr particle) const +#else bool ISF::GenParticleGenericFilter::pass(const HepMC::GenParticle& particle) const +#endif { bool pass = true; +#ifdef HEPMC3 + HepMC::ConstGenVertexPtr productionVertex = particle->production_vertex(); +#else HepMC::ConstGenVertexPtr productionVertex = particle.production_vertex(); +#endif const auto* position = productionVertex ? &productionVertex->position() : nullptr; if (!position || position->perp()<=m_maxApplicableRadius) { pass = check_cuts_passed(particle); } +#ifdef HEPMC3 + const auto& momentum = particle->momentum(); +#else const auto& momentum = particle.momentum(); +#endif ATH_MSG_VERBOSE( "GenParticle '" << particle << "' with " << (position ? "pos: r=" + std::to_string(position->perp()) : "") << ", mom: eta=" << momentum.eta() << " phi=" << momentum.phi() @@ -102,12 +114,18 @@ bool ISF::GenParticleGenericFilter::pass(const HepMC::GenParticle& particle) con /** Check whether the given particle passes all configure cuts or not */ +#ifdef HEPMC3 +bool ISF::GenParticleGenericFilter::check_cuts_passed(HepMC::ConstGenParticlePtr particle) const { + const auto momentum = particle->momentum(); + int pdg = particle->pdg_id(); +#else bool ISF::GenParticleGenericFilter::check_cuts_passed(const HepMC::GenParticle &particle) const { const auto& momentum = particle.momentum(); + int pdg = particle.pdg_id(); +#endif double mom = std::sqrt(momentum.x()*momentum.x()+momentum.y()*momentum.y()+momentum.z()*momentum.z()); double eta = momentum.eta(); double phi = momentum.phi(); - int pdg = particle.pdg_id(); // check the particle pdg code if( m_pdgs.size() && std::find(std::begin(m_pdgs), std::end(m_pdgs), pdg) == std::end(m_pdgs) ) { diff --git a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleGenericFilter.h b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleGenericFilter.h index b4c7129bcac638e5e794fe3ae6f0f250b26032a6..ed77e642c0e77e2ea7f4ce9a7276609a7ae7a16c 100644 --- a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleGenericFilter.h +++ b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleGenericFilter.h @@ -52,11 +52,19 @@ typedef std::vector<int> PDGCodes; StatusCode finalize(); /// Interface method that returns whether the given particle passes all cuts or not +#ifdef HEPMC3 + bool pass(HepMC::ConstGenParticlePtr particle) const; +#else bool pass(const HepMC::GenParticle& particle) const; +#endif private: /// Check whether the given particle passes all configure cuts or not +#ifdef HEPMC3 + bool check_cuts_passed(HepMC::ConstGenParticlePtr particle) const; +#else bool check_cuts_passed(const HepMC::GenParticle& particle) const; +#endif /// the cuts defined by the use double m_minEta; //!< min pseudorapidity cut diff --git a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleInteractingFilter.cxx b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleInteractingFilter.cxx index dbf3eff7450518947215361baa8f25e2e23b0dd5..c5d93d002fd25b912d1562ce5ec5bf743be0e6a0 100644 --- a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleInteractingFilter.cxx +++ b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleInteractingFilter.cxx @@ -11,6 +11,7 @@ // HepMC includes #include "AtlasHepMC/GenParticle.h" +#include "AtlasHepMC/Flow.h" // Helper function #include "TruthUtils/HepMCHelpers.h" @@ -67,6 +68,19 @@ StatusCode ISF::GenParticleInteractingFilter::initialize() } /** passes through to the private version of the filter */ +#ifdef HEPMC3 +bool ISF::GenParticleInteractingFilter::pass(HepMC::ConstGenParticlePtr particle) const +{ + const int pdg_id = particle->pdg_id(); + const bool isInteracting = find(m_additionalInteractingParticleTypes.begin(), + m_additionalInteractingParticleTypes.end(), + pdg_id) != m_additionalInteractingParticleTypes.end(); + const bool isNonInteracting = find(m_additionalNonInteractingParticleTypes.begin(), + m_additionalNonInteractingParticleTypes.end(), + pdg_id) != m_additionalNonInteractingParticleTypes.end(); + return !(MC::isNonInteracting( particle ) || isNonInteracting) || isInteracting; +} +#else bool ISF::GenParticleInteractingFilter::pass(const HepMC::GenParticle& particle) const { const int& pdg_id = particle.pdg_id(); @@ -78,4 +92,5 @@ bool ISF::GenParticleInteractingFilter::pass(const HepMC::GenParticle& particle) pdg_id) != m_additionalNonInteractingParticleTypes.end(); return !(MC::isNonInteracting( &particle ) || isNonInteracting) || isInteracting; } +#endif diff --git a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleInteractingFilter.h b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleInteractingFilter.h index 97f0011043c85df66ccbcbabcbe3737547953f16..ea2f829f04770bedbc1074b1a1fa818f95676012 100644 --- a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleInteractingFilter.h +++ b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleInteractingFilter.h @@ -18,6 +18,7 @@ // STL includes #include <string> +#include "AtlasHepMC/GenParticle.h" namespace ISF { class ISFParticle; @@ -40,9 +41,14 @@ namespace ISF { /** Framework methods */ virtual StatusCode initialize() override; +#ifdef HEPMC3 + /** passes through to the private version */ + virtual bool pass(HepMC::ConstGenParticlePtr particle ) const override; +#else /** passes through to the private version */ virtual bool pass(const HepMC::GenParticle& particle ) const override; +#endif /** Additional PDG codes to classify as interacting */ std::vector<int> m_additionalInteractingParticleTypes; diff --git a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleLifetimeFilter.cxx b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleLifetimeFilter.cxx index dd4edc16bdb1fb559a6aad539a3f5d2087d2ec3c..10891c17de6a4ccf1e8c73f869677f40c3d69611 100644 --- a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleLifetimeFilter.cxx +++ b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleLifetimeFilter.cxx @@ -27,10 +27,18 @@ ISF::GenParticleLifetimeFilter::GenParticleLifetimeFilter( const std::string& t, /** does the given particle pass the filter? */ +#ifdef HEPMC3 +bool ISF::GenParticleLifetimeFilter::pass(HepMC::ConstGenParticlePtr particle) const +#else bool ISF::GenParticleLifetimeFilter::pass(const HepMC::GenParticle& particle) const +#endif { // the GenParticle end vertex +#ifdef HEPMC3 + auto endVtx = particle->end_vertex(); +#else auto endVtx = particle.end_vertex(); +#endif // no production vertex? if (!endVtx) { ATH_MSG_DEBUG("GenParticle does not have an end vertex, this is fine"); @@ -40,7 +48,11 @@ bool ISF::GenParticleLifetimeFilter::pass(const HepMC::GenParticle& particle) co const auto& end4Vec = endVtx->position(); // the GenParticle production vertex +#ifdef HEPMC3 + auto prodVtx = particle->production_vertex(); +#else auto prodVtx = particle.production_vertex(); +#endif // no production vertex? if (!prodVtx) { ATH_MSG_DEBUG("GenParticle does not have a production vertex, filtering it out"); diff --git a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleLifetimeFilter.h b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleLifetimeFilter.h index f5629f8adde5119f4db87219932a1a8d47362f4b..b434bb8c10d976a97dcf8a07e98a2c47a459ec16 100644 --- a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleLifetimeFilter.h +++ b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleLifetimeFilter.h @@ -34,7 +34,11 @@ namespace ISF { ~GenParticleLifetimeFilter(){} /** does the given particle pass the filter? */ +#ifdef HEPMC3 + bool pass(HepMC::ConstGenParticlePtr particle) const; +#else bool pass(const HepMC::GenParticle& particle) const; +#endif private: double m_minLifetime{0.000001}; //units of c*ns diff --git a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticlePositionFilter.cxx b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticlePositionFilter.cxx index 597933ec224e891d99c7fe75bb8bc64755828033..33031f1e66d1d7c4a2f81428e299483298e8785b 100644 --- a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticlePositionFilter.cxx +++ b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticlePositionFilter.cxx @@ -12,6 +12,7 @@ // HepMC includes #include "AtlasHepMC/GenParticle.h" #include "AtlasHepMC/GenVertex.h" +#include "AtlasHepMC/SimpleVector.h" /** Constructor **/ ISF::GenParticlePositionFilter::GenParticlePositionFilter( const std::string& t, @@ -48,10 +49,17 @@ StatusCode ISF::GenParticlePositionFilter::initialize() /** does the given particle pass the filter? */ +#ifdef HEPMC3 +bool ISF::GenParticlePositionFilter::pass(HepMC::ConstGenParticlePtr particle) const +{ + // the GenParticle production vertex + auto vtx = particle->production_vertex(); +#else bool ISF::GenParticlePositionFilter::pass(const HepMC::GenParticle& particle) const { // the GenParticle production vertex HepMC::GenVertexPtr vtx = particle.production_vertex(); +#endif // no production vertex? if (!vtx) { diff --git a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticlePositionFilter.h b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticlePositionFilter.h index 18b0c3201542fab123b18be0dc50150b42fd8818..8bbe7b4c06228ec50d71d71e122a56e39facde4c 100644 --- a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticlePositionFilter.h +++ b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticlePositionFilter.h @@ -45,7 +45,11 @@ namespace ISF { StatusCode finalize(); /** does the given particle pass the filter? */ +#ifdef HEPMC3 + bool pass(HepMC::ConstGenParticlePtr particle) const; +#else bool pass(const HepMC::GenParticle& particle) const; +#endif private: ServiceHandle<IGeoIDSvc> m_geoIDSvc; diff --git a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleSimWhiteList.cxx b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleSimWhiteList.cxx index c4fefcb3daf6369f5a2641e073cd7c9a61cdc0e0..dcffa77c2c0c17d36803f7abff92f52f8e433721 100644 --- a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleSimWhiteList.cxx +++ b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleSimWhiteList.cxx @@ -72,6 +72,33 @@ StatusCode ISF::GenParticleSimWhiteList::initialize() } /** passes through to the private version of the filter */ +#ifdef HEPMC3 +bool ISF::GenParticleSimWhiteList::pass(HepMC::ConstGenParticlePtr particle) const +{ + + ATH_MSG_VERBOSE( "Checking whether " << particle << " passes the filter." ); + + static std::vector<int> vertices(500); + vertices.clear(); + bool so_far_so_good = pass( particle , vertices ); + + // Test all parent particles + if (so_far_so_good && particle->production_vertex() && m_qs){ + for (auto pit: particle->production_vertex()->particles_in()){ + // Loop breaker + if ( HepMC::barcode(pit) == HepMC::barcode(particle) ) continue; + // Check this particle + vertices.clear(); + bool parent_all_clear = pass( pit , vertices ); + ATH_MSG_VERBOSE( "Parent all clear: " << parent_all_clear << + "\nIf true, will not pass the daughter because it should have been picked up through the parent already (to avoid multi-counting)." ); + so_far_so_good = so_far_so_good && !parent_all_clear; + } // Loop over parents + } // particle had parents + + return so_far_so_good; +} +#else bool ISF::GenParticleSimWhiteList::pass(const HepMC::GenParticle& particle) const { @@ -98,8 +125,42 @@ bool ISF::GenParticleSimWhiteList::pass(const HepMC::GenParticle& particle) cons return so_far_so_good; } +#endif /** returns true if the the particle and all daughters are on the white list */ +#ifdef HEPMC3 +bool ISF::GenParticleSimWhiteList::pass(HepMC::ConstGenParticlePtr particle , std::vector<int> & used_vertices ) const +{ + // See if the particle is in the white list + bool passFilter = std::binary_search( m_pdgId.begin() , m_pdgId.end() , particle->pdg_id() ) || MC::PID::isNucleus( particle->pdg_id() ); + // Remove documentation particles + passFilter = passFilter && particle->status()<3; + // Test all daughter particles + if (particle->end_vertex() && m_qs && passFilter){ + // Break loops + if ( std::find( used_vertices.begin() , used_vertices.end() , HepMC::barcode(particle->end_vertex()) )==used_vertices.end() ){ + used_vertices.push_back( HepMC::barcode(particle->end_vertex()) ); + for (auto pit: particle->end_vertex()->particles_out()){ + passFilter = passFilter && pass( pit , used_vertices ); + if (!passFilter) { + ATH_MSG_VERBOSE( "Daughter particle " << pit << " does not pass." ); + break; + } + } // Loop over daughters + } // Break loops + } // particle had daughters + else if (!particle->end_vertex() && !passFilter && particle->status()<3) { // no daughters... No end vertex... Check if this isn't trouble + ATH_MSG_ERROR( "Found a particle with no end vertex that does not appear in the white list." ); + ATH_MSG_ERROR( "This is VERY likely pointing to a problem with either the configuration you "); + ATH_MSG_ERROR( "are using, or a bug in the generator. Either way it should be fixed. The"); + ATH_MSG_ERROR( "particle will come next, and then we will throw."); + ATH_MSG_ERROR( particle ); + throw; + } + + return passFilter; +} +#else bool ISF::GenParticleSimWhiteList::pass(const HepMC::GenParticle& particle , std::vector<int> & used_vertices ) const { // See if the particle is in the white list @@ -132,6 +193,7 @@ bool ISF::GenParticleSimWhiteList::pass(const HepMC::GenParticle& particle , std return passFilter; } +#endif StatusCode ISF::GenParticleSimWhiteList::finalize() { diff --git a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleSimWhiteList.h b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleSimWhiteList.h index bcd25eebef1da8bf59e7b2571b9a84810a3919a0..9dd60edc95a351016f5ef48c895030660a558002 100644 --- a/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleSimWhiteList.h +++ b/Simulation/ISF/ISF_HepMC/ISF_HepMC_Tools/src/GenParticleSimWhiteList.h @@ -19,6 +19,7 @@ #include <string> #include <vector> +#include "AtlasHepMC/GenParticle.h" namespace ISF { class ISFParticle; @@ -44,11 +45,19 @@ namespace ISF { StatusCode finalize(); /** passes through to the private version */ +#ifdef HEPMC3 + bool pass(HepMC::ConstGenParticlePtr particle ) const; +#else bool pass(const HepMC::GenParticle& particle ) const; +#endif private: /** returns true if the the particle and all daughters are on the white list */ +#ifdef HEPMC3 + bool pass(HepMC::ConstGenParticlePtr particle , std::vector<int> & used_vertices ) const; +#else bool pass(const HepMC::GenParticle& particle , std::vector<int> & used_vertices ) const; +#endif std::vector<std::string> m_whiteLists; //!< The location of the white lists std::vector<long int> m_pdgId; //!< Allowed PDG IDs bool m_qs; //!< Switch for quasi-stable particle simulation