00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #include "G4eBremsstrahlungSpectrum.hh"
00050 #include "G4BremsstrahlungParameters.hh"
00051 #include "Randomize.hh"
00052 #include "G4SystemOfUnits.hh"
00053
00054 G4eBremsstrahlungSpectrum::G4eBremsstrahlungSpectrum(const G4DataVector& bins,
00055 const G4String& name):G4VEnergySpectrum(),
00056 lowestE(0.1*eV),
00057 xp(bins)
00058 {
00059 length = xp.size();
00060 theBRparam = new G4BremsstrahlungParameters(name,length+1);
00061
00062 verbose = 0;
00063 }
00064
00065
00066 G4eBremsstrahlungSpectrum::~G4eBremsstrahlungSpectrum()
00067 {
00068 delete theBRparam;
00069 }
00070
00071
00072 G4double G4eBremsstrahlungSpectrum::Probability(G4int Z,
00073 G4double tmin,
00074 G4double tmax,
00075 G4double e,
00076 G4int,
00077 const G4ParticleDefinition*) const
00078 {
00079 G4double tm = std::min(tmax, e);
00080 G4double t0 = std::max(tmin, lowestE);
00081 if(t0 >= tm) return 0.0;
00082
00083 t0 /= e;
00084 tm /= e;
00085
00086 G4double z0 = lowestE/e;
00087 G4DataVector p;
00088
00089
00090 for (size_t i=0; i<=length; i++) {
00091 p.push_back(theBRparam->Parameter(i, Z, e));
00092 }
00093
00094 G4double x = IntSpectrum(t0, tm, p);
00095 G4double y = IntSpectrum(z0, 1.0, p);
00096
00097
00098 if(1 < verbose) {
00099 G4cout << "tcut(MeV)= " << tmin/MeV
00100 << "; tMax(MeV)= " << tmax/MeV
00101 << "; t0= " << t0
00102 << "; tm= " << tm
00103 << "; xp[0]= " << xp[0]
00104 << "; z= " << z0
00105 << "; val= " << x
00106 << "; nor= " << y
00107 << G4endl;
00108 }
00109 p.clear();
00110
00111 if(y > 0.0) x /= y;
00112 else x = 0.0;
00113
00114
00115 return x;
00116 }
00117
00118
00119 G4double G4eBremsstrahlungSpectrum::AverageEnergy(G4int Z,
00120 G4double tmin,
00121 G4double tmax,
00122 G4double e,
00123 G4int,
00124 const G4ParticleDefinition*) const
00125 {
00126 G4double tm = std::min(tmax, e);
00127 G4double t0 = std::max(tmin, lowestE);
00128 if(t0 >= tm) return 0.0;
00129
00130 t0 /= e;
00131 tm /= e;
00132
00133 G4double z0 = lowestE/e;
00134
00135 G4DataVector p;
00136
00137
00138 for (size_t i=0; i<=length; i++) {
00139 p.push_back(theBRparam->Parameter(i, Z, e));
00140 }
00141
00142 G4double x = AverageValue(t0, tm, p);
00143 G4double y = IntSpectrum(z0, 1.0, p);
00144
00145
00146 G4double zmin = tmin/e;
00147 if(zmin < t0) {
00148 G4double c = std::sqrt(theBRparam->ParameterC(Z));
00149 x += p[0]*(t0 - zmin - c*(std::atan(t0/c) - std::atan(zmin/c)));
00150 }
00151 x *= e;
00152
00153 if(1 < verbose) {
00154 G4cout << "tcut(MeV)= " << tmin/MeV
00155 << "; tMax(MeV)= " << tmax/MeV
00156 << "; e(MeV)= " << e/MeV
00157 << "; t0= " << t0
00158 << "; tm= " << tm
00159 << "; y= " << y
00160 << "; x= " << x
00161 << G4endl;
00162 }
00163 p.clear();
00164
00165 if(y > 0.0) x /= y;
00166 else x = 0.0;
00167
00168
00169 return x;
00170 }
00171
00172
00173 G4double G4eBremsstrahlungSpectrum::SampleEnergy(G4int Z,
00174 G4double tmin,
00175 G4double tmax,
00176 G4double e,
00177 G4int,
00178 const G4ParticleDefinition*) const
00179 {
00180 G4double tm = std::min(tmax, e);
00181 G4double t0 = std::max(tmin, lowestE);
00182 if(t0 >= tm) return 0.0;
00183
00184 t0 /= e;
00185 tm /= e;
00186
00187 G4DataVector p;
00188
00189 for (size_t i=0; i<=length; i++) {
00190 p.push_back(theBRparam->Parameter(i, Z, e));
00191 }
00192 G4double amaj = std::max(p[length], 1. - (p[1] - p[0])*xp[0]/(xp[1] - xp[0]) );
00193
00194 G4double amax = std::log(tm);
00195 G4double amin = std::log(t0);
00196 G4double tgam, q, fun;
00197
00198 do {
00199 G4double x = amin + G4UniformRand()*(amax - amin);
00200 tgam = std::exp(x);
00201 fun = Function(tgam, p);
00202
00203 if(fun > amaj) {
00204 G4cout << "WARNING in G4eBremsstrahlungSpectrum::SampleEnergy:"
00205 << " Majoranta " << amaj
00206 << " < " << fun
00207 << G4endl;
00208 }
00209
00210 q = amaj * G4UniformRand();
00211 } while (q > fun);
00212
00213 tgam *= e;
00214
00215 p.clear();
00216
00217 return tgam;
00218 }
00219
00220 G4double G4eBremsstrahlungSpectrum::IntSpectrum(G4double xMin,
00221 G4double xMax,
00222 const G4DataVector& p) const
00223 {
00224 G4double x1 = std::min(xMin, xp[0]);
00225 G4double x2 = std::min(xMax, xp[0]);
00226 G4double sum = 0.0;
00227
00228 if(x1 < x2) {
00229 G4double k = (p[1] - p[0])/(xp[1] - xp[0]);
00230 sum += (1. - k*xp[0])*std::log(x2/x1) + k*(x2 - x1);
00231 }
00232
00233 for (size_t i=0; i<length-1; i++) {
00234 x1 = std::max(xMin, xp[i]);
00235 x2 = std::min(xMax, xp[i+1]);
00236 if(x1 < x2) {
00237 G4double z1 = p[i];
00238 G4double z2 = p[i+1];
00239 sum += z2 - z1 + std::log(x2/x1)*(z1*x2 - z2*x1)/(x2 - x1);
00240 }
00241 }
00242 if(sum < 0.0) sum = 0.0;
00243 return sum;
00244 }
00245
00246 G4double G4eBremsstrahlungSpectrum::AverageValue(G4double xMin,
00247 G4double xMax,
00248 const G4DataVector& p) const
00249 {
00250 G4double x1 = std::min(xMin, xp[0]);
00251 G4double x2 = std::min(xMax, xp[0]);
00252 G4double z1 = x1;
00253 G4double z2 = x2;
00254 G4double sum = 0.0;
00255
00256 if(x1 < x2) {
00257 G4double k = (p[1] - p[0])/(xp[1] - xp[0]);
00258 sum += (z2 - z1)*(1. - k*xp[0]);
00259 z1 *= x1;
00260 z2 *= x2;
00261 sum += 0.5*k*(z2 - z1);
00262 }
00263
00264 for (size_t i=0; i<length-1; i++) {
00265 x1 = std::max(xMin, xp[i]);
00266 x2 = std::min(xMax, xp[i+1]);
00267 if(x1 < x2) {
00268 z1 = p[i];
00269 z2 = p[i+1];
00270 sum += 0.5*(z2 - z1)*(x2 + x1) + z1*x2 - z2*x1;
00271 }
00272 }
00273 if(sum < 0.0) sum = 0.0;
00274 return sum;
00275 }
00276
00277 G4double G4eBremsstrahlungSpectrum::Function(G4double x,
00278 const G4DataVector& p) const
00279 {
00280 G4double f = 0.0;
00281
00282 if(x <= xp[0]) {
00283 f = p[0] + (p[1] - p[0])*(x - xp[0])/(xp[1] - xp[0]);
00284
00285 } else {
00286
00287 for (size_t i=0; i<length-1; i++) {
00288
00289 if(x <= xp[i+1]) {
00290 f = p[i] + (p[i+1] - p[i])*(x - xp[i])/(xp[i+1] - xp[i]);
00291 break;
00292 }
00293 }
00294 }
00295 return f;
00296 }
00297
00298 void G4eBremsstrahlungSpectrum::PrintData() const
00299 { theBRparam->PrintData(); }
00300
00301 G4double G4eBremsstrahlungSpectrum::Excitation(G4int , G4double ) const
00302 {
00303 return 0.0;
00304 }
00305
00306 G4double G4eBremsstrahlungSpectrum::MaxEnergyOfSecondaries(G4double kineticEnergy,
00307 G4int,
00308 const G4ParticleDefinition*) const
00309 {
00310 return kineticEnergy;
00311 }