Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions
G4PenelopeBremsstrahlungFS Class Reference

#include <G4PenelopeBremsstrahlungFS.hh>

Public Member Functions

 G4PenelopeBremsstrahlungFS (G4int verbosity=0)
 Only master models are supposed to create instances. More...
 
 ~G4PenelopeBremsstrahlungFS ()
 
G4double GetEffectiveZSquared (const G4Material *mat) const
 
size_t GetNBinsX () const
 
G4double GetMomentumIntegral (G4double *y, G4double up, G4int momOrder) const
 
const G4PhysicsTableGetScaledXSTable (const G4Material *, const G4double cut) const
 
G4double SampleGammaEnergy (G4double energy, const G4Material *, const G4double cut) const
 
void ClearTables (G4bool isMaster=true)
 Reserved for the master model: they build and handle tables. More...
 
void BuildScaledXSTable (const G4Material *material, G4double cut, G4bool isMaster)
 
void SetVerbosity (G4int ver)
 
G4int GetVerbosity ()
 

Detailed Description

Definition at line 61 of file G4PenelopeBremsstrahlungFS.hh.

Constructor & Destructor Documentation

G4PenelopeBremsstrahlungFS::G4PenelopeBremsstrahlungFS ( G4int  verbosity = 0)

Only master models are supposed to create instances.

Definition at line 51 of file G4PenelopeBremsstrahlungFS.cc.

References G4Cache< VALTYPE >::Put().

51  :
52  theReducedXSTable(0),theEffectiveZSq(0),theSamplingTable(0),
53  thePBcut(0),fVerbosity(verbosity)
54 {
55  fCache.Put(0);
56  G4double tempvector[nBinsX] =
57  {1.0e-12,0.025e0,0.05e0,0.075e0,0.1e0,0.15e0,0.2e0,0.25e0,
58  0.3e0,0.35e0,0.4e0,0.45e0,0.5e0,0.55e0,0.6e0,0.65e0,0.7e0,
59  0.75e0,0.8e0,0.85e0,0.9e0,0.925e0,0.95e0,0.97e0,0.99e0,
60  0.995e0,0.999e0,0.9995e0,0.9999e0,0.99995e0,0.99999e0,1.0e0};
61 
62  for (size_t ix=0;ix<nBinsX;ix++)
63  theXGrid[ix] = tempvector[ix];
64 
65  for (size_t i=0;i<nBinsE;i++)
66  theEGrid[i] = 0.;
67 
68  theElementData = new std::map<G4int,G4DataVector*>;
69 }
double G4double
Definition: G4Types.hh:76
void Put(const value_type &val) const
Definition: G4Cache.hh:257
G4PenelopeBremsstrahlungFS::~G4PenelopeBremsstrahlungFS ( )

Definition at line 73 of file G4PenelopeBremsstrahlungFS.cc.

References ClearTables().

74 {
75  ClearTables();
76 
77  //The G4Physics*Vector pointers contained in the fCache are automatically deleted by
78  //the G4Allocator, so there is no need to take care of them manually
79 
80  //Clear manually theElementData
81  if (theElementData)
82  {
83  std::map<G4int,G4DataVector*>::iterator i;
84  for (i=theElementData->begin(); i != theElementData->end(); i++)
85  delete i->second;
86  delete theElementData;
87  theElementData = 0;
88  }
89 
90 }
void ClearTables(G4bool isMaster=true)
Reserved for the master model: they build and handle tables.

Member Function Documentation

void G4PenelopeBremsstrahlungFS::BuildScaledXSTable ( const G4Material material,
G4double  cut,
G4bool  isMaster 
)

Definition at line 177 of file G4PenelopeBremsstrahlungFS.cc.

