Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 "G4OpAbsorption.hh"
42 #include "G4OpRayleigh.hh"
43 #include "G4OpMieHG.hh"
44 
45 #include "G4OpBoundaryProcess.hh"
46 
47 #include "G4OpWLS.hh"
48 #include "G4Scintillation.hh"
49 #include "G4Cerenkov.hh"
50 
51 #include "G4LossTableManager.hh"
52 #include "G4EmSaturation.hh"
53 
54 #include "G4GenericMessenger.hh"
55 
56 // factory
58 //
60 
61 
62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
63 
65  : G4VPhysicsConstructor(name),
66 
67  fMaxNumPhotons(100),
68  fMaxBetaChange(10.0),
69  fYieldFactor(1.),
70  fExcitationRatio(0.0),
71  fProfile("delta"),
72  fFiniteRiseTime(false),
73  fScintillationByParticleType(false),
74  fScintillationTrackInfo(false),
75  fInvokeSD(true),
76  fCerenkovStackPhotons(true),
77  fScintillationStackPhotons(true)
78 {
79  verboseLevel = verbose;
80  fMessenger = new G4OpticalPhysicsMessenger(this);
81 
82  for ( G4int i=0; i<kNoProcess; i++ ) {
83  fProcessUse.push_back(true);
84  fProcessTrackSecondariesFirst.push_back(true);
85  }
86 }
87 
88 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
89 
91 {
92  delete fMessenger;
93 }
94 
95 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
96 
97 void G4OpticalPhysics::PrintStatistics() const
98 {
99 // Print all processes activation and their parameters
100 
101  for ( G4int i=0; i<kNoProcess; i++ ) {
102  G4cout << " " << G4OpticalProcessName(i) << " process: ";
103  if ( ! fProcessUse[i] ) {
104  G4cout << "not used" << G4endl;
105  }
106  else {
107  G4cout << "used" << G4endl;
108  if ( i == kCerenkov ) {
109  G4cout << " Max number of photons per step: " << fMaxNumPhotons << G4endl;
110  G4cout << " Max beta change per step: " << fMaxBetaChange << G4endl;
111  if ( fProcessTrackSecondariesFirst[kCerenkov] ) {
112  G4cout << " Track secondaries first: activated" << G4endl;
113  }
114  else {
115  G4cout << " Track secondaries first: inactivated" << G4endl;
116  }
117  }
118  if ( i == kScintillation ) {
119  if (fScintillationByParticleType)
120  G4cout << " Scintillation by Particle Type: activated " << G4endl;
121  G4cout << " Yield factor: " << fYieldFactor << G4endl;
122  G4cout << " ExcitationRatio: " << fExcitationRatio << G4endl;
123  if ( fProcessTrackSecondariesFirst[kScintillation] ) {
124  G4cout << " Track secondaries first: activated" << G4endl;
125  }
126  else {
127  G4cout << " Track secondaries first: inactivated" << G4endl;
128  }
129  }
130  if ( i == kWLS ) {
131  G4cout << " WLS process time profile: " << fProfile << G4endl;
132  }
133  }
134  }
135 }
136 
137 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
138 
139 #include "G4OpticalPhoton.hh"
140 
142 {
144 
145  // optical photon
147 }
148 
149 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
150 #define DIR_CMDS "/process/optical"
151 #define GUIDANCE "Commands related to the optical physics simulation engine for "
152 
153 namespace UIhelpers {
154  //Helper functions to create UI commands for processes
155 
156  template<class T>
157  void buildCommands(T* proc,const char* dir, const char* guidance)
158  {
159  //Generic function to add a "verbose" command for a process
160  G4GenericMessenger* mess = new G4GenericMessenger(proc,dir,guidance);
162  G4GenericMessenger::Command& wlscmd4 = mess->DeclareMethod("verbose",&T::SetVerboseLevel,
163  "Set the verbose level");
164  wlscmd4.SetParameterName("ver",true);
165  wlscmd4.SetDefaultValue("1");
166  wlscmd4.SetStates(G4State_Idle);
167  }
168 
169  void buildCommands( G4OpWLS* op )
170  {
171  //Build UI commands for WLS
172  G4GenericMessenger* mess = new G4GenericMessenger(op,DIR_CMDS"/wls/",GUIDANCE" for WLS process.");
174  //Here, more correctly DeclareProperty should be used, but to do that, I would need public/friend
175  //access of G4GenericMessenger to private members of G4Scintillation. Thus I use the approach
176  //of DeclareMethod, that has a draw back: range checking does not work
177  G4GenericMessenger::Command& wlscmd1 = mess->DeclareMethod("setTimeProfile",&G4OpWLS::UseTimeProfile,
178  "Set the WLS time profile (delta or exponential)");
179  wlscmd1.SetParameterName("profile",false);
180  wlscmd1.SetCandidates("delta exponential");
181  wlscmd1.SetStates(G4State_Idle);
182  buildCommands(op,DIR_CMDS"/wls/",GUIDANCE" for WLS process.");
183  }
184 
185  void buildCommands(G4Scintillation* ScintillationProcess)
186  {
187  //Build UI commands for scintillation
188  G4GenericMessenger* mess = new G4GenericMessenger(ScintillationProcess,DIR_CMDS"/scintillation/",GUIDANCE" for scintillation process.");
190  G4GenericMessenger::Command& sccmd1 = mess->DeclareMethod("setFiniteRiseTime",
192  "Set option of a finite rise-time for G4Scintillation - If set, the G4Scintillation process expects the user to have set the constant material property FAST/SLOWSCINTILLATIONRISETIME");
193  sccmd1.SetParameterName("time",false);
194  sccmd1.SetStates(G4State_Idle);
195 
196  G4GenericMessenger::Command& sccmd2 = mess->DeclareMethod("setYieldFactor",
198  "Set scintillation yield factor");
199  sccmd2.SetParameterName("factor",false);
200  //sccmd2.SetRange("factor>=0."); //LIMITATION: w/ DeclareMethod range checking does not work
201  sccmd2.SetStates(G4State_Idle);
202 
203  G4GenericMessenger::Command& sccmd3 = mess->DeclareMethod("setExcitationRatio",
205  "Set scintillation excitation ratio");
206  sccmd3.SetParameterName("ratio",false);
207  //sccmd3.SetRange("ratio>=0.&&ratio<=1.");//LIMITATION: w/ DeclareMethod range checking does not work
208  sccmd3.SetStates(G4State_Idle);
209 
210  G4GenericMessenger::Command& sccmd4 = mess->DeclareMethod("setByParticleType",
212  "Activate/Inactivate scintillation process by particle type");
213  sccmd4.SetParameterName("flag", false);
214  sccmd4.SetStates(G4State_Idle);
215 
216  G4GenericMessenger::Command& sccmd5 = mess->DeclareMethod("setTrackInfo",
218  "Activate/Inactivate scintillation track info");
219  sccmd5.SetParameterName("flag", false);
220  sccmd5.SetStates(G4State_Idle);
221 
222  G4GenericMessenger::Command& sccmd6 = mess->DeclareMethod("setTrackSecondariesFirst",
224  "Set option to track secondaries before finishing their parent track");
225  sccmd6.SetParameterName("flag",false);
226  sccmd6.SetStates(G4State_Idle);
227 
228  buildCommands(ScintillationProcess,DIR_CMDS"/scintillation/",GUIDANCE" for scintillation process.");
229  }
230 
231  void buildCommands(G4Cerenkov* CerenkovProcess)
232  {
233  //BUild UI commands for cerenkov
234  G4GenericMessenger* mess = new G4GenericMessenger(CerenkovProcess,DIR_CMDS"/cerenkov/",GUIDANCE" for Cerenkov process.");
236  G4GenericMessenger::Command& cecmd1 = mess->DeclareMethod("setMaxPhotons",
238  "Set maximum number of photons per step");
239  cecmd1.SetParameterName("max",false);
240  //cecmd1.SetRange("max>=0");//LIMITATION: w/ DeclareMethod range checking does not work
241  cecmd1.SetStates(G4State_Idle);
242 
243  G4GenericMessenger::Command& cecmd2 = mess->DeclareMethod("setMaxBetaChange",
245  "Set maximum change of beta of parent particle per step");
246  cecmd2.SetParameterName("max",false);
247  //cecmd2.SetRange("max>=0.");//LIMITATION: w/ DeclareMethod range checking does not work
248  cecmd2.SetStates(G4State_Idle);
249 
250  G4GenericMessenger::Command& cecmd3 = mess->DeclareMethod("setTrackSecondariesFirst",
252  "Set option to track secondaries before finishing their parent track");
253  cecmd3.SetParameterName("flag",false);
254  cecmd3.SetStates(G4State_Idle);
255 
256  buildCommands(CerenkovProcess,DIR_CMDS"/cerenkov/",GUIDANCE" for Cerenkov process.");
257  }
258 }
259 
260 
261 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
262 
263 #include "G4Threading.hh"
264 #include "G4ParticleDefinition.hh"
265 #include "G4ProcessManager.hh"
266 #include "G4AutoDelete.hh"
267 
269 {
270 // Construct optical processes.
271 
272  if(verboseLevel>0)
273  G4cout <<"G4OpticalPhysics:: Add Optical Physics Processes"<< G4endl;
274 
275  // A vector of optical processes
276  std::vector<G4VProcess*> OpProcesses;
277 
278  for ( G4int i=0; i<kNoProcess; i++ ) OpProcesses.push_back(NULL);
279 
280  // Add Optical Processes
281 
282  G4OpAbsorption* OpAbsorptionProcess = new G4OpAbsorption();
283  UIhelpers::buildCommands(OpAbsorptionProcess,DIR_CMDS"/absorption/",GUIDANCE" for absorption process");
284  OpProcesses[kAbsorption] = OpAbsorptionProcess;
285 
286  G4OpRayleigh* OpRayleighScatteringProcess = new G4OpRayleigh();
287  UIhelpers::buildCommands(OpRayleighScatteringProcess,DIR_CMDS"/rayleigh/",GUIDANCE" for Reyleigh scattering process");
288  OpProcesses[kRayleigh] = OpRayleighScatteringProcess;
289 
290  G4OpMieHG* OpMieHGScatteringProcess = new G4OpMieHG();
291  UIhelpers::buildCommands(OpMieHGScatteringProcess,DIR_CMDS"/mie/",GUIDANCE" for Mie cattering process");
292  OpProcesses[kMieHG] = OpMieHGScatteringProcess;
293 
294  G4OpBoundaryProcess* OpBoundaryProcess = new G4OpBoundaryProcess();
295  UIhelpers::buildCommands(OpBoundaryProcess,DIR_CMDS"/boundary/",GUIDANCE" for boundary process");
296  OpBoundaryProcess->SetInvokeSD(fInvokeSD);
297  OpProcesses[kBoundary] = OpBoundaryProcess;
298 
299  G4OpWLS* OpWLSProcess = new G4OpWLS();
300  OpWLSProcess->UseTimeProfile(fProfile);
301  UIhelpers::buildCommands(OpWLSProcess);
302  OpProcesses[kWLS] = OpWLSProcess;
303 
304  G4ProcessManager * pManager = 0;
306 
307  if (!pManager) {
308  std::ostringstream o;
309  o << "Optical Photon without a Process Manager";
310  G4Exception("G4OpticalPhysics::ConstructProcess()","",
311  FatalException,o.str().c_str());
312  return;
313  }
314 
315  for ( G4int i=kAbsorption; i<=kWLS; i++ ) {
316  if ( fProcessUse[i] ) {
317  pManager->AddDiscreteProcess(OpProcesses[i]);
318  }
319  }
320 
321  G4Scintillation* ScintillationProcess = new G4Scintillation();
322  ScintillationProcess->SetScintillationYieldFactor(fYieldFactor);
323  ScintillationProcess->SetScintillationExcitationRatio(fExcitationRatio);
324  ScintillationProcess->SetFiniteRiseTime(fFiniteRiseTime);
325  ScintillationProcess->SetScintillationByParticleType(fScintillationByParticleType);
326  ScintillationProcess->SetScintillationTrackInfo(fScintillationTrackInfo);
327  ScintillationProcess->SetTrackSecondariesFirst(fProcessTrackSecondariesFirst[kScintillation]);
328  ScintillationProcess->SetStackPhotons(fScintillationStackPhotons);
330  ScintillationProcess->AddSaturation(emSaturation);
331  UIhelpers::buildCommands(ScintillationProcess);
332  OpProcesses[kScintillation] = ScintillationProcess;
333 
334  G4Cerenkov* CerenkovProcess = new G4Cerenkov();
335  CerenkovProcess->SetMaxNumPhotonsPerStep(fMaxNumPhotons);
336  CerenkovProcess->SetMaxBetaChangePerStep(fMaxBetaChange);
337  CerenkovProcess->SetTrackSecondariesFirst(fProcessTrackSecondariesFirst[kCerenkov]);
338  CerenkovProcess->SetStackPhotons(fCerenkovStackPhotons);
339  UIhelpers::buildCommands(CerenkovProcess);
340  OpProcesses[kCerenkov] = CerenkovProcess;
341 
342  auto myParticleIterator=GetParticleIterator();
343  myParticleIterator->reset();
344 
345  while( (*myParticleIterator)() ){
346 
347  G4ParticleDefinition* particle = myParticleIterator->value();
348  G4String particleName = particle->GetParticleName();
349 
350  pManager = particle->GetProcessManager();
351  if (!pManager) {
352  std::ostringstream o;
353  o << "Particle " << particleName << "without a Process Manager";
354  G4Exception("G4OpticalPhysics::ConstructProcess()","",
355  FatalException,o.str().c_str());
356  return; // else coverity complains for pManager use below
357  }
358 
359  if( CerenkovProcess->IsApplicable(*particle) &&
360  fProcessUse[kCerenkov] ) {
361  pManager->AddProcess(CerenkovProcess);
362  pManager->SetProcessOrdering(CerenkovProcess,idxPostStep);
363  }
364  if( ScintillationProcess->IsApplicable(*particle) &&
365  fProcessUse[kScintillation] ){
366  pManager->AddProcess(ScintillationProcess);
367  pManager->SetProcessOrderingToLast(ScintillationProcess,idxAtRest);
368  pManager->SetProcessOrderingToLast(ScintillationProcess,idxPostStep);
369  }
370 
371  }
372 
373  // Add verbose
374  for ( G4int i=0; i<kNoProcess; i++ ) {
375  if ( fProcessUse[i] ) OpProcesses[i]->SetVerboseLevel(verboseLevel);
376  }
377 
378  if (verboseLevel > 1) PrintStatistics();
379  if (verboseLevel > 0)
380  G4cout << "### " << namePhysics << " physics constructed." << G4endl;
381 }
382 
384 {
386 
387  fYieldFactor = yieldFactor;
388  //G4Scintillation::SetScintillationYieldFactor(yieldFactor);
389 }
390 
392 {
394 
395  fExcitationRatio = excitationRatio;
396 // G4Scintillation::SetScintillationExcitationRatio(excitationRatio);
397 }
398 
400 {
402 
403  fMaxNumPhotons = maxNumPhotons;
404 // G4Cerenkov::SetMaxNumPhotonsPerStep(maxNumPhotons);
405 }
406 
408 {
410 
411  fMaxBetaChange = maxBetaChange;
412 // G4Cerenkov::SetMaxBetaChangePerStep(maxBetaChange);
413 }
414 
416 {
418  fProfile = profile;
419 }
420 
421 //void G4OpticalPhysics::AddScintillationSaturation(G4EmSaturation* saturation)
422 //{
424 // G4Scintillation::AddSaturation(saturation);
425 //}
426 
428  SetScintillationByParticleType(G4bool scintillationByParticleType)
429 {
430  fScintillationByParticleType = scintillationByParticleType;
431  //G4Scintillation::SetScintillationByParticleType(scintillationByParticleType);
432 }
433 
435  SetScintillationTrackInfo(G4bool scintillationTrackInfo)
436 {
437  fScintillationTrackInfo = scintillationTrackInfo;
438  //G4Scintillation::SetScintillationTrackInfo(scintillationTrackInfo);
439 }
440 
442  G4bool trackSecondariesFirst)
443 {
444  if ( index >= kNoProcess ) return;
445  if ( fProcessTrackSecondariesFirst[index] == trackSecondariesFirst ) return;
446  fProcessTrackSecondariesFirst[index] = trackSecondariesFirst;
447 
448 // if ( index == kCerenkov )
449 // G4Cerenkov::SetTrackSecondariesFirst(trackSecondariesFirst);
450 // if ( index == kScintillation)
451 // G4Scintillation::SetTrackSecondariesFirst(trackSecondariesFirst);
452 }
453 
455 {
456  fFiniteRiseTime = finiteRiseTime;
457  //G4Scintillation::SetFiniteRiseTime(finiteRiseTime);
458 }
459 
461 {
462  fInvokeSD = invokeSD;
463 }
464 
466 {
467  fCerenkovStackPhotons = stackingFlag;
468 }
469 
471 {
472  fScintillationStackPhotons = stackingFlag;
473 }
474 
476 {
477  // Configure the physics constructor to use/not use a selected process.
478  // This method can only be called in PreInit> phase (before execution of
479  // ConstructProcess). The process is not added to particle's process manager
480  // and so it cannot be re-activated later in Idle> phase with the command
481  // /process/activate.
482 
483  if ( index >= kNoProcess ) return;
484  if ( fProcessUse[index] == isUse ) return;
485  fProcessUse[index] = isUse;
486 }
487 
488 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void SetScintillationByParticleType(const G4bool)
const XML_Char * name
Definition: expat.h:151
void SetMaxBetaChangePerStep(const G4double d)
Definition: G4Cerenkov.cc:150
void SetScintillationTrackInfo(const G4bool trackType)
static G4LossTableManager * Instance()
void SetFiniteRiseTime(const G4bool state)
Number of processes, no selected process.
virtual void ConstructParticle()
G4OpticalProcessIndex
void SetTrackSecondariesFirst(const G4bool state)
Definition: G4Cerenkov.cc:145
void SetMaxBetaChangePerStep(G4double)
This class is generic messenger.
void SetInvokeSD(G4bool)
G4int AddDiscreteProcess(G4VProcess *aProcess, G4int ord=ordDefault)
Command & DeclareMethod(const G4String &name, const G4AnyMethod &fun, const G4String &doc="")
Scintillation process index.
Mie scattering process index.
void SetFiniteRiseTime(G4bool)
Absorption process index.
int G4int
Definition: G4Types.hh:78
#define DIR_CMDS
const G4String & GetParticleName() const
void SetScintillationByParticleType(G4bool)
function profile(XB)
Definition: hijing1.383.f:4673
void UseTimeProfile(const G4String name)
Definition: G4OpWLS.cc:417
virtual void ConstructProcess()
virtual ~G4OpticalPhysics()
Command & SetDefaultValue(const G4String &)
G4ParticleTable::G4PTblDicIterator * GetParticleIterator() const
void SetScintillationYieldFactor(const G4double yieldfactor)
void SetStackPhotons(const G4bool)
Definition: G4Cerenkov.hh:251
void Register(T *inst)
Definition: G4AutoDelete.hh:65
void SetStackPhotons(const G4bool)
G4GLOB_DLL std::ostream G4cout
void SetMaxNumPhotonsPerStep(G4int)
bool G4bool
Definition: G4Types.hh:79
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.cc:155
void SetProcessOrdering(G4VProcess *aProcess, G4ProcessVectorDoItIndex idDoIt, G4int ordDoIt=ordDefault)
Command & SetStates(G4ApplicationState s0)
Wave Length Shifting process index.
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void SetScintillationExcitationRatio(const G4double ratio)
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 SetScintillationStackPhotons(G4bool)
void SetProcessOrderingToLast(G4VProcess *aProcess, G4ProcessVectorDoItIndex idDoIt)
G4ProcessManager * GetProcessManager() const
Command & SetCandidates(const G4String &)
void buildCommands(T *proc, const char *dir, const char *guidance)
G4bool IsApplicable(const G4ParticleDefinition &aParticleType) override
Definition: G4Cerenkov.cc:133
Cerenkov process index.
void SetScintillationTrackInfo(G4bool)
void SetWLSTimeProfile(G4String)
void SetTrackSecondariesFirst(G4OpticalProcessIndex, G4bool)
Command & SetParameterName(const G4String &, G4bool, G4bool=false)
#define G4endl
Definition: G4ios.hh:61
static G4OpticalPhoton * OpticalPhotonDefinition()
Rayleigh scattering process index.
#define GUIDANCE
double G4double
Definition: G4Types.hh:76
G4bool IsApplicable(const G4ParticleDefinition &aParticleType) override
void SetCerenkovStackPhotons(G4bool)
void AddSaturation(G4EmSaturation *sat)
#define G4_DECLARE_PHYSCONSTR_FACTORY(physics_constructor)