From a5611104c71f628bfcc18f55aca1ae6ac962fa52 Mon Sep 17 00:00:00 2001 From: John Chapman <John.Chapman@cern.ch> Date: Mon, 24 Mar 2025 10:16:35 +0100 Subject: [PATCH] TruthUtils: Tidy up helper functions to identify non-standard generator defined PDG ID values --- .../xAOD/xAODTruth/Root/TruthParticle_v1.cxx | 2 +- .../xAODTruth/versions/TruthParticle_v1.h | 2 +- Generators/TruthUtils/TruthUtils/AtlasPID.h | 22 +++++++++++-------- Generators/TruthUtils/share/AtlasPIDTest.ref | 2 +- Generators/TruthUtils/test/listPDGIDs.cxx | 4 ++-- Generators/TruthUtils/test/pdgInfo.cxx | 4 ++-- Generators/TruthUtils/test/testPIDs.cxx | 4 ++-- 7 files changed, 22 insertions(+), 18 deletions(-) diff --git a/Event/xAOD/xAODTruth/Root/TruthParticle_v1.cxx b/Event/xAOD/xAODTruth/Root/TruthParticle_v1.cxx index 5bcf5c77aab..7a69aaf4278 100644 --- a/Event/xAOD/xAODTruth/Root/TruthParticle_v1.cxx +++ b/Event/xAOD/xAODTruth/Root/TruthParticle_v1.cxx @@ -308,7 +308,7 @@ namespace xAOD { MC_PID_HELPER( bool, isZ ) MC_PID_HELPER( bool, isHiggs ) MC_PID_HELPER( bool, isResonance ) - MC_PID_HELPER( bool, isGenSpecific ) + MC_PID_HELPER( bool, isGenInternal ) MC_PID_HELPER( bool, isBSM ) // Forget about this macro: diff --git a/Event/xAOD/xAODTruth/xAODTruth/versions/TruthParticle_v1.h b/Event/xAOD/xAODTruth/xAODTruth/versions/TruthParticle_v1.h index 2b5e6752e8b..e1859ed3212 100644 --- a/Event/xAOD/xAODTruth/xAODTruth/versions/TruthParticle_v1.h +++ b/Event/xAOD/xAODTruth/xAODTruth/versions/TruthParticle_v1.h @@ -302,7 +302,7 @@ namespace xAOD { /// Check if this particle is a resonant state bool isResonance() const; /// Check if this is a generator specific (non-physical) particle - bool isGenSpecific() const; + bool isGenInternal() const; /// Check if this is a BSM particle bool isBSM() const; /// Check if this is generator stable particle diff --git a/Generators/TruthUtils/TruthUtils/AtlasPID.h b/Generators/TruthUtils/TruthUtils/AtlasPID.h index eb74b1a7118..f68c5d15431 100644 --- a/Generators/TruthUtils/TruthUtils/AtlasPID.h +++ b/Generators/TruthUtils/TruthUtils/AtlasPID.h @@ -371,14 +371,18 @@ template<class T> inline bool isResonance(const T& p) { return isZ(p) || isW(p) template<class T> inline bool isLeptoQuark(const T& p){return isLeptoQuark(p->pdg_id());} template<> inline bool isLeptoQuark(const int& p){ return std::abs(p) == LEPTOQUARK; } -template<class T> inline bool isPythia8Specific(const T& p){return isPythia8Specific(p->pdg_id());} -template<> inline bool isPythia8Specific(const DecodedPID& p){ return (p.ndigits() == 7 && p(0) == 9 && p(1) == 9);} -template<> inline bool isPythia8Specific(const int& p){ auto value_digits = DecodedPID(p); return isPythia8Specific(value_digits);} +/// PDG rule 12: +/// Occasionally program authors add their own states. To avoid +/// confusion, these should be flagged by setting nn_r = 99. +/// APID: Noting that Pythia8 often defines PDG IDs in this range. +template<class T> inline bool isGeneratorDefined(const T& p){return isGeneratorDefined(p->pdg_id());} +template<> inline bool isGeneratorDefined(const DecodedPID& p){ return (p.ndigits() == 7 && p(0) == 9 && p(1) == 9);} +template<> inline bool isGeneratorDefined(const int& p){ auto value_digits = DecodedPID(p); return isGeneratorDefined(value_digits);} /// Main Table /// for MC internal use 81–100,901–930,998-999,1901–1930,2901–2930, and 3901–3930 -template<class T> inline bool isGenSpecific(const T& p){return isGenSpecific(p->pdg_id());} -template<> inline bool isGenSpecific(const int& p){ +template<class T> inline bool isGenInternal(const T& p){return isGenInternal(p->pdg_id());} +template<> inline bool isGenInternal(const int& p){ if (p >= 81 && p <= 100) return true; if (p >= 901 && p <= 930) return true; if (p >= 998 && p <= 999) return true; @@ -408,7 +412,7 @@ template<> inline bool isGlueball(const int& p) { auto value_digits = DecodedPI /// occurs, such as between the winos and charged Higgsinos to give charginos, or between left and right sfermions, the /// lighter physical state is given the smaller basis state number. template<class T> inline bool isSUSY(const T& p){return isSUSY(p->pdg_id());} -template<> inline bool isSUSY(const DecodedPID& p){return (p.ndigits() == 7 && (p(0) == 1 || p(0) == 2) && !isGenSpecific(p.shift(2).pid()));} +template<> inline bool isSUSY(const DecodedPID& p){return (p.ndigits() == 7 && (p(0) == 1 || p(0) == 2) && !isGenInternal(p.shift(2).pid()));} template<> inline bool isSUSY(const int& p){ auto value_digits = DecodedPID(p); return isSUSY(value_digits);} @@ -794,11 +798,11 @@ template<> inline bool isTransportable(const int& p){ auto value_digits = Decode template<class T> inline bool isValid(const T& p){return isValid(p->pdg_id());} template<> inline bool isValid(const DecodedPID& p){ return p.pid() !=0 && ( isQuark(p) || isLepton(p) || isBoson(p) || isGlueball(p) || - isTrajectory(p.pid()) || isGenSpecific(p.pid()) || isDiquark(p) || + isTrajectory(p.pid()) || isGenInternal(p.pid()) || isDiquark(p) || isBSM(p) || isHadron(p) || isNucleus(p) || isGeantino(p.pid()) || - isPythia8Specific(p) ); } + isGeneratorDefined(p) ); } template<> inline bool isValid(const int& p){ if (!p) return false; if (std::abs(p) < 42) return true; - if (isGenSpecific(p)) return true; + if (isGenInternal(p)) return true; auto value_digits = DecodedPID(p); return isValid(value_digits); } diff --git a/Generators/TruthUtils/share/AtlasPIDTest.ref b/Generators/TruthUtils/share/AtlasPIDTest.ref index 161c8efc8a4..bbef1260238 100644 --- a/Generators/TruthUtils/share/AtlasPIDTest.ref +++ b/Generators/TruthUtils/share/AtlasPIDTest.ref @@ -480,4 +480,4 @@ 1000100200 20 60 10 30 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 10 1 0 30 1000822080 208 624 82 246 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 82 1 0 246 1000922350 235 705 92 276 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 92 1 0 276 -PDG_ID baryonNumber baryonNumber3 charge charge3 hasBottom hasCharm hasStrange hasTop isBBbarMeson isBSM isBaryon isBoson isBottom isBottomBaryon isBottomHadron isBottomMeson isCCbarMeson isChLepton isCharged isCharm isCharmBaryon isCharmHadron isCharmMeson isDM isDiquark isEMInteracting isElectron isExcited isGaugino isGeantino isGenSpecific isGenericMultichargedParticle isGlueball isGluon isGraviton isHadron isHeavyBaryon isHeavyHadron isHeavyMeson isHiddenValley isHiggs isKK isLeptoQuark isLepton isLightBaryon isLightHadron isLightMeson isMeson isMonopole isMuon isNeutral isNeutrino isNucleus isParton isPentaquark isPhoton isPythia8Specific isQuark isRBaryon isRGlueball isRHadron isRMeson isResonance isSlepton isSleptonLH isSleptonRH isSMLepton isSMNeutrino isSUSY isSquark isSquarkLH isSquarkRH isStrange isStrangeBaryon isStrangeHadron isStrangeMeson isStrongInteracting isTau isTechnicolor isTetraquark isTop isTopBaryon isTopHadron isTopMeson isTrajectory isTransportable isValid isW isWeaklyDecayingBHadron isWeaklyDecayingCHadron isZ leadingQuark numberOfLambdas numberOfProtons spin2 strangeness threeCharge +PDG_ID baryonNumber baryonNumber3 charge charge3 hasBottom hasCharm hasStrange hasTop isBBbarMeson isBSM isBaryon isBoson isBottom isBottomBaryon isBottomHadron isBottomMeson isCCbarMeson isChLepton isCharged isCharm isCharmBaryon isCharmHadron isCharmMeson isDM isDiquark isEMInteracting isElectron isExcited isGaugino isGeantino isGenInternal isGenericMultichargedParticle isGlueball isGluon isGraviton isHadron isHeavyBaryon isHeavyHadron isHeavyMeson isHiddenValley isHiggs isKK isLeptoQuark isLepton isLightBaryon isLightHadron isLightMeson isMeson isMonopole isMuon isNeutral isNeutrino isNucleus isParton isPentaquark isPhoton isGeneratorDefined isQuark isRBaryon isRGlueball isRHadron isRMeson isResonance isSlepton isSleptonLH isSleptonRH isSMLepton isSMNeutrino isSUSY isSquark isSquarkLH isSquarkRH isStrange isStrangeBaryon isStrangeHadron isStrangeMeson isStrongInteracting isTau isTechnicolor isTetraquark isTop isTopBaryon isTopHadron isTopMeson isTrajectory isTransportable isValid isW isWeaklyDecayingBHadron isWeaklyDecayingCHadron isZ leadingQuark numberOfLambdas numberOfProtons spin2 strangeness threeCharge diff --git a/Generators/TruthUtils/test/listPDGIDs.cxx b/Generators/TruthUtils/test/listPDGIDs.cxx index dab6fab8bcf..3815b43f942 100644 --- a/Generators/TruthUtils/test/listPDGIDs.cxx +++ b/Generators/TruthUtils/test/listPDGIDs.cxx @@ -52,7 +52,7 @@ int main(int argc, char** argv) { TEST_FUNCTION(isExcited) TEST_FUNCTION(isGaugino) TEST_FUNCTION(isGeantino) - TEST_FUNCTION(isGenSpecific) + TEST_FUNCTION(isGenInternal) TEST_FUNCTION(isGenericMultichargedParticle) TEST_FUNCTION(isGlueball) TEST_FUNCTION(isGluon) @@ -78,7 +78,7 @@ int main(int argc, char** argv) { TEST_FUNCTION(isParton) TEST_FUNCTION(isPentaquark) TEST_FUNCTION(isPhoton) - TEST_FUNCTION(isPythia8Specific) + TEST_FUNCTION(isGeneratorDefined) TEST_FUNCTION(isQuark) TEST_FUNCTION(isRBaryon) TEST_FUNCTION(isRGlueball) diff --git a/Generators/TruthUtils/test/pdgInfo.cxx b/Generators/TruthUtils/test/pdgInfo.cxx index 7756ffe55dc..80c8c13ebc1 100644 --- a/Generators/TruthUtils/test/pdgInfo.cxx +++ b/Generators/TruthUtils/test/pdgInfo.cxx @@ -36,11 +36,11 @@ int main(int argc, char** argv) { TEST_FUNCTION(isCharged) TEST_FUNCTION(isEMInteracting) TEST_FUNCTION(isGeantino) - TEST_FUNCTION(isGenSpecific) + TEST_FUNCTION(isGenInternal) TEST_FUNCTION(isLepton) TEST_FUNCTION(isNeutral) TEST_FUNCTION(isNucleus) - TEST_FUNCTION(isPythia8Specific) + TEST_FUNCTION(isGeneratorDefined) TEST_FUNCTION(isQuark) TEST_FUNCTION(isResonance) TEST_FUNCTION(isSUSY) diff --git a/Generators/TruthUtils/test/testPIDs.cxx b/Generators/TruthUtils/test/testPIDs.cxx index 42d13a43848..387a057de39 100644 --- a/Generators/TruthUtils/test/testPIDs.cxx +++ b/Generators/TruthUtils/test/testPIDs.cxx @@ -69,7 +69,7 @@ int main(int argc, char** argv) { TEST_FUNCTION(isExcited) TEST_FUNCTION(isGaugino) TEST_FUNCTION(isGeantino) - TEST_FUNCTION(isGenSpecific) + TEST_FUNCTION(isGenInternal) TEST_FUNCTION(isGenericMultichargedParticle) TEST_FUNCTION(isGlueball) TEST_FUNCTION(isGluon) // 30 @@ -95,7 +95,7 @@ int main(int argc, char** argv) { TEST_FUNCTION(isParton) // 50 TEST_FUNCTION(isPentaquark) TEST_FUNCTION(isPhoton) - TEST_FUNCTION(isPythia8Specific) + TEST_FUNCTION(isGeneratorDefined) TEST_FUNCTION(isQuark) TEST_FUNCTION(isRBaryon) TEST_FUNCTION(isRGlueball) -- GitLab