34 #include "G4Version.hh"
35 #include "G4UserRunAction.hh"
36 #include "G4UserEventAction.hh"
37 #include "G4UserTrackingAction.hh"
38 #include "G4UserStackingAction.hh"
39 #include "G4UserSteppingAction.hh"
40 #include "G4VUserPhysicsList.hh"
41 #include "G4VModularPhysicsList.hh"
42 #include "G4VUserPrimaryGeneratorAction.hh"
43 #include "G4VUserActionInitialization.hh"
44 #include "G4VUserDetectorConstruction.hh"
51 G4Mutex action_mutex=G4MUTEX_INITIALIZER;
58 namespace Simulation {
292 (*m_sequence)(
s, fpSteppingManager);
304 public SequenceHdl<Geant4DetectorConstructionSequence>
332 public SequenceHdl<Geant4UserInitializationSequence>
343 virtual void Build()
const;
379 (*m_sequence)(event);
382 throw std::runtime_error(
"GeneratePrimaries: Panic! No action sequencer defined. "
383 "No primary particles can be produced.");
388 G4AutoLock protection_lock(&action_mutex);
402 G4AutoLock protection_lock(&action_mutex);
406 m_sequence->
except(
"+++ Executing G4 detector construction did not result in a valid world volume!");
413 G4AutoLock protection_lock(&action_mutex);
419 m_sequence->
info(
"+++ Executing Geant4UserActionInitialization::Build. "
420 "Context:%p Kernel:%p [%ld]", (
void*)ctx, (
void*)&krnl, krnl.
id());
428 SetUserAction(gen_action);
432 SetUserAction(run_action);
438 SetUserAction(evt_action);
444 SetUserAction(action);
450 SetUserAction(action);
456 SetUserAction(action);
464 m_sequence->
info(
"+++ Executing Geant4UserActionInitialization::BuildForMaster....");
477 using namespace DD4hep;
478 using namespace DD4hep::Simulation;
481 #include "G4RunManager.hh"
482 #include "G4PhysListFactory.hh"
494 printout(
WARNING,
"Geant4Exec",
"+++ Building default Geant4DetectorConstruction for single threaded compatibility.");
497 cr = PluginService::Create<Geant4Action*>(
"Geant4DetectorGeometryConstruction",ctx,string(
"ConstructGeometry"));
502 throw runtime_error(
"Panic! Failed to build Geant4DetectorGeometryConstruction.");
504 cr = PluginService::Create<Geant4Action*>(
"Geant4DetectorSensitivesConstruction",ctx,string(
"ConstructSensitives"));
509 throw runtime_error(
"Panic! Failed to build Geant4DetectorSensitivesConstruction.");
524 Geant4Random::setMainInstance(rndm);
528 G4RunManager& runManager = kernel.
runManager();
533 "You sure you loaded the geometry properly?",
540 throw runtime_error(
"Panic! No valid detector construction sequencer present. [Mandatory MT]");
546 runManager.SetUserInitialization(det_seq);
550 if ( 0 == phys_seq ) {
551 string phys_model =
"QGSP_BERT";
557 throw runtime_error(
"Panic! No valid user physics list present!");
562 physics->SetDefaultCutValue(phys_seq->
m_rangecut);
566 runManager.SetUserInitialization(physics);
571 throw runtime_error(
"Panic! No valid user initialization sequencer present. [Mandatory MT]");
578 runManager.SetUserInitialization(init);
585 G4RunManager& runManager = kernel.
runManager();
590 runManager.Initialize();
597 string value = p.
value<
string>();
600 if ( !value.empty() ) {
609 ui->
except(
"++ Geant4Exec: Failed to start UI interface.");
611 throw runtime_error(
format(
"Geant4Exec",
"++ Failed to locate UI interface %s.",value.c_str()));
virtual void prepare()
Preparation callback.
Geant4UserInitializationSequence * userInitialization(bool create)
Access to the user initialization object.
virtual ~Geant4UserDetectorConstruction()
Default destructor.
void setTrackMgr(G4TrackingManager *mgr)
Access the tracking manager.
The property class to assign options to actions.
Concrete implementation of the Geant4 stepping action sequence.
Concrete implementation of the Geant4 user initialization action sequence.
Geant4Kernel & worker(unsigned long thread_identifier, bool create_if=false)
Access worker instance by it's identifier.
static unsigned long int thread_self()
Access thread identifier.
User event context for DDG4.
virtual const HandleMap & sensitiveDetectors() const =0
Accessor to the map of sub-detectors.
Geant4UserActionInitialization(Geant4Context *ctxt, Geant4UserInitializationSequence *seq)
Standard constructor.
Class to orchestrate a modular initializion of a multi- or single threaded Geant4 application...
double m_rangecut
global range cut for secondary productions
virtual void constructGeo(Geant4DetectorConstructionContext *ctxt)
Geometry construction callback. Called at "Construct()".
void deletePtr(T *&p)
Helper to delete objects from heap and reset the pointer. Saves many many lines of code...
Geant4UserRunAction * runAction
Geant4Kernel & kernel() const
Access to the kernel object.
G4VPhysicalVolume * world
Reference to the world after construction.
Geant4SteppingActionSequence * steppingAction(bool create)
Access stepping action sequence.
virtual void UserSteppingAction(const G4Step *s)
User stepping callback.
virtual void EndOfEventAction(const G4Event *evt)
End-of-event callback.
virtual void BeginOfRunAction(const G4Run *run)
Begin-of-run callback.
SequenceHdl(Geant4Context *ctxt, T *seq)
Concrete implementation of the Geant4 generator action.
virtual ~Geant4UserGeneratorAction()
Default destructor.
void destroyClientContext(const G4Run *)
Geant4TrackingActionSequence * trackingAction(bool create)
Access tracking action sequence.
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
virtual void end(const G4Run *run)
End-of-run callback.
static void decrement(T *)
Decrement count according to type information.
Concrete basic implementation of the Geant4 detector construction sequencer.
Geant4Context * context() const
void createClientContext(const G4Run *run)
void adopt(Geant4DetectorConstruction *action)
Add an actor responding to all callbacks. Sequence takes ownership.
Geant4StackingActionSequence * stackingAction(bool create)
Access stacking action sequence.
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
virtual ~Geant4UserSteppingAction()
Default destructor.
virtual void end(const G4Track *track)
Post-tracking action callback.
virtual void NewStage()
New-stage callback.
Concrete implementation of the Geant4 run action.
LCDD & lcdd() const
Access to detector description.
Sequence handler implementing common actions to all sequences.
Concrete implementation of the Geant4 event action sequence.
void createClientContext(const G4Event *evt)
PrintLevel printLevel()
Access the current printer level.
void build(Q *p, void(T::*f)())
Register callback to setup worker. Types Q and T must be polymorph!
virtual void BuildForMaster() const
Build the action sequences for the master thread.
virtual ~Geant4UserActionInitialization()
Default destructor.
Property & property(const std::string &name)
Access single property.
Geant4Context * context() const
Access the context.
Concrete implementation of the Geant4 tracking action sequence.
virtual void constructSensitives(Geant4DetectorConstructionContext *ctxt)
Sensitive detector construction callback. Called at "ConstructSDandField()".
void destroyClientContext(const G4Event *)
Geant4UserEventAction(Geant4Context *ctxt, Geant4EventActionSequence *seq)
Standard constructor.
Geant4Kernel & kernel() const
void except(const char *fmt,...) const
Support of exceptions: Print fatal message and throw runtime_error.
std::string format(const std::string &src, const std::string &fmt,...)
Build formatted string.
void releasePtr(T &p)
Helper to delete objects from heap and reset the pointer. Saves many many lines of code...
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
void initialize()
Initialize the instance.
Concrete implementation of the Geant4 stacking action sequence.
static Geant4Random * instance(bool throw_exception=true)
Access the main Geant4 random generator instance. Must be created before used!
virtual G4VPhysicalVolume * Construct()
Call the actions to construct the detector geometry.
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Class, which allows all Geant4Action derivatives to access the DDG4 kernel structures.
virtual ~Geant4UserTrackingAction()
Default destructor.
Geant4DetectorConstructionSequence * buildDefaultDetectorConstruction(Geant4Kernel &kernel)
virtual void EndOfRunAction(const G4Run *run)
End-of-run callback.
Geant4PhysicsListActionSequence * physicsList(bool create)
Access to the physics list.
Geant4UserDetectorConstruction(Geant4Context *ctxt, Geant4DetectorConstructionSequence *seq)
Standard constructor.
Geant4EventActionSequence * eventAction(bool create)
Access run action sequence.
Property & property(const std::string &name)
Access single property.
bool isMultiThreaded() const
virtual void GeneratePrimaries(G4Event *event)
Generate primary particles.
virtual void PrepareNewEvent()
Preparation callback.
The implementation of the single Geant4 physics list action sequence.
virtual void newStage()
New-stage callback.
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
virtual ~Geant4UserRunAction()
Default destructor.
virtual void end(const G4Event *event)
End-of-event callback.
User run context for DDG4.
Concrete implementation of the Geant4 user detector construction action sequence. ...
virtual void Build() const
Build the actions for the worker thread.
Geant4GeneratorActionSequence * generatorAction(bool create)
Access generator action sequence.
Concrete implementation of the Geant4 generator action sequence.
Concrete basic implementation of the Geant4 run action sequencer.
virtual ~Geant4UserStackingAction()
Default destructor.
Geant4Context * workerContext()
Thread's Geant4 execution context.
Geant4UserSteppingAction(Geant4Context *ctxt, Geant4SteppingActionSequence *seq)
Standard constructor.
Geant4UserRunAction(Geant4Context *ctxt, Geant4RunActionSequence *seq)
Standard constructor.
virtual void updateContext(Geant4Context *ctxt)
Set client context.
void updateContext(Geant4Context *ctxt)
TYPE value() const
Retrieve value.
Geant4DetectorConstructionSequence * detectorConstruction(bool create)
Access detector construcion action sequence (geometry+sensitives+field)
static void increment(T *)
Increment count according to type information.
virtual bool executePhase(const std::string &name, const void **args) const
Execute phase action if it exists.
void setEvent(Geant4Event *new_event)
Set the geant4 event reference.
virtual void PostUserTrackingAction(const G4Track *trk)
Post-track action callback.
Geant4Context * m_activeContext
virtual void ConstructSDandField()
Call the actions for the construction of the sensitive detectors and the field.
Geant4UserGeneratorAction(Geant4Context *ctxt, Geant4GeneratorActionSequence *seq)
Standard constructor.
void setRun(Geant4Run *new_run)
Set the geant4 run reference.
virtual void BeginOfEventAction(const G4Event *evt)
Begin-of-event callback.
G4RunManager & runManager()
Access to the Geant4 run manager.
Concrete implementation of the Geant4 stacking action sequence.
Geant4Event * eventPtr() const
Access the geant4 event by ptr. Must be checked by clients!
Concrete implementation of the Geant4 event action.
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Generic context to extend user, run and event information.
void buildMaster(Q *p, void(T::*f)())
Register callback to setup master. Types Q and T must be polymorph!
Geant4DetectorConstructionContext m_ctxt
Basic implementation of the Geant4 detector construction action.
Geant4UserEventAction * eventAction
The main interface to the DD4hep detector description package.
Concrete implementation of the Geant4 stepping action.
Mini interface to THE random generator of the application.
G4VUserPhysicsList * extensionList()
Extend physics list from factory:
unsigned long id() const
Access worker identifier.
void info(const char *fmt,...) const
Support of info messages.
Concrete implementation of the Geant4 tracking action.
virtual void PreUserTrackingAction(const G4Track *trk)
Pre-track action callback.
virtual ~Geant4UserEventAction()
Default destructor.
Callback interface class with argument.
int printout(PrintLevel severity, const char *src, const char *fmt,...)
Calls the display action with a given severity level.
Geant4UserTrackingAction(Geant4Context *ctxt, Geant4TrackingActionSequence *seq)
Standard constructor.
void set(const TYPE &value)
Set value of this property.
SequenceHdl()
Default constructor.
Geant4Action * globalAction(const std::string &action_name, bool throw_if_not_present=true)
Retrieve action from repository.
virtual void constructField(Geant4DetectorConstructionContext *ctxt)
Electromagnetic field construction callback. Called at "ConstructSDandField()".
Default base class for all Geant 4 actions and derivates thereof.
virtual void begin(const G4Event *event)
Begin-of-event callback.
void configureFiber(Geant4Context *ctxt)
Geant4 detector construction context definition.
virtual void begin(const G4Track *track)
Pre-tracking action callback.
Geant4Run * runPtr() const
Access the geant4 run by ptr. Must be checked by clients!
Geant4RunActionSequence * runAction(bool create)
Access run action sequence.
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Geant4UserStackingAction(Geant4Context *ctxt, Geant4StackingActionSequence *seq)
Standard constructor.
virtual void begin(const G4Run *run)
Begin-of-run callback.