Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPU integration of G4HepEM using the tracking manager #316

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions examples/Example1/example1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int main(int argc, char **argv)
}

// Initialization of default Run manager
auto *runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
std::unique_ptr<G4RunManager> runManager(G4RunManagerFactory::CreateRunManager());
// auto *runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Serial);

// Detector geometry:
Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion examples/common/src/FTFP_BERT_AdePT.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion examples/common/src/FTFP_BERT_HepEm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions include/AdePT/integration/HepEMPhysics.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
112 changes: 61 additions & 51 deletions src/HepEMPhysics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

// include the G4HepEmProcess from the G4HepEm lib.
#include "G4HepEmProcess.hh"
#include "G4HepEmTrackingManager.hh"

#include "G4ParticleDefinition.hh"
#include "G4ProcessManager.hh"
Expand Down Expand Up @@ -42,15 +43,15 @@
#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();
param->SetVerbose(1);

// Range factor: (can be set from the G4 macro)
param->SetMscRangeFactor(0.04);
//

SetPhysicsType(bElectromagnetic);
}
Expand All @@ -59,71 +60,80 @@ HepEMPhysics::~HepEMPhysics() {}

void HepEMPhysics::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);

G4PhysicsListHelper *ph = G4PhysicsListHelper::GetPhysicsListHelper();
// // Integration trough G4 process:

// from G4EmStandardPhysics
G4EmBuilder::PrepareEMPhysics();
// G4PhysicsListHelper *ph = G4PhysicsListHelper::GetPhysicsListHelper();

G4EmParameters *param = G4EmParameters::Instance();
// // from G4EmStandardPhysics
// G4EmBuilder::PrepareEMPhysics();

// 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
}
Loading