 |
DD4hep
1.35.0
Detector Description Toolkit for High Energy Physics
|
Go to the documentation of this file.
24 #include <G4VPhysicsConstructor.hh>
25 #include <G4PhysListFactory.hh>
26 #include <G4ProcessManager.hh>
27 #include <G4ParticleTable.hh>
28 #include <G4RunManager.hh>
29 #include <G4VProcess.hh>
31 #include <G4EmParameters.hh>
32 #include <G4HadronicParameters.hh>
42 struct MyPhysics : G4VUserPhysicsList {
43 void AddTransportation() { this->G4VUserPhysicsList::AddTransportation(); }
46 struct EmptyPhysics :
public G4VModularPhysicsList {
47 EmptyPhysics() =
default;
48 virtual ~EmptyPhysics() =
default;
52 G4VUserPhysicsList* phys;
54 virtual ~ParticlePhysics() =
default;
55 virtual void ConstructProcess() {
58 MyPhysics* ph = (MyPhysics*)phys;
59 ph->AddTransportation();
62 virtual void ConstructParticle() {
70 : ordAtRestDoIt(-1), ordAlongSteptDoIt(-1), ordPostStepDoIt(-1) {
74 :
name(p.
name), ordAtRestDoIt(p.ordAtRestDoIt), ordAlongSteptDoIt(p.ordAlongSteptDoIt), ordPostStepDoIt(p.ordPostStepDoIt) {
107 printout(ALWAYS,
name(),
"+++ Geant4PhysicsList Dump");
110 printout(ALWAYS,
name(),
"+++ PhysicsConstructor: %s",p.c_str());
112 printout(ALWAYS,
name(),
"+++ ParticleConstructor: %s",p.c_str());
114 printout(ALWAYS,
name(),
"+++ ParticleGroupConstructor: %s",p.c_str());
116 printout(ALWAYS,
name(),
"+++ DiscretePhysicsProcesses of particle %s",part_name.c_str());
117 for (ParticleProcesses::const_iterator ip = procs.begin(); ip != procs.end(); ++ip) {
118 printout(ALWAYS,
name(),
"+++ Process %s", (*ip).name.c_str());
121 for (
const auto& [part_name, procs] :
m_processes ) {
122 printout(ALWAYS,
name(),
"+++ PhysicsProcesses of particle %s",part_name.c_str());
123 for (
const Process& p : procs ) {
124 printout(ALWAYS,
name(),
"+++ Process %s ordAtRestDoIt=%d ordAlongSteptDoIt=%d ordPostStepDoIt=%d",
125 p.name.c_str(),p.ordAtRestDoIt,p.ordAlongSteptDoIt,p.ordPostStepDoIt);
142 const std::string& proc_name,
144 int ordAlongSteptDoIt,
157 const std::string& proc_name)
166 physics().emplace_back(phys_name);
174 return (*(ret.first)).second;
181 except(
"Failed to access the physics process '%s' [Unknown-Process]", nam.c_str());
182 throw std::runtime_error(
"Failed to access the physics process");
190 return (*(ret.first)).second;
197 except(
"Failed to access the physics process '%s' [Unknown-Process]", nam.c_str());
198 throw std::runtime_error(
"Failed to access the physics process");
205 if (
nullptr == ctor.pointer )
206 except(
"Failed to instaniate the physics for constructor '%s'", nam.c_str());
210 except(
"Failed to access the physics for constructor '%s' [Unknown physics]", nam.c_str());
211 throw std::runtime_error(
"Failed to access the physics process");
225 except(
"Failed to adopt action object %s as physics constructor. [Invalid-Base]",action->
c_name());
227 except(
"Failed to adopt invalid Geant4Action as PhysicsConstructor. [Invalid-object]");
232 debug(
"constructPhysics %p", physics_pointer);
234 if ( 0 == ctor.pointer ) {
239 except(
"Failed to create the physics for G4VPhysicsConstructor '%s'", ctor.c_str());
242 if( !ctor.physics_list ) {
243 ctor.physics_list = physics_pointer;
244 physics_pointer->RegisterPhysics(ctor.pointer);
245 info(
"+++ Registered Geant4 physics constructor %s to modular physics list id:%d",
246 ctor.c_str(), physics_pointer->GetInstanceID());
253 debug(
"addPhysics %s", physics_type.c_str());
255 if( physics_type == ctor ) {
256 warning(
"+++ Physics type %s is already present. [using existing, creation denied]",
257 physics_type.c_str());
263 ctor.
pointer = PluginService::Create<G4VPhysicsConstructor*>(physics_type);
264 if( ctor.
pointer ==
nullptr ) {
268 info(
"+++ Added Geant4 physics constructor %s to physics list", ctor.c_str());
274 debug(
"constructParticles %p", physics_pointer);
277 G4ParticleDefinition* def = PluginService::Create<G4ParticleDefinition*>(ctor);
280 long* result = (
long*) PluginService::Create<long>(ctor);
281 if ( !result || *result != 1L ) {
282 except(
"Failed to create particle type '%s' result=%d", ctor.c_str(), result);
284 info(
"Constructed Geant4 particle %s [using signature long (*)()]",ctor.c_str());
290 long* result = (
long*) PluginService::Create<long>(ctor);
291 if ( !result || *result != 1L ) {
292 except(
"Failed to create particle type '%s' result=%d", ctor.c_str(), result);
294 info(
"Constructed Geant4 particle group %s [using signature long (*)()]",ctor.c_str());
300 debug(
"constructProcesses %p", physics_pointer);
303 if ( defs.empty() ) {
304 except(
"Particle:%s Cannot find the corresponding entry in the particle table.", part_name.c_str());
306 for (
const Process& p : procs ) {
307 if ( G4VProcess* g4 = PluginService::Create<G4VProcess*>(p.name) ) {
308 for ( G4ParticleDefinition* particle : defs ) {
309 G4ProcessManager* mgr = particle->GetProcessManager();
310 mgr->AddDiscreteProcess(g4);
311 info(
"Particle:%s -> [%s] added discrete process %s",
312 part_name.c_str(), particle->GetParticleName().c_str(), p.name.c_str());
316 except(
"Cannot create discrete physics process %s", p.name.c_str());
319 for (
const auto& [part_name, procs] :
m_processes ) {
322 except(
"Particle:%s Cannot find the corresponding entry in the particle table.", part_name.c_str());
324 for (
const Process& p : procs ) {
325 if ( G4VProcess* g4 = PluginService::Create<G4VProcess*>(p.name) ) {
326 for ( G4ParticleDefinition* particle : defs ) {
327 G4ProcessManager* mgr = particle->GetProcessManager();
328 mgr->AddProcess(g4, p.ordAtRestDoIt, p.ordAlongSteptDoIt, p.ordPostStepDoIt);
329 info(
"Particle:%s -> [%s] added process %s with flags (%d,%d,%d)",
330 part_name.c_str(), particle->GetParticleName().c_str(), p.name.c_str(),
331 p.ordAtRestDoIt, p.ordAlongSteptDoIt, p.ordPostStepDoIt);
335 except(
"Cannot create physics process %s", p.name.c_str());
366 #include <G4FastSimulationPhysics.hh>
370 G4VModularPhysicsList* physics = (
m_extends.empty() )
372 : G4PhysListFactory().GetReferencePhysList(
m_extends);
375 G4FastSimulationPhysics* fastSimulationPhysics =
new G4FastSimulationPhysics();
381 fastSimulationPhysics->ActivateFastSimulation(
"e-");
382 fastSimulationPhysics->ActivateFastSimulation(
"e+");
388 physics->RegisterPhysics( fastSimulationPhysics );
396 physics->RegisterPhysics(
new ParticlePhysics(
this,physics));
400 G4EmParameters::Instance()->SetVerbose(
m_verbosity);
401 G4HadronicParameters::Instance()->SetVerboseLevel(
m_verbosity);
413 printout(ALWAYS,
name(),
"+++ Dump of physics list component(s)");
414 printout(ALWAYS,
name(),
"+++ Extension name %s",
m_extends.c_str());
416 printout(ALWAYS,
name(),
"+++ Program decays: %d",
m_decays);
429 except(
"Geant4EventActionSequence: Attempt to add invalid actor!");
455 G4ParticleTable* pt = G4ParticleTable::GetParticleTable();
456 G4ParticleTable::G4PTblDicIterator* iter = pt->GetIterator();
458 G4Decay* decay =
new G4Decay();
459 info(
"ConstructDecays %p",physics_pointer);
462 G4ParticleDefinition* p = iter->value();
463 G4ProcessManager* mgr = p->GetProcessManager();
464 if (decay->IsApplicable(*p)) {
465 mgr->AddProcess(decay);
467 mgr->SetProcessOrdering(decay, idxPostStep);
468 mgr->SetProcessOrdering(decay, idxAtRest);
G4VPhysicsConstructor * pointer
Pointer to physics constructor object.
ParticleConstructors & particlegroups()
Access all physics particlegroups.
bool m_needsControl
Default property: Flag to create control instance.
virtual void constructPhysics(G4VModularPhysicsList *physics)
constructPhysics callback
void addParticleGroup(const std::string &part_name)
Add physics particle group constructor by name (Leptons, Bosons, Mesons, etc.)
virtual void constructParticles(G4VUserPhysicsList *physics)
Callback to construct particles.
Structure describing a G4 process.
Geant4UIMessenger * control() const
Access to the UI messenger.
CallbackSequence m_physics
Callback sequence for G4 physics constructors.
Process & operator=(const Process &p)
Assignment operator.
G4VUserPhysicsList * extensionList()
Extend physics list from factory:
G4VModularPhysicsList * physics_list
Pointer to the physics list the constructor belongs.
virtual void installCommandMessenger() override
Install command control messenger if wanted.
static std::vector< G4ParticleDefinition * > g4DefinitionsRegEx(const std::string &expression)
Access Geant4 particle definitions by regular expression.
virtual void constructProcesses(G4VUserPhysicsList *physics)
Execute sequence of G4 physics constructors.
void adopt(Geant4PhysicsList *action)
Add an actor responding to all callbacks. Sequence takes ownership.
Process()
Default constructor.
static void increment(T *)
Increment count according to type information.
Actors< Geant4PhysicsList > m_actors
The list of action objects to be called.
void warning(const char *fmt,...) const
Support of warning messages.
virtual void constructParticles(G4VUserPhysicsList *physics)
Execute sequence of G4 particle constructors.
void constructPhysics(Q *p, void(T::*f)(G4VModularPhysicsList *))
Register physics construction callback.
std::vector< Process > ParticleProcesses
bool m_transportation
Property: Flag if particle transportation is to be added.
int m_physics_verbosity
Property: Verbosity level for G4VUserPhysicsList instance (See G4VUserPhysicsList....
void info(const char *fmt,...) const
Support of info messages.
ParticleConstructors & particles()
Access all physics particles.
void except(const char *fmt,...) const
Support of exceptions: Print fatal message and throw runtime_error.
virtual void installCommandMessenger() override
Install command control messenger if wanted.
double m_rangecut
Property: global range cut for secondary productions.
Geant4PhysicsList(Geant4Context *context, const std::string &nam)
Standard constructor with initailization parameters.
virtual void constructDecays(G4VUserPhysicsList *physics)
Callback to construct particle decays.
CallbackSequence m_particle
Callback sequence for G4 particle constructors.
void addPhysicsConstructor(const std::string &physics_name)
Add PhysicsConstructor by name.
PhysicsConstructors & physics()
Access all physics constructors.
void dump()
Dump content to stdout.
Definition of the generic callback structure for member functions.
ParticleConstructors m_particles
Geant4Action & declareProperty(const std::string &nam, T &val)
Declare property.
static void decrement(T *)
Decrement count according to type information.
CallbackSequence m_process
Callback sequence for G4 process constructors.
PhysicsProcesses & processes()
Access all physics processes.
The implementation of the single Geant4 physics list action sequence.
G4VPhysicsConstructor * addPhysicsConstructorType(const std::string &physics_name)
Callback to add a physics type to the physics list.
Default base class for all Geant 4 actions and derivates thereof.
long release()
Decrease reference count. Implicit destruction.
virtual ~Geant4PhysicsList()
Default destructor.
const std::string & name() const
Access name of the action.
void dump()
Dump content to stdout.
void addParticleProcess(const std::string &part_name, const std::string &proc_name, int ordAtRestDoIt, int ordAlongSteptDoIt, int ordPostStepDoIt)
Add particle process by name with arguments.
PhysicsProcesses m_processes
void clear()
Clear the sequence and remove all callbacks.
Structure describing a G4 physics constructor.
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
PhysicsProcesses m_discreteProcesses
bool m_decays
Property: Flag if particle decays are to be added.
Concrete basic implementation of a Geant4 physics list action.
virtual ~Geant4PhysicsListActionSequence()
Default destructor.
bool transportation() const
Access the transportation flag.
Geant4PhysicsListActionSequence(Geant4Context *context, const std::string &nam)
Standard constructor.
int m_verbosity
Property: verbosity level for the physics list.
void adoptPhysicsConstructor(Geant4Action *action)
Add PhysicsConstructor as Geant4Action object.
PhysicsProcesses & discreteProcesses()
Access all physics discrete processes.
long addRef()
Increase reference count.
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
virtual void constructProcesses(G4VUserPhysicsList *physics)
Callback to construct processes (uses the G4 particle table)
const char * c_name() const
Access name of the action.
void addDiscreteParticleProcess(const std::string &part_name, const std::string &proc_name)
Add discrete particle process by name with arguments.
PhysicsConstructors m_physics
void addCall(const std::string &name, const std::string &description, const Callback &cb, size_t npar=0)
Add a new callback structure.
void debug(const char *fmt,...) const
Support of debug messages.
virtual void enable(G4VUserPhysicsList *physics)
Enable physics list: actions necessary to be propagated to Geant4.
void addParticleConstructor(const std::string &part_name)
Add physics particle constructor by name.
ParticleConstructors m_particlegroups
virtual void enable(G4VUserPhysicsList *physics)
Enable physics list: actions necessary to be propagated to Geant4.
Generic context to extend user, run and event information.
std::string m_extends
Property: Store name of basic predefined Geant4 physics list.