References python.hepunit::barn, python.hepunit::classic_electr_radius, python.hepunit::electron_mass_c2, G4PhysicsVector::Energy(), python.hepunit::eV, FatalException, python.hepunit::fine_structure_const, g(), G4cout, G4endl, G4Exception(), G4Material::GetElementVector(), G4Material::GetFractionVector(), GetMomentumIntegral(), G4Material::GetName(), G4Material::GetNumberOfElements(), python.hepunit::keV, python.hepunit::millibarn, python.hepunit::mole, G4PhysicsTable::push_back(), and G4PhysicsFreeVector::PutValue().

Referenced by G4PenelopeBremsstrahlungModel::Initialise().

179 {
180  //Corresponds to subroutines EBRaW and EBRaR of PENELOPE
181  /*
182  This method generates the table of the scaled energy-loss cross section from
183  bremsstrahlung emission for the given material. Original data are read from
184  file. The table is normalized according to the Berger-Seltzer cross section.
185  */
186 
187  //Just to check
188  if (!isMaster)
189  G4Exception("G4PenelopeBremsstrahlungFS::BuildScaledXSTable()",
190  "em0100",FatalException,"Worker thread in this method");
191 
192  if (fVerbosity > 2)
193  {
194  G4cout << "Entering in G4PenelopeBremsstrahlungFS::BuildScaledXSTable for " <<
195  material->GetName() << G4endl;
196  G4cout << "Threshold = " << cut/keV << " keV, isMaster= " << isMaster <<
197  G4endl;
198  }
199 
200  //This method should be accessed by the master only
201  if (!theSamplingTable)
202  theSamplingTable =
203  new std::map< std::pair<const G4Material*,G4double> , G4PhysicsTable*>;
204  if (!thePBcut)
205  thePBcut =
206  new std::map< std::pair<const G4Material*,G4double> , G4PhysicsFreeVector* >;
207 
208  //check if the container exists (if not, create it)
209  if (!theReducedXSTable)
210  theReducedXSTable = new std::map< std::pair<const G4Material*,G4double> ,
211  G4PhysicsTable*>;
212  if (!theEffectiveZSq)
213  theEffectiveZSq = new std::map<const G4Material*,G4double>;
214 
215 
216 
217  //*********************************************************************
218  //Determine the equivalent atomic number <Z^2>
219  //*********************************************************************
220  std::vector<G4double> *StechiometricFactors = new std::vector<G4double>;
221  G4int nElements = material->GetNumberOfElements();
222  const G4ElementVector* elementVector = material->GetElementVector();
223  const G4double* fractionVector = material->GetFractionVector();
224  for (G4int i=0;i<nElements;i++)
225  {
226  G4double fraction = fractionVector[i];
227  G4double atomicWeigth = (*elementVector)[i]->GetA()/(g/mole);
228  StechiometricFactors->push_back(fraction/atomicWeigth);
229  }
230  //Find max
231  G4double MaxStechiometricFactor = 0.;
232  for (G4int i=0;i<nElements;i++)
233  {
234  if ((*StechiometricFactors)[i] > MaxStechiometricFactor)
235  MaxStechiometricFactor = (*StechiometricFactors)[i];
236  }
237  //Normalize
238  for (G4int i=0;i<nElements;i++)
239  (*StechiometricFactors)[i] /= MaxStechiometricFactor;
240 
241  G4double sumz2 = 0;
242  G4double sums = 0;
243  for (G4int i=0;i<nElements;i++)
244  {
245  G4double Z = (*elementVector)[i]->GetZ();
246  sumz2 += (*StechiometricFactors)[i]*Z*Z;
247  sums += (*StechiometricFactors)[i];
248  }
249  G4double ZBR2 = sumz2/sums;
250 
251  theEffectiveZSq->insert(std::make_pair(material,ZBR2));
252 
253 
254  //*********************************************************************
255  // loop on elements and read data files
256  //*********************************************************************
257  G4DataVector* tempData = new G4DataVector(nBinsE);
258  G4DataVector* tempMatrix = new G4DataVector(nBinsE*nBinsX,0.);
259 
260  for (G4int iel=0;iel<nElements;iel++)
261  {
262  G4double Z = (*elementVector)[iel]->GetZ();
263  G4int iZ = (G4int) Z;
264  G4double wgt = (*StechiometricFactors)[iel]*Z*Z/ZBR2;
265  //
266 
267  //the element is not already loaded
268  if (!theElementData->count(iZ))
269  {
270  ReadDataFile(iZ);
271  if (!theElementData->count(iZ))
272  {
274  ed << "Error in G4PenelopeBremsstrahlungFS::BuildScaledXSTable" << G4endl;
275  ed << "Unable to retrieve data for element " << iZ << G4endl;
276  G4Exception("G4PenelopeBremsstrahlungFS::BuildScaledXSTable()",
277  "em2009",FatalException,ed);
278  }
279  }
280 
281  G4DataVector* atomData = theElementData->find(iZ)->second;
282 
283  for (size_t ie=0;ie<nBinsE;ie++)
284  {
285  (*tempData)[ie] += wgt*(*atomData)[ie*(nBinsX+1)+nBinsX]; //last column contains total XS
286  for (size_t ix=0;ix<nBinsX;ix++)
287  (*tempMatrix)[ie*nBinsX+ix] += wgt*(*atomData)[ie*(nBinsX+1)+ix];
288  }
289  }
290 
291  //*********************************************************************
292  // the total energy loss spectrum is re-normalized to reproduce the total
293  // scaled cross section of Berger and Seltzer
294  //*********************************************************************
295  for (size_t ie=0;ie<nBinsE;ie++)
296  {
297  //for each energy, calculate integral of dSigma/dx over dx
298  G4double* tempData2 = new G4double[nBinsX];
299  for (size_t ix=0;ix<nBinsX;ix++)
300  tempData2[ix] = (*tempMatrix)[ie*nBinsX+ix];
301  G4double rsum = GetMomentumIntegral(tempData2,1.0,0);
302  delete[] tempData2;
303  G4double fact = millibarn*(theEGrid[ie]+electron_mass_c2)*(1./fine_structure_const)/
305  G4double fnorm = (*tempData)[ie]/(rsum*fact);
306  G4double TST = 100.*std::fabs(fnorm-1.0);
307  if (TST > 1.0)
308  {
310  ed << "G4PenelopeBremsstrahlungFS. Corrupted data files?" << G4endl;
311  G4cout << "TST= " << TST << "; fnorm = " << fnorm << G4endl;
312  G4cout << "rsum = " << rsum << G4endl;
313  G4cout << "fact = " << fact << G4endl;
314  G4cout << ie << " " << theEGrid[ie]/keV << " " << (*tempData)[ie]/barn << G4endl;
315  G4Exception("G4PenelopeBremsstrahlungFS::BuildScaledXSTable()",
316  "em2010",FatalException,ed);
317  }
318  for (size_t ix=0;ix<nBinsX;ix++)
319  (*tempMatrix)[ie*nBinsX+ix] *= fnorm;
320  }
321 
322  //*********************************************************************
323  // create and fill the tables
324  //*********************************************************************
325  G4PhysicsTable* thePhysicsTable = new G4PhysicsTable();
326  // the table will contain 32 G4PhysicsFreeVectors with different
327  // values of x. Each of the G4PhysicsFreeVectors has a profile of
328  // log(XS) vs. log(E)
329 
330  //reserve space of the vectors. Everything is log-log
331  //I add one extra "fake" point at low energy, since the Penelope
332  //table starts at 1 keV
333  for (size_t i=0;i<nBinsX;i++)
334  thePhysicsTable->push_back(new G4PhysicsFreeVector(nBinsE+1));
335 
336  for (size_t ix=0;ix<nBinsX;ix++)
337  {
338  G4PhysicsFreeVector* theVec =
339  (G4PhysicsFreeVector*) ((*thePhysicsTable)[ix]);
340  for (size_t ie=0;ie<nBinsE;ie++)
341  {
342  G4double logene = std::log(theEGrid[ie]);
343  G4double aValue = (*tempMatrix)[ie*nBinsX+ix];
344  if (aValue < 1e-20*millibarn) //protection against log(0)
345  aValue = 1e-20*millibarn;
346  theVec->PutValue(ie+1,logene,std::log(aValue));
347  }
348  //Add fake point at 1 eV using an extrapolation with the derivative
349  //at the first valid point (Penelope approach)
350  G4double derivative = ((*theVec)[2]-(*theVec)[1])/(theVec->Energy(2) - theVec->Energy(1));
351  G4double log1eV = std::log(1*eV);
352  G4double val1eV = (*theVec)[1]+derivative*(log1eV-theVec->Energy(1));
353  //fake point at very low energy
354  theVec->PutValue(0,log1eV,val1eV);
355  }
356  std::pair<const G4Material*,G4double> theKey = std::make_pair(material,cut);
357  theReducedXSTable->insert(std::make_pair(theKey,thePhysicsTable));
358 
359  delete StechiometricFactors;
360  delete tempData;
361  delete tempMatrix;
362 
363  //Do here also the initialization of the energy sampling
364  if (!(theSamplingTable->count(theKey)))
365  InitializeEnergySampling(material,cut);
366 
367  return;
368 }
G4double GetMomentumIntegral(G4double *y, G4double up, G4int momOrder) const
std::vector< G4Element * > G4ElementVector
void PutValue(size_t binNumber, G4double binValue, G4double dataValue)
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
const G4String & GetName() const
Definition: G4Material.hh:176
void push_back(G4PhysicsVector *)
const G4ElementVector * GetElementVector() const
Definition: G4Material.hh:188
int G4int
Definition: G4Types.hh:78
int millibarn
Definition: hepunit.py:40
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5205
G4GLOB_DLL std::ostream G4cout
float electron_mass_c2
Definition: hepunit.py:274
G4double Energy(size_t index) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
#define G4endl
Definition: G4ios.hh:61
size_t GetNumberOfElements() const
Definition: G4Material.hh:184
double G4double
Definition: G4Types.hh:76
const G4double * GetFractionVector() const
Definition: G4Material.hh:192
void G4PenelopeBremsstrahlungFS::ClearTables ( G4bool  isMaster = true)

