DD4hep  1.37.0
Detector Description Toolkit for High Energy Physics
Geant4OpticalPhotonPhysics.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
26 #ifndef DDG4_GEANT4OPTICALPHOTONPHYSICS_H
27 #define DDG4_GEANT4OPTICALPHOTONPHYSICS_H 1
28 
29 // Framework include files
30 #include <DDG4/Geant4PhysicsList.h>
31 
33 #include <G4OpAbsorption.hh>
34 #include <G4OpRayleigh.hh>
35 #include <G4OpMieHG.hh>
36 #include <G4OpBoundaryProcess.hh>
37 #include <G4OpWLS.hh>
38 #include <G4OpWLS2.hh>
39 #include <G4ParticleDefinition.hh>
40 #include <G4ParticleTypes.hh>
41 #include <G4ParticleTable.hh>
42 #include <G4ProcessManager.hh>
43 #include <G4Version.hh>
44 
45 #if G4VERSION_NUMBER >= 1070
46 #include <G4OpticalParameters.hh>
47 #endif
48 
50 namespace dd4hep {
51 
53  namespace sim {
54 
56 
62  public:
68  Geant4OpticalPhotonPhysics(Geant4Context* ctxt, const std::string& nam)
69  : Geant4PhysicsList(ctxt, nam)
70  {
71  declareProperty("VerboseLevel", m_verbosity = 0);
72  declareProperty("BoundaryInvokeSD", m_boundaryInvokeSD = false);
73  }
75  virtual ~Geant4OpticalPhotonPhysics() = default;
77  virtual void constructProcesses(G4VUserPhysicsList* physics_list) {
78  this->Geant4PhysicsList::constructProcesses(physics_list);
79  info("+++ Constructing optical_photon processes:");
80  G4ParticleTable* table = G4ParticleTable::GetParticleTable();
81  G4ParticleDefinition* particle = table->FindParticle("opticalphoton");
82  if (0 == particle) {
83  except("++ Cannot resolve 'opticalphoton' particle definition!");
84  }
85 
86  G4ProcessManager* pmanager = particle->GetProcessManager();
87 
88 #if G4VERSION_NUMBER >= 1070
89  G4OpticalParameters* params = G4OpticalParameters::Instance();
90  params->SetBoundaryVerboseLevel(m_verbosity);
91  params->SetBoundaryInvokeSD(m_boundaryInvokeSD);
92 
93  // Always add boundary process (controls surface interactions)
94  pmanager->AddDiscreteProcess(new G4OpBoundaryProcess());
95 
96  // Add remaining processes only if activated in G4OpticalParameters.
97  // This allows callers to disable unused processes (e.g. OpMieHG when no
98  // material defines MIE scattering tables) to reduce GPIL overhead.
99  auto addIf = [&](const G4String& key, G4VDiscreteProcess* proc, G4int verbosity) {
100  if (params->GetProcessActivation(key)) {
101  proc->SetVerboseLevel(verbosity);
102  pmanager->AddDiscreteProcess(proc);
103  } else {
104  delete proc;
105  }
106  };
107  addIf("OpAbsorption", new G4OpAbsorption(), m_verbosity);
108  addIf("OpRayleigh", new G4OpRayleigh(), m_verbosity);
109  addIf("OpMieHG", new G4OpMieHG(), m_verbosity);
110  addIf("OpWLS", new G4OpWLS(), m_verbosity);
111  addIf("OpWLS2", new G4OpWLS2(), m_verbosity);
112 
113  // Log which processes are actually registered
114  std::string active = "+++ G4OpBoundaryProcess";
115  for (const char* key : {"OpAbsorption", "OpRayleigh", "OpMieHG", "OpWLS", "OpWLS2"}) {
116  if (params->GetProcessActivation(key)) active += std::string(" G4") + key;
117  }
118  info("%s", active.c_str());
119 #else
120  info("+++ G4OpAbsorption G4OpRayleigh G4OpMieHG G4OpBoundaryProcess");
121  G4OpBoundaryProcess* fBoundaryProcess = new G4OpBoundaryProcess();
122  G4OpAbsorption* fAbsorptionProcess = new G4OpAbsorption();
123  G4OpRayleigh* fRayleighScatteringProcess = new G4OpRayleigh();
124  G4OpMieHG* fMieHGScatteringProcess = new G4OpMieHG();
125  fAbsorptionProcess->SetVerboseLevel(m_verbosity);
126  fRayleighScatteringProcess->SetVerboseLevel(m_verbosity);
127  fMieHGScatteringProcess->SetVerboseLevel(m_verbosity);
128  fBoundaryProcess->SetVerboseLevel(m_verbosity);
129 #if G4VERSION_NUMBER >= 1000
130  fBoundaryProcess->SetInvokeSD(m_boundaryInvokeSD);
131 #endif
132  pmanager->AddDiscreteProcess(fAbsorptionProcess);
133  pmanager->AddDiscreteProcess(fRayleighScatteringProcess);
134  pmanager->AddDiscreteProcess(fMieHGScatteringProcess);
135  pmanager->AddDiscreteProcess(fBoundaryProcess);
136 #endif
137  }
138  private:
141  };
142  }
143 }
144 #endif // DDG4_GEANT4OPTICALPHOTONPHYSICS_H
145 
146 #include <DDG4/Factories.h>
147 using namespace dd4hep::sim;
dd4hep::sim::Geant4OpticalPhotonPhysics
Geant4 physics list action to enable OpticalPhoton physics.
Definition: Geant4OpticalPhotonPhysics.cpp:61
Geant4PhysicsList.h
dd4hep::sim::Geant4OpticalPhotonPhysics::Geant4OpticalPhotonPhysics
Geant4OpticalPhotonPhysics()=delete
Default constructor.
DECLARE_GEANT4ACTION
#define DECLARE_GEANT4ACTION(name)
Plugin defintion to create Geant4Action objects.
Definition: Factories.h:210
dd4hep::sim::Geant4Action::info
void info(const char *fmt,...) const
Support of info messages.
Definition: Geant4Action.cpp:215
dd4hep::sim::Geant4Action::except
void except(const char *fmt,...) const
Support of exceptions: Print fatal message and throw runtime_error.
Definition: Geant4Action.cpp:256
dd4hep::sim::Geant4OpticalPhotonPhysics::m_boundaryInvokeSD
bool m_boundaryInvokeSD
Definition: Geant4OpticalPhotonPhysics.cpp:140
dd4hep::sim::Geant4OpticalPhotonPhysics::~Geant4OpticalPhotonPhysics
virtual ~Geant4OpticalPhotonPhysics()=default
Default destructor.
dd4hep::sim::Geant4Action::declareProperty
Geant4Action & declareProperty(const std::string &nam, T &val)
Declare property.
Definition: Geant4Action.h:366
dd4hep::sim::Geant4OpticalPhotonPhysics::Geant4OpticalPhotonPhysics
Geant4OpticalPhotonPhysics(const Geant4OpticalPhotonPhysics &)=delete
Copy constructor.
dd4hep::sim::Geant4PhysicsList
Concrete basic implementation of a Geant4 physics list action.
Definition: Geant4PhysicsList.h:41
Factories.h
key
unsigned char key
Definition: AlignmentsCalculator.cpp:69
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: EDM4hepFileReader.cpp:46
dd4hep::sim::Geant4PhysicsList::constructProcesses
virtual void constructProcesses(G4VUserPhysicsList *physics)
Callback to construct processes (uses the G4 particle table)
Definition: Geant4PhysicsList.cpp:299
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::sim::Geant4OpticalPhotonPhysics::Geant4OpticalPhotonPhysics
Geant4OpticalPhotonPhysics(Geant4Context *ctxt, const std::string &nam)
Initializing constructor.
Definition: Geant4OpticalPhotonPhysics.cpp:68
dd4hep::sim::Geant4OpticalPhotonPhysics::m_verbosity
int m_verbosity
Definition: Geant4OpticalPhotonPhysics.cpp:139
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
dd4hep::sim::Geant4OpticalPhotonPhysics::constructProcesses
virtual void constructProcesses(G4VUserPhysicsList *physics_list)
Callback to construct processes (uses the G4 particle table)
Definition: Geant4OpticalPhotonPhysics.cpp:77