3 #include <G4RunManager.hh>
4 #include <G4UImanager.hh>
5 #include <G4ParticleTable.hh>
6 #include <G4VUserDetectorConstruction.hh>
7 #include <G4VUserPrimaryGeneratorAction.hh>
8 #include <G4VUserPhysicsList.hh>
10 #include <G4ParticleDefinition.hh>
11 #include <G4ProcessVector.hh>
12 #include <G4VisManager.hh>
13 #include <G4UImanager.hh>
19 #include <fwk/CentralConfig.h>
20 #include <fwk/RandomEngineRegistry.h>
21 #include <utl/ErrorLogger.h>
23 #include <utl/AugerException.h>
24 #include <tls/DefaultPhysicsList.h>
25 #include <tls/G4OutputHandler.h>
32 Geant4Manager::Geant4Manager() :
33 fRunManager(new G4RunManager()),
36 fPhysicsInitialized(false),
41 INFO(
"creating and initializing runmanager..");
44 CLHEP::HepRandom::setTheEngine(
69 throw utl::AugerException(
"Cannot set default physics list after Geant4 run manager is initialized.");
71 cd.SetPhysicsList(physicsList);
80 INFO(
"Initializing physics...");
105 INFO(
"deleting G4RunManager..");
109 WARNING(
"RunManger was already deleted at an earlier stage!");
112 INFO(
"deleting G4VisManager..");
117 ERROR(
"The use of Geant4Manager seems inconsistent! More Modules ask for deletion than initially registered!");
131 "G4 should have already failed at this point..");
156 msg <<
"Unknown Geant4 customization: " << name;
160 cout <<
"Customizing " << name << endl;
162 G4VUserDetectorConstruction*
const detectorConstruction = it->second.GetDetectorConstruction();
164 fRunManager->SetUserInitialization(detectorConstruction);
169 INFO(
"Updating geometry...");
170 fRunManager->DefineWorldVolume(detectorConstruction->Construct(),
true);
173 INFO(
"Updating processes...");
175 if (physicsListCustomization) {
183 fRunManager->SetUserAction(it->second.GetPrimaryGenerator());
185 fRunManager->SetUserAction(it->second.GetStackingAction());
186 fRunManager->SetUserAction(it->second.GetTrackingAction());
187 fRunManager->SetUserAction(it->second.GetSteppingAction());
188 fRunManager->SetUserAction(it->second.GetEventAction());
189 fRunManager->SetUserAction(it->second.GetRunAction());
203 INFO(
"Setting default geometry...");
204 G4VUserDetectorConstruction*
const detectorConstruction =
fCustomizations[
"Default"].GetDetectorConstruction();
206 fRunManager->SetUserInitialization(detectorConstruction);
207 fRunManager->DefineWorldVolume(detectorConstruction->Construct(),
true);
215 fRunManager->SetUserAction(static_cast<G4VUserPrimaryGeneratorAction*>(
nullptr));
216 fRunManager->SetUserAction(static_cast<G4UserStackingAction*>(
nullptr));
217 fRunManager->SetUserAction(static_cast<G4UserTrackingAction*>(
nullptr));
218 fRunManager->SetUserAction(static_cast<G4UserSteppingAction*>(
nullptr));
219 fRunManager->SetUserAction(static_cast<G4UserEventAction*>(
nullptr));
220 fRunManager->SetUserAction(static_cast<G4UserRunAction*>(
nullptr));
227 INFO(
"dumping process info for all particles--");
228 auto& partIt = *G4ParticleTable::GetParticleTable()->GetIterator();
229 for (partIt.reset(); partIt(); ) {
231 cout <<
"particle " <<
particle.GetParticleName() << endl;
232 const auto procMan =
particle.GetProcessManager();
234 ERROR(
"ProcessManager not found!");
236 auto& procList = *procMan->GetProcessList();
237 for (
unsigned int j = 0, n = procList.size(); j < n; ++j)
238 G4cerr <<
"process " << procList[j]->GetProcessName() <<
' '
239 << (procMan->GetProcessActivation(procList[j]) ?
"active" :
"inactive") << G4endl;
250 auto& partIt = *G4ParticleTable::GetParticleTable()->GetIterator();
251 std::ostringstream msg;
252 for (partIt.reset(); partIt(); ) {
254 auto& procMan = *
particle.GetProcessManager();
255 auto& proc = *procMan.GetProcessList();
256 for (
int i = 0, n = procMan.GetProcessListLength(); i < n; ++i) {
257 proc[i]->SetVerboseLevel(0);
258 msg <<
"process: " << proc[i]->GetProcessName() <<
" for "
259 <<
particle.GetParticleName() <<
": " << proc[i]->GetVerboseLevel() <<
'\n';
G4VUserPhysicsList to aggregate physics lists to be used by multiple Geant4 modules in one offline se...
Base class for all exceptions used in the auger offline code.
G4VisManager * fVisManager
virtual bool InactivateCustomProcesses()=0
#define INFO(message)
Macro for logging informational messages.
void Reset()
Undo the customizations introduced by the current configuration.
void AddCustomization(Geant4Customization &custom)
unsigned int fClosedModules
void AddVisManager(G4VisManager *visManager)
Add a visualization manager. Only one visualization manager is accepted.
GlobalPhysicsList * fMasterPhysicsList
void RegisterPhysics(const G4String &name, G4VUserPhysicsList *userList)
This class redirects Geant4's streams G4cerr and G4cerr to the framework's utl::ErrorLogger.
std::string GetName() const
virtual bool ActivateCustomProcesses()=0
G4RunManager * fRunManager
void NotifyDelete()
Book-keeping method. Call this to let the manager know your module does not need Geant4 anymore...
std::map< std::string, Geant4Customization > fCustomizations
Data structure to hold the different Geant4 global objects required to run a single module...
#define WARNING(message)
Macro for logging warning messages.
void SetVerbosity(int verbosity)
std::string fCurrentCustomization
unsigned int fVerboseLevel
G4VUserPhysicsList * GetPhysicsList()
virtual void SetCustomCuts()=0
struct particle_info particle[80]
G4VUserDetectorConstruction * GetDetectorConstruction()
utl::CoordinateSystemPtr Get(const std::string &id)
Get a well-known Coordinate System.
#define ERROR(message)
Macro for logging error messages.
void Customize(const std::string &name)
void SetDefaultPhysicsList(G4VUserPhysicsList *physicsList)
Set the default physics list. This will throw an exception if the run manager has been initialized al...
Class to specify customization of the standard global PhysicsList that are handled by the Geant4Manag...
Default physics list to be used by multiple Geant4 modules in one offline session.