Reserved for the master model: they build and handle tables.

Definition at line 95 of file G4PenelopeBremsstrahlungFS.cc.

References FatalException, G4Exception(), and tab().

Referenced by ~G4PenelopeBremsstrahlungFS().

96 {
97  //Just to check
98  if (!isMaster)
99  G4Exception("G4PenelopeBremsstrahlungFS::ClearTables()",
100  "em0100",FatalException,"Worker thread in this method");
101 
102  std::map< std::pair<const G4Material*,G4double> ,G4PhysicsTable*>::iterator j;
103 
104  if (theReducedXSTable)
105  {
106  for (j=theReducedXSTable->begin(); j != theReducedXSTable->end(); j++)
107  {
108  G4PhysicsTable* tab = j->second;
109  //tab->clearAndDestroy();
110  delete tab;
111  }
112  delete theReducedXSTable;
113  theReducedXSTable = 0;
114  }
115 
116  if (theSamplingTable)
117  {
118  for (j=theSamplingTable->begin(); j != theSamplingTable->end(); j++)
119  {
120  G4PhysicsTable* tab = j->second;
121  // tab->clearAndDestroy();
122  delete tab;
123  }
124  delete theSamplingTable;
125  theSamplingTable = 0;
126  }
127  if (thePBcut)
128  {
129  /*
130  std::map< std::pair<const G4Material*,G4double> ,G4PhysicsFreeVector*>::iterator kk;
131  for (kk=thePBcut->begin(); kk != thePBcut->end(); kk++)
132  delete kk->second;
133  */
134  delete thePBcut;
135  thePBcut = 0;
136  }
137 
138 
139  if (theEffectiveZSq)
140  {
141  delete theEffectiveZSq;
142  theEffectiveZSq = 0;
143  }
144 
145  return;
146 }
std::ostream & tab(std::ostream &)
Definition: CCalutils.cc:89
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4double G4PenelopeBremsstrahlungFS::GetEffectiveZSquared ( const G4Material mat) const

