From ea7df69e3fc430dded97e1fc76b82586c606e310 Mon Sep 17 00:00:00 2001 From: Frank Winklmeier <frank.winklmeier@cern.ch> Date: Thu, 17 Nov 2022 11:47:18 +0100 Subject: [PATCH] MCTruth: use non-const particles This is similar to !58354 and removes unnecessary `const` qualifiers on `GenParticle` and `ISFParticle` to avoid `const_cast` downstream for the following classes: - `PrimaryParticleInformation` - `TrackBarcodeInfo` - `TrackInformation` - `VTrackInformation` --- .../MCTruth/PrimaryParticleInformation.h | 18 +++++----- .../G4Sim/MCTruth/MCTruth/TrackBarcodeInfo.h | 18 +++++----- .../G4Sim/MCTruth/MCTruth/TrackInformation.h | 28 ++++++++------- .../G4Sim/MCTruth/MCTruth/VTrackInformation.h | 19 +++++----- .../src/PrimaryParticleInformation.cxx | 18 +++------- .../G4Sim/MCTruth/src/TrackBarcodeInfo.cxx | 21 ++--------- Simulation/G4Sim/MCTruth/src/TrackHelper.cxx | 4 +-- .../G4Sim/MCTruth/src/TrackInformation.cxx | 17 +++------ .../G4Sim/MCTruth/src/VTrackInformation.cxx | 24 +++---------- .../src/AthenaTrackingAction.cxx | 13 ++----- .../ISF_Event/ISF_Event/ISFTruthIncident.h | 2 +- .../ISF_Event/ISF_Event/TruthBinding.h | 8 +++-- .../ISF_Event/ISF_Event/TruthBinding.icc | 4 ++- .../ISF_Event/src/ISFTruthIncident.cxx | 2 +- .../ISF_Services/src/InputConverter.cxx | 6 ++-- .../ISF_Services/src/InputConverter.h | 4 +-- .../ISF_Geant4Event/ISFG4Helper.h | 4 +-- .../ISF_Geant4Event/src/ISFG4Helper.cxx | 4 +-- .../ISF_Geant4Tools/src/ISFTrajectory.cxx | 4 +-- .../src/PhysicsValidationUserAction.cxx | 6 +--- .../src/TrackProcessorUserActionBase.cxx | 36 ++++++------------- .../src/TrackProcessorUserActionPassBack.cxx | 13 +++---- 22 files changed, 102 insertions(+), 171 deletions(-) diff --git a/Simulation/G4Sim/MCTruth/MCTruth/PrimaryParticleInformation.h b/Simulation/G4Sim/MCTruth/MCTruth/PrimaryParticleInformation.h index 009e9e79883c..a83ea7b30b61 100644 --- a/Simulation/G4Sim/MCTruth/MCTruth/PrimaryParticleInformation.h +++ b/Simulation/G4Sim/MCTruth/MCTruth/PrimaryParticleInformation.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration */ #ifndef PrimaryParticleInformation_H @@ -16,21 +16,23 @@ namespace ISF { class PrimaryParticleInformation: public G4VUserPrimaryParticleInformation { public: PrimaryParticleInformation(); - PrimaryParticleInformation(HepMC::ConstGenParticlePtr, const ISF::ISFParticle* isp=0); - HepMC::ConstGenParticlePtr GetHepMCParticle() const; + PrimaryParticleInformation(HepMC::GenParticlePtr, ISF::ISFParticle* isp=0); + HepMC::ConstGenParticlePtr GetHepMCParticle() const { return m_theParticle; } + HepMC::GenParticlePtr GetHepMCParticle() { return m_theParticle; } int GetParticleBarcode() const; void SuggestBarcode(int bc); - void SetParticle(HepMC::ConstGenParticlePtr); + void SetParticle(HepMC::GenParticlePtr); void Print() const {} int GetRegenerationNr() {return m_regenerationNr;} void SetRegenerationNr(int i) {m_regenerationNr=i;} - void SetISFParticle(const ISF::ISFParticle* isp); - const ISF::ISFParticle* GetISFParticle() const; + void SetISFParticle(ISF::ISFParticle* isp); + const ISF::ISFParticle* GetISFParticle() const { return m_theISFParticle; } + ISF::ISFParticle* GetISFParticle() { return m_theISFParticle; } private: - HepMC::ConstGenParticlePtr m_theParticle{}; - const ISF::ISFParticle* m_theISFParticle{}; + HepMC::GenParticlePtr m_theParticle{}; + ISF::ISFParticle* m_theISFParticle{}; int m_regenerationNr{0}; int m_barcode{-1}; diff --git a/Simulation/G4Sim/MCTruth/MCTruth/TrackBarcodeInfo.h b/Simulation/G4Sim/MCTruth/MCTruth/TrackBarcodeInfo.h index 23da1bd6b518..33297ed94cc1 100644 --- a/Simulation/G4Sim/MCTruth/MCTruth/TrackBarcodeInfo.h +++ b/Simulation/G4Sim/MCTruth/MCTruth/TrackBarcodeInfo.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration */ #ifndef TrackBarcodeInfo_H @@ -13,15 +13,17 @@ namespace ISF { class TrackBarcodeInfo: public VTrackInformation { public: - TrackBarcodeInfo(int bc, const ISF::ISFParticle* baseIsp=0); - int GetParticleBarcode() const; - const ISF::ISFParticle *GetBaseISFParticle() const; - void SetBaseISFParticle(const ISF::ISFParticle*); - void SetReturnedToISF(bool returned); - bool GetReturnedToISF() const; + TrackBarcodeInfo(int bc, ISF::ISFParticle* baseIsp=0); + virtual int GetParticleBarcode() const override {return m_barcode;} + virtual const ISF::ISFParticle *GetBaseISFParticle() const override {return m_theBaseISFParticle;} + virtual ISF::ISFParticle *GetBaseISFParticle() override {return m_theBaseISFParticle;} + + virtual void SetBaseISFParticle(ISF::ISFParticle*) override; + virtual void SetReturnedToISF(bool returned) override; + virtual bool GetReturnedToISF() const override {return m_returnedToISF;} private: - const ISF::ISFParticle *m_theBaseISFParticle; + ISF::ISFParticle *m_theBaseISFParticle; int m_barcode; bool m_returnedToISF; }; diff --git a/Simulation/G4Sim/MCTruth/MCTruth/TrackInformation.h b/Simulation/G4Sim/MCTruth/MCTruth/TrackInformation.h index 6726589ae766..459d35198870 100644 --- a/Simulation/G4Sim/MCTruth/MCTruth/TrackInformation.h +++ b/Simulation/G4Sim/MCTruth/MCTruth/TrackInformation.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration */ #ifndef TrackInformation_H @@ -14,20 +14,22 @@ namespace ISF { class TrackInformation: public VTrackInformation { public: TrackInformation(); - TrackInformation(HepMC::ConstGenParticlePtr,const ISF::ISFParticle* baseIsp=0); - HepMC::ConstGenParticlePtr GetHepMCParticle() const; - const ISF::ISFParticle *GetBaseISFParticle() const; - int GetParticleBarcode() const; - void SetParticle(HepMC::ConstGenParticlePtr); - void SetBaseISFParticle(const ISF::ISFParticle*); - void SetReturnedToISF(bool returned) {m_returnedToISF=returned;}; - bool GetReturnedToISF() const {return m_returnedToISF;}; - void SetRegenerationNr(int i) {m_regenerationNr=i;}; - int GetRegenerationNr() const {return m_regenerationNr;}; + TrackInformation(HepMC::GenParticlePtr p, ISF::ISFParticle* baseIsp=0); + virtual HepMC::ConstGenParticlePtr GetHepMCParticle() const override {return m_theParticle;} + virtual HepMC::GenParticlePtr GetHepMCParticle() override {return m_theParticle;} + virtual const ISF::ISFParticle *GetBaseISFParticle() const override {return m_theBaseISFParticle;} + virtual ISF::ISFParticle *GetBaseISFParticle() override {return m_theBaseISFParticle;} + virtual int GetParticleBarcode() const override; + virtual void SetParticle(HepMC::GenParticlePtr) override; + virtual void SetBaseISFParticle(ISF::ISFParticle*) override; + virtual void SetReturnedToISF(bool returned) override {m_returnedToISF=returned;} + virtual bool GetReturnedToISF() const override {return m_returnedToISF;} + void SetRegenerationNr(int i) {m_regenerationNr=i;} + int GetRegenerationNr() const {return m_regenerationNr;} private: int m_regenerationNr; - HepMC::ConstGenParticlePtr m_theParticle; - const ISF::ISFParticle *m_theBaseISFParticle; + HepMC::GenParticlePtr m_theParticle; + ISF::ISFParticle *m_theBaseISFParticle; bool m_returnedToISF; }; diff --git a/Simulation/G4Sim/MCTruth/MCTruth/VTrackInformation.h b/Simulation/G4Sim/MCTruth/MCTruth/VTrackInformation.h index 902492c41c04..660d94a2403c 100644 --- a/Simulation/G4Sim/MCTruth/MCTruth/VTrackInformation.h +++ b/Simulation/G4Sim/MCTruth/MCTruth/VTrackInformation.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration */ #ifndef VTrackInformation_H @@ -18,21 +18,24 @@ namespace ISF { class VTrackInformation: public G4VUserTrackInformation { public: VTrackInformation(TrackClassification tc=Primary); - HepMC::ConstGenParticlePtr GetPrimaryHepMCParticle() const; - void SetPrimaryHepMCParticle(HepMC::ConstGenParticlePtr); - virtual HepMC::ConstGenParticlePtr GetHepMCParticle() const; - virtual const ISF::ISFParticle *GetBaseISFParticle() const; + HepMC::ConstGenParticlePtr GetPrimaryHepMCParticle() const {return m_thePrimaryParticle;} + HepMC::GenParticlePtr GetPrimaryHepMCParticle() {return m_thePrimaryParticle;} + void SetPrimaryHepMCParticle(HepMC::GenParticlePtr); + virtual HepMC::ConstGenParticlePtr GetHepMCParticle() const {return nullptr;} + virtual HepMC::GenParticlePtr GetHepMCParticle() {return nullptr;} + virtual const ISF::ISFParticle *GetBaseISFParticle() const {return nullptr;} + virtual ISF::ISFParticle *GetBaseISFParticle() {return nullptr;} virtual bool GetReturnedToISF() const; virtual int GetParticleBarcode() const =0; - virtual void SetParticle(HepMC::ConstGenParticlePtr); - virtual void SetBaseISFParticle(const ISF::ISFParticle*); + virtual void SetParticle(HepMC::GenParticlePtr); + virtual void SetBaseISFParticle(ISF::ISFParticle*); virtual void SetReturnedToISF(bool) ; virtual void Print() const {} void SetClassification(TrackClassification tc) {m_classify=tc;} TrackClassification GetClassification() const {return m_classify;} private: TrackClassification m_classify; - HepMC::ConstGenParticlePtr m_thePrimaryParticle{}; + HepMC::GenParticlePtr m_thePrimaryParticle{}; }; #endif diff --git a/Simulation/G4Sim/MCTruth/src/PrimaryParticleInformation.cxx b/Simulation/G4Sim/MCTruth/src/PrimaryParticleInformation.cxx index c4a1e311f2a6..992f9ddb5992 100644 --- a/Simulation/G4Sim/MCTruth/src/PrimaryParticleInformation.cxx +++ b/Simulation/G4Sim/MCTruth/src/PrimaryParticleInformation.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration */ #include "MCTruth/PrimaryParticleInformation.h" @@ -8,20 +8,10 @@ PrimaryParticleInformation::PrimaryParticleInformation() { } -PrimaryParticleInformation::PrimaryParticleInformation(HepMC::ConstGenParticlePtr p, const ISF::ISFParticle* isp):m_theParticle(p),m_theISFParticle(isp) +PrimaryParticleInformation::PrimaryParticleInformation(HepMC::GenParticlePtr p, ISF::ISFParticle* isp):m_theParticle(p),m_theISFParticle(isp) { } -HepMC::ConstGenParticlePtr PrimaryParticleInformation::GetHepMCParticle() const -{ - return m_theParticle; -} - -const ISF::ISFParticle* PrimaryParticleInformation::GetISFParticle() const -{ - return m_theISFParticle; -} - void PrimaryParticleInformation::SuggestBarcode(int bc) { m_barcode=bc; @@ -35,12 +25,12 @@ int PrimaryParticleInformation::GetParticleBarcode() const return m_theParticle?HepMC::barcode(m_theParticle):m_barcode; } -void PrimaryParticleInformation::SetParticle(HepMC::ConstGenParticlePtr p) +void PrimaryParticleInformation::SetParticle(HepMC::GenParticlePtr p) { m_theParticle=p; } -void PrimaryParticleInformation::SetISFParticle(const ISF::ISFParticle* p) +void PrimaryParticleInformation::SetISFParticle(ISF::ISFParticle* p) { m_theISFParticle=p; } diff --git a/Simulation/G4Sim/MCTruth/src/TrackBarcodeInfo.cxx b/Simulation/G4Sim/MCTruth/src/TrackBarcodeInfo.cxx index 8464402d7043..9d30bf58564e 100644 --- a/Simulation/G4Sim/MCTruth/src/TrackBarcodeInfo.cxx +++ b/Simulation/G4Sim/MCTruth/src/TrackBarcodeInfo.cxx @@ -1,34 +1,19 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration */ #include "MCTruth/TrackBarcodeInfo.h" -TrackBarcodeInfo::TrackBarcodeInfo(int bc, const ISF::ISFParticle* baseIsp):VTrackInformation(BarcodeOnly),m_theBaseISFParticle(baseIsp),m_barcode(bc),m_returnedToISF(false) +TrackBarcodeInfo::TrackBarcodeInfo(int bc, ISF::ISFParticle* baseIsp):VTrackInformation(BarcodeOnly),m_theBaseISFParticle(baseIsp),m_barcode(bc),m_returnedToISF(false) { } -int TrackBarcodeInfo::GetParticleBarcode() const -{ - return m_barcode; -} - -void TrackBarcodeInfo::SetBaseISFParticle(const ISF::ISFParticle* isp) +void TrackBarcodeInfo::SetBaseISFParticle(ISF::ISFParticle* isp) { m_theBaseISFParticle=isp; } -const ISF::ISFParticle* TrackBarcodeInfo::GetBaseISFParticle() const -{ - return m_theBaseISFParticle; -} - void TrackBarcodeInfo::SetReturnedToISF(bool returned) { m_returnedToISF = returned; } - -bool TrackBarcodeInfo::GetReturnedToISF() const -{ - return m_returnedToISF; -} diff --git a/Simulation/G4Sim/MCTruth/src/TrackHelper.cxx b/Simulation/G4Sim/MCTruth/src/TrackHelper.cxx index ef1b087d6a62..265130717270 100644 --- a/Simulation/G4Sim/MCTruth/src/TrackHelper.cxx +++ b/Simulation/G4Sim/MCTruth/src/TrackHelper.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration */ #include "MCTruth/TrackHelper.h" @@ -31,7 +31,7 @@ bool TrackHelper::IsSecondary() const } int TrackHelper::GetBarcode() const { - if (m_trackInfo==0 || m_trackInfo->GetHepMCParticle()==0) return 0; + if (m_trackInfo==0 || std::as_const(m_trackInfo)->GetHepMCParticle()==0) return 0; return m_trackInfo->GetParticleBarcode(); } diff --git a/Simulation/G4Sim/MCTruth/src/TrackInformation.cxx b/Simulation/G4Sim/MCTruth/src/TrackInformation.cxx index a983733076c4..24c5519ddc54 100644 --- a/Simulation/G4Sim/MCTruth/src/TrackInformation.cxx +++ b/Simulation/G4Sim/MCTruth/src/TrackInformation.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration */ #include "MCTruth/TrackInformation.h" @@ -11,7 +11,7 @@ TrackInformation::TrackInformation():m_regenerationNr(0),m_theParticle(0),m_theB { } -TrackInformation::TrackInformation(HepMC::ConstGenParticlePtr p,const ISF::ISFParticle* baseIsp): +TrackInformation::TrackInformation(HepMC::GenParticlePtr p, ISF::ISFParticle* baseIsp): m_regenerationNr(0), m_theParticle(p), m_theBaseISFParticle(baseIsp), @@ -19,26 +19,17 @@ TrackInformation::TrackInformation(HepMC::ConstGenParticlePtr p,const ISF::ISFPa { } -HepMC::ConstGenParticlePtr TrackInformation::GetHepMCParticle() const -{ - return m_theParticle; -} -const ISF::ISFParticle* TrackInformation::GetBaseISFParticle() const -{ - return m_theBaseISFParticle; -} - int TrackInformation::GetParticleBarcode() const { return ( m_theParticle ? HepMC::barcode(m_theParticle) : 0 ); } -void TrackInformation::SetParticle(HepMC::ConstGenParticlePtr p) +void TrackInformation::SetParticle(HepMC::GenParticlePtr p) { m_theParticle=p; } -void TrackInformation::SetBaseISFParticle(const ISF::ISFParticle* p) +void TrackInformation::SetBaseISFParticle(ISF::ISFParticle* p) { m_theBaseISFParticle=p; } diff --git a/Simulation/G4Sim/MCTruth/src/VTrackInformation.cxx b/Simulation/G4Sim/MCTruth/src/VTrackInformation.cxx index 022afaf4f887..be9a20c530d4 100644 --- a/Simulation/G4Sim/MCTruth/src/VTrackInformation.cxx +++ b/Simulation/G4Sim/MCTruth/src/VTrackInformation.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration */ #include "MCTruth/VTrackInformation.h" @@ -8,40 +8,24 @@ VTrackInformation::VTrackInformation(TrackClassification tc):m_classify(tc) { } -HepMC::ConstGenParticlePtr VTrackInformation::GetPrimaryHepMCParticle() const -{ - return m_thePrimaryParticle; -} - -void VTrackInformation::SetPrimaryHepMCParticle(HepMC::ConstGenParticlePtr p) +void VTrackInformation::SetPrimaryHepMCParticle(HepMC::GenParticlePtr p) { m_thePrimaryParticle=p; } - -HepMC::ConstGenParticlePtr VTrackInformation::GetHepMCParticle() const -{ - return 0; -} - -const ISF::ISFParticle* VTrackInformation::GetBaseISFParticle() const -{ - return 0; -} - bool VTrackInformation::GetReturnedToISF() const { return false; } -void VTrackInformation::SetParticle(HepMC::ConstGenParticlePtr /*p*/) +void VTrackInformation::SetParticle(HepMC::GenParticlePtr /*p*/) { // you should not call this, perhaps throw an exception? std::cerr<<"ERROR VTrackInformation::SetParticle() not supported "<<std::endl; } -void VTrackInformation::SetBaseISFParticle(const ISF::ISFParticle* /*p*/) +void VTrackInformation::SetBaseISFParticle(ISF::ISFParticle* /*p*/) { // you should not call this, perhaps throw an exception? std::cerr<<"ERROR VTrackInformation::SetBaseISFParticle() not supported "<<std::endl; diff --git a/Simulation/G4Utilities/G4UserActions/src/AthenaTrackingAction.cxx b/Simulation/G4Utilities/G4UserActions/src/AthenaTrackingAction.cxx index a823beb22787..da32b8f9a912 100644 --- a/Simulation/G4Utilities/G4UserActions/src/AthenaTrackingAction.cxx +++ b/Simulation/G4Utilities/G4UserActions/src/AthenaTrackingAction.cxx @@ -43,17 +43,8 @@ namespace G4UA // Condition for storing the GenParticle in the AtlasG4EventUserInfo for later. if (trackHelper.IsPrimary() || trackHelper.IsRegisteredSecondary()) { - // Why a const_cast??? - // This is an ugly way to communicate the GenParticle... -#ifdef HEPMC3 - HepMC::GenParticlePtr part = - std::const_pointer_cast<HepMC3::GenParticle>( trackHelper.GetTrackInformation()-> - GetHepMCParticle() ); -#else - HepMC::GenParticlePtr part = - const_cast<HepMC::GenParticlePtr>( trackHelper.GetTrackInformation()-> - GetHepMCParticle() ); -#endif + HepMC::GenParticlePtr part = trackHelper.GetTrackInformation()->GetHepMCParticle(); + // Assign the GenParticle to the AtlasG4EventUserInfo. AtlasG4EventUserInfo* atlasG4EvtUserInfo = static_cast<AtlasG4EventUserInfo*> (G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetUserInformation()); diff --git a/Simulation/ISF/ISF_Core/ISF_Event/ISF_Event/ISFTruthIncident.h b/Simulation/ISF/ISF_Core/ISF_Event/ISF_Event/ISFTruthIncident.h index ac16c8185f1b..cd35b68c8c7d 100644 --- a/Simulation/ISF/ISF_Core/ISF_Event/ISF_Event/ISFTruthIncident.h +++ b/Simulation/ISF/ISF_Core/ISF_Event/ISF_Event/ISFTruthIncident.h @@ -112,7 +112,7 @@ namespace ISF { inline HepMC::GenParticlePtr getHepMCTruthParticle( ISF::ISFParticle& particle ) const; /** convert ISFParticle to GenParticle and attach to ISFParticle's TruthBinding */ - inline HepMC::GenParticlePtr updateHepMCTruthParticle( ISF::ISFParticle& particle, const ISF::ISFParticle* parent=nullptr ) const; + inline HepMC::GenParticlePtr updateHepMCTruthParticle( ISF::ISFParticle& particle, ISF::ISFParticle* parent=nullptr ) const; ISF::ISFParticle& m_parent; const ISFParticleVector& m_children; diff --git a/Simulation/ISF/ISF_Core/ISF_Event/ISF_Event/TruthBinding.h b/Simulation/ISF/ISF_Core/ISF_Event/ISF_Event/TruthBinding.h index 689786ea008f..c5ea7705b414 100644 --- a/Simulation/ISF/ISF_Core/ISF_Event/ISF_Event/TruthBinding.h +++ b/Simulation/ISF/ISF_Core/ISF_Event/ISF_Event/TruthBinding.h @@ -27,7 +27,7 @@ namespace ISF { /** constructor setting all truth particle pointers to the given particle */ inline TruthBinding(HepMC::GenParticlePtr allTruthP); /** constructor setting all truth particle pointers individually */ - inline TruthBinding(HepMC::GenParticlePtr truthP, HepMC::ConstGenParticlePtr primaryTruthP, HepMC::ConstGenParticlePtr genZeroTruthP); + inline TruthBinding(HepMC::GenParticlePtr truthP, HepMC::GenParticlePtr primaryTruthP, HepMC::GenParticlePtr genZeroTruthP); /** copy constructors */ inline TruthBinding(const TruthBinding &rhs) = default; @@ -51,16 +51,18 @@ namespace ISF { inline void setTruthParticle(HepMC::GenParticlePtr p); /** pointer to the primary particle in the simulation truth */ + inline HepMC::GenParticlePtr getPrimaryTruthParticle(); inline HepMC::ConstGenParticlePtr getPrimaryTruthParticle() const; /** pointer to the simulation truth particle before any regeneration happened (eg. brem) */ + inline HepMC::GenParticlePtr getGenerationZeroTruthParticle(); inline HepMC::ConstGenParticlePtr getGenerationZeroTruthParticle() const; inline void setGenerationZeroTruthParticle(HepMC::GenParticlePtr p); private: HepMC::GenParticlePtr m_truthParticle{}; //!< pointer to particle in MC truth - HepMC::ConstGenParticlePtr m_primaryTruthParticle{}; //!< pointer to corresponding primary (generator) particle - HepMC::ConstGenParticlePtr m_generationZeroTruthParticle{}; //!< pointer to corresponding truth particle before any regenration + HepMC::GenParticlePtr m_primaryTruthParticle{}; //!< pointer to corresponding primary (generator) particle + HepMC::GenParticlePtr m_generationZeroTruthParticle{}; //!< pointer to corresponding truth particle before any regenration }; } // end of namespace diff --git a/Simulation/ISF/ISF_Core/ISF_Event/ISF_Event/TruthBinding.icc b/Simulation/ISF/ISF_Core/ISF_Event/ISF_Event/TruthBinding.icc index cddf2b165517..a8fe524692c2 100644 --- a/Simulation/ISF/ISF_Core/ISF_Event/ISF_Event/TruthBinding.icc +++ b/Simulation/ISF/ISF_Core/ISF_Event/ISF_Event/TruthBinding.icc @@ -12,7 +12,7 @@ namespace ISF { m_generationZeroTruthParticle(allTruthP) { } /** constructor setting all truth particle pointers individually */ - TruthBinding::TruthBinding(HepMC::GenParticlePtr truthP, HepMC::ConstGenParticlePtr primaryTruthP, HepMC::ConstGenParticlePtr genZeroTruthP) : + TruthBinding::TruthBinding(HepMC::GenParticlePtr truthP, HepMC::GenParticlePtr primaryTruthP, HepMC::GenParticlePtr genZeroTruthP) : m_truthParticle(truthP), m_primaryTruthParticle(primaryTruthP), m_generationZeroTruthParticle(genZeroTruthP) { } @@ -80,9 +80,11 @@ namespace ISF { void TruthBinding::setTruthParticle(HepMC::GenParticlePtr p) { m_truthParticle = p; } /** pointer to the primary particle in the simulation truth */ + HepMC::GenParticlePtr TruthBinding::getPrimaryTruthParticle() { return m_primaryTruthParticle; } HepMC::ConstGenParticlePtr TruthBinding::getPrimaryTruthParticle() const { return m_primaryTruthParticle; } /** pointer to the simulation truth particle before any regeneration (eg. brem) */ + HepMC::GenParticlePtr TruthBinding::getGenerationZeroTruthParticle() { return m_generationZeroTruthParticle; } HepMC::ConstGenParticlePtr TruthBinding::getGenerationZeroTruthParticle() const { return m_generationZeroTruthParticle; } void TruthBinding::setGenerationZeroTruthParticle(HepMC::GenParticlePtr p) { m_generationZeroTruthParticle = p; } diff --git a/Simulation/ISF/ISF_Core/ISF_Event/src/ISFTruthIncident.cxx b/Simulation/ISF/ISF_Core/ISF_Event/src/ISFTruthIncident.cxx index c8fb4d4f0acb..293ec2dfdd8f 100644 --- a/Simulation/ISF/ISF_Core/ISF_Event/src/ISFTruthIncident.cxx +++ b/Simulation/ISF/ISF_Core/ISF_Event/src/ISFTruthIncident.cxx @@ -177,7 +177,7 @@ HepMC::GenParticlePtr ISF::ISFTruthIncident::getHepMCTruthParticle( ISF::ISFPart /** convert ISFParticle to GenParticle and attach to ISFParticle's TruthBinding */ HepMC::GenParticlePtr ISF::ISFTruthIncident::updateHepMCTruthParticle( ISF::ISFParticle& particle, - const ISF::ISFParticle* parent ) const { + ISF::ISFParticle* parent ) const { auto* truthBinding = particle.getTruthBinding(); HepMC::GenParticlePtr hepTruthParticle = ParticleHelper::convert( particle ); diff --git a/Simulation/ISF/ISF_Core/ISF_Services/src/InputConverter.cxx b/Simulation/ISF/ISF_Core/ISF_Services/src/InputConverter.cxx index bdf7c0074991..08db70d73927 100644 --- a/Simulation/ISF/ISF_Core/ISF_Services/src/InputConverter.cxx +++ b/Simulation/ISF/ISF_Core/ISF_Services/src/InputConverter.cxx @@ -516,7 +516,7 @@ double SetProperTimeFromDetectorFrameDecayLength(G4PrimaryParticle& g4particle,c //________________________________________________________________________ #ifdef HEPMC3 -G4PrimaryParticle* ISF::InputConverter::getG4PrimaryParticle(HepMC::ConstGenParticlePtr genpart) const{ +G4PrimaryParticle* ISF::InputConverter::getG4PrimaryParticle(HepMC::GenParticlePtr genpart) const{ ATH_MSG_VERBOSE("Creating G4PrimaryParticle from GenParticle."); const G4ParticleDefinition *particleDefinition = this->getG4ParticleDefinition(genpart->pdg_id()); @@ -601,7 +601,7 @@ G4PrimaryParticle* ISF::InputConverter::getG4PrimaryParticle(HepMC::ConstGenPart return g4particle.release(); } #else -G4PrimaryParticle* ISF::InputConverter::getG4PrimaryParticle(const HepMC::GenParticle& genpart) const +G4PrimaryParticle* ISF::InputConverter::getG4PrimaryParticle(HepMC::GenParticle& genpart) const { ATH_MSG_VERBOSE("Creating G4PrimaryParticle from GenParticle."); @@ -703,7 +703,7 @@ G4PrimaryParticle* ISF::InputConverter::getG4PrimaryParticle(ISF::ISFParticle& i return nullptr; //The G4Exception call above should abort the job, but Coverity does not seem to pick this up. } HepMC::GenParticlePtr genpart = truthBinding->getTruthParticle(); - HepMC::ConstGenParticlePtr primaryGenpart = truthBinding->getPrimaryTruthParticle(); + HepMC::GenParticlePtr primaryGenpart = truthBinding->getPrimaryTruthParticle(); const G4ParticleDefinition *particleDefinition = this->getG4ParticleDefinition(isp.pdgCode()); diff --git a/Simulation/ISF/ISF_Core/ISF_Services/src/InputConverter.h b/Simulation/ISF/ISF_Core/ISF_Services/src/InputConverter.h index 651f1f8c344d..a97c4453641d 100644 --- a/Simulation/ISF/ISF_Core/ISF_Services/src/InputConverter.h +++ b/Simulation/ISF/ISF_Core/ISF_Services/src/InputConverter.h @@ -80,9 +80,9 @@ namespace ISF { const G4ParticleDefinition* getG4ParticleDefinition(int pdgcode) const; #ifdef HEPMC3 - G4PrimaryParticle* getG4PrimaryParticle(HepMC::ConstGenParticlePtr gp) const; + G4PrimaryParticle* getG4PrimaryParticle(HepMC::GenParticlePtr gp) const; #else - G4PrimaryParticle* getG4PrimaryParticle(const HepMC::GenParticle& gp) const; + G4PrimaryParticle* getG4PrimaryParticle(HepMC::GenParticle& gp) const; #endif G4PrimaryParticle* getG4PrimaryParticle(ISF::ISFParticle& isp, bool useHepMC) const; diff --git a/Simulation/ISF/ISF_Geant4/ISF_Geant4Event/ISF_Geant4Event/ISFG4Helper.h b/Simulation/ISF/ISF_Geant4/ISF_Geant4Event/ISF_Geant4Event/ISFG4Helper.h index 0223978d6294..74ee3b4198ca 100644 --- a/Simulation/ISF/ISF_Geant4/ISF_Geant4Event/ISF_Geant4Event/ISFG4Helper.h +++ b/Simulation/ISF/ISF_Geant4/ISF_Geant4Event/ISF_Geant4Event/ISFG4Helper.h @@ -47,9 +47,9 @@ class ISFG4Helper { /** attach a new TrackInformation object to the given new (!) G4Track * (the G4Track must not have a UserInformation object attached to it) */ static TrackInformation* attachTrackInfoToNewG4Track( G4Track& aTrack, - const ISF::ISFParticle& baseIsp, + ISF::ISFParticle& baseIsp, TrackClassification classification, - HepMC::ConstGenParticlePtr nonRegeneratedTruthParticle = nullptr); + HepMC::GenParticlePtr nonRegeneratedTruthParticle = nullptr); /** return pointer to current AtlasG4EventUserInfo */ static AtlasG4EventUserInfo* getAtlasG4EventUserInfo(); diff --git a/Simulation/ISF/ISF_Geant4/ISF_Geant4Event/src/ISFG4Helper.cxx b/Simulation/ISF/ISF_Geant4/ISF_Geant4Event/src/ISFG4Helper.cxx index 029cdcd9e784..27ff16929b85 100644 --- a/Simulation/ISF/ISF_Geant4/ISF_Geant4Event/src/ISFG4Helper.cxx +++ b/Simulation/ISF/ISF_Geant4/ISF_Geant4Event/src/ISFG4Helper.cxx @@ -77,9 +77,9 @@ iGeant4::ISFG4Helper::getISFTrackInfo(const G4Track& aTrack) /** link the given G4Track to the given ISFParticle */ TrackInformation* iGeant4::ISFG4Helper::attachTrackInfoToNewG4Track( G4Track& aTrack, - const ISF::ISFParticle& baseIsp, + ISF::ISFParticle& baseIsp, TrackClassification classification, - HepMC::ConstGenParticlePtr nonRegeneratedTruthParticle) + HepMC::GenParticlePtr nonRegeneratedTruthParticle) { if ( aTrack.GetUserInformation() ) { G4ExceptionDescription description; diff --git a/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/ISFTrajectory.cxx b/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/ISFTrajectory.cxx index a4bcb087f976..df574632384a 100644 --- a/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/ISFTrajectory.cxx +++ b/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/ISFTrajectory.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration */ /////////////////////////////////////////////////////////////////// @@ -89,7 +89,7 @@ void iGeant4::ISFTrajectory::AppendStep(const G4Step* aStep) return; //The G4Exception call above should abort the job, but Coverity does not seem to pick this up. } - ISF::ISFParticle* baseIsp = const_cast<ISF::ISFParticle*>( trackInfo->GetBaseISFParticle() ); + ISF::ISFParticle* baseIsp = trackInfo->GetBaseISFParticle(); if (!baseIsp) { G4ExceptionDescription description; description << G4String("AppendStep: ") + "NULL ISFParticle pointer for current G4Step (trackID " diff --git a/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/PhysicsValidationUserAction.cxx b/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/PhysicsValidationUserAction.cxx index 6ce8d54fde84..03ed176aa4f5 100644 --- a/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/PhysicsValidationUserAction.cxx +++ b/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/PhysicsValidationUserAction.cxx @@ -239,11 +239,7 @@ namespace G4UA{ m_scIn = creation? creation->GetProcessSubType() : -1; VTrackInformation * trackInfo= static_cast<VTrackInformation*>(track->GetUserInformation()); -#ifdef HEPMC3 - HepMC::GenParticlePtr genpart=trackInfo ? std::const_pointer_cast<HepMC3::GenParticle>(trackInfo->GetHepMCParticle()):nullptr; -#else - HepMC::GenParticlePtr genpart= trackInfo ? const_cast<HepMC::GenParticlePtr>(trackInfo->GetHepMCParticle()):0; -#endif + HepMC::GenParticlePtr genpart= trackInfo ? trackInfo->GetHepMCParticle() : nullptr; HepMC::GenVertexPtr vtx = genpart ? genpart->production_vertex() : 0; m_gen = genpart? 0 : -1; diff --git a/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/TrackProcessorUserActionBase.cxx b/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/TrackProcessorUserActionBase.cxx index 0980e5f48b78..16159963c4b2 100644 --- a/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/TrackProcessorUserActionBase.cxx +++ b/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/TrackProcessorUserActionBase.cxx @@ -155,7 +155,7 @@ void TrackProcessorUserActionBase::setupPrimary(G4Track& aTrack) return; // The G4Exception call above should abort the job, but Coverity does not seem to pick this up. } - auto* truthBinding = baseISP->getTruthBinding(); + ISF::TruthBinding* truthBinding = baseISP->getTruthBinding(); if (!truthBinding) { G4ExceptionDescription description; description << G4String("PreUserTrackingAction: ") + "No ISF::TruthBinding associated with primary particle (trackID: " @@ -166,17 +166,11 @@ void TrackProcessorUserActionBase::setupPrimary(G4Track& aTrack) } int regenerationNr = ppInfo->GetRegenerationNr(); -#ifdef HEPMC3 - auto primaryTruthParticle = truthBinding->getGenerationZeroTruthParticle(); - auto generationZeroTruthParticle = truthBinding->getGenerationZeroTruthParticle(); - auto currentlyTracedHepPart = truthBinding->getTruthParticle(); - auto currentlyTracedHepPart_nc = std::const_pointer_cast<HepMC3::GenParticle>(currentlyTracedHepPart); -#else - auto* primaryTruthParticle = truthBinding->getGenerationZeroTruthParticle(); - auto* generationZeroTruthParticle = truthBinding->getGenerationZeroTruthParticle(); - auto* currentlyTracedHepPart = truthBinding->getTruthParticle(); - auto currentlyTracedHepPart_nc = const_cast<HepMC::GenParticlePtr>(currentlyTracedHepPart); -#endif + + HepMC::GenParticlePtr primaryTruthParticle = truthBinding->getGenerationZeroTruthParticle(); + HepMC::GenParticlePtr generationZeroTruthParticle = truthBinding->getGenerationZeroTruthParticle(); + HepMC::GenParticlePtr currentlyTracedHepPart = truthBinding->getTruthParticle(); + auto classification = classify(primaryTruthParticle, generationZeroTruthParticle, currentlyTracedHepPart, @@ -188,9 +182,9 @@ void TrackProcessorUserActionBase::setupPrimary(G4Track& aTrack) generationZeroTruthParticle ); newTrackInfo->SetRegenerationNr(regenerationNr); - setCurrentParticle(const_cast<ISF::ISFParticle*>(baseISP), + setCurrentParticle(baseISP, primaryTruthParticle, - currentlyTracedHepPart_nc); + currentlyTracedHepPart); return; } @@ -199,20 +193,12 @@ void TrackProcessorUserActionBase::setupSecondary(const G4Track& aTrack) { auto* trackInfo = ::iGeant4::ISFG4Helper::getISFTrackInfo(aTrack); - // why does TrackInformation return *const* GenParticle and ISFParticle objects!? -#ifdef HEPMC3 - HepMC::GenParticlePtr currentlyTracedTruthParticle = std::const_pointer_cast<HepMC3::GenParticle>( trackInfo->GetHepMCParticle() ); - HepMC::GenParticlePtr primaryTruthParticle = std::const_pointer_cast<HepMC3::GenParticle>( trackInfo->GetPrimaryHepMCParticle() ); - auto* baseISFParticle = const_cast<ISF::ISFParticle*>( trackInfo->GetBaseISFParticle() ); + HepMC::GenParticlePtr currentlyTracedTruthParticle = trackInfo->GetHepMCParticle(); + HepMC::GenParticlePtr primaryTruthParticle = trackInfo->GetPrimaryHepMCParticle(); + ISF::ISFParticle* baseISFParticle = trackInfo->GetBaseISFParticle(); setCurrentParticle(baseISFParticle, primaryTruthParticle, currentlyTracedTruthParticle); -#else - HepMC::GenParticlePtr currentlyTracedTruthParticle = const_cast<HepMC::GenParticlePtr>( trackInfo->GetHepMCParticle() ); - HepMC::GenParticlePtr primaryTruthParticle = const_cast<HepMC::GenParticlePtr>( trackInfo->GetPrimaryHepMCParticle() ); - auto* baseISFParticle = const_cast<ISF::ISFParticle*>( trackInfo->GetBaseISFParticle() ); - setCurrentParticle(baseISFParticle, primaryTruthParticle, currentlyTracedTruthParticle); -#endif return; } diff --git a/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/TrackProcessorUserActionPassBack.cxx b/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/TrackProcessorUserActionPassBack.cxx index 8779ebe974a5..3765dcfd482f 100644 --- a/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/TrackProcessorUserActionPassBack.cxx +++ b/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/TrackProcessorUserActionPassBack.cxx @@ -213,7 +213,7 @@ namespace G4UA { // ATH_MSG_DEBUG(" -> Secondary particle generated in this G4Step is returned to ISF."); // attach TrackInformation instance to the new secondary G4Track - const ISF::ISFParticle *parent = curISP; + ISF::ISFParticle *parent = curISP; HepMC::GenParticlePtr generationZeroTruthParticle = nullptr; ::iGeant4::ISFG4Helper::attachTrackInfoToNewG4Track( *aTrack_2nd, *parent, @@ -241,14 +241,9 @@ namespace G4UA { G4Exception("iGeant4::TrackProcessorUserActionPassBack", "NoTrackInformation", FatalException, description); return nullptr; //The G4Exception call above should abort the job, but Coverity does not seem to pick this up. } -#ifdef HEPMC3 - HepMC::GenParticlePtr primaryHepParticle = std::const_pointer_cast<HepMC3::GenParticle>(trackInfo->GetPrimaryHepMCParticle()); - HepMC::GenParticlePtr generationZeroHepParticle = std::const_pointer_cast<HepMC3::GenParticle>(trackInfo->GetHepMCParticle()); - -#else - HepMC::GenParticlePtr primaryHepParticle = const_cast<HepMC::GenParticlePtr>(trackInfo->GetPrimaryHepMCParticle()); - HepMC::GenParticlePtr generationZeroHepParticle = const_cast<HepMC::GenParticlePtr>(trackInfo->GetHepMCParticle()); -#endif + + HepMC::GenParticlePtr primaryHepParticle = trackInfo->GetPrimaryHepMCParticle(); + HepMC::GenParticlePtr generationZeroHepParticle = trackInfo->GetHepMCParticle(); ISF::TruthBinding* tBinding = new ISF::TruthBinding(truthParticle, primaryHepParticle, generationZeroHepParticle); -- GitLab