Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4Scintillation.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$
28 //
30 // Scintillation Light Class Implementation
32 //
33 // File: G4Scintillation.cc
34 // Description: RestDiscrete Process - Generation of Scintillation Photons
35 // Version: 1.0
36 // Created: 1998-11-07
37 // Author: Peter Gumplinger
38 // Updated: 2010-10-20 Allow the scintillation yield to be a function
39 // of energy deposited by particle type
40 // Thanks to Zach Hartwig (Department of Nuclear
41 // Science and Engineeering - MIT)
42 // 2010-09-22 by Peter Gumplinger
43 // > scintillation rise time included, thanks to
44 // > Martin Goettlich/DESY
45 // 2005-08-17 by Peter Gumplinger
46 // > change variable name MeanNumPhotons -> MeanNumberOfPhotons
47 // 2005-07-28 by Peter Gumplinger
48 // > add G4ProcessType to constructor
49 // 2004-08-05 by Peter Gumplinger
50 // > changed StronglyForced back to Forced in GetMeanLifeTime
51 // 2002-11-21 by Peter Gumplinger
52 // > change to use G4Poisson for small MeanNumberOfPhotons
53 // 2002-11-07 by Peter Gumplinger
54 // > now allow for fast and slow scintillation component
55 // 2002-11-05 by Peter Gumplinger
56 // > now use scintillation constants from G4Material
57 // 2002-05-09 by Peter Gumplinger
58 // > use only the PostStepPoint location for the origin of
59 // scintillation photons when energy is lost to the medium
60 // by a neutral particle
61 // 2000-09-18 by Peter Gumplinger
62 // > change: aSecondaryPosition=x0+rand*aStep.GetDeltaPosition();
63 // aSecondaryTrack->SetTouchable(0);
64 // 2001-09-17, migration of Materials to pure STL (mma)
65 // 2003-06-03, V.Ivanchenko fix compilation warnings
66 //
67 // mail: gum@triumf.ca
68 //
70 
71 #include "G4ios.hh"
72 #include "globals.hh"
73 #include "G4PhysicalConstants.hh"
74 #include "G4SystemOfUnits.hh"
75 #include "G4ParticleTypes.hh"
76 #include "G4EmProcessSubType.hh"
77 
78 #include "G4Scintillation.hh"
79 
81 // Class Implementation
83 
85  // Operators
87 
88 // G4Scintillation::operator=(const G4Scintillation &right)
89 // {
90 // }
91 
93  // Constructors
95 
97  G4ProcessType type)
98  : G4VRestDiscreteProcess(processName, type)
99 {
101 
102  fTrackSecondariesFirst = false;
103  fFiniteRiseTime = false;
104 
105  YieldFactor = 1.0;
106  ExcitationRatio = 1.0;
107 
109 
110  theFastIntegralTable = NULL;
111  theSlowIntegralTable = NULL;
112 
113  if (verboseLevel>0) {
114  G4cout << GetProcessName() << " is created " << G4endl;
115  }
116 
118 
119  emSaturation = NULL;
120 }
121 
123  // Destructors
125 
127 {
128  if (theFastIntegralTable != NULL) {
130  delete theFastIntegralTable;
131  }
132  if (theSlowIntegralTable != NULL) {
134  delete theSlowIntegralTable;
135  }
136 }
137 
139  // Methods
141 
142 // AtRestDoIt
143 // ----------
144 //
146 G4Scintillation::AtRestDoIt(const G4Track& aTrack, const G4Step& aStep)
147 
148 // This routine simply calls the equivalent PostStepDoIt since all the
149 // necessary information resides in aStep.GetTotalEnergyDeposit()
150 
151 {
152  return G4Scintillation::PostStepDoIt(aTrack, aStep);
153 }
154 
155 // PostStepDoIt
156 // -------------
157 //
159 G4Scintillation::PostStepDoIt(const G4Track& aTrack, const G4Step& aStep)
160 
161 // This routine is called for each tracking step of a charged particle
162 // in a scintillator. A Poisson/Gauss-distributed number of photons is
163 // generated according to the scintillation yield formula, distributed
164 // evenly along the track segment and uniformly into 4pi.
165 
166 {
167  aParticleChange.Initialize(aTrack);
168 
169  const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle();
170  const G4Material* aMaterial = aTrack.GetMaterial();
171 
172  G4StepPoint* pPreStepPoint = aStep.GetPreStepPoint();
173  G4StepPoint* pPostStepPoint = aStep.GetPostStepPoint();
174 
175  G4ThreeVector x0 = pPreStepPoint->GetPosition();
176  G4ThreeVector p0 = aStep.GetDeltaPosition().unit();
177  G4double t0 = pPreStepPoint->GetGlobalTime();
178 
179  G4double TotalEnergyDeposit = aStep.GetTotalEnergyDeposit();
180 
181  G4MaterialPropertiesTable* aMaterialPropertiesTable =
182  aMaterial->GetMaterialPropertiesTable();
183  if (!aMaterialPropertiesTable)
184  return G4VRestDiscreteProcess::PostStepDoIt(aTrack, aStep);
185 
186  G4MaterialPropertyVector* Fast_Intensity =
187  aMaterialPropertiesTable->GetProperty("FASTCOMPONENT");
188  G4MaterialPropertyVector* Slow_Intensity =
189  aMaterialPropertiesTable->GetProperty("SLOWCOMPONENT");
190 
191  if (!Fast_Intensity && !Slow_Intensity )
192  return G4VRestDiscreteProcess::PostStepDoIt(aTrack, aStep);
193 
194  G4int nscnt = 1;
195  if (Fast_Intensity && Slow_Intensity) nscnt = 2;
196 
197  G4double ScintillationYield = 0.;
198 
200  // The scintillation response is a function of the energy
201  // deposited by particle types.
202 
203  // Get the definition of the current particle
204  G4ParticleDefinition *pDef = aParticle->GetDefinition();
205  G4MaterialPropertyVector *Scint_Yield_Vector = NULL;
206 
207  // Obtain the G4MaterialPropertyVectory containing the
208  // scintillation light yield as a function of the deposited
209  // energy for the current particle type
210 
211  // Protons
212  if(pDef==G4Proton::ProtonDefinition())
213  Scint_Yield_Vector = aMaterialPropertiesTable->
214  GetProperty("PROTONSCINTILLATIONYIELD");
215 
216  // Deuterons
217  else if(pDef==G4Deuteron::DeuteronDefinition())
218  Scint_Yield_Vector = aMaterialPropertiesTable->
219  GetProperty("DEUTERONSCINTILLATIONYIELD");
220 
221  // Tritons
222  else if(pDef==G4Triton::TritonDefinition())
223  Scint_Yield_Vector = aMaterialPropertiesTable->
224  GetProperty("TRITONSCINTILLATIONYIELD");
225 
226  // Alphas
227  else if(pDef==G4Alpha::AlphaDefinition())
228  Scint_Yield_Vector = aMaterialPropertiesTable->
229  GetProperty("ALPHASCINTILLATIONYIELD");
230 
231  // Ions (particles derived from G4VIon and G4Ions)
232  // and recoil ions below tracking cut from neutrons after hElastic
233  else if(pDef->GetParticleType()== "nucleus" ||
235  Scint_Yield_Vector = aMaterialPropertiesTable->
236  GetProperty("IONSCINTILLATIONYIELD");
237 
238  // Electrons (must also account for shell-binding energy
239  // attributed to gamma from standard PhotoElectricEffect)
240  else if(pDef==G4Electron::ElectronDefinition() ||
241  pDef==G4Gamma::GammaDefinition())
242  Scint_Yield_Vector = aMaterialPropertiesTable->
243  GetProperty("ELECTRONSCINTILLATIONYIELD");
244 
245  // Default for particles not enumerated/listed above
246  else
247  Scint_Yield_Vector = aMaterialPropertiesTable->
248  GetProperty("ELECTRONSCINTILLATIONYIELD");
249 
250  // If the user has not specified yields for (p,d,t,a,carbon)
251  // then these unspecified particles will default to the
252  // electron's scintillation yield
253  if(!Scint_Yield_Vector){
254  Scint_Yield_Vector = aMaterialPropertiesTable->
255  GetProperty("ELECTRONSCINTILLATIONYIELD");
256  }
257 
258  // Throw an exception if no scintillation yield is found
259  if (!Scint_Yield_Vector) {
261  ed << "\nG4Scintillation::PostStepDoIt(): "
262  << "Request for scintillation yield for energy deposit and particle type without correct entry in MaterialPropertiesTable\n"
263  << "ScintillationByParticleType requires at minimum that ELECTRONSCINTILLATIONYIELD is set by the user\n"
264  << G4endl;
265  G4String comments = "Missing MaterialPropertiesTable entry - No correct entry in MaterialPropertiesTable";
266  G4Exception("G4Scintillation::PostStepDoIt","Scint01",
267  FatalException,ed,comments);
268  return G4VRestDiscreteProcess::PostStepDoIt(aTrack, aStep);
269  }
270 
271  if (verboseLevel>1) {
272  G4cout << "\n"
273  << "Particle = " << pDef->GetParticleName() << "\n"
274  << "Energy Dep. = " << TotalEnergyDeposit/MeV << "\n"
275  << "Yield = "
276  << Scint_Yield_Vector->Value(TotalEnergyDeposit)
277  << "\n" << G4endl;
278  }
279 
280  // Obtain the scintillation yield using the total energy
281  // deposited by the particle in this step.
282 
283  // Units: [# scintillation photons]
284  ScintillationYield = Scint_Yield_Vector->
285  Value(TotalEnergyDeposit);
286  } else {
287  // The default linear scintillation process
288  ScintillationYield = aMaterialPropertiesTable->
289  GetConstProperty("SCINTILLATIONYIELD");
290 
291  // Units: [# scintillation photons / MeV]
292  ScintillationYield *= YieldFactor;
293  }
294 
295  G4double ResolutionScale = aMaterialPropertiesTable->
296  GetConstProperty("RESOLUTIONSCALE");
297 
298  // Birks law saturation:
299 
300  //G4double constBirks = 0.0;
301 
302  //constBirks = aMaterial->GetIonisation()->GetBirksConstant();
303 
304  G4double MeanNumberOfPhotons;
305 
306  // Birk's correction via emSaturation and specifying scintillation by
307  // by particle type are physically mutually exclusive
308 
310  MeanNumberOfPhotons = ScintillationYield;
311  else if (emSaturation)
312  MeanNumberOfPhotons = ScintillationYield*
313  (emSaturation->VisibleEnergyDeposition(&aStep));
314  else
315  MeanNumberOfPhotons = ScintillationYield*TotalEnergyDeposit;
316 
317  G4int NumPhotons;
318 
319  if (MeanNumberOfPhotons > 10.)
320  {
321  G4double sigma = ResolutionScale * std::sqrt(MeanNumberOfPhotons);
322  NumPhotons = G4int(G4RandGauss::shoot(MeanNumberOfPhotons,sigma)+0.5);
323  }
324  else
325  {
326  NumPhotons = G4int(G4Poisson(MeanNumberOfPhotons));
327  }
328 
329  if (NumPhotons <= 0)
330  {
331  // return unchanged particle and no secondaries
332 
334 
335  return G4VRestDiscreteProcess::PostStepDoIt(aTrack, aStep);
336  }
337 
339 
341 
343  if (aTrack.GetTrackStatus() == fAlive )
345  }
346 
348 
349  G4int materialIndex = aMaterial->GetIndex();
350 
351  // Retrieve the Scintillation Integral for this material
352  // new G4PhysicsOrderedFreeVector allocated to hold CII's
353 
354  G4int Num = NumPhotons;
355 
356  for (G4int scnt = 1; scnt <= nscnt; scnt++) {
357 
358  G4double ScintillationTime = 0.*ns;
359  G4double ScintillationRiseTime = 0.*ns;
360  G4PhysicsOrderedFreeVector* ScintillationIntegral = NULL;
361 
362  if (scnt == 1) {
363  if (nscnt == 1) {
364  if(Fast_Intensity){
365  ScintillationTime = aMaterialPropertiesTable->
366  GetConstProperty("FASTTIMECONSTANT");
367  if (fFiniteRiseTime) {
368  ScintillationRiseTime = aMaterialPropertiesTable->
369  GetConstProperty("FASTSCINTILLATIONRISETIME");
370  }
371  ScintillationIntegral =
372  (G4PhysicsOrderedFreeVector*)((*theFastIntegralTable)(materialIndex));
373  }
374  if(Slow_Intensity){
375  ScintillationTime = aMaterialPropertiesTable->
376  GetConstProperty("SLOWTIMECONSTANT");
377  if (fFiniteRiseTime) {
378  ScintillationRiseTime = aMaterialPropertiesTable->
379  GetConstProperty("SLOWSCINTILLATIONRISETIME");
380  }
381  ScintillationIntegral =
382  (G4PhysicsOrderedFreeVector*)((*theSlowIntegralTable)(materialIndex));
383  }
384  }
385  else {
386  G4double YieldRatio = aMaterialPropertiesTable->
387  GetConstProperty("YIELDRATIO");
388  if ( ExcitationRatio == 1.0 ) {
389  Num = G4int (std::min(YieldRatio,1.0) * NumPhotons);
390  }
391  else {
392  Num = G4int (std::min(ExcitationRatio,1.0) * NumPhotons);
393  }
394  ScintillationTime = aMaterialPropertiesTable->
395  GetConstProperty("FASTTIMECONSTANT");
396  if (fFiniteRiseTime) {
397  ScintillationRiseTime = aMaterialPropertiesTable->
398  GetConstProperty("FASTSCINTILLATIONRISETIME");
399  }
400  ScintillationIntegral =
401  (G4PhysicsOrderedFreeVector*)((*theFastIntegralTable)(materialIndex));
402  }
403  }
404  else {
405  Num = NumPhotons - Num;
406  ScintillationTime = aMaterialPropertiesTable->
407  GetConstProperty("SLOWTIMECONSTANT");
408  if (fFiniteRiseTime) {
409  ScintillationRiseTime = aMaterialPropertiesTable->
410  GetConstProperty("SLOWSCINTILLATIONRISETIME");
411  }
412  ScintillationIntegral =
413  (G4PhysicsOrderedFreeVector*)((*theSlowIntegralTable)(materialIndex));
414  }
415 
416  if (!ScintillationIntegral) continue;
417 
418  // Max Scintillation Integral
419 
420  G4double CIImax = ScintillationIntegral->GetMaxValue();
421 
422  for (G4int i = 0; i < Num; i++) {
423 
424  // Determine photon energy
425 
426  G4double CIIvalue = G4UniformRand()*CIImax;
427  G4double sampledEnergy =
428  ScintillationIntegral->GetEnergy(CIIvalue);
429 
430  if (verboseLevel>1) {
431  G4cout << "sampledEnergy = " << sampledEnergy << G4endl;
432  G4cout << "CIIvalue = " << CIIvalue << G4endl;
433  }
434 
435  // Generate random photon direction
436 
437  G4double cost = 1. - 2.*G4UniformRand();
438  G4double sint = std::sqrt((1.-cost)*(1.+cost));
439 
440  G4double phi = twopi*G4UniformRand();
441  G4double sinp = std::sin(phi);
442  G4double cosp = std::cos(phi);
443 
444  G4double px = sint*cosp;
445  G4double py = sint*sinp;
446  G4double pz = cost;
447 
448  // Create photon momentum direction vector
449 
450  G4ParticleMomentum photonMomentum(px, py, pz);
451 
452  // Determine polarization of new photon
453 
454  G4double sx = cost*cosp;
455  G4double sy = cost*sinp;
456  G4double sz = -sint;
457 
458  G4ThreeVector photonPolarization(sx, sy, sz);
459 
460  G4ThreeVector perp = photonMomentum.cross(photonPolarization);
461 
462  phi = twopi*G4UniformRand();
463  sinp = std::sin(phi);
464  cosp = std::cos(phi);
465 
466  photonPolarization = cosp * photonPolarization + sinp * perp;
467 
468  photonPolarization = photonPolarization.unit();
469 
470  // Generate a new photon:
471 
472  G4DynamicParticle* aScintillationPhoton =
474  photonMomentum);
475  aScintillationPhoton->SetPolarization
476  (photonPolarization.x(),
477  photonPolarization.y(),
478  photonPolarization.z());
479 
480  aScintillationPhoton->SetKineticEnergy(sampledEnergy);
481 
482  // Generate new G4Track object:
483 
484  G4double rand;
485 
486  if (aParticle->GetDefinition()->GetPDGCharge() != 0) {
487  rand = G4UniformRand();
488  } else {
489  rand = 1.0;
490  }
491 
492  G4double delta = rand * aStep.GetStepLength();
493  G4double deltaTime = delta /
494  ((pPreStepPoint->GetVelocity()+
495  pPostStepPoint->GetVelocity())/2.);
496 
497  // emission time distribution
498  if (ScintillationRiseTime==0.0) {
499  deltaTime = deltaTime -
500  ScintillationTime * std::log( G4UniformRand() );
501  } else {
502  deltaTime = deltaTime +
503  sample_time(ScintillationRiseTime, ScintillationTime);
504  }
505 
506  G4double aSecondaryTime = t0 + deltaTime;
507 
508  G4ThreeVector aSecondaryPosition =
509  x0 + rand * aStep.GetDeltaPosition();
510 
511  G4Track* aSecondaryTrack =
512  new G4Track(aScintillationPhoton,aSecondaryTime,aSecondaryPosition);
513 
514  aSecondaryTrack->SetTouchableHandle(
516  // aSecondaryTrack->SetTouchableHandle((G4VTouchable*)0);
517 
518  aSecondaryTrack->SetParentID(aTrack.GetTrackID());
519 
520  aParticleChange.AddSecondary(aSecondaryTrack);
521 
522  }
523  }
524 
525  if (verboseLevel>0) {
526  G4cout << "\n Exiting from G4Scintillation::DoIt -- NumberOfSecondaries = "
528  }
529 
530  return G4VRestDiscreteProcess::PostStepDoIt(aTrack, aStep);
531 }
532 
533 // BuildThePhysicsTable for the scintillation process
534 // --------------------------------------------------
535 //
536 
538 {
540 
541  const G4MaterialTable* theMaterialTable =
543  G4int numOfMaterials = G4Material::GetNumberOfMaterials();
544 
545  // create new physics table
546 
547  if(!theFastIntegralTable)theFastIntegralTable = new G4PhysicsTable(numOfMaterials);
548  if(!theSlowIntegralTable)theSlowIntegralTable = new G4PhysicsTable(numOfMaterials);
549 
550  // loop for materials
551 
552  for (G4int i=0 ; i < numOfMaterials; i++)
553  {
554  G4PhysicsOrderedFreeVector* aPhysicsOrderedFreeVector =
556  G4PhysicsOrderedFreeVector* bPhysicsOrderedFreeVector =
558 
559  // Retrieve vector of scintillation wavelength intensity for
560  // the material from the material's optical properties table.
561 
562  G4Material* aMaterial = (*theMaterialTable)[i];
563 
564  G4MaterialPropertiesTable* aMaterialPropertiesTable =
565  aMaterial->GetMaterialPropertiesTable();
566 
567  if (aMaterialPropertiesTable) {
568 
569  G4MaterialPropertyVector* theFastLightVector =
570  aMaterialPropertiesTable->GetProperty("FASTCOMPONENT");
571 
572  if (theFastLightVector) {
573 
574  // Retrieve the first intensity point in vector
575  // of (photon energy, intensity) pairs
576 
577  G4double currentIN = (*theFastLightVector)[0];
578 
579  if (currentIN >= 0.0) {
580 
581  // Create first (photon energy, Scintillation
582  // Integral pair
583 
584  G4double currentPM = theFastLightVector->Energy(0);
585 
586  G4double currentCII = 0.0;
587 
588  aPhysicsOrderedFreeVector->
589  InsertValues(currentPM , currentCII);
590 
591  // Set previous values to current ones prior to loop
592 
593  G4double prevPM = currentPM;
594  G4double prevCII = currentCII;
595  G4double prevIN = currentIN;
596 
597  // loop over all (photon energy, intensity)
598  // pairs stored for this material
599 
600  for (size_t ii = 1;
601  ii < theFastLightVector->GetVectorLength();
602  ++ii)
603  {
604  currentPM = theFastLightVector->Energy(ii);
605  currentIN = (*theFastLightVector)[ii];
606 
607  currentCII = 0.5 * (prevIN + currentIN);
608 
609  currentCII = prevCII +
610  (currentPM - prevPM) * currentCII;
611 
612  aPhysicsOrderedFreeVector->
613  InsertValues(currentPM, currentCII);
614 
615  prevPM = currentPM;
616  prevCII = currentCII;
617  prevIN = currentIN;
618  }
619 
620  }
621  }
622 
623  G4MaterialPropertyVector* theSlowLightVector =
624  aMaterialPropertiesTable->GetProperty("SLOWCOMPONENT");
625 
626  if (theSlowLightVector) {
627 
628  // Retrieve the first intensity point in vector
629  // of (photon energy, intensity) pairs
630 
631  G4double currentIN = (*theSlowLightVector)[0];
632 
633  if (currentIN >= 0.0) {
634 
635  // Create first (photon energy, Scintillation
636  // Integral pair
637 
638  G4double currentPM = theSlowLightVector->Energy(0);
639 
640  G4double currentCII = 0.0;
641 
642  bPhysicsOrderedFreeVector->
643  InsertValues(currentPM , currentCII);
644 
645  // Set previous values to current ones prior to loop
646 
647  G4double prevPM = currentPM;
648  G4double prevCII = currentCII;
649  G4double prevIN = currentIN;
650 
651  // loop over all (photon energy, intensity)
652  // pairs stored for this material
653 
654  for (size_t ii = 1;
655  ii < theSlowLightVector->GetVectorLength();
656  ++ii)
657  {
658  currentPM = theSlowLightVector->Energy(ii);
659  currentIN = (*theSlowLightVector)[ii];
660 
661  currentCII = 0.5 * (prevIN + currentIN);
662 
663  currentCII = prevCII +
664  (currentPM - prevPM) * currentCII;
665 
666  bPhysicsOrderedFreeVector->
667  InsertValues(currentPM, currentCII);
668 
669  prevPM = currentPM;
670  prevCII = currentCII;
671  prevIN = currentIN;
672  }
673 
674  }
675  }
676  }
677 
678  // The scintillation integral(s) for a given material
679  // will be inserted in the table(s) according to the
680  // position of the material in the material table.
681 
682  theFastIntegralTable->insertAt(i,aPhysicsOrderedFreeVector);
683  theSlowIntegralTable->insertAt(i,bPhysicsOrderedFreeVector);
684 
685  }
686 }
687 
688 // Called by the user to set the scintillation yield as a function
689 // of energy deposited by particle type
690 
692 {
693  if (emSaturation) {
694  G4Exception("G4Scintillation::SetScintillationByParticleType", "Scint02",
695  JustWarning, "Redefinition: Birks Saturation is replaced by ScintillationByParticleType!");
697  }
698  scintillationByParticleType = scintType;
699 }
700 
701 // GetMeanFreePath
702 // ---------------
703 //
704 
706  G4double ,
708 {
709  *condition = StronglyForced;
710 
711  return DBL_MAX;
712 
713 }
714 
715 // GetMeanLifeTime
716 // ---------------
717 //
718 
721 {
722  *condition = Forced;
723 
724  return DBL_MAX;
725 
726 }
727 
728 G4double G4Scintillation::sample_time(G4double tau1, G4double tau2)
729 {
730 // tau1: rise time and tau2: decay time
731 
732  while(1) {
733  // two random numbers
734  G4double ran1 = G4UniformRand();
735  G4double ran2 = G4UniformRand();
736  //
737  // exponential distribution as envelope function: very efficient
738  //
739  G4double d = (tau1+tau2)/tau2;
740  // make sure the envelope function is
741  // always larger than the bi-exponential
742  G4double t = -1.0*tau2*std::log(1-ran1);
743  G4double gg = d*single_exp(t,tau2);
744  if (ran2 <= bi_exp(t,tau1,tau2)/gg) return t;
745  }
746  return -1.0;
747 }