Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // >> 26 // $Id: G4UniversalFluctuation.cc,v 1.8 2006/06/29 19:53:32 gunter Exp $ >> 27 // GEANT4 tag $Name: geant4-08-01-patch-01 $ 26 // 28 // 27 // ------------------------------------------- 29 // ------------------------------------------------------------------- 28 // 30 // 29 // GEANT4 Class file 31 // GEANT4 Class file 30 // 32 // 31 // 33 // 32 // File name: G4UniversalFluctuation 34 // File name: G4UniversalFluctuation 33 // 35 // 34 // Author: V. Ivanchenko for Laszlo Urb << 36 // Author: Vladimir Ivanchenko 35 // 37 // 36 // Creation date: 03.01.2002 38 // Creation date: 03.01.2002 37 // 39 // 38 // Modifications: 40 // Modifications: 39 // 41 // 40 // << 42 // 28-12-02 add method Dispersion (V.Ivanchenko) >> 43 // 07-02-03 change signature (V.Ivanchenko) >> 44 // 13-02-03 Add name (V.Ivanchenko) >> 45 // 16-10-03 Changed interface to Initialisation (V.Ivanchenko) >> 46 // 07-11-03 Fix problem of rounding of double in G4UniversalFluctuations >> 47 // 06-02-04 Add control on big sigma > 2*meanLoss (V.Ivanchenko) >> 48 // 26-04-04 Comment out the case of very small step (V.Ivanchenko) >> 49 // 07-02-05 define problim = 5.e-3 (mma) >> 50 // 03-05-05 conditions of Gaussian fluctuation changed (bugfix) >> 51 // + smearing for very small loss (L.Urban) >> 52 // 03-10-05 energy dependent rate -> cut dependence of the >> 53 // distribution is much weaker (L.Urban) >> 54 // 17-10-05 correction for very small loss (L.Urban) >> 55 // 41 56 42 //....oooOO0OOooo........oooOO0OOooo........oo 57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 43 //....oooOO0OOooo........oooOO0OOooo........oo 58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 44 59 45 #include "G4UniversalFluctuation.hh" 60 #include "G4UniversalFluctuation.hh" 46 #include "G4PhysicalConstants.hh" << 47 #include "G4SystemOfUnits.hh" << 48 #include "Randomize.hh" 61 #include "Randomize.hh" 49 #include "G4Poisson.hh" 62 #include "G4Poisson.hh" >> 63 #include "G4Step.hh" 50 #include "G4Material.hh" 64 #include "G4Material.hh" 51 #include "G4MaterialCutsCouple.hh" << 52 #include "G4DynamicParticle.hh" 65 #include "G4DynamicParticle.hh" 53 #include "G4ParticleDefinition.hh" 66 #include "G4ParticleDefinition.hh" 54 #include "G4Log.hh" << 55 67 56 //....oooOO0OOooo........oooOO0OOooo........oo 68 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 57 69 >> 70 using namespace std; >> 71 58 G4UniversalFluctuation::G4UniversalFluctuation 72 G4UniversalFluctuation::G4UniversalFluctuation(const G4String& nam) 59 :G4VEmFluctuationModel(nam), 73 :G4VEmFluctuationModel(nam), 60 minLoss(10.*CLHEP::eV) << 74 particle(0), >> 75 minNumberInteractionsBohr(10.0), >> 76 theBohrBeta2(50.0*keV/proton_mass_c2), >> 77 minLoss(10.*eV), >> 78 problim(5.e-3), >> 79 alim(10.), >> 80 nmaxCont1(4.), >> 81 nmaxCont2(16.) 61 { 82 { 62 rndmarray = new G4double[sizearray]; << 83 sumalim = -log(problim); >> 84 lastMaterial = 0; 63 } 85 } 64 86 65 //....oooOO0OOooo........oooOO0OOooo........oo 87 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 66 88 67 G4UniversalFluctuation::~G4UniversalFluctuatio 89 G4UniversalFluctuation::~G4UniversalFluctuation() 68 { << 90 {} 69 delete [] rndmarray; << 70 } << 71 91 72 //....oooOO0OOooo........oooOO0OOooo........oo 92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 73 93 74 void G4UniversalFluctuation::InitialiseMe(cons 94 void G4UniversalFluctuation::InitialiseMe(const G4ParticleDefinition* part) 75 { 95 { 76 particle = part; << 96 particle = part; 77 particleMass = part->GetPDGMass(); << 97 particleMass = part->GetPDGMass(); 78 const G4double q = part->GetPDGCharge()/CLHE << 98 G4double q = part->GetPDGCharge()/eplus; 79 << 99 chargeSquare = q*q; 80 // Derived quantities << 81 m_Inv_particleMass = 1.0 / particleMass; << 82 m_massrate = CLHEP::electron_mass_c2 * m_Inv << 83 chargeSquare = q*q; << 84 } 100 } 85 101 86 //....oooOO0OOooo........oooOO0OOooo........oo 102 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 87 103 88 G4double << 104 G4double G4UniversalFluctuation::SampleFluctuations(const G4Material* material, 89 G4UniversalFluctuation::SampleFluctuations(con << 105 const G4DynamicParticle* dp, 90 con << 106 G4double& tmax, 91 con << 107 G4double& length, 92 con << 108 G4double& meanLoss) 93 con << 94 con << 95 { 109 { 96 // Calculate actual loss from the mean loss. << 110 // Calculate actual loss from the mean loss. 97 // The model used to get the fluctuations is << 111 // The model used to get the fluctuations is essentially the same 98 // as in Glandz in Geant3 (Cern program libr << 112 // as in Glandz in Geant3 (Cern program library W5013, phys332). 99 // L. Urban et al. NIM A362, p.416 (1995) an << 113 // L. Urban et al. NIM A362, p.416 (1995) and Geant4 Physics Reference Manual 100 114 101 // shortcut for very small loss or from a st << 115 // shortcut for very very small loss (out of validity of the model) 102 // (out of validity of the model) << 103 // 116 // 104 if (averageLoss < minLoss) { return averageL << 117 if (meanLoss < minLoss) return meanLoss; 105 meanLoss = averageLoss; << 106 const G4double tkin = dp->GetKineticEnergy( << 107 //G4cout<< "Emean= "<< meanLoss<< " tmax= "< << 108 << 109 if(dp->GetDefinition() != particle) { Initia << 110 << 111 CLHEP::HepRandomEngine* rndmEngineF = G4Rand << 112 << 113 const G4double gam = tkin * m_Inv_particle << 114 const G4double gam2 = gam*gam; << 115 const G4double beta = dp->GetBeta(); << 116 const G4double beta2 = beta*beta; << 117 118 118 G4double loss(0.), siga(0.); << 119 if(!particle) InitialiseMe(dp->GetDefinition()); >> 120 >> 121 G4double tau = dp->GetKineticEnergy()/particleMass; >> 122 G4double gam = tau + 1.0; >> 123 G4double gam2 = gam*gam; >> 124 G4double beta2 = tau*(tau + 2.0)/gam2; 119 125 120 const G4Material* material = couple->GetMate << 126 G4double loss(0.), siga(0.); 121 127 122 // Gaussian regime 128 // Gaussian regime 123 // for heavy particles only and conditions 129 // for heavy particles only and conditions 124 // for Gauusian fluct. has been changed 130 // for Gauusian fluct. has been changed 125 // 131 // 126 if (particleMass > CLHEP::electron_mass_c2 & << 132 if ((particleMass > electron_mass_c2) && 127 meanLoss >= minNumberInteractionsBohr*tc << 133 (meanLoss >= minNumberInteractionsBohr*tmax)) 128 << 134 { 129 siga = std::sqrt((tmax/beta2 - 0.5*tcut)*C << 135 G4double massrate = electron_mass_c2/particleMass ; 130 length*chargeSquare*mate << 136 G4double tmaxkine = 2.*electron_mass_c2*beta2*gam2/ 131 const G4double sn = meanLoss/siga; << 137 (1.+massrate*(2.*gam+massrate)) ; 132 << 138 if (tmaxkine <= 2.*tmax) 133 // thick target case << 139 { 134 if (sn >= 2.0) { << 140 electronDensity = material->GetElectronDensity(); 135 << 141 siga = (1.0/beta2 - 0.5) * twopi_mc2_rcl2 * tmax * length 136 const G4double twomeanLoss = meanLoss + << 142 * electronDensity * chargeSquare; 137 do { << 143 siga = sqrt(siga); 138 loss = G4RandGauss::shoot(rndmEngineF, meanL << 144 G4double twomeanLoss = meanLoss + meanLoss; 139 // Loop checking, 03-Aug-2015, Vladimir Ivan << 145 if (twomeanLoss < siga) { 140 } while (0.0 > loss || twomeanLoss < lo << 146 G4double x; 141 << 147 do { 142 // Gamma distribution << 148 loss = twomeanLoss*G4UniformRand(); 143 } else { << 149 x = (loss - meanLoss)/siga; 144 << 150 } while (1.0 - 0.5*x*x < G4UniformRand()); 145 const G4double neff = sn*sn; << 151 } else { 146 loss = meanLoss*G4RandGamma::shoot(rndmE << 152 do { >> 153 loss = G4RandGauss::shoot(meanLoss,siga); >> 154 } while (loss < 0. || loss > twomeanLoss); >> 155 } >> 156 return loss; 147 } 157 } 148 //G4cout << "Gauss: " << loss << G4endl; << 149 return loss; << 150 } 158 } 151 159 152 auto ioni = material->GetIonisation(); << 160 // Glandz regime : initialisation 153 e0 = ioni->GetEnergy0fluct(); << 161 // 154 << 162 if (material != lastMaterial) { 155 // very small step or low-density material << 163 f1Fluct = material->GetIonisation()->GetF1fluct(); 156 if(tcut <= e0) { return meanLoss; } << 164 f2Fluct = material->GetIonisation()->GetF2fluct(); 157 << 165 e1Fluct = material->GetIonisation()->GetEnergy1fluct(); 158 ipotFluct = ioni->GetMeanExcitationEnergy(); << 166 e2Fluct = material->GetIonisation()->GetEnergy2fluct(); 159 ipotLogFluct = ioni->GetLogMeanExcEnergy(); << 167 e1LogFluct = material->GetIonisation()->GetLogEnergy1fluct(); >> 168 e2LogFluct = material->GetIonisation()->GetLogEnergy2fluct(); >> 169 ipotFluct = material->GetIonisation()->GetMeanExcitationEnergy(); >> 170 ipotLogFluct = material->GetIonisation()->GetLogMeanExcEnergy(); >> 171 lastMaterial = material; >> 172 } 160 173 161 // width correction for small cuts << 174 G4double a1 = 0. , a2 = 0., a3 = 0. ; 162 const G4double scaling = std::min(1.+0.5*CLH << 175 G4double p1,p2,p3; 163 meanLoss /= scaling; << 176 // cut and material dependent rate -------------------------------- 164 << 177 G4double rate = 0.173+0.027*log(tmax/ipotFluct) ; 165 w2 = (tcut > ipotFluct) ? << 178 if(rate < 0.) rate = 0. ; 166 G4Log(2.*CLHEP::electron_mass_c2*beta2*gam << 179 if(rate > 1.) rate = 1. ; 167 return SampleGlandz(rndmEngineF, material, t << 180 168 } << 181 G4double w1 = tmax/ipotFluct; >> 182 G4double w2 = log(2.*electron_mass_c2*beta2*gam2)-beta2; >> 183 >> 184 if(w2 > ipotLogFluct) >> 185 { >> 186 G4double C = meanLoss*(1.-rate)/(w2-ipotLogFluct); >> 187 a1 = C*f1Fluct*(w2-e1LogFluct)/e1Fluct; >> 188 a2 = C*f2Fluct*(w2-e2LogFluct)/e2Fluct; >> 189 if(a2 < 0.) >> 190 { >> 191 a1 = 0. ; >> 192 a2 = 0. ; >> 193 rate = 1. ; >> 194 } >> 195 } >> 196 else >> 197 { >> 198 rate = 1. ; >> 199 } 169 200 170 //....oooOO0OOooo........oooOO0OOooo........oo << 201 if(tmax > ipotFluct) >> 202 a3 = rate*meanLoss*(tmax-ipotFluct)/(ipotFluct*tmax*log(w1)); 171 203 172 G4double << 204 G4double suma = a1+a2+a3; 173 G4UniversalFluctuation::SampleGlandz(CLHEP::He << 174 const G4M << 175 const G4d << 176 { << 177 G4double a1(0.0), a3(0.0); << 178 G4double loss = 0.0; << 179 G4double e1 = ipotFluct; << 180 << 181 if(tcut > e1) { << 182 a1 = meanLoss*(1.-rate)/e1; << 183 if(a1 < a0) { << 184 const G4double fwnow = 0.1+(fw-0.1)*std: << 185 a1 /= fwnow; << 186 e1 *= fwnow; << 187 } else { << 188 a1 /= fw; << 189 e1 *= fw; << 190 } << 191 } << 192 << 193 const G4double w1 = tcut/e0; << 194 a3 = rate*meanLoss*(tcut - e0)/(e0*tcut*G4Lo << 195 if(a1 <= 0.) { a3 /= rate; } << 196 205 197 //'nearly' Gaussian fluctuation if a1>nmaxCo << 206 // Glandz regime 198 G4double emean = 0.; << 207 // 199 G4double sig2e = 0.; << 208 if (suma > sumalim) 200 << 209 { 201 // excitation of type 1 << 210 p1 = 0., p2 = 0 ; 202 if(a1 > 0.0) { AddExcitation(rndmEngineF, a1 << 211 if((a1+a2) > 0.) 203 << 212 { 204 if(sig2e > 0.0) { SampleGauss(rndmEngineF, e << 213 // excitation type 1 205 << 214 if (a1>alim) { 206 // ionisation << 215 siga=sqrt(a1) ; 207 if(a3 > 0.) { << 216 p1 = max(0.,G4RandGauss::shoot(a1,siga)+0.5); 208 emean = 0.; << 217 } else { 209 sig2e = 0.; << 218 p1 = G4double(G4Poisson(a1)); 210 G4double p3 = a3; << 219 } 211 G4double alfa = 1.; << 220 212 if(a3 > nmaxCont) { << 221 // excitation type 2 213 alfa = w1*(nmaxCont+a3)/(w1*nmaxCont+a3) << 222 if (a2>alim) { 214 const G4double alfa1 = alfa*G4Log(alfa) << 223 siga=sqrt(a2) ; 215 const G4double namean = a3*w1*(alfa-1.)/ << 224 p2 = max(0.,G4RandGauss::shoot(a2,siga)+0.5); 216 emean += namean*e0*alfa1; << 225 } else { 217 sig2e += e0*e0*namean*(alfa-alfa1*alfa1) << 226 p2 = G4double(G4Poisson(a2)); 218 p3 = a3 - namean; << 227 } >> 228 >> 229 loss = p1*e1Fluct+p2*e2Fluct; >> 230 >> 231 // smearing to avoid unphysical peaks >> 232 if (p2 > 0.) >> 233 loss += (1.-2.*G4UniformRand())*e2Fluct; >> 234 else if (loss>0.) >> 235 loss += (1.-2.*G4UniformRand())*e1Fluct; >> 236 if (loss < 0.) loss = 0.0; 219 } 237 } 220 238 221 const G4double w3 = alfa*e0; << 239 // ionisation 222 if(tcut > w3) { << 240 if (a3 > 0.) { 223 const G4double w = (tcut-w3)/tcut; << 241 if (a3>alim) { 224 const G4int nnb = (G4int)G4Poisson(p3); << 242 siga=sqrt(a3) ; 225 if(nnb > 0) { << 243 p3 = max(0.,G4RandGauss::shoot(a3,siga)+0.5); 226 if(nnb > sizearray) { << 244 } else { 227 sizearray = nnb; << 245 p3 = G4double(G4Poisson(a3)); 228 delete [] rndmarray; << 229 rndmarray = new G4double[nnb]; << 230 } << 231 rndmEngineF->flatArray(nnb, rndmarray) << 232 for (G4int k=0; k<nnb; ++k) { loss += << 233 } 246 } >> 247 G4double lossc = 0.; >> 248 if (p3 > 0) { >> 249 G4double na = 0.; >> 250 G4double alfa = 1.; >> 251 if (p3 > nmaxCont2) { >> 252 G4double rfac = p3/(nmaxCont2+p3); >> 253 G4double namean = p3*rfac; >> 254 G4double sa = nmaxCont1*rfac; >> 255 na = G4RandGauss::shoot(namean,sa); >> 256 if (na > 0.) { >> 257 alfa = w1*(nmaxCont2+p3)/(w1*nmaxCont2+p3); >> 258 G4double alfa1 = alfa*log(alfa)/(alfa-1.); >> 259 G4double ea = na*ipotFluct*alfa1; >> 260 G4double sea = ipotFluct*sqrt(na*(alfa-alfa1*alfa1)); >> 261 lossc += G4RandGauss::shoot(ea,sea); >> 262 } >> 263 } >> 264 >> 265 if (p3 > na) { >> 266 w2 = alfa*ipotFluct; >> 267 G4double w = (tmax-w2)/tmax; >> 268 G4int nb = G4int(p3-na); >> 269 for (G4int k=0; k<nb; k++) lossc += w2/(1.-w*G4UniformRand()); >> 270 } >> 271 } >> 272 loss += lossc; 234 } 273 } 235 if(sig2e > 0.0) { SampleGauss(rndmEngineF, << 274 return loss; 236 } 275 } 237 //G4cout << "### loss=" << loss << G4endl; << 276 238 return loss; << 277 // suma < sumalim; very small energy loss; >> 278 // >> 279 G4double e0 = material->GetIonisation()->GetEnergy0fluct(); >> 280 >> 281 if(tmax <= e0) return meanLoss; >> 282 else a3 = meanLoss*(tmax-e0)/(tmax*e0*log(tmax/e0)); >> 283 >> 284 if (a3 > alim) >> 285 { >> 286 siga=sqrt(a3); >> 287 p3 = max(0.,G4RandGauss::shoot(a3,siga)+0.5); >> 288 } else { >> 289 p3 = G4double(G4Poisson(a3)); >> 290 } >> 291 if (p3 > 0.) { >> 292 G4double w = (tmax-e0)/tmax; >> 293 G4double corrfac = 1.; >> 294 if (p3 > nmaxCont2) { >> 295 corrfac = p3/nmaxCont2; >> 296 p3 = nmaxCont2; >> 297 } >> 298 G4int ip3 = (G4int)p3; >> 299 for (G4int i=0; i<ip3; i++) loss += 1./(1.-w*G4UniformRand()); >> 300 loss *= e0*corrfac; >> 301 // smearing for losses near to e0 >> 302 if(p3 <= 2.) >> 303 loss += e0*(1.-2.*G4UniformRand()) ; >> 304 } >> 305 >> 306 return loss; 239 } 307 } 240 308 241 //....oooOO0OOooo........oooOO0OOooo........oo 309 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 242 310 243 311 244 G4double G4UniversalFluctuation::Dispersion( 312 G4double G4UniversalFluctuation::Dispersion( 245 const G4Material* ma 313 const G4Material* material, 246 const G4DynamicParti 314 const G4DynamicParticle* dp, 247 const G4double tcut, << 315 G4double& tmax, 248 const G4double tmax, << 316 G4double& length) 249 const G4double lengt << 250 { 317 { 251 if(dp->GetDefinition() != particle) { Initia << 318 if(!particle) InitialiseMe(dp->GetDefinition()); 252 const G4double beta = dp->GetBeta(); << 253 return (tmax/(beta*beta) - 0.5*tcut) * CLHEP << 254 * material->GetElectronDensity() * chargeS << 255 } << 256 319 257 //....oooOO0OOooo........oooOO0OOooo........oo << 320 electronDensity = material->GetElectronDensity(); 258 321 259 void << 322 G4double gam = (dp->GetKineticEnergy())/particleMass + 1.0; 260 G4UniversalFluctuation::SetParticleAndCharge(c << 323 G4double beta2 = 1.0 - 1.0/(gam*gam); 261 G << 324 262 { << 325 G4double siga = (1.0/beta2 - 0.5) * twopi_mc2_rcl2 * tmax * length 263 if(part != particle) { << 326 * electronDensity * chargeSquare; 264 particle = part; << 327 265 particleMass = part->GetPDGMass(); << 328 return siga; 266 << 267 // Derived quantities << 268 m_Inv_particleMass = 1.0 / particleMass; << 269 m_massrate = CLHEP::electron_mass_c2 * m_I << 270 } << 271 chargeSquare = q2; << 272 } 329 } 273 330 274 //....oooOO0OOooo........oooOO0OOooo........oo 331 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 275 332