G4eBremsstrahlungSpectrum.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id$
00027 //
00028 // -------------------------------------------------------------------
00029 //
00030 // GEANT4 Class file
00031 //
00032 //
00033 // File name:     G4eBremsstrahlungSpectrum
00034 //
00035 // Author:        V.Ivanchenko (Vladimir.Ivanchenko@cern.ch)
00036 //
00037 // Creation date: 29 September 2001
00038 //
00039 // Modifications:
00040 // 10.10.01  MGP  Revision to improve code quality and consistency with design
00041 // 15.11.01  VI   Update spectrum model Bethe-Haitler spectrum at high energy
00042 // 30.05.02  VI   Update interpolation between 2 last energy points in the
00043 //                parametrisation
00044 // 21.02.03  V.Ivanchenko    Energy bins are defined in the constructor
00045 // 28.02.03  V.Ivanchenko    Filename is defined in the constructor
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   // Access parameters
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   //  if(x < 0.0) x  = 0.0;
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   // Access parameters
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   // Add integrant over lowest energies
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   //  if(x < 0.0) x  = 0.0;
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, // Z,
00308                                                            const G4ParticleDefinition*) const
00309 {
00310   return kineticEnergy;
00311 }

Generated on Mon May 27 17:48:05 2013 for Geant4 by  doxygen 1.4.7