From beaa6b19109e073b9c86108dec488b4042ce1584 Mon Sep 17 00:00:00 2001 From: JuanGonzalezCaminero Date: Tue, 15 Oct 2024 10:18:59 +0200 Subject: [PATCH 1/3] Using the hepem tracking manager on CPU --- src/HepEMPhysics.cc | 104 +++++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 49 deletions(-) diff --git a/src/HepEMPhysics.cc b/src/HepEMPhysics.cc index 10ee3a1fd..a7e7d1bfb 100644 --- a/src/HepEMPhysics.cc +++ b/src/HepEMPhysics.cc @@ -5,6 +5,7 @@ // include the G4HepEmProcess from the G4HepEm lib. #include "G4HepEmProcess.hh" +#include "G4HepEmTrackingManager.hh" #include "G4ParticleDefinition.hh" #include "G4ProcessManager.hh" @@ -59,71 +60,76 @@ HepEMPhysics::~HepEMPhysics() {} void HepEMPhysics::ConstructProcess() { + // Register custom tracking manager for e-/e+ and gammas. + auto trackingManager = new G4HepEmTrackingManager(); + G4Electron::Definition()->SetTrackingManager(trackingManager); + G4Positron::Definition()->SetTrackingManager(trackingManager); + G4Gamma::Definition()->SetTrackingManager(trackingManager); - G4PhysicsListHelper *ph = G4PhysicsListHelper::GetPhysicsListHelper(); + // G4PhysicsListHelper *ph = G4PhysicsListHelper::GetPhysicsListHelper(); - // from G4EmStandardPhysics - G4EmBuilder::PrepareEMPhysics(); + // // from G4EmStandardPhysics + // G4EmBuilder::PrepareEMPhysics(); - G4EmParameters *param = G4EmParameters::Instance(); + // G4EmParameters *param = G4EmParameters::Instance(); - // processes used by several particles - G4hMultipleScattering *hmsc = new G4hMultipleScattering("ionmsc"); + // // processes used by several particles + // G4hMultipleScattering *hmsc = new G4hMultipleScattering("ionmsc"); - // nuclear stopping is enabled if th eenergy limit above zero - G4double nielEnergyLimit = param->MaxNIELEnergy(); - G4NuclearStopping *pnuc = nullptr; - if (nielEnergyLimit > 0.0) { - pnuc = new G4NuclearStopping(); - pnuc->SetMaxKinEnergy(nielEnergyLimit); - } - // end of G4EmStandardPhysics + // // nuclear stopping is enabled if th eenergy limit above zero + // G4double nielEnergyLimit = param->MaxNIELEnergy(); + // G4NuclearStopping *pnuc = nullptr; + // if (nielEnergyLimit > 0.0) { + // pnuc = new G4NuclearStopping(); + // pnuc->SetMaxKinEnergy(nielEnergyLimit); + // } + // // end of G4EmStandardPhysics - // creae the only one G4HepEm process that will be assigned to e-/e+ and gamma - G4HepEmProcess *hepEmProcess = new G4HepEmProcess(); + // // creae the only one G4HepEm process that will be assigned to e-/e+ and gamma + // G4HepEmProcess *hepEmProcess = new G4HepEmProcess(); - // Add standard EM Processes - // - auto aParticleIterator = GetParticleIterator(); - aParticleIterator->reset(); - while ((*aParticleIterator)()) { - G4ParticleDefinition *particle = aParticleIterator->value(); - G4String particleName = particle->GetParticleName(); + // // Add standard EM Processes + // // + // auto aParticleIterator = GetParticleIterator(); + // aParticleIterator->reset(); + // while ((*aParticleIterator)()) { + // G4ParticleDefinition *particle = aParticleIterator->value(); + // G4String particleName = particle->GetParticleName(); - if (particleName == "gamma") { + // if (particleName == "gamma") { - // Add G4HepEm process to gamma: includes Conversion, Compton and photoelectric effect. - particle->GetProcessManager()->AddProcess(hepEmProcess, -1, -1, 1); + // // Add G4HepEm process to gamma: includes Conversion, Compton and photoelectric effect. + // particle->GetProcessManager()->AddProcess(hepEmProcess, -1, -1, 1); - } else if (particleName == "e-") { + // } else if (particleName == "e-") { - // Add G4HepEm process to e-: includes Ionisation and Bremsstrahlung for e- - particle->GetProcessManager()->AddProcess(hepEmProcess, -1, -1, 1); + // // Add G4HepEm process to e-: includes Ionisation and Bremsstrahlung for e- + // particle->GetProcessManager()->AddProcess(hepEmProcess, -1, -1, 1); - } else if (particleName == "e+") { + // } else if (particleName == "e+") { - // Add G4HepEm process to e+: includes Ionisation, Bremsstrahlung and e+e- - // annihilation into 2 gamma interactions for e+ - particle->GetProcessManager()->AddProcess(hepEmProcess, -1, -1, 1); - } - } + // // Add G4HepEm process to e+: includes Ionisation, Bremsstrahlung and e+e- + // // annihilation into 2 gamma interactions for e+ + // particle->GetProcessManager()->AddProcess(hepEmProcess, -1, -1, 1); + // } + // } - // from G4EmStandardPhysics + // // from G4EmStandardPhysics - // generic ion - G4ParticleDefinition *particle = G4GenericIon::GenericIon(); - G4ionIonisation *ionIoni = new G4ionIonisation(); - ph->RegisterProcess(hmsc, particle); - ph->RegisterProcess(ionIoni, particle); - if (nullptr != pnuc) { - ph->RegisterProcess(pnuc, particle); - } + // // generic ion + // G4ParticleDefinition *particle = G4GenericIon::GenericIon(); + // G4ionIonisation *ionIoni = new G4ionIonisation(); + // ph->RegisterProcess(hmsc, particle); + // ph->RegisterProcess(ionIoni, particle); + // if (nullptr != pnuc) { + // ph->RegisterProcess(pnuc, particle); + // } - // muons, hadrons ions - G4EmBuilder::ConstructCharged(hmsc, pnuc); + // // muons, hadrons ions + // G4EmBuilder::ConstructCharged(hmsc, pnuc); - // extra configuration - G4EmModelActivator mact(GetPhysicsName()); + // // extra configuration + // G4EmModelActivator mact(GetPhysicsName()); - // end of G4EmStandardPhysics + // // end of G4EmStandardPhysics } From ee621f6e4f2bed699d19270b4053478360b3294f Mon Sep 17 00:00:00 2001 From: JuanGonzalezCaminero Date: Tue, 15 Oct 2024 16:07:21 +0200 Subject: [PATCH 2/3] Temp --- examples/Example1/example1.cpp | 4 +- examples/common/src/FTFP_BERT_AdePT.cc | 2 +- examples/common/src/FTFP_BERT_HepEm.cc | 2 +- include/AdePT/integration/HepEMPhysics.hh | 8 +- src/HepEMPhysics.cc | 116 +++++++++++----------- 5 files changed, 68 insertions(+), 64 deletions(-) diff --git a/examples/Example1/example1.cpp b/examples/Example1/example1.cpp index 469eee83b..8607d9d4b 100644 --- a/examples/Example1/example1.cpp +++ b/examples/Example1/example1.cpp @@ -48,7 +48,7 @@ int main(int argc, char **argv) } // Initialization of default Run manager - auto *runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default); + std::unique_ptr runManager(G4RunManagerFactory::CreateRunManager()); // auto *runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Serial); // Detector geometry: @@ -84,7 +84,5 @@ int main(int argc, char **argv) // owned and deleted by the run manager, so they should not // be deleted in the main() program ! - delete runManager; - return err; } diff --git a/examples/common/src/FTFP_BERT_AdePT.cc b/examples/common/src/FTFP_BERT_AdePT.cc index 13b2ca82c..b5d702b77 100644 --- a/examples/common/src/FTFP_BERT_AdePT.cc +++ b/examples/common/src/FTFP_BERT_AdePT.cc @@ -39,7 +39,7 @@ FTFP_BERT_AdePT::FTFP_BERT_AdePT(G4int ver) // Register the EM physics to use for tracking on CPU // RegisterPhysics(new G4EmStandardPhysics()); - RegisterPhysics(new HepEMPhysics()); + RegisterPhysics(new HepEMPhysics(ver)); // Register the AdePT physics RegisterPhysics(new AdePTPhysics()); diff --git a/examples/common/src/FTFP_BERT_HepEm.cc b/examples/common/src/FTFP_BERT_HepEm.cc index f00f016d8..53dc99508 100644 --- a/examples/common/src/FTFP_BERT_HepEm.cc +++ b/examples/common/src/FTFP_BERT_HepEm.cc @@ -36,7 +36,7 @@ FTFP_BERT_HepEm::FTFP_BERT_HepEm(G4int ver) // EM Physics // RegisterPhysics( new G4EmStandardPhysics(ver)); - RegisterPhysics(new HepEMPhysics()); + RegisterPhysics(new HepEMPhysics(ver)); // Synchroton Radiation & GN Physics // comenting out to remove gamma- and lepto-nuclear processes diff --git a/include/AdePT/integration/HepEMPhysics.hh b/include/AdePT/integration/HepEMPhysics.hh index 0163c6549..1960e8074 100644 --- a/include/AdePT/integration/HepEMPhysics.hh +++ b/include/AdePT/integration/HepEMPhysics.hh @@ -4,12 +4,14 @@ #ifndef HepEMPhysics_h #define HepEMPhysics_h 1 -#include "G4VPhysicsConstructor.hh" +// #include "G4VPhysicsConstructor.hh" +#include "G4EmStandardPhysics.hh" #include "globals.hh" -class HepEMPhysics : public G4VPhysicsConstructor { +// class HepEMPhysics : public G4VPhysicsConstructor { +class HepEMPhysics : public G4EmStandardPhysics { public: - HepEMPhysics(const G4String &name = "G4HepEm-physics-list"); + HepEMPhysics(int ver, const G4String &name = "G4HepEm-physics-list"); ~HepEMPhysics(); public: diff --git a/src/HepEMPhysics.cc b/src/HepEMPhysics.cc index a7e7d1bfb..422776179 100644 --- a/src/HepEMPhysics.cc +++ b/src/HepEMPhysics.cc @@ -43,7 +43,8 @@ #include "G4ionIonisation.hh" #include "G4NuclearStopping.hh" -HepEMPhysics::HepEMPhysics(const G4String &name) : G4VPhysicsConstructor(name) +HepEMPhysics::HepEMPhysics(int ver, const G4String &name) : G4EmStandardPhysics(ver, name) +// HepEMPhysics::HepEMPhysics(int ver, const G4String &name) : G4VPhysicsConstructor(name) { G4EmParameters *param = G4EmParameters::Instance(); param->SetDefaults(); @@ -51,7 +52,6 @@ HepEMPhysics::HepEMPhysics(const G4String &name) : G4VPhysicsConstructor(name) // Range factor: (can be set from the G4 macro) param->SetMscRangeFactor(0.04); - // SetPhysicsType(bElectromagnetic); } @@ -60,76 +60,80 @@ HepEMPhysics::~HepEMPhysics() {} void HepEMPhysics::ConstructProcess() { - // Register custom tracking manager for e-/e+ and gammas. - auto trackingManager = new G4HepEmTrackingManager(); - G4Electron::Definition()->SetTrackingManager(trackingManager); - G4Positron::Definition()->SetTrackingManager(trackingManager); - G4Gamma::Definition()->SetTrackingManager(trackingManager); + // G4EmStandardPhysics::ConstructProcess(); + + // // Register custom tracking manager for e-/e+ and gammas. + // auto *trackingManager = new G4HepEmTrackingManager(); + // G4Electron::Definition()->SetTrackingManager(trackingManager); + // G4Positron::Definition()->SetTrackingManager(trackingManager); + // G4Gamma::Definition()->SetTrackingManager(trackingManager); + + // Integration trough G4 process: - // G4PhysicsListHelper *ph = G4PhysicsListHelper::GetPhysicsListHelper(); + G4PhysicsListHelper *ph = G4PhysicsListHelper::GetPhysicsListHelper(); - // // from G4EmStandardPhysics - // G4EmBuilder::PrepareEMPhysics(); + // from G4EmStandardPhysics + G4EmBuilder::PrepareEMPhysics(); - // G4EmParameters *param = G4EmParameters::Instance(); + G4EmParameters *param = G4EmParameters::Instance(); - // // processes used by several particles - // G4hMultipleScattering *hmsc = new G4hMultipleScattering("ionmsc"); + // processes used by several particles + G4hMultipleScattering *hmsc = new G4hMultipleScattering("ionmsc"); - // // nuclear stopping is enabled if th eenergy limit above zero - // G4double nielEnergyLimit = param->MaxNIELEnergy(); - // G4NuclearStopping *pnuc = nullptr; - // if (nielEnergyLimit > 0.0) { - // pnuc = new G4NuclearStopping(); - // pnuc->SetMaxKinEnergy(nielEnergyLimit); - // } - // // end of G4EmStandardPhysics + // nuclear stopping is enabled if th eenergy limit above zero + G4double nielEnergyLimit = param->MaxNIELEnergy(); + G4NuclearStopping *pnuc = nullptr; + if (nielEnergyLimit > 0.0) { + pnuc = new G4NuclearStopping(); + pnuc->SetMaxKinEnergy(nielEnergyLimit); + } + // end of G4EmStandardPhysics - // // creae the only one G4HepEm process that will be assigned to e-/e+ and gamma - // G4HepEmProcess *hepEmProcess = new G4HepEmProcess(); + // creae the only one G4HepEm process that will be assigned to e-/e+ and gamma + G4HepEmProcess *hepEmProcess = new G4HepEmProcess(); - // // Add standard EM Processes - // // - // auto aParticleIterator = GetParticleIterator(); - // aParticleIterator->reset(); - // while ((*aParticleIterator)()) { - // G4ParticleDefinition *particle = aParticleIterator->value(); - // G4String particleName = particle->GetParticleName(); + // Add standard EM Processes + // + auto aParticleIterator = GetParticleIterator(); + aParticleIterator->reset(); + while ((*aParticleIterator)()) { + G4ParticleDefinition *particle = aParticleIterator->value(); + G4String particleName = particle->GetParticleName(); - // if (particleName == "gamma") { + if (particleName == "gamma") { - // // Add G4HepEm process to gamma: includes Conversion, Compton and photoelectric effect. - // particle->GetProcessManager()->AddProcess(hepEmProcess, -1, -1, 1); + // Add G4HepEm process to gamma: includes Conversion, Compton and photoelectric effect. + particle->GetProcessManager()->AddProcess(hepEmProcess, -1, -1, 1); - // } else if (particleName == "e-") { + } else if (particleName == "e-") { - // // Add G4HepEm process to e-: includes Ionisation and Bremsstrahlung for e- - // particle->GetProcessManager()->AddProcess(hepEmProcess, -1, -1, 1); + // Add G4HepEm process to e-: includes Ionisation and Bremsstrahlung for e- + particle->GetProcessManager()->AddProcess(hepEmProcess, -1, -1, 1); - // } else if (particleName == "e+") { + } else if (particleName == "e+") { - // // Add G4HepEm process to e+: includes Ionisation, Bremsstrahlung and e+e- - // // annihilation into 2 gamma interactions for e+ - // particle->GetProcessManager()->AddProcess(hepEmProcess, -1, -1, 1); - // } - // } + // Add G4HepEm process to e+: includes Ionisation, Bremsstrahlung and e+e- + // annihilation into 2 gamma interactions for e+ + particle->GetProcessManager()->AddProcess(hepEmProcess, -1, -1, 1); + } + } - // // from G4EmStandardPhysics + // from G4EmStandardPhysics - // // generic ion - // G4ParticleDefinition *particle = G4GenericIon::GenericIon(); - // G4ionIonisation *ionIoni = new G4ionIonisation(); - // ph->RegisterProcess(hmsc, particle); - // ph->RegisterProcess(ionIoni, particle); - // if (nullptr != pnuc) { - // ph->RegisterProcess(pnuc, particle); - // } + // generic ion + G4ParticleDefinition *particle = G4GenericIon::GenericIon(); + G4ionIonisation *ionIoni = new G4ionIonisation(); + ph->RegisterProcess(hmsc, particle); + ph->RegisterProcess(ionIoni, particle); + if (nullptr != pnuc) { + ph->RegisterProcess(pnuc, particle); + } - // // muons, hadrons ions - // G4EmBuilder::ConstructCharged(hmsc, pnuc); + // muons, hadrons ions + G4EmBuilder::ConstructCharged(hmsc, pnuc); - // // extra configuration - // G4EmModelActivator mact(GetPhysicsName()); + // extra configuration + G4EmModelActivator mact(GetPhysicsName()); - // // end of G4EmStandardPhysics + // end of G4EmStandardPhysics } From cc2e232f163fb481f247ce2241be3e975aac9bc5 Mon Sep 17 00:00:00 2001 From: JuanGonzalezCaminero Date: Tue, 15 Oct 2024 16:40:26 +0200 Subject: [PATCH 3/3] Activate G4HepEM Tracking manager --- src/HepEMPhysics.cc | 112 ++++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/src/HepEMPhysics.cc b/src/HepEMPhysics.cc index 422776179..5d3e77809 100644 --- a/src/HepEMPhysics.cc +++ b/src/HepEMPhysics.cc @@ -60,80 +60,80 @@ HepEMPhysics::~HepEMPhysics() {} void HepEMPhysics::ConstructProcess() { - // G4EmStandardPhysics::ConstructProcess(); + G4EmStandardPhysics::ConstructProcess(); - // // Register custom tracking manager for e-/e+ and gammas. - // auto *trackingManager = new G4HepEmTrackingManager(); - // G4Electron::Definition()->SetTrackingManager(trackingManager); - // G4Positron::Definition()->SetTrackingManager(trackingManager); - // G4Gamma::Definition()->SetTrackingManager(trackingManager); + // Register custom tracking manager for e-/e+ and gammas. + auto *trackingManager = new G4HepEmTrackingManager(); + G4Electron::Definition()->SetTrackingManager(trackingManager); + G4Positron::Definition()->SetTrackingManager(trackingManager); + G4Gamma::Definition()->SetTrackingManager(trackingManager); - // Integration trough G4 process: + // // Integration trough G4 process: - G4PhysicsListHelper *ph = G4PhysicsListHelper::GetPhysicsListHelper(); + // G4PhysicsListHelper *ph = G4PhysicsListHelper::GetPhysicsListHelper(); - // from G4EmStandardPhysics - G4EmBuilder::PrepareEMPhysics(); + // // from G4EmStandardPhysics + // G4EmBuilder::PrepareEMPhysics(); - G4EmParameters *param = G4EmParameters::Instance(); + // G4EmParameters *param = G4EmParameters::Instance(); - // processes used by several particles - G4hMultipleScattering *hmsc = new G4hMultipleScattering("ionmsc"); + // // processes used by several particles + // G4hMultipleScattering *hmsc = new G4hMultipleScattering("ionmsc"); - // nuclear stopping is enabled if th eenergy limit above zero - G4double nielEnergyLimit = param->MaxNIELEnergy(); - G4NuclearStopping *pnuc = nullptr; - if (nielEnergyLimit > 0.0) { - pnuc = new G4NuclearStopping(); - pnuc->SetMaxKinEnergy(nielEnergyLimit); - } - // end of G4EmStandardPhysics + // // nuclear stopping is enabled if th eenergy limit above zero + // G4double nielEnergyLimit = param->MaxNIELEnergy(); + // G4NuclearStopping *pnuc = nullptr; + // if (nielEnergyLimit > 0.0) { + // pnuc = new G4NuclearStopping(); + // pnuc->SetMaxKinEnergy(nielEnergyLimit); + // } + // // end of G4EmStandardPhysics - // creae the only one G4HepEm process that will be assigned to e-/e+ and gamma - G4HepEmProcess *hepEmProcess = new G4HepEmProcess(); + // // creae the only one G4HepEm process that will be assigned to e-/e+ and gamma + // G4HepEmProcess *hepEmProcess = new G4HepEmProcess(); - // Add standard EM Processes - // - auto aParticleIterator = GetParticleIterator(); - aParticleIterator->reset(); - while ((*aParticleIterator)()) { - G4ParticleDefinition *particle = aParticleIterator->value(); - G4String particleName = particle->GetParticleName(); + // // Add standard EM Processes + // // + // auto aParticleIterator = GetParticleIterator(); + // aParticleIterator->reset(); + // while ((*aParticleIterator)()) { + // G4ParticleDefinition *particle = aParticleIterator->value(); + // G4String particleName = particle->GetParticleName(); - if (particleName == "gamma") { + // if (particleName == "gamma") { - // Add G4HepEm process to gamma: includes Conversion, Compton and photoelectric effect. - particle->GetProcessManager()->AddProcess(hepEmProcess, -1, -1, 1); + // // Add G4HepEm process to gamma: includes Conversion, Compton and photoelectric effect. + // particle->GetProcessManager()->AddProcess(hepEmProcess, -1, -1, 1); - } else if (particleName == "e-") { + // } else if (particleName == "e-") { - // Add G4HepEm process to e-: includes Ionisation and Bremsstrahlung for e- - particle->GetProcessManager()->AddProcess(hepEmProcess, -1, -1, 1); + // // Add G4HepEm process to e-: includes Ionisation and Bremsstrahlung for e- + // particle->GetProcessManager()->AddProcess(hepEmProcess, -1, -1, 1); - } else if (particleName == "e+") { + // } else if (particleName == "e+") { - // Add G4HepEm process to e+: includes Ionisation, Bremsstrahlung and e+e- - // annihilation into 2 gamma interactions for e+ - particle->GetProcessManager()->AddProcess(hepEmProcess, -1, -1, 1); - } - } + // // Add G4HepEm process to e+: includes Ionisation, Bremsstrahlung and e+e- + // // annihilation into 2 gamma interactions for e+ + // particle->GetProcessManager()->AddProcess(hepEmProcess, -1, -1, 1); + // } + // } - // from G4EmStandardPhysics + // // from G4EmStandardPhysics - // generic ion - G4ParticleDefinition *particle = G4GenericIon::GenericIon(); - G4ionIonisation *ionIoni = new G4ionIonisation(); - ph->RegisterProcess(hmsc, particle); - ph->RegisterProcess(ionIoni, particle); - if (nullptr != pnuc) { - ph->RegisterProcess(pnuc, particle); - } + // // generic ion + // G4ParticleDefinition *particle = G4GenericIon::GenericIon(); + // G4ionIonisation *ionIoni = new G4ionIonisation(); + // ph->RegisterProcess(hmsc, particle); + // ph->RegisterProcess(ionIoni, particle); + // if (nullptr != pnuc) { + // ph->RegisterProcess(pnuc, particle); + // } - // muons, hadrons ions - G4EmBuilder::ConstructCharged(hmsc, pnuc); + // // muons, hadrons ions + // G4EmBuilder::ConstructCharged(hmsc, pnuc); - // extra configuration - G4EmModelActivator mact(GetPhysicsName()); + // // extra configuration + // G4EmModelActivator mact(GetPhysicsName()); - // end of G4EmStandardPhysics + // // end of G4EmStandardPhysics }