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$ >> 27 // GEANT4 tag $Name: geant4-09-01-ref-00 $ 26 // 28 // 27 // ------------------------------------------- 29 // ------------------------------------------------------------------- 28 // 30 // 29 // GEANT4 Class file 31 // GEANT4 Class file 30 // 32 // 31 // 33 // 32 // File name: G4RDeBremsstrahlungSpectrum 34 // File name: G4RDeBremsstrahlungSpectrum 33 // 35 // 34 // Author: V.Ivanchenko (Vladimir.Ivanc 36 // Author: V.Ivanchenko (Vladimir.Ivanchenko@cern.ch) 35 // 37 // 36 // Creation date: 29 September 2001 38 // Creation date: 29 September 2001 37 // 39 // 38 // Modifications: 40 // Modifications: 39 // 10.10.01 MGP Revision to improve code qua 41 // 10.10.01 MGP Revision to improve code quality and consistency with design 40 // 15.11.01 VI Update spectrum model Bethe- 42 // 15.11.01 VI Update spectrum model Bethe-Haitler spectrum at high energy 41 // 30.05.02 VI Update interpolation between 43 // 30.05.02 VI Update interpolation between 2 last energy points in the 42 // parametrisation 44 // parametrisation 43 // 21.02.03 V.Ivanchenko Energy bins are d 45 // 21.02.03 V.Ivanchenko Energy bins are defined in the constructor 44 // 28.02.03 V.Ivanchenko Filename is defin 46 // 28.02.03 V.Ivanchenko Filename is defined in the constructor 45 // 47 // 46 // ------------------------------------------- 48 // ------------------------------------------------------------------- 47 49 48 #include "G4RDeBremsstrahlungSpectrum.hh" 50 #include "G4RDeBremsstrahlungSpectrum.hh" 49 #include "G4RDBremsstrahlungParameters.hh" 51 #include "G4RDBremsstrahlungParameters.hh" 50 #include "Randomize.hh" 52 #include "Randomize.hh" 51 #include "G4SystemOfUnits.hh" 53 #include "G4SystemOfUnits.hh" 52 54 53 55 54 G4RDeBremsstrahlungSpectrum::G4RDeBremsstrahlu 56 G4RDeBremsstrahlungSpectrum::G4RDeBremsstrahlungSpectrum(const G4DataVector& bins, 55 const G4String& name):G4RDVEnergySpectrum(), 57 const G4String& name):G4RDVEnergySpectrum(), 56 lowestE(0.1*eV), 58 lowestE(0.1*eV), 57 xp(bins) 59 xp(bins) 58 { 60 { 59 length = xp.size(); 61 length = xp.size(); 60 theBRparam = new G4RDBremsstrahlungParameter 62 theBRparam = new G4RDBremsstrahlungParameters(name,length+1); 61 63 62 verbose = 0; 64 verbose = 0; 63 } 65 } 64 66 65 67 66 G4RDeBremsstrahlungSpectrum::~G4RDeBremsstrahl 68 G4RDeBremsstrahlungSpectrum::~G4RDeBremsstrahlungSpectrum() 67 { 69 { 68 delete theBRparam; 70 delete theBRparam; 69 } 71 } 70 72 71 73 72 G4double G4RDeBremsstrahlungSpectrum::Probabil 74 G4double G4RDeBremsstrahlungSpectrum::Probability(G4int Z, 73 75 G4double tmin, 74 76 G4double tmax, 75 77 G4double e, 76 78 G4int, 77 const G 79 const G4ParticleDefinition*) const 78 { 80 { 79 G4double tm = std::min(tmax, e); 81 G4double tm = std::min(tmax, e); 80 G4double t0 = std::max(tmin, lowestE); 82 G4double t0 = std::max(tmin, lowestE); 81 if(t0 >= tm) return 0.0; 83 if(t0 >= tm) return 0.0; 82 84 83 t0 /= e; 85 t0 /= e; 84 tm /= e; 86 tm /= e; 85 87 86 G4double z0 = lowestE/e; 88 G4double z0 = lowestE/e; 87 G4DataVector p; 89 G4DataVector p; 88 90 89 // Access parameters 91 // Access parameters 90 for (size_t i=0; i<=length; i++) { 92 for (size_t i=0; i<=length; i++) { 91 p.push_back(theBRparam->Parameter(i, Z, e) 93 p.push_back(theBRparam->Parameter(i, Z, e)); 92 } 94 } 93 95 94 G4double x = IntSpectrum(t0, tm, p); 96 G4double x = IntSpectrum(t0, tm, p); 95 G4double y = IntSpectrum(z0, 1.0, p); 97 G4double y = IntSpectrum(z0, 1.0, p); 96 98 97 99 98 if(1 < verbose) { 100 if(1 < verbose) { 99 G4cout << "tcut(MeV)= " << tmin/MeV 101 G4cout << "tcut(MeV)= " << tmin/MeV 100 << "; tMax(MeV)= " << tmax/MeV 102 << "; tMax(MeV)= " << tmax/MeV 101 << "; t0= " << t0 103 << "; t0= " << t0 102 << "; tm= " << tm 104 << "; tm= " << tm 103 << "; xp[0]= " << xp[0] 105 << "; xp[0]= " << xp[0] 104 << "; z= " << z0 106 << "; z= " << z0 105 << "; val= " << x 107 << "; val= " << x 106 << "; nor= " << y 108 << "; nor= " << y 107 << G4endl; 109 << G4endl; 108 } 110 } 109 p.clear(); 111 p.clear(); 110 112 111 if(y > 0.0) x /= y; 113 if(y > 0.0) x /= y; 112 else x = 0.0; 114 else x = 0.0; 113 // if(x < 0.0) x = 0.0; 115 // if(x < 0.0) x = 0.0; 114 116 115 return x; 117 return x; 116 } 118 } 117 119 118 120 119 G4double G4RDeBremsstrahlungSpectrum::AverageE 121 G4double G4RDeBremsstrahlungSpectrum::AverageEnergy(G4int Z, 120 122 G4double tmin, 121 123 G4double tmax, 122 124 G4double e, 123 125 G4int, 124 const G4ParticleDefinition*) con 126 const G4ParticleDefinition*) const 125 { 127 { 126 G4double tm = std::min(tmax, e); 128 G4double tm = std::min(tmax, e); 127 G4double t0 = std::max(tmin, lowestE); 129 G4double t0 = std::max(tmin, lowestE); 128 if(t0 >= tm) return 0.0; 130 if(t0 >= tm) return 0.0; 129 131 130 t0 /= e; 132 t0 /= e; 131 tm /= e; 133 tm /= e; 132 134 133 G4double z0 = lowestE/e; 135 G4double z0 = lowestE/e; 134 136 135 G4DataVector p; 137 G4DataVector p; 136 138 137 // Access parameters 139 // Access parameters 138 for (size_t i=0; i<=length; i++) { 140 for (size_t i=0; i<=length; i++) { 139 p.push_back(theBRparam->Parameter(i, Z, 141 p.push_back(theBRparam->Parameter(i, Z, e)); 140 } 142 } 141 143 142 G4double x = AverageValue(t0, tm, p); 144 G4double x = AverageValue(t0, tm, p); 143 G4double y = IntSpectrum(z0, 1.0, p); 145 G4double y = IntSpectrum(z0, 1.0, p); 144 146 145 // Add integrant over lowest energies 147 // Add integrant over lowest energies 146 G4double zmin = tmin/e; 148 G4double zmin = tmin/e; 147 if(zmin < t0) { 149 if(zmin < t0) { 148 G4double c = std::sqrt(theBRparam->Parame 150 G4double c = std::sqrt(theBRparam->ParameterC(Z)); 149 x += p[0]*(t0 - zmin - c*(std::atan(t0/c) 151 x += p[0]*(t0 - zmin - c*(std::atan(t0/c) - std::atan(zmin/c))); 150 } 152 } 151 x *= e; 153 x *= e; 152 154 153 if(1 < verbose) { 155 if(1 < verbose) { 154 G4cout << "tcut(MeV)= " << tmin/MeV 156 G4cout << "tcut(MeV)= " << tmin/MeV 155 << "; tMax(MeV)= " << tmax/MeV 157 << "; tMax(MeV)= " << tmax/MeV 156 << "; e(MeV)= " << e/MeV 158 << "; e(MeV)= " << e/MeV 157 << "; t0= " << t0 159 << "; t0= " << t0 158 << "; tm= " << tm 160 << "; tm= " << tm 159 << "; y= " << y 161 << "; y= " << y 160 << "; x= " << x 162 << "; x= " << x 161 << G4endl; 163 << G4endl; 162 } 164 } 163 p.clear(); 165 p.clear(); 164 166 165 if(y > 0.0) x /= y; 167 if(y > 0.0) x /= y; 166 else x = 0.0; 168 else x = 0.0; 167 // if(x < 0.0) x = 0.0; 169 // if(x < 0.0) x = 0.0; 168 170 169 return x; 171 return x; 170 } 172 } 171 173 172 174 173 G4double G4RDeBremsstrahlungSpectrum::SampleEn 175 G4double G4RDeBremsstrahlungSpectrum::SampleEnergy(G4int Z, 174 176 G4double tmin, 175 177 G4double tmax, 176 178 G4double e, 177 179 G4int, 178 const G4ParticleDefinition*) cons 180 const G4ParticleDefinition*) const 179 { 181 { 180 G4double tm = std::min(tmax, e); 182 G4double tm = std::min(tmax, e); 181 G4double t0 = std::max(tmin, lowestE); 183 G4double t0 = std::max(tmin, lowestE); 182 if(t0 >= tm) return 0.0; 184 if(t0 >= tm) return 0.0; 183 185 184 t0 /= e; 186 t0 /= e; 185 tm /= e; 187 tm /= e; 186 188 187 G4DataVector p; 189 G4DataVector p; 188 190 189 for (size_t i=0; i<=length; i++) { 191 for (size_t i=0; i<=length; i++) { 190 p.push_back(theBRparam->Parameter(i, Z, e) 192 p.push_back(theBRparam->Parameter(i, Z, e)); 191 } 193 } 192 G4double amaj = std::max(p[length], 1. - (p[ 194 G4double amaj = std::max(p[length], 1. - (p[1] - p[0])*xp[0]/(xp[1] - xp[0]) ); 193 195 194 G4double amax = std::log(tm); 196 G4double amax = std::log(tm); 195 G4double amin = std::log(t0); 197 G4double amin = std::log(t0); 196 G4double tgam, q, fun; 198 G4double tgam, q, fun; 197 199 198 do { 200 do { 199 G4double x = amin + G4UniformRand()*(amax 201 G4double x = amin + G4UniformRand()*(amax - amin); 200 tgam = std::exp(x); 202 tgam = std::exp(x); 201 fun = Function(tgam, p); 203 fun = Function(tgam, p); 202 204 203 if(fun > amaj) { 205 if(fun > amaj) { 204 G4cout << "WARNING in G4RDeBremsstra 206 G4cout << "WARNING in G4RDeBremsstrahlungSpectrum::SampleEnergy:" 205 << " Majoranta " << amaj 207 << " Majoranta " << amaj 206 << " < " << fun 208 << " < " << fun 207 << G4endl; 209 << G4endl; 208 } 210 } 209 211 210 q = amaj * G4UniformRand(); 212 q = amaj * G4UniformRand(); 211 } while (q > fun); 213 } while (q > fun); 212 214 213 tgam *= e; 215 tgam *= e; 214 216 215 p.clear(); 217 p.clear(); 216 218 217 return tgam; 219 return tgam; 218 } 220 } 219 221 220 G4double G4RDeBremsstrahlungSpectrum::IntSpect 222 G4double G4RDeBremsstrahlungSpectrum::IntSpectrum(G4double xMin, 221 223 G4double xMax, 222 const G4DataVector& p) const 224 const G4DataVector& p) const 223 { 225 { 224 G4double x1 = std::min(xMin, xp[0]); 226 G4double x1 = std::min(xMin, xp[0]); 225 G4double x2 = std::min(xMax, xp[0]); 227 G4double x2 = std::min(xMax, xp[0]); 226 G4double sum = 0.0; 228 G4double sum = 0.0; 227 229 228 if(x1 < x2) { 230 if(x1 < x2) { 229 G4double k = (p[1] - p[0])/(xp[1] - xp[0]) 231 G4double k = (p[1] - p[0])/(xp[1] - xp[0]); 230 sum += (1. - k*xp[0])*std::log(x2/x1) + k* 232 sum += (1. - k*xp[0])*std::log(x2/x1) + k*(x2 - x1); 231 } 233 } 232 234 233 for (size_t i=0; i<length-1; i++) { 235 for (size_t i=0; i<length-1; i++) { 234 x1 = std::max(xMin, xp[i]); 236 x1 = std::max(xMin, xp[i]); 235 x2 = std::min(xMax, xp[i+1]); 237 x2 = std::min(xMax, xp[i+1]); 236 if(x1 < x2) { 238 if(x1 < x2) { 237 G4double z1 = p[i]; 239 G4double z1 = p[i]; 238 G4double z2 = p[i+1]; 240 G4double z2 = p[i+1]; 239 sum += z2 - z1 + std::log(x2/x1)*(z1*x2 241 sum += z2 - z1 + std::log(x2/x1)*(z1*x2 - z2*x1)/(x2 - x1); 240 } 242 } 241 } 243 } 242 if(sum < 0.0) sum = 0.0; 244 if(sum < 0.0) sum = 0.0; 243 return sum; 245 return sum; 244 } 246 } 245 247 246 G4double G4RDeBremsstrahlungSpectrum::AverageV 248 G4double G4RDeBremsstrahlungSpectrum::AverageValue(G4double xMin, 247 249 G4double xMax, 248 const G4DataVector& p) const 250 const G4DataVector& p) const 249 { 251 { 250 G4double x1 = std::min(xMin, xp[0]); 252 G4double x1 = std::min(xMin, xp[0]); 251 G4double x2 = std::min(xMax, xp[0]); 253 G4double x2 = std::min(xMax, xp[0]); 252 G4double z1 = x1; 254 G4double z1 = x1; 253 G4double z2 = x2; 255 G4double z2 = x2; 254 G4double sum = 0.0; 256 G4double sum = 0.0; 255 257 256 if(x1 < x2) { 258 if(x1 < x2) { 257 G4double k = (p[1] - p[0])/(xp[1] - xp[0]) 259 G4double k = (p[1] - p[0])/(xp[1] - xp[0]); 258 sum += (z2 - z1)*(1. - k*xp[0]); 260 sum += (z2 - z1)*(1. - k*xp[0]); 259 z1 *= x1; 261 z1 *= x1; 260 z2 *= x2; 262 z2 *= x2; 261 sum += 0.5*k*(z2 - z1); 263 sum += 0.5*k*(z2 - z1); 262 } 264 } 263 265 264 for (size_t i=0; i<length-1; i++) { 266 for (size_t i=0; i<length-1; i++) { 265 x1 = std::max(xMin, xp[i]); 267 x1 = std::max(xMin, xp[i]); 266 x2 = std::min(xMax, xp[i+1]); 268 x2 = std::min(xMax, xp[i+1]); 267 if(x1 < x2) { 269 if(x1 < x2) { 268 z1 = p[i]; 270 z1 = p[i]; 269 z2 = p[i+1]; 271 z2 = p[i+1]; 270 sum += 0.5*(z2 - z1)*(x2 + x1) + z1*x2 - 272 sum += 0.5*(z2 - z1)*(x2 + x1) + z1*x2 - z2*x1; 271 } 273 } 272 } 274 } 273 if(sum < 0.0) sum = 0.0; 275 if(sum < 0.0) sum = 0.0; 274 return sum; 276 return sum; 275 } 277 } 276 278 277 G4double G4RDeBremsstrahlungSpectrum::Function 279 G4double G4RDeBremsstrahlungSpectrum::Function(G4double x, 278 const G4DataVector& p) const 280 const G4DataVector& p) const 279 { 281 { 280 G4double f = 0.0; 282 G4double f = 0.0; 281 283 282 if(x <= xp[0]) { 284 if(x <= xp[0]) { 283 f = p[0] + (p[1] - p[0])*(x - xp[0])/(xp[1 285 f = p[0] + (p[1] - p[0])*(x - xp[0])/(xp[1] - xp[0]); 284 286 285 } else { 287 } else { 286 288 287 for (size_t i=0; i<length-1; i++) { 289 for (size_t i=0; i<length-1; i++) { 288 290 289 if(x <= xp[i+1]) { 291 if(x <= xp[i+1]) { 290 f = p[i] + (p[i+1] - p[i])*(x - xp[i]) 292 f = p[i] + (p[i+1] - p[i])*(x - xp[i])/(xp[i+1] - xp[i]); 291 break; 293 break; 292 } 294 } 293 } 295 } 294 } 296 } 295 return f; 297 return f; 296 } 298 } 297 299 298 void G4RDeBremsstrahlungSpectrum::PrintData() 300 void G4RDeBremsstrahlungSpectrum::PrintData() const 299 { theBRparam->PrintData(); } 301 { theBRparam->PrintData(); } 300 302 301 G4double G4RDeBremsstrahlungSpectrum::Excitati 303 G4double G4RDeBremsstrahlungSpectrum::Excitation(G4int , G4double ) const 302 { 304 { 303 return 0.0; 305 return 0.0; 304 } 306 } 305 307 306 G4double G4RDeBremsstrahlungSpectrum::MaxEnerg 308 G4double G4RDeBremsstrahlungSpectrum::MaxEnergyOfSecondaries(G4double kineticEnergy, 307 G4int, // Z, 309 G4int, // Z, 308 const G4ParticleDefinition*) 310 const G4ParticleDefinition*) const 309 { 311 { 310 return kineticEnergy; 312 return kineticEnergy; 311 } 313 } 312 314