Geant4_10
G4OpticalPhysics.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 //---------------------------------------------------------------------------
28 //
29 // ClassName: G4OpticalPhysics
30 //
31 // Author: P.Gumplinger 30.09.2009
32 //
33 // Modified: P.Gumplinger 29.09.2011
34 // (based on code from I. Hrivnacova)
35 //
36 //----------------------------------------------------------------------------
37 //
38 
39 #include "G4OpticalPhysics.hh"
40 
41 #include "G4LossTableManager.hh"
42 #include "G4EmSaturation.hh"
43 
44 G4ThreadLocal G4bool G4OpticalPhysics::wasActivated = false;
45 // factory
47 //
49 
50 
51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
52 
54  : G4VPhysicsConstructor(name),
55 
56  fScintillationProcess(NULL),
57  fCerenkovProcess(NULL),
58  fOpWLSProcess(NULL),
59  fOpAbsorptionProcess(NULL),
60  fOpRayleighScatteringProcess(NULL),
61  fOpMieHGScatteringProcess(NULL),
62  fOpBoundaryProcess(NULL),
63  fMaxNumPhotons(100),
64  fMaxBetaChange(10.0),
65  fYieldFactor(1.),
66  fExcitationRatio(0.0),
67  fProfile("delta"),
68  fFiniteRiseTime(false),
69  fScintillationByParticleType(false)
70 {
71  verboseLevel = verbose;
72  fMessenger = new G4OpticalPhysicsMessenger(this);
73 
74  for ( G4int i=0; i<kNoProcess; i++ ) {
75  fProcesses.push_back(NULL);
76  fProcessUse.push_back(true);
77  fProcessVerbose.push_back(verbose);
78  fProcessTrackSecondariesFirst.push_back(true);
79  }
80 }
81 
82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
83 
85 {
86  delete fMessenger;
87 
88 // Process objects are deleted elsewhere.
89 /************* if (wasActivated) {
90 
91  if (fScintillationProcess) delete fScintillationProcess;
92  if (fCerenkovProcess) delete fCerenkovProcess;
93  if (fOpWLSProcess) delete fOpWLSProcess;
94 
95  if (fOpAbsorptionProcess) delete fOpAbsorptionProcess;
96  if (fOpRayleighScatteringProcess) delete fOpRayleighScatteringProcess;
97  if (fOpMieHGScatteringProcess) delete fOpMieHGScatteringProcess;
98  if (fOpBoundaryProcess) delete fOpBoundaryProcess;
99 
100  wasActivated = false;
101  } ************************/
102 }
103 
104 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
105 
106 void G4OpticalPhysics::PrintStatistics() const
107 {
108 // Print all processes activation and their parameters
109 
110  for ( G4int i=0; i<kNoProcess; i++ ) {
111  G4cout << " " << G4OpticalProcessName(i) << " process: ";
112  if ( ! fProcessUse[i] ) {
113  G4cout << "not used" << G4endl;
114  }
115  else {
116  G4cout << "used" << G4endl;
117  if ( i == kCerenkov ) {
118  G4cout << " Max number of photons per step: " << fMaxNumPhotons << G4endl;
119  G4cout << " Max beta change per step: " << fMaxBetaChange << G4endl;
120  if ( fProcessTrackSecondariesFirst[kCerenkov] ) G4cout << " Track secondaries first: activated" << G4endl;
121  }
122  if ( i == kScintillation ) {
123  if (fScintillationByParticleType)
124  G4cout << " Scintillation by Particle Type: activated " << G4endl;
125  G4cout << " Yield factor: " << fYieldFactor << G4endl;
126  G4cout << " ExcitationRatio: " << fExcitationRatio << G4endl;
127  if ( fProcessTrackSecondariesFirst[kScintillation] ) G4cout << " Track secondaries first: activated" << G4endl;
128  }
129  if ( i == kWLS ) {
130  G4cout << " WLS process time profile: " << fProfile << G4endl;
131  }
132  }
133  }
134 }
135 
136 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
137 
138 #include "G4OpticalPhoton.hh"
139 
141 {
143 
144  // optical photon
146 }
147 
148 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
149 
150 #include "G4ParticleDefinition.hh"
151 #include "G4ProcessManager.hh"
152 
154 {
155 // Construct optical processes.
156 
157  if (wasActivated) return;
158 
159  if(verboseLevel>0)
160  G4cout <<"G4OpticalPhysics:: Add Optical Physics Processes"<< G4endl;
161 
162  // Add Optical Processes
163 
164  fProcesses[kAbsorption] = fOpAbsorptionProcess = new G4OpAbsorption();
165  fProcesses[kRayleigh] = fOpRayleighScatteringProcess = new G4OpRayleigh();
166  fProcesses[kMieHG] = fOpMieHGScatteringProcess = new G4OpMieHG();
167 
168  fProcesses[kBoundary] = fOpBoundaryProcess = new G4OpBoundaryProcess();
169 
170  fProcesses[kWLS] = fOpWLSProcess = new G4OpWLS();
171  fOpWLSProcess->UseTimeProfile(fProfile);
172 
173  G4ProcessManager * pManager = 0;
175 
176  if (!pManager) {
177  std::ostringstream o;
178  o << "Optical Photon without a Process Manager";
179  G4Exception("G4OpticalPhysics::ConstructProcess()","",
180  FatalException,o.str().c_str());
181  return;
182  }
183 
184  for ( G4int i=kAbsorption; i<=kWLS; i++ ) {
185  if ( fProcessUse[i] ) {
186  pManager->AddDiscreteProcess(fProcesses[i]);
187  }
188  }
189 
190  fProcesses[kScintillation] = fScintillationProcess = new G4Scintillation();
191  fScintillationProcess->SetScintillationYieldFactor(fYieldFactor);
192  fScintillationProcess->SetScintillationExcitationRatio(fExcitationRatio);
193  fScintillationProcess->SetFiniteRiseTime(fFiniteRiseTime);
194  fScintillationProcess->SetScintillationByParticleType(fScintillationByParticleType);
195  fScintillationProcess->
196  SetTrackSecondariesFirst(fProcessTrackSecondariesFirst[kScintillation]);
197 
198  // Use Birks Correction in the Scintillation process
199 
201  fScintillationProcess->AddSaturation(emSaturation);
202 
203  fProcesses[kCerenkov] = fCerenkovProcess = new G4Cerenkov();
204  fCerenkovProcess->SetMaxNumPhotonsPerStep(fMaxNumPhotons);
205  fCerenkovProcess->SetMaxBetaChangePerStep(fMaxBetaChange);
206  fCerenkovProcess->
207  SetTrackSecondariesFirst(fProcessTrackSecondariesFirst[kCerenkov]);
208 
209  aParticleIterator->reset();
210 
211  while( (*aParticleIterator)() ){
212 
213  G4ParticleDefinition* particle = aParticleIterator->value();
214  G4String particleName = particle->GetParticleName();
215 
216  pManager = particle->GetProcessManager();
217  if (!pManager) {
218  std::ostringstream o;
219  o << "Particle " << particleName << "without a Process Manager";
220  G4Exception("G4OpticalPhysics::ConstructProcess()","",
221  FatalException,o.str().c_str());
222  return; // else coverity complains for pManager use below
223  }
224 
225  if( fCerenkovProcess->IsApplicable(*particle) &&
226  fProcessUse[kCerenkov] ) {
227  pManager->AddProcess(fCerenkovProcess);
228  pManager->SetProcessOrdering(fCerenkovProcess,idxPostStep);
229  }
230  if( fScintillationProcess->IsApplicable(*particle) &&
231  fProcessUse[kScintillation] ){
232  pManager->AddProcess(fScintillationProcess);
233  pManager->SetProcessOrderingToLast(fScintillationProcess,idxAtRest);
234  pManager->SetProcessOrderingToLast(fScintillationProcess,idxPostStep);
235  }
236 
237  }
238 
239  // Add verbose
240  for ( G4int i=0; i<kNoProcess; i++ ) {
241  fProcesses[i]->SetVerboseLevel(fProcessVerbose[i]);
242  }
243 
244  if (verboseLevel > 1) PrintStatistics();
245  if (verboseLevel > 0)
246  G4cout << "### " << namePhysics << " physics constructed." << G4endl;
247 
248  wasActivated = true;
249 
250 }
251 
253 {
255 
256  fYieldFactor = yieldFactor;
257 
258  if(fScintillationProcess)
259  fScintillationProcess->SetScintillationYieldFactor(yieldFactor);
260 }
261 
263 {
265 
266  fExcitationRatio = excitationRatio;
267 
268  if(fScintillationProcess)
269  fScintillationProcess->SetScintillationExcitationRatio(excitationRatio);
270 }
271 
273 {
275 
276  fMaxNumPhotons = maxNumPhotons;
277 
278  if(fCerenkovProcess)
279  fCerenkovProcess->SetMaxNumPhotonsPerStep(maxNumPhotons);
280 }
281 
283 {
285 
286  fMaxBetaChange = maxBetaChange;
287 
288  if(fCerenkovProcess)
289  fCerenkovProcess->SetMaxBetaChangePerStep(maxBetaChange);
290 }
291 
293 {
295 
296  fProfile = profile;
297 
298  if(fOpWLSProcess)
299  fOpWLSProcess->UseTimeProfile(fProfile);
300 }
301 
303 {
305 
306  if(fScintillationProcess)
307  fScintillationProcess->AddSaturation(saturation);
308 }
309 
311 {
312  fScintillationByParticleType = scintillationByParticleType;
313 
314  if (fScintillationProcess)
315  fScintillationProcess->SetScintillationByParticleType(scintillationByParticleType);
316 }
317 
319  G4bool trackSecondariesFirst)
320 {
321  if ( index >= kNoProcess ) return;
322  if ( fProcessTrackSecondariesFirst[index] == trackSecondariesFirst ) return;
323  fProcessTrackSecondariesFirst[index] = trackSecondariesFirst;
324 
325  if(fCerenkovProcess && index == kCerenkov )
326  fCerenkovProcess->SetTrackSecondariesFirst(trackSecondariesFirst);
327 
328  if(fScintillationProcess && index == kScintillation)
329  fScintillationProcess->SetTrackSecondariesFirst(trackSecondariesFirst);
330 }
331 
333 {
334  fFiniteRiseTime = finiteRiseTime;
335  if(fScintillationProcess)
336  fScintillationProcess->SetFiniteRiseTime(finiteRiseTime);
337 }
338 
340 {
341  // Configure the physics constructor to use/not use a selected process.
342  // This method can only be called in PreInit> phase (before execution of
343  // ConstructProcess). The process is not added to particle's process manager
344  // and so it cannot be re-activated later in Idle> phase with the command
345  // /process/activate.
346 
347  if ( index >= kNoProcess ) return;
348  if ( fProcessUse[index] == isUse ) return;
349  fProcessUse[index] = isUse;
350 }
351 
353  G4int inputVerboseLevel)
354 {
355  // Set new verbose level to a selected process
356 
357  if ( index >= kNoProcess ) return;
358  if ( fProcessVerbose[index] == inputVerboseLevel ) return;
359 
360  fProcessVerbose[index] = inputVerboseLevel;
361 
362  if ( fProcesses[index] ) fProcesses[index]->SetVerboseLevel(inputVerboseLevel);
363 }
364 
365 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void SetScintillationByParticleType(const G4bool)
void SetMaxBetaChangePerStep(const G4double d)
Definition: G4Cerenkov.hh:223
void SetProcessVerbose(G4int, G4int)
static G4LossTableManager * Instance()
void SetFiniteRiseTime(const G4bool state)
Number of processes, no selected process.
virtual void ConstructParticle()
Int_t index
Definition: macro.C:9
G4OpticalProcessIndex
void AddScintillationSaturation(G4EmSaturation *)
void SetTrackSecondariesFirst(const G4bool state)
Definition: G4Cerenkov.hh:217
void SetMaxBetaChangePerStep(G4double)
void SetScintillationExcitationRatio(const G4double excitationratio)
G4int AddDiscreteProcess(G4VProcess *aProcess, G4int ord=ordDefault)
const XML_Char * name
Definition: expat.h:151
Scintillation process index.
G4bool IsApplicable(const G4ParticleDefinition &aParticleType)
Mie scattering process index.
#define G4ThreadLocal
Definition: tls.hh:52
void SetFiniteRiseTime(G4bool)
Absorption process index.
G4ProcessManager * GetProcessManager() const
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
void SetScintillationByParticleType(G4bool)
function profile(XB)
Definition: hijing1.383.f:4673
void UseTimeProfile(const G4String name)
Definition: G4OpWLS.cc:418
virtual void ConstructProcess()
virtual ~G4OpticalPhysics()
void SetScintillationYieldFactor(const G4double yieldfactor)
G4GLOB_DLL std::ostream G4cout
void SetMaxNumPhotonsPerStep(G4int)
bool G4bool
Definition: G4Types.hh:79
#define aParticleIterator
void Configure(G4OpticalProcessIndex, G4bool)
G4int AddProcess(G4VProcess *aProcess, G4int ordAtRestDoIt=ordInActive, G4int ordAlongSteptDoIt=ordInActive, G4int ordPostStepDoIt=ordInActive)
G4EmSaturation * EmSaturation()
void SetMaxNumPhotonsPerStep(const G4int NumPhotons)
Definition: G4Cerenkov.hh:229
void SetProcessOrdering(G4VProcess *aProcess, G4ProcessVectorDoItIndex idDoIt, G4int ordDoIt=ordDefault)
Wave Length Shifting process index.
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4OpticalPhoton * OpticalPhoton()
void SetScintillationExcitationRatio(G4double)
G4String G4OpticalProcessName(G4int)
Return the name for a given optical process index.
G4OpticalPhysics(G4int verbose=0, const G4String &name="Optical")
Boundary process index.
void SetScintillationYieldFactor(G4double)
void SetTrackSecondariesFirst(const G4bool state)
void SetProcessOrderingToLast(G4VProcess *aProcess, G4ProcessVectorDoItIndex idDoIt)
Cerenkov process index.
void SetWLSTimeProfile(G4String)
void SetTrackSecondariesFirst(G4OpticalProcessIndex, G4bool)
#define G4endl
Definition: G4ios.hh:61
static G4OpticalPhoton * OpticalPhotonDefinition()
Rayleigh scattering process index.
double G4double
Definition: G4Types.hh:76
void AddSaturation(G4EmSaturation *sat)
#define G4_DECLARE_PHYSCONSTR_FACTORY(physics_constructor)
G4bool IsApplicable(const G4ParticleDefinition &aParticleType)
Definition: G4Cerenkov.cc:128