Geant4_10
G4OpWLS.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 // $Id: G4OpWLS.cc 71487 2013-06-17 08:19:40Z gcosmo $
28 //
30 // Optical Photon WaveLength Shifting (WLS) Class Implementation
32 //
33 // File: G4OpWLS.cc
34 // Description: Discrete Process -- Wavelength Shifting of Optical Photons
35 // Version: 1.0
36 // Created: 2003-05-13
37 // Author: John Paul Archambault
38 // (Adaptation of G4Scintillation and G4OpAbsorption)
39 // Updated: 2005-07-28 - add G4ProcessType to constructor
40 // 2006-05-07 - add G4VWLSTimeGeneratorProfile
41 // mail: gum@triumf.ca
42 // jparcham@phys.ualberta.ca
43 //
45 
46 #include "G4OpWLS.hh"
47 
48 #include "G4ios.hh"
49 #include "G4PhysicalConstants.hh"
50 #include "G4SystemOfUnits.hh"
51 #include "G4OpProcessSubType.hh"
52 
55 
57 // Class Implementation
59 
61 // Constructors
63 
64 G4OpWLS::G4OpWLS(const G4String& processName, G4ProcessType type)
65  : G4VDiscreteProcess(processName, type)
66 {
68 
69  theIntegralTable = NULL;
70 
71  if (verboseLevel>0) {
72  G4cout << GetProcessName() << " is created " << G4endl;
73  }
74 
76  new G4WLSTimeGeneratorProfileDelta("WLSTimeGeneratorProfileDelta");
77 
78 }
79 
81 // Destructors
83 
85 {
86  if (theIntegralTable != 0) {
88  delete theIntegralTable;
89  }
91 }
92 
94 // Methods
96 
98 {
99  if (!theIntegralTable) BuildThePhysicsTable();
100 }
101 
102 // PostStepDoIt
103 // -------------
104 //
106 G4OpWLS::PostStepDoIt(const G4Track& aTrack, const G4Step& aStep)
107 {
108  aParticleChange.Initialize(aTrack);
109 
111 
112  if (verboseLevel>0) {
113  G4cout << "\n** Photon absorbed! **" << G4endl;
114  }
115 
116  const G4Material* aMaterial = aTrack.GetMaterial();
117 
118  G4StepPoint* pPostStepPoint = aStep.GetPostStepPoint();
119 
120  G4MaterialPropertiesTable* aMaterialPropertiesTable =
121  aMaterial->GetMaterialPropertiesTable();
122  if (!aMaterialPropertiesTable)
123  return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
124 
125  const G4MaterialPropertyVector* WLS_Intensity =
126  aMaterialPropertiesTable->GetProperty("WLSCOMPONENT");
127 
128  if (!WLS_Intensity)
129  return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
130 
131  G4int NumPhotons = 1;
132 
133  if (aMaterialPropertiesTable->ConstPropertyExists("WLSMEANNUMBERPHOTONS")) {
134 
135  G4double MeanNumberOfPhotons = aMaterialPropertiesTable->
136  GetConstProperty("WLSMEANNUMBERPHOTONS");
137 
138  NumPhotons = G4int(G4Poisson(MeanNumberOfPhotons));
139 
140  if (NumPhotons <= 0) {
141 
142  // return unchanged particle and no secondaries
143 
145 
146  return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
147 
148  }
149 
150  }
151 
153 
154  G4double primaryEnergy = aTrack.GetDynamicParticle()->GetKineticEnergy();
155 
156  G4int materialIndex = aMaterial->GetIndex();
157 
158  // Retrieve the WLS Integral for this material
159  // new G4PhysicsOrderedFreeVector allocated to hold CII's
160 
161  G4double WLSTime = 0.*ns;
162  G4PhysicsOrderedFreeVector* WLSIntegral = 0;
163 
164  WLSTime = aMaterialPropertiesTable->
165  GetConstProperty("WLSTIMECONSTANT");
166  WLSIntegral =
167  (G4PhysicsOrderedFreeVector*)((*theIntegralTable)(materialIndex));
168 
169  // Max WLS Integral
170 
171  G4double CIImax = WLSIntegral->GetMaxValue();
172 
173  G4int NumberOfPhotons = NumPhotons;
174 
175  for (G4int i = 0; i < NumPhotons; i++) {
176 
177  G4double sampledEnergy;
178 
179  // Make sure the energy of the secondary is less than that of the primary
180 
181  for (G4int j = 1; j <= 100; j++) {
182 
183  // Determine photon energy
184 
185  G4double CIIvalue = G4UniformRand()*CIImax;
186  sampledEnergy = WLSIntegral->GetEnergy(CIIvalue);
187 
188  if (verboseLevel>1) {
189  G4cout << "sampledEnergy = " << sampledEnergy << G4endl;
190  G4cout << "CIIvalue = " << CIIvalue << G4endl;
191  }
192 
193  if (sampledEnergy <= primaryEnergy) break;
194  }
195 
196  // If no such energy can be sampled, return one less secondary, or none
197 
198  if (sampledEnergy > primaryEnergy) {
199  if (verboseLevel>1)
200  G4cout << " *** One less WLS photon will be returned ***" << G4endl;
201  NumberOfPhotons--;
202  aParticleChange.SetNumberOfSecondaries(NumberOfPhotons);
203  if (NumberOfPhotons == 0) {
204  if (verboseLevel>1)
205  G4cout << " *** No WLS photon can be sampled for this primary ***"
206  << G4endl;
207  // return unchanged particle and no secondaries
208  return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
209  }
210  continue;
211  }
212 
213  // Generate random photon direction
214 
215  G4double cost = 1. - 2.*G4UniformRand();
216  G4double sint = std::sqrt((1.-cost)*(1.+cost));
217 
218  G4double phi = twopi*G4UniformRand();
219  G4double sinp = std::sin(phi);
220  G4double cosp = std::cos(phi);
221 
222  G4double px = sint*cosp;
223  G4double py = sint*sinp;
224  G4double pz = cost;
225 
226  // Create photon momentum direction vector
227 
228  G4ParticleMomentum photonMomentum(px, py, pz);
229 
230  // Determine polarization of new photon
231 
232  G4double sx = cost*cosp;
233  G4double sy = cost*sinp;
234  G4double sz = -sint;
235 
236  G4ThreeVector photonPolarization(sx, sy, sz);
237 
238  G4ThreeVector perp = photonMomentum.cross(photonPolarization);
239 
240  phi = twopi*G4UniformRand();
241  sinp = std::sin(phi);
242  cosp = std::cos(phi);
243 
244  photonPolarization = cosp * photonPolarization + sinp * perp;
245 
246  photonPolarization = photonPolarization.unit();
247 
248  // Generate a new photon:
249 
250  G4DynamicParticle* aWLSPhoton =
252  photonMomentum);
253  aWLSPhoton->SetPolarization
254  (photonPolarization.x(),
255  photonPolarization.y(),
256  photonPolarization.z());
257 
258  aWLSPhoton->SetKineticEnergy(sampledEnergy);
259 
260  // Generate new G4Track object:
261 
262  // Must give position of WLS optical photon
263 
264  G4double TimeDelay = WLSTimeGeneratorProfile->GenerateTime(WLSTime);
265  G4double aSecondaryTime = (pPostStepPoint->GetGlobalTime()) + TimeDelay;
266 
267  G4ThreeVector aSecondaryPosition = pPostStepPoint->GetPosition();
268 
269  G4Track* aSecondaryTrack =
270  new G4Track(aWLSPhoton,aSecondaryTime,aSecondaryPosition);
271 
272  aSecondaryTrack->SetTouchableHandle(aTrack.GetTouchableHandle());
273  // aSecondaryTrack->SetTouchableHandle((G4VTouchable*)0);
274 
275  aSecondaryTrack->SetParentID(aTrack.GetTrackID());
276 
277  aParticleChange.AddSecondary(aSecondaryTrack);
278  }
279 
280  if (verboseLevel>0) {
281  G4cout << "\n Exiting from G4OpWLS::DoIt -- NumberOfSecondaries = "
283  }
284 
285  return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
286 }
287 
288 // BuildThePhysicsTable for the wavelength shifting process
289 // --------------------------------------------------
290 //
291 
292 void G4OpWLS::BuildThePhysicsTable()
293 {
294  if (theIntegralTable) return;
295 
296  const G4MaterialTable* theMaterialTable =
298  G4int numOfMaterials = G4Material::GetNumberOfMaterials();
299 
300  // create new physics table
301 
302  if(!theIntegralTable)theIntegralTable = new G4PhysicsTable(numOfMaterials);
303 
304  // loop for materials
305 
306  for (G4int i=0 ; i < numOfMaterials; i++)
307  {
308  G4PhysicsOrderedFreeVector* aPhysicsOrderedFreeVector =
310 
311  // Retrieve vector of WLS wavelength intensity for
312  // the material from the material's optical properties table.
313 
314  G4Material* aMaterial = (*theMaterialTable)[i];
315 
316  G4MaterialPropertiesTable* aMaterialPropertiesTable =
317  aMaterial->GetMaterialPropertiesTable();
318 
319  if (aMaterialPropertiesTable) {
320 
321  G4MaterialPropertyVector* theWLSVector =
322  aMaterialPropertiesTable->GetProperty("WLSCOMPONENT");
323 
324  if (theWLSVector) {
325 
326  // Retrieve the first intensity point in vector
327  // of (photon energy, intensity) pairs
328 
329  G4double currentIN = (*theWLSVector)[0];
330 
331  if (currentIN >= 0.0) {
332 
333  // Create first (photon energy)
334 
335  G4double currentPM = theWLSVector->Energy(0);
336 
337  G4double currentCII = 0.0;
338 
339  aPhysicsOrderedFreeVector->
340  InsertValues(currentPM , currentCII);
341 
342  // Set previous values to current ones prior to loop
343 
344  G4double prevPM = currentPM;
345  G4double prevCII = currentCII;
346  G4double prevIN = currentIN;
347 
348  // loop over all (photon energy, intensity)
349  // pairs stored for this material
350 
351  for (size_t j = 1;
352  j < theWLSVector->GetVectorLength();
353  j++)
354  {
355  currentPM = theWLSVector->Energy(j);
356  currentIN = (*theWLSVector)[j];
357 
358  currentCII = 0.5 * (prevIN + currentIN);
359 
360  currentCII = prevCII +
361  (currentPM - prevPM) * currentCII;
362 
363  aPhysicsOrderedFreeVector->
364  InsertValues(currentPM, currentCII);
365 
366  prevPM = currentPM;
367  prevCII = currentCII;
368  prevIN = currentIN;
369  }
370  }
371  }
372  }
373  // The WLS integral for a given material
374  // will be inserted in the table according to the
375  // position of the material in the material table.
376 
377  theIntegralTable->insertAt(i,aPhysicsOrderedFreeVector);
378  }
379 }
380 
381 // GetMeanFreePath
382 // ---------------
383 //
385  G4double ,
387 {
388  const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle();
389  const G4Material* aMaterial = aTrack.GetMaterial();
390 
391  G4double thePhotonEnergy = aParticle->GetTotalEnergy();
392 
393  G4MaterialPropertiesTable* aMaterialPropertyTable;
394  G4MaterialPropertyVector* AttenuationLengthVector;
395 
396  G4double AttenuationLength = DBL_MAX;
397 
398  aMaterialPropertyTable = aMaterial->GetMaterialPropertiesTable();
399 
400  if ( aMaterialPropertyTable ) {
401  AttenuationLengthVector = aMaterialPropertyTable->
402  GetProperty("WLSABSLENGTH");
403  if ( AttenuationLengthVector ){
404  AttenuationLength = AttenuationLengthVector->
405  Value(thePhotonEnergy);
406  }
407  else {
408  // G4cout << "No WLS absorption length specified" << G4endl;
409  }
410  }
411  else {
412  // G4cout << "No WLS absortion length specified" << G4endl;
413  }
414 
415  return AttenuationLength;
416 }
417 
419 {
420  if (name == "delta")
421  {
424  new G4WLSTimeGeneratorProfileDelta("delta");
425  }
426  else if (name == "exponential")
427  {
430  new G4WLSTimeGeneratorProfileExponential("exponential");
431  }
432  else
433  {
434  G4Exception("G4OpWLS::UseTimeProfile", "em0202",
436  "generator does not exist");
437  }
438 }
G4long G4Poisson(G4double mean)
Definition: G4Poisson.hh:51
G4int GetNumberOfSecondaries() const
G4MaterialPropertyVector * GetProperty(const char *key)
G4int verboseLevel
Definition: G4VProcess.hh:368
G4double GetKineticEnergy() const
G4double GetTotalEnergy() const
double x() const
const G4DynamicParticle * GetDynamicParticle() const
G4VParticleChange * PostStepDoIt(const G4Track &aTrack, const G4Step &aStep)
Definition: G4OpWLS.cc:106
size_t GetIndex() const
Definition: G4Material.hh:260
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:564
std::vector< G4Material * > G4MaterialTable
const XML_Char * name
Definition: expat.h:151
void SetTouchableHandle(const G4TouchableHandle &apValue)
size_t GetVectorLength() const
int G4int
Definition: G4Types.hh:78
double z() const
void UseTimeProfile(const G4String name)
Definition: G4OpWLS.cc:418
#define G4UniformRand()
Definition: Randomize.hh:87
G4GLOB_DLL std::ostream G4cout
virtual G4double GenerateTime(const G4double time_constant)=0
const G4ThreeVector & GetPosition() const
void BuildPhysicsTable(const G4ParticleDefinition &aParticleType)
Definition: G4OpWLS.cc:97
G4VWLSTimeGeneratorProfile * WLSTimeGeneratorProfile
Definition: G4OpWLS.hh:142
void SetProcessSubType(G4int)
Definition: G4VProcess.hh:432
~G4OpWLS()
Definition: G4OpWLS.cc:84
Definition: G4Step.hh:76
G4int GetTrackID() const
void SetPolarization(G4double polX, G4double polY, G4double polZ)
G4double Energy(size_t index) const
static size_t GetNumberOfMaterials()
Definition: G4Material.cc:571
const G4String & GetProcessName() const
Definition: G4VProcess.hh:408
void SetKineticEnergy(G4double aEnergy)
const G4TouchableHandle & GetTouchableHandle() const
G4double GetEnergy(G4double aValue)
G4Material * GetMaterial() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4OpticalPhoton * OpticalPhoton()
virtual void Initialize(const G4Track &)
G4MaterialPropertiesTable * GetMaterialPropertiesTable() const
Definition: G4Material.hh:250
void SetNumberOfSecondaries(G4int totSecondaries)
Hep3Vector unit() const
void SetParentID(const G4int aValue)
G4StepPoint * GetPostStepPoint() const
double y() const
G4ParticleChange aParticleChange
Definition: G4VProcess.hh:289
G4bool ConstPropertyExists(const char *key)
G4OpWLS(const G4String &processName="OpWLS", G4ProcessType type=fOptical)
Definition: G4OpWLS.cc:64
void AddSecondary(G4Track *aSecondary)
void insertAt(size_t, G4PhysicsVector *)
#define G4endl
Definition: G4ios.hh:61
G4double GetGlobalTime() const
Hep3Vector cross(const Hep3Vector &) const
double G4double
Definition: G4Types.hh:76
void ProposeTrackStatus(G4TrackStatus status)
G4ForceCondition
G4PhysicsTable * theIntegralTable
Definition: G4OpWLS.hh:143
#define DBL_MAX
Definition: templates.hh:83
#define ns
Definition: xmlparse.cc:597
virtual G4VParticleChange * PostStepDoIt(const G4Track &, const G4Step &)
G4double GetMeanFreePath(const G4Track &aTrack, G4double, G4ForceCondition *)
Definition: G4OpWLS.cc:384
void clearAndDestroy()
G4ProcessType