Master and workers (do not touch tables) All of them are const

Definition at line 150 of file G4PenelopeBremsstrahlungFS.cc.

References FatalException, G4endl, G4Exception(), and G4Material::GetName().

151 {
152  if (!theEffectiveZSq)
153  {
155  ed << "The container for the <Z^2> values is not initialized" << G4endl;
156  G4Exception("G4PenelopeBremsstrahlungFS::GetEffectiveZSquared()",
157  "em2007",FatalException,ed);
158  return 0;
159  }
160  //found in the table: return it
161  if (theEffectiveZSq->count(material))
162  return theEffectiveZSq->find(material)->second;
163  else
164  {
166  ed << "The value of <Z^2> is not properly set for material " <<
167  material->GetName() << G4endl;
168  //requires running of BuildScaledXSTable()
169  G4Exception("G4PenelopeBremsstrahlungFS::GetEffectiveZSquared()",
170  "em2008",FatalException,ed);
171  }
172  return 0;
173 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
string material
Definition: eplot.py:19
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
#define G4endl
Definition: G4ios.hh:61
G4double G4PenelopeBremsstrahlungFS::GetMomentumIntegral ( G4double y,
G4double  up,
G4int  momOrder 
) const

Definition at line 441 of file G4PenelopeBremsstrahlungFS.cc.

References test::a, test::b, FatalException, G4endl, G4Exception(), G4INCL::Math::max(), and G4INCL::Math::min().

Referenced by BuildScaledXSTable().

444 {
445  //Corresponds to the function RLMOM of Penelope
446  //This method performs the calculation of the integral of (x^momOrder)*y over the interval
447  //from x[0] to xup, obtained by linear interpolation on a table of y.
448  //The independent variable is assumed to take positive values only.
449  //
450  size_t size = nBinsX;
451  const G4double eps = 1e-35;
452 
453  //Check that the call is valid
454  if (momOrder<-1 || size<2 || theXGrid[0]<0)
455  {
456  G4Exception("G4PenelopeBremsstrahlungFS::GetMomentumIntegral()",
457  "em2011",FatalException,"Invalid call");
458  }
459 
460  for (size_t i=1;i<size;i++)
461  {
462  if (theXGrid[i]<0 || theXGrid[i]<theXGrid[i-1])
463  {
465  ed << "Invalid call for bin " << i << G4endl;
466  G4Exception("G4PenelopeBremsstrahlungFS::GetMomentumIntegral()",
467  "em2012",FatalException,ed);
468  }
469  }
470 
471  //Compute the integral
472  G4double result = 0;
473  if (xup < theXGrid[0])
474  return result;
475  bool loopAgain = true;
476  G4double xt = std::min(xup,theXGrid[size-1]);
477  G4double xtc = 0;
478  for (size_t i=0;i<size-1;i++)
479  {
480  G4double x1 = std::max(theXGrid[i],eps);
481  G4double y1 = y[i];
482  G4double x2 = std::max(theXGrid[i+1],eps);
483  G4double y2 = y[i+1];
484  if (xt < x2)
485  {
486  xtc = xt;
487  loopAgain = false;
488  }
489  else
490  xtc = x2;
491  G4double dx = x2-x1;
492  G4double dy = y2-y1;
493  G4double ds = 0;
494  if (std::fabs(dx)>1e-14*std::fabs(dy))
495  {
496  G4double b=dy/dx;
497  G4double a=y1-b*x1;
498  if (momOrder == -1)
499  ds = a*std::log(xtc/x1)+b*(xtc-x1);
500  else if (momOrder == 0) //speed it up, not using pow()
501  ds = a*(xtc-x1) + 0.5*b*(xtc*xtc-x1*x1);
502  else
503  ds = a*(std::pow(xtc,momOrder+1)-std::pow(x1,momOrder+1))/((G4double) (momOrder + 1))
504  + b*(std::pow(xtc,momOrder+2)-std::pow(x1,momOrder+2))/((G4double) (momOrder + 2));
505  }
506  else
507  ds = 0.5*(y1+y2)*(xtc-x1)*std::pow(xtc,momOrder);
508  result += ds;
509  if (!loopAgain)
510  return result;
511  }
512  return result;
513 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
T max(const T t1, const T t2)
brief Return the largest of the two arguments
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
size_t G4PenelopeBremsstrahlungFS::GetNBinsX ( ) const
inline

Definition at line 73 of file G4PenelopeBremsstrahlungFS.hh.

73 {return nBinsX;};
const G4PhysicsTable * G4PenelopeBremsstrahlungFS::GetScaledXSTable ( const G4Material mat,
const G4double  cut 
) const

Definition at line 517 of file G4PenelopeBremsstrahlungFS.cc.

References FatalException, and G4Exception().

519 {
520  //check if it already contains the entry
521  std::pair<const G4Material*,G4double> theKey = std::make_pair(mat,cut);
522 
523  if (!(theReducedXSTable->count(theKey)))
524  {
525  G4Exception("G4PenelopeBremsstrahlungFS::GetScaledXSTable()",
526  "em2013",FatalException,"Unable to retrieve the cross section table");
527  }
528 
529  return theReducedXSTable->find(theKey)->second;
530 }
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4int G4PenelopeBremsstrahlungFS::GetVerbosity ( )
inline

Definition at line 87 of file G4PenelopeBremsstrahlungFS.hh.

87 {return fVerbosity;};
G4double G4PenelopeBremsstrahlungFS::SampleGammaEnergy ( G4double  energy,
const G4Material mat,
const G4double  cut 
) const

Definition at line 610 of file G4PenelopeBremsstrahlungFS.cc.

References energy(), FatalException, G4cout, G4endl, G4Exception(), G4UniformRand, G4Cache< VALTYPE >::Get(), G4Material::GetName(), JustWarning, python.hepunit::keV, G4INCL::Math::max(), G4Cache< VALTYPE >::Put(), and G4PhysicsFreeVector::PutValue().

Referenced by G4PenelopeBremsstrahlungModel::SampleSecondaries().

612 {
613  std::pair<const G4Material*,G4double> theKey = std::make_pair(mat,cut);
614  if (!(theSamplingTable->count(theKey)) || !(thePBcut->count(theKey)))
615  {
617  ed << "Unable to retrieve the SamplingTable: " <<
618  theSamplingTable->count(theKey) << " " <<
619  thePBcut->count(theKey) << G4endl;
620  G4Exception("G4PenelopeBremsstrahlungFS::SampleGammaEnergy()",
621  "em2014",FatalException,ed);
622  }
623 
624 
625  const G4PhysicsTable* theTableInte = theSamplingTable->find(theKey)->second;
626  const G4PhysicsTable* theTableRed = theReducedXSTable->find(theKey)->second;
627 
628  //Find the energy bin using bi-partition
629  size_t eBin = 0;
630  G4bool firstOrLastBin = false;
631 
632  if (energy < theEGrid[0]) //below first bin
633  {
634  eBin = 0;
635  firstOrLastBin = true;
636  }
637  else if (energy > theEGrid[nBinsE-1]) //after last bin
638  {
639  eBin = nBinsE-1;
640  firstOrLastBin = true;
641  }
642  else
643  {
644  size_t i=0;
645  size_t j=nBinsE-1;
646  while ((j-i)>1)
647  {
648  size_t k = (i+j)/2;
649  if (energy > theEGrid[k])
650  i = k;
651  else
652  j = k;
653  }
654  eBin = i;
655  }
656 
657  //Get the appropriate physics vector
658  const G4PhysicsFreeVector* theVec1 = (G4PhysicsFreeVector*) (*theTableInte)[eBin];
659 
660  //Use a "temporary" vector which contains the linear interpolation of the x spectra
661  //in energy. The temporary vector is thread-local, so that there is no conflict.
662  //This is achieved via G4Cache. The theTempVect is allocated only once per thread
663  //(member variable), but it is overwritten at every call of this method
664  //(because the interpolation factors change!)
665  G4PhysicsFreeVector* theTempVec = fCache.Get();
666  if (!theTempVec) //First time this thread gets the cache
667  {
668  theTempVec = new G4PhysicsFreeVector(nBinsX);
669  //The G4Physics*Vector pointers are automatically deleted by the G4Allocator,
670  //so there is no need to take care of it manually
671  fCache.Put(theTempVec);
672  if (fVerbosity > 4)
673  G4cout << "Creating new instance of G4PhysicsFreeVector() on the worker" << G4endl;
674  }
675 
676  //theTempVect is allocated only once (member variable), but it is overwritten at
677  //every call of this method (because the interpolation factors change!)
678  if (!firstOrLastBin)
679  {
680  const G4PhysicsFreeVector* theVec2 = (G4PhysicsFreeVector*) (*theTableInte)[eBin+1];
681  for (size_t iloop=0;iloop<nBinsX;iloop++)
682  {
683  G4double val = (*theVec1)[iloop]+(((*theVec2)[iloop]-(*theVec1)[iloop]))*
684  (energy-theEGrid[eBin])/(theEGrid[eBin+1]-theEGrid[eBin]);
685  theTempVec->PutValue(iloop,theXGrid[iloop],val);
686  }
687  }
688  else //first or last bin, no interpolation
689  {
690  for (size_t iloop=0;iloop<nBinsX;iloop++)
691  theTempVec->PutValue(iloop,theXGrid[iloop],(*theVec1)[iloop]);
692  }
693 
694  //Start the game
695  G4double pbcut = (*(thePBcut->find(theKey)->second))[eBin];
696 
697  if (!firstOrLastBin) //linear interpolation on pbcut as well
698  {
699  pbcut = (*(thePBcut->find(theKey)->second))[eBin] +
700  ((*(thePBcut->find(theKey)->second))[eBin+1]-(*(thePBcut->find(theKey)->second))[eBin])*
701  (energy-theEGrid[eBin])/(theEGrid[eBin+1]-theEGrid[eBin]);
702  }
703 
704  G4double pCumulative = (*theTempVec)[nBinsX-1]; //last value
705 
706  G4double eGamma = 0;
707  do
708  {
709  G4double pt = pbcut + G4UniformRand()*(pCumulative - pbcut);
710 
711  //find where it is
712  size_t ibin = 0;
713  if (pt < (*theTempVec)[0])
714  ibin = 0;
715  else if (pt > (*theTempVec)[nBinsX-1])
716  {
717  //We observed problems due to numerical rounding here (STT).
718  //delta here is a tiny positive number
719  G4double delta = pt-(*theTempVec)[nBinsX-1];
720  if (delta < pt*1e-10) // very small! Numerical rounding only
721  {
722  ibin = nBinsX-2;
724  ed << "Found that (pt > (*theTempVec)[nBinsX-1]) with pt = " << pt <<
725  " , (*theTempVec)[nBinsX-1] = " << (*theTempVec)[nBinsX-1] << " and delta = " <<
726  (pt-(*theTempVec)[nBinsX-1]) << G4endl;
727  ed << "Possible symptom of problem with numerical precision" << G4endl;
728  G4Exception("G4PenelopeBremsstrahlungFS::SampleGammaEnergy()",
729  "em2015",JustWarning,ed);
730  }
731  else //real problem
732  {
734  ed << "Crash at (pt > (*theTempVec)[nBinsX-1]) with pt = " << pt <<
735  " , (*theTempVec)[nBinsX-1]=" << (*theTempVec)[nBinsX-1] << " and nBinsX = " <<
736  nBinsX << G4endl;
737  ed << "Material: " << mat->GetName() << ", energy = " << energy/keV << " keV" <<
738  G4endl;
739  G4Exception("G4PenelopeBremsstrahlungFS::SampleGammaEnergy()",
740  "em2015",FatalException,ed);
741  }
742  }
743  else
744  {
745  size_t i=0;
746  size_t j=nBinsX-1;
747  while ((j-i)>1)
748  {
749  size_t k = (i+j)/2;
750  if (pt > (*theTempVec)[k])
751  i = k;
752  else
753  j = k;
754  }
755  ibin = i;
756  }
757 
758  G4double w1 = theXGrid[ibin];
759  G4double w2 = theXGrid[ibin+1];
760 
761  const G4PhysicsFreeVector* v1 = (G4PhysicsFreeVector*) (*theTableRed)[ibin];
762  const G4PhysicsFreeVector* v2 = (G4PhysicsFreeVector*) (*theTableRed)[ibin+1];
763  //Remember: the table theReducedXSTable has a fake first point in energy
764  //so, it contains one more bin than nBinsE.
765  G4double pdf1 = std::exp((*v1)[eBin+1]);
766  G4double pdf2 = std::exp((*v2)[eBin+1]);
767  G4double deltaW = w2-w1;
768  G4double dpdfb = pdf2-pdf1;
769  G4double B = dpdfb/deltaW;
770  G4double A = pdf1-B*w1;
771  //I already made an interpolation in energy, so I can use the actual value for the
772  //calculation of the wbcut, instead of the grid values (except for the last bin)
773  G4double wbcut = (cut < energy) ? cut/energy : 1.0;
774  if (firstOrLastBin) //this is an particular case: no interpolation available
775  wbcut = (cut < theEGrid[eBin]) ? cut/theEGrid[eBin] : 1.0;
776 
777  if (w1 < wbcut)
778  w1 = wbcut;
779  if (w2 < w1)
780  {
781  //This configuration can happen if initially wbcut > w2 > w1. Due to the previous
782  //statement, (w1 = wbcut), it becomes wbcut = w1 > w2. In this case, it is not a
783  //real problem. It becomes a problem if w2 < w1 before the w1 = wbcut statement. Issue
784  //a warning only in this specific case.
785  if (w2 > wbcut)
786  {
788  ed << "Warning in G4PenelopeBremsstrahlungFS::SampleX()" << G4endl;
789  ed << "Conflicting end-point values: w1=" << w1 << "; w2 = " << w2 << G4endl;
790  ed << "wbcut = " << wbcut << " energy= " << energy/keV << " keV" << G4endl;
791  ed << "cut = " << cut/keV << " keV" << G4endl;
792  G4Exception("G4PenelopeBremsstrahlungFS::SampleGammaEnergy()","em2015",
793  JustWarning,ed);
794  }
795  return w1*energy;
796  }
797 
798  G4double pmax = std::max(A+B*w1,A+B*w2);
799  G4bool loopAgain = false;
800  do
801  {
802  loopAgain = false;
803  eGamma = w1* std::pow((w2/w1),G4UniformRand());
804  if (G4UniformRand()*pmax > (A+B*eGamma))
805  loopAgain = true;
806  }while(loopAgain);
807  eGamma *= energy;
808  }while(eGamma < cut); //repeat if sampled sub-cut!
809 
810  return eGamma;
811 }
void PutValue(size_t binNumber, G4double binValue, G4double dataValue)
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
const G4String & GetName() const
Definition: G4Material.hh:176
value_type & Get() const
Definition: G4Cache.hh:253
double precision function energy(A, Z)
Definition: dpm25nuc6.f:4106
#define G4UniformRand()
Definition: Randomize.hh:87
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
T max(const T t1, const T t2)
brief Return the largest of the two arguments
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
void Put(const value_type &val) const
Definition: G4Cache.hh:257
void G4PenelopeBremsstrahlungFS::SetVerbosity ( G4int  ver)
inline

Definition at line 86 of file G4PenelopeBremsstrahlungFS.hh.

86 {fVerbosity=ver;};

The documentation for this class was generated from the following files: