Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4OpticalParameters.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// GEANT4 Class file
29//
30// File name: G4OpticalParameters
31//
32// Author: Daren Sawkey based on G4EmParameters
33//
34// Creation date: 14.07.2020
35//
36// Modifications:
37//
38// -------------------------------------------------------------------
39//
40//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
41//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
42
46#include "G4UnitsTable.hh"
47#include "G4SystemOfUnits.hh"
48#include "G4ApplicationState.hh"
49#include "G4StateManager.hh"
50
51G4OpticalParameters* G4OpticalParameters::theInstance = nullptr;
52
53#ifdef G4MULTITHREADED
54 G4Mutex G4OpticalParameters::opticalParametersMutex = G4MUTEX_INITIALIZER;
55#endif
56
57//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
58
60{
61 if(nullptr == theInstance) {
62#ifdef G4MULTITHREADED
63 G4MUTEXLOCK(&opticalParametersMutex);
64 if(nullptr == theInstance) {
65#endif
66 static G4OpticalParameters manager;
67 theInstance = &manager;
68#ifdef G4MULTITHREADED
69 }
70 G4MUTEXUNLOCK(&opticalParametersMutex);
71#endif
72 }
73 return theInstance;
74}
75
76//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
77
79{
80 delete theMessenger;
81}
82
83//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
84
85G4OpticalParameters::G4OpticalParameters()
86{
87 theMessenger = new G4OpticalParametersMessenger(this);
88 Initialise();
89
90 fStateManager = G4StateManager::GetStateManager();
91}
92
94{
95 if(!IsLocked()) {
96 Initialise();
97 }
98}
99
100void G4OpticalParameters::Initialise()
101{
102 verboseLevel = 0;
103
104 cerenkovStackPhotons = true;
105 cerenkovTrackSecondariesFirst = true;
106 cerenkovVerboseLevel = 0;
107 cerenkovMaxPhotons = 100;
108 cerenkovMaxBetaChange = 10.;
109
110 scintByParticleType = false;
111 scintTrackInfo = false;
112 scintStackPhotons = true;
113 scintEnhancedTimeConstants = false;
114 scintFiniteRiseTime = false;
115 scintTrackSecondariesFirst = true;
116 scintYieldFactor = 1.;
117 scintExcitationRatio = 1.;
118 scintVerboseLevel = 0;
119
120 wlsTimeProfileName = "delta";
121 wlsVerboseLevel = 0;
122
123 wls2TimeProfileName = "delta";
124 wls2VerboseLevel = 0;
125
126 absorptionVerboseLevel = 0;
127
128 rayleighVerboseLevel = 0;
129
130 mieVerboseLevel = 0;
131
132 boundaryInvokeSD = false;
133 boundaryVerboseLevel = 0;
134
135 processActivation["OpRayleigh"] = true;
136 processActivation["OpBoundary"] = true;
137 processActivation["OpMieHG"] = true;
138 processActivation["OpAbsorption"] = true;
139 processActivation["OpWLS"] = true;
140 processActivation["OpWLS2"] = true;
141 processActivation["Cerenkov"] = true;
142 processActivation["Scintillation"] = true;
143
144}
145
147{
148 if(IsLocked()) { return; }
149 verboseLevel = val;
150 SetCerenkovVerboseLevel(verboseLevel);
151 SetScintVerboseLevel(verboseLevel);
152 SetRayleighVerboseLevel(verboseLevel);
153 SetAbsorptionVerboseLevel(verboseLevel);
154 SetMieVerboseLevel(verboseLevel);
155 SetBoundaryVerboseLevel(verboseLevel);
156 SetWLSVerboseLevel(verboseLevel);
157 SetWLS2VerboseLevel(verboseLevel);
158}
159
161{
162 return verboseLevel;
163}
164
166{
167 // Configure the physics constructor to use/not use a selected process.
168 // This method can only be called in PreInit> phase (before execution of
169 // ConstructProcess). The process is not added to particle's process manager
170 // and so it cannot be re-activated later in Idle> phase with the command
171 // /process/activate.
172
173 if(IsLocked()) { return; }
174 if (processActivation[process] == val) return;
175
176 // processActivation keys defined at initialisation
177 if (processActivation.find(process) != processActivation.end()) {
178 processActivation[process] = val;
179 }
180 else {
182 ed << "Process name " << process << " out of bounds.";
183 G4Exception("G4OpticalParameters::SetProcessActivation()", "Optical013",
184 FatalException, ed);
185 }
186}
187
189{ return processActivation.find(process)->second; }
190
192{
193 // DEPRECATED. Use SetProcessActivation instead.
194
195 // Configure the physics constructor to use/not use a selected process.
196 // This method can only be called in PreInit> phase (before execution of
197 // ConstructProcess). The process is not added to particle's process manager
198 // and so it cannot be re-activated later in Idle> phase with the command
199 // /process/activate.
200
201 if(IsLocked()) { return; }
202 if (index == kCerenkov) processActivation["Cerenkov"] = val;
203 else if (index == kScintillation) processActivation["Scintillation"] = val;
204 else if (index == kAbsorption) processActivation["OpAbsorption"] = val;
205 else if (index == kRayleigh) processActivation["OpRayleigh"] = val;
206 else if (index == kMieHG) processActivation["OpMieHG"] = val;
207 else if (index == kWLS) processActivation["OpWLS"] = val;
208 else if (index == kWLS2) processActivation["OpWLS2"] = val;
209 else {
211 ed << "Process index " << index << " out of bounds.";
212 G4Exception("G4OpticalParameters::Configure()", "Optical010", FatalException, ed);
213 }
215 ed2 << "Method Configure(G4OpticalProcessIndex, G4bool) is deprecated "
216 << "and will be removed in a future Geant4 version. Please use "
217 << "SetProcessActivation(G4String, G4bool) instead.";
218 PrintWarning(ed2);
219}
220
222{
223 // DEPRECATED. Use GetProcessActivation instead.
224 if (index == kCerenkov) return processActivation["Cerenkov"];
225 else if (index == kScintillation) return processActivation["Scintillation"];
226 else if (index == kAbsorption) return processActivation["OpAbsorption"];
227 else if (index == kRayleigh) return processActivation["OpRayleigh"];
228 else if (index == kMieHG) return processActivation["OpMieHG"];
229 else if (index == kWLS) return processActivation["OpWLS"];
230 else if (index == kWLS2) return processActivation["OpWLS2"];
231 else {
233 ed << "Process index " << index << " out of bounds.";
234 G4Exception("G4OpticalParameters::GetConfiguration()", "Optical011", JustWarning, ed);
235 }
237 ed2 << "Method GetConfiguration(G4OpticalProcessIndex) is deprecated "
238 << "and will be removed in a future Geant4 version. Please use "
239 << "GetProcessActivation(G4String) instead.";
240 PrintWarning(ed2);
241 return true;
242}
243
245 G4bool val)
246{
247 // DEPRECATED. Use SetCerenkovTrackSecondariesFirst and
248 // SetScintTrackSecondariesFirst instead.
249 if(IsLocked()) { return; }
250 if (index == kCerenkov) cerenkovTrackSecondariesFirst = val;
251 else if (index == kScintillation) scintTrackSecondariesFirst = val;
252 else {
254 ed << "Process index " << index << " out of bounds.";
255 G4Exception("G4OpticalParameters::SetTrackSecondariesFirst()",
256 "Optical013", FatalException, ed);
257 }
259 ed2 << "Method SetTrackSecondariesFirst(G4OpticalProcessIndex, G4bool) is "
260 << "deprecated and will be removed in a future Geant4 version. Please use "
261 << "SetCerenkovTrackSecondariesFirst(G4bool) and "
262 << "SetScintTrackSecondariesFirst(G4bool) instead.";
263 PrintWarning(ed2);
264
265}
266
268// DEPRECATED. Use GetCerenkovTrackSecondariesFirst and
269// GetScintTrackSecondariesFirst instead.
270{
271 if (index == kCerenkov) return cerenkovTrackSecondariesFirst;
272 else if (index == kScintillation) return scintTrackSecondariesFirst;
273 else {
275 ed << "Process index " << index << " out of bounds.";
276 G4Exception("G4OpticalParameters::GetTrackSecondariesFirst()",
277 "Optical012", JustWarning, ed);
278 }
280 ed2 << "Method GetTrackSecondariesFirst(G4OpticalProcessIndex) is "
281 << "deprecated and will be removed in a future Geant4 version. Please use "
282 << "GetCerenkovTrackSecondariesFirst() and "
283 << "GetScintTrackSecondariesFirst() instead.";
284 PrintWarning(ed2);
285 return true;
286}
287
289{
290 if(IsLocked()) { return; }
291 cerenkovStackPhotons = val;
292}
293
295{
296 return cerenkovStackPhotons;
297}
298
300{
301 if(IsLocked()) { return; }
302 cerenkovVerboseLevel = val;
303}
304
306{
307 return cerenkovVerboseLevel;
308}
309
311{
312 if(IsLocked()) { return; }
313 cerenkovMaxPhotons = val;
314}
315
317{
318 return cerenkovMaxPhotons;
319}
320
322{
323 if(IsLocked()) { return; }
324 cerenkovMaxBetaChange = val;
325}
326
328{
329 return cerenkovMaxBetaChange;
330}
331
333{
334 if(IsLocked()) { return; }
335 cerenkovTrackSecondariesFirst = val;
336}
337
339{
340 return cerenkovTrackSecondariesFirst;
341}
342
344{
345 if(IsLocked()) { return; }
346 scintYieldFactor = val;
347}
348
350{
351 return scintYieldFactor;
352}
353
355{
356 if(IsLocked()) { return; }
357 scintExcitationRatio = val;
358}
359
361{
362 return scintExcitationRatio;
363}
364
366{
367 if(IsLocked()) { return; }
368 scintByParticleType = val;
369}
370
372{
373 return scintByParticleType;
374}
375
377{
378 if(IsLocked()) { return; }
379 scintTrackInfo = val;
380}
381
383{
384 return scintTrackInfo;
385}
386
388{
389 if(IsLocked()) { return; }
390 scintTrackSecondariesFirst = val;
391}
392
394{
395 return scintTrackSecondariesFirst;
396}
397
399{
400 if(IsLocked()) { return; }
401 scintFiniteRiseTime = val;
402}
403
405{
406 return scintFiniteRiseTime;
407}
408
410{
411 if(IsLocked()) { return; }
412 scintStackPhotons = val;
413}
414
416{
417 return scintStackPhotons;
418}
419
421{
422 if(IsLocked()) { return; }
423 scintVerboseLevel = val;
424}
425
427{
428 return scintVerboseLevel;
429}
430
432{
433 if(IsLocked()) { return; }
434 scintEnhancedTimeConstants = val;
435}
436
438{
439 return scintEnhancedTimeConstants;
440}
441
443{
444 if(IsLocked()) { return; }
445 wlsTimeProfileName = val;
446}
447
449{
450 return wlsTimeProfileName;
451}
452
454{
455 if(IsLocked()) {return; }
456 wlsVerboseLevel = val;
457}
458
460{
461 return wlsVerboseLevel;
462}
463
465{
466 if(IsLocked()) { return; }
467 wls2TimeProfileName = val;
468}
469
471{
472 return wls2TimeProfileName;
473}
474
476{
477 if(IsLocked()) {return; }
478 wls2VerboseLevel = val;
479}
480
482{
483 return wls2VerboseLevel;
484}
485
487{
488 if(IsLocked()) {return;}
489 boundaryVerboseLevel = val;
490}
491
493{
494 return boundaryVerboseLevel;
495}
496
498{
499 if(IsLocked()) {return;}
500 boundaryInvokeSD = val;
501}
502
504{
505 return boundaryInvokeSD;
506}
507
509{
510 if(IsLocked()) {return;}
511 absorptionVerboseLevel = val;
512}
513
515{
516 return absorptionVerboseLevel;
517}
518
520{
521 if(IsLocked()) {return;}
522 rayleighVerboseLevel = val;
523}
524
526{
527 return rayleighVerboseLevel;
528}
529
531{
532 if(IsLocked()) {return;}
533 mieVerboseLevel = val;
534}
535
537{
538 return mieVerboseLevel;
539}
540
541void G4OpticalParameters::PrintWarning(G4ExceptionDescription& ed) const
542{
543 G4Exception("G4EmParameters", "Optical0020", JustWarning, ed);
544}
545
546void G4OpticalParameters::StreamInfo(std::ostream& os) const
547{
548 G4int prec = os.precision(5);
549 os << "=======================================================================" << "\n";
550 os << "====== Optical Physics Parameters ========" << "\n";
551 os << "=======================================================================" << "\n";
552
553 os << " Cerenkov process active: " << GetProcessActivation("Cerenkov") << "\n";
554 os << " Cerenkov maximum photons per step: " << cerenkovMaxPhotons << "\n";
555 os << " Cerenkov maximum beta change per step: " << cerenkovMaxBetaChange << " %\n";
556 os << " Cerenkov stack photons: " << cerenkovStackPhotons << "\n";
557 os << " Cerenkov track secondaries first: " << cerenkovTrackSecondariesFirst << "\n";
558 os << " Scintillation process active: " << GetProcessActivation("Scintillation") << "\n";
559 os << " Scintillation yield factor: " << scintYieldFactor << "\n";
560 os << " Scintillation excitation ratio: " << scintExcitationRatio << "\n";
561 os << " Scintillation finite rise time: " << scintFiniteRiseTime << "\n";
562 os << " Scintillation by particle type: " << scintByParticleType << "\n";
563 os << " Scintillation record track info: " << scintTrackInfo << "\n";
564 os << " Scintillation stack photons: " << scintStackPhotons << "\n";
565 os << " Scintillation use enhanced time constants: " << scintEnhancedTimeConstants << "\n";
566 os << " Scintillation track secondaries first: " << scintTrackSecondariesFirst << "\n";
567 os << " WLS process active: " << GetProcessActivation("OpWLS") << "\n";
568 os << " WLS time profile name: " << wlsTimeProfileName << "\n";
569 os << " WLS2 process active: " << GetProcessActivation("OpWLS2") << "\n";
570 os << " WLS2 time profile name: " << wls2TimeProfileName << "\n";
571 os << " Boundary process active: " << GetProcessActivation("OpBoundary") << "\n";
572 os << " Boundary invoke sensitive detector: " << boundaryInvokeSD << "\n";
573 os << " Rayleigh process active: " << GetProcessActivation("OpRayleigh") << "\n";
574 os << " MieHG process active: " << GetProcessActivation("OpMieHG") << "\n";
575 os << " Absorption process active: " << GetProcessActivation("OpAbsorption") << "\n";
576 os << "=======================================================================" << "\n";
577 os.precision(prec);
578}
579
581{
582#ifdef G4MULTITHREADED
583 G4MUTEXLOCK(&opticalParametersMutex);
584#endif
586#ifdef G4MULTITHREADED
587 G4MUTEXUNLOCK(&opticalParametersMutex);
588#endif
589}
590
591std::ostream& operator<< (std::ostream& os, const G4OpticalParameters& par)
592{
593 par.StreamInfo(os);
594 return os;
595}
596
597G4bool G4OpticalParameters::IsLocked() const
598{
599 return (!G4Threading::IsMasterThread() ||
600 (fStateManager->GetCurrentState() != G4State_PreInit &&
601 fStateManager->GetCurrentState() != G4State_Init &&
602 fStateManager->GetCurrentState() != G4State_Idle));
603}
@ G4State_Init
@ G4State_Idle
@ G4State_PreInit
@ JustWarning
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
std::ostream & operator<<(std::ostream &os, const G4OpticalParameters &par)
G4OpticalProcessIndex
@ kWLS
Wave Length Shifting process index.
@ kScintillation
Scintillation process index.
@ kWLS2
Second Wave Length Shifting process index.
@ kRayleigh
Rayleigh scattering process index.
@ kAbsorption
Absorption process index.
@ kCerenkov
Cerenkov process index.
@ kMieHG
Mie scattering process index.
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:85
#define G4MUTEXLOCK(mutex)
Definition: G4Threading.hh:251
#define G4MUTEXUNLOCK(mutex)
Definition: G4Threading.hh:254
std::mutex G4Mutex
Definition: G4Threading.hh:81
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4GLOB_DLL std::ostream G4cout
G4bool GetBoundaryInvokeSD() const
void SetScintByParticleType(G4bool)
void SetCerenkovMaxBetaChange(G4double)
void SetRayleighVerboseLevel(G4int)
void SetCerenkovMaxPhotonsPerStep(G4int)
void SetBoundaryInvokeSD(G4bool)
void Configure(G4OpticalProcessIndex, G4bool)
void SetBoundaryVerboseLevel(G4int)
G4int GetCerenkovVerboseLevel() const
void SetScintTrackSecondariesFirst(G4bool)
void SetScintEnhancedTimeConstants(G4bool)
G4int GetScintVerboseLevel() const
void StreamInfo(std::ostream &os) const
void SetTrackSecondariesFirst(G4OpticalProcessIndex, G4bool)
G4int GetAbsorptionVerboseLevel() const
void SetScintStackPhotons(G4bool)
G4bool GetScintStackPhotons() const
G4int GetBoundaryVerboseLevel() const
G4int GetRayleighVerboseLevel() const
G4int GetWLS2VerboseLevel() const
G4String GetWLS2TimeProfile() const
G4bool GetTrackSecondariesFirst(G4OpticalProcessIndex)
G4int GetMieVerboseLevel() const
void SetWLS2TimeProfile(const G4String &)
G4int GetCerenkovMaxPhotonsPerStep() const
static G4OpticalParameters * Instance()
G4double GetCerenkovMaxBetaChange() const
G4double GetScintExcitationRatio() const
G4bool GetConfiguration(G4OpticalProcessIndex)
void SetAbsorptionVerboseLevel(G4int)
G4bool GetProcessActivation(const G4String &) const
void SetCerenkovStackPhotons(G4bool)
void SetCerenkovTrackSecondariesFirst(G4bool)
void SetScintFiniteRiseTime(G4bool)
G4String GetWLSTimeProfile() const
G4bool GetScintEnhancedTimeConstants() const
G4bool GetScintByParticleType() const
void SetWLSTimeProfile(const G4String &)
G4bool GetScintFiniteRiseTime() const
void SetCerenkovVerboseLevel(G4int)
G4double GetScintYieldFactor() const
G4bool GetScintTrackInfo() const
void SetScintExcitationRatio(G4double)
G4bool GetCerenkovTrackSecondariesFirst() const
void SetScintYieldFactor(G4double)
G4int GetWLSVerboseLevel() const
void SetProcessActivation(const G4String &, G4bool)
G4bool GetScintTrackSecondariesFirst() const
G4bool GetCerenkovStackPhotons() const
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
G4bool IsMasterThread()
Definition: G4Threading.cc:124