Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4PenelopeBremsstrahlungFS Class Reference

#include <G4PenelopeBremsstrahlungFS.hh>

Public Member Functions

 G4PenelopeBremsstrahlungFS ()
 
 ~G4PenelopeBremsstrahlungFS ()
 
G4double GetEffectiveZSquared (const G4Material *mat)
 
void ClearTables ()
 
size_t GetNBinsX ()
 
G4double GetMomentumIntegral (G4double *y, G4double up, G4int momOrder)
 
G4PhysicsTableGetScaledXSTable (const G4Material *, G4double cut)
 
G4double SampleGammaEnergy (G4double energy, const G4Material *, G4double cut)
 

Detailed Description

Definition at line 55 of file G4PenelopeBremsstrahlungFS.hh.

Constructor & Destructor Documentation

◆ G4PenelopeBremsstrahlungFS()

G4PenelopeBremsstrahlungFS::G4PenelopeBremsstrahlungFS ( )

Definition at line 50 of file G4PenelopeBremsstrahlungFS.cc.

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

◆ ~G4PenelopeBremsstrahlungFS()

G4PenelopeBremsstrahlungFS::~G4PenelopeBremsstrahlungFS ( )

Definition at line 72 of file G4PenelopeBremsstrahlungFS.cc.

73{
75
76 if (theTempVec)
77 delete theTempVec;
78
79 //Clear manually theElementData
80 std::map<G4int,G4DataVector*>::iterator i;
81 if (theElementData)
82 {
83 for (i=theElementData->begin(); i != theElementData->end(); i++)
84 delete i->second;
85 delete theElementData;
86 theElementData = 0;
87 }
88
89}

Member Function Documentation

◆ ClearTables()

void G4PenelopeBremsstrahlungFS::ClearTables ( )

Definition at line 94 of file G4PenelopeBremsstrahlungFS.cc.

95{
96 std::map< std::pair<const G4Material*,G4double> ,G4PhysicsTable*>::iterator j;
97
98 if (theReducedXSTable)
99 {
100 for (j=theReducedXSTable->begin(); j != theReducedXSTable->end(); j++)
101 {
102 G4PhysicsTable* tab = j->second;
103 tab->clearAndDestroy();
104 delete tab;
105 }
106 delete theReducedXSTable;
107 theReducedXSTable = 0;
108 }
109
110 if (theSamplingTable)
111 {
112 for (j=theSamplingTable->begin(); j != theSamplingTable->end(); j++)
113 {
114 G4PhysicsTable* tab = j->second;
115 tab->clearAndDestroy();
116 delete tab;
117 }
118 delete theSamplingTable;
119 theSamplingTable = 0;
120 }
121
122 std::map< std::pair<const G4Material*,G4double> ,G4PhysicsFreeVector*>::iterator kk;
123 if (thePBcut)
124 {
125 for (kk=thePBcut->begin(); kk != thePBcut->end(); kk++)
126 delete kk->second;
127 delete thePBcut;
128 thePBcut = 0;
129 }
130
131
132 if (theEffectiveZSq)
133 {
134 delete theEffectiveZSq;
135 theEffectiveZSq = 0;
136 }
137
138 return;
139}
void clearAndDestroy()

Referenced by ~G4PenelopeBremsstrahlungFS().

◆ GetEffectiveZSquared()

G4double G4PenelopeBremsstrahlungFS::GetEffectiveZSquared ( const G4Material mat)

Definition at line 143 of file G4PenelopeBremsstrahlungFS.cc.

144{
145 if (!theEffectiveZSq)
146 {
148 ed << "The container for the <Z^2> values is not initialized" << G4endl;
149 G4Exception("G4PenelopeBremsstrahlungFS::GetEffectiveZSquared()",
150 "em2007",FatalException,ed);
151 return 0;
152 }
153 //found in the table: return it
154 if (theEffectiveZSq->count(material))
155 return theEffectiveZSq->find(material)->second;
156 else
157 {
159 ed << "The value of <Z^2> is not properly set for material " <<
160 material->GetName() << G4endl;
161 //requires running of BuildScaledXSTable()
162 G4Exception("G4PenelopeBremsstrahlungFS::GetEffectiveZSquared()",
163 "em2008",FatalException,ed);
164 }
165 return 0;
166}
@ FatalException
#define G4endl
Definition: G4ios.hh:52
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76

◆ GetMomentumIntegral()

G4double G4PenelopeBremsstrahlungFS::GetMomentumIntegral ( G4double y,
G4double  up,
G4int  momOrder 
)

Definition at line 400 of file G4PenelopeBremsstrahlungFS.cc.

403{
404 //Corresponds to the function RLMOM of Penelope
405 //This method performs the calculation of the integral of (x^momOrder)*y over the interval
406 //from x[0] to xup, obtained by linear interpolation on a table of y.
407 //The independent variable is assumed to take positive values only.
408 //
409 size_t size = nBinsX;
410 const G4double eps = 1e-35;
411
412 //Check that the call is valid
413 if (momOrder<-1 || size<2 || theXGrid[0]<0)
414 {
415 G4Exception("G4PenelopeBremsstrahlungFS::GetMomentumIntegral()",
416 "em2011",FatalException,"Invalid call");
417 }
418
419 for (size_t i=1;i<size;i++)
420 {
421 if (theXGrid[i]<0 || theXGrid[i]<theXGrid[i-1])
422 {
424 ed << "Invalid call for bin " << i << G4endl;
425 G4Exception("G4PenelopeBremsstrahlungFS::GetMomentumIntegral()",
426 "em2012",FatalException,ed);
427 }
428 }
429
430 //Compute the integral
431 G4double result = 0;
432 if (xup < theXGrid[0])
433 return result;
434 bool loopAgain = true;
435 G4double xt = std::min(xup,theXGrid[size-1]);
436 G4double xtc = 0;
437 for (size_t i=0;i<size-1;i++)
438 {
439 G4double x1 = std::max(theXGrid[i],eps);
440 G4double y1 = y[i];
441 G4double x2 = std::max(theXGrid[i+1],eps);
442 G4double y2 = y[i+1];
443 if (xt < x2)
444 {
445 xtc = xt;
446 loopAgain = false;
447 }
448 else
449 xtc = x2;
450 G4double dx = x2-x1;
451 G4double dy = y2-y1;
452 G4double ds = 0;
453 if (std::fabs(dx)>1e-14*std::fabs(dy))
454 {
455 G4double b=dy/dx;
456 G4double a=y1-b*x1;
457 if (momOrder == -1)
458 ds = a*std::log(xtc/x1)+b*(xtc-x1);
459 else if (momOrder == 0) //speed it up, not using pow()
460 ds = a*(xtc-x1) + 0.5*b*(xtc*xtc-x1*x1);
461 else
462 ds = a*(std::pow(xtc,momOrder+1)-std::pow(x1,momOrder+1))/((G4double) (momOrder + 1))
463 + b*(std::pow(xtc,momOrder+2)-std::pow(x1,momOrder+2))/((G4double) (momOrder + 2));
464 }
465 else
466 ds = 0.5*(y1+y2)*(xtc-x1)*std::pow(xtc,momOrder);
467 result += ds;
468 if (!loopAgain)
469 return result;
470 }
471 return result;
472}

◆ GetNBinsX()

size_t G4PenelopeBremsstrahlungFS::GetNBinsX ( )
inline

Definition at line 64 of file G4PenelopeBremsstrahlungFS.hh.

64{return nBinsX;};

◆ GetScaledXSTable()

G4PhysicsTable * G4PenelopeBremsstrahlungFS::GetScaledXSTable ( const G4Material mat,
G4double  cut 
)

Definition at line 476 of file G4PenelopeBremsstrahlungFS.cc.

478{
479 //check if the container exists (if not, create it)
480 if (!theReducedXSTable)
481 theReducedXSTable = new std::map< std::pair<const G4Material*,G4double> ,
483 if (!theEffectiveZSq)
484 theEffectiveZSq = new std::map<const G4Material*,G4double>;
485
486 //check if it already contains the entry
487 std::pair<const G4Material*,G4double> theKey = std::make_pair(mat,cut);
488 if (!(theReducedXSTable->count(theKey))) //not found
489 BuildScaledXSTable(mat,cut);
490
491 if (!(theReducedXSTable->count(theKey)))
492 {
493 G4Exception("G4PenelopeBremsstrahlungFS::GetScaledXSTable()",
494 "em2013",FatalException,"Unable to retrieve the cross section table");
495 }
496
497 return theReducedXSTable->find(theKey)->second;
498}

◆ SampleGammaEnergy()

G4double G4PenelopeBremsstrahlungFS::SampleGammaEnergy ( G4double  energy,
const G4Material mat,
G4double  cut 
)

Definition at line 571 of file G4PenelopeBremsstrahlungFS.cc.

573{
574 if (!theSamplingTable)
575 theSamplingTable =
576 new std::map< std::pair<const G4Material*,G4double> , G4PhysicsTable*>;
577 if (!thePBcut)
578 thePBcut =
579 new std::map< std::pair<const G4Material*,G4double> , G4PhysicsFreeVector* >;
580
581 std::pair<const G4Material*,G4double> theKey = std::make_pair(mat,cut);
582
583 if (!(theSamplingTable->count(theKey)))
584 {
585 InitializeEnergySampling(mat,cut);
586 if (!(theSamplingTable->count(theKey)) || !(thePBcut->count(theKey)))
587 {
589 ed << "Unable to create the SamplingTable: " <<
590 theSamplingTable->count(theKey) << " " <<
591 thePBcut->count(theKey) << G4endl;
592 G4Exception("G4PenelopeBremsstrahlungFS::SampleGammaEnergy()",
593 "em2014",FatalException,ed);
594 }
595 }
596
597 G4PhysicsTable* theTableInte = theSamplingTable->find(theKey)->second;
598 G4PhysicsTable* theTableRed = theReducedXSTable->find(theKey)->second;
599
600 //Find the energy bin using bi-partition
601 size_t eBin = 0;
602 G4bool firstOrLastBin = false;
603
604 if (energy < theEGrid[0]) //below first bin
605 {
606 eBin = 0;
607 firstOrLastBin = true;
608 }
609 else if (energy > theEGrid[nBinsE-1]) //after last bin
610 {
611 eBin = nBinsE-1;
612 firstOrLastBin = true;
613 }
614 else
615 {
616 size_t i=0;
617 size_t j=nBinsE-1;
618 while ((j-i)>1)
619 {
620 size_t k = (i+j)/2;
621 if (energy > theEGrid[k])
622 i = k;
623 else
624 j = k;
625 }
626 eBin = i;
627 }
628
629 //Get the appropriate physics vector
630 G4PhysicsFreeVector* theVec1 = (G4PhysicsFreeVector*) (*theTableInte)[eBin];
631
632 //use a "temporary" vector which contains the linear interpolation of the x spectra
633 //in energy
634
635 //theTempVect is allocated only once (member variable), but it is overwritten at
636 //every call of this method (because the interpolation factors change!)
637 if (!firstOrLastBin)
638 {
639 G4PhysicsFreeVector* theVec2 = (G4PhysicsFreeVector*) (*theTableInte)[eBin+1];
640 for (size_t iloop=0;iloop<nBinsX;iloop++)
641 {
642 G4double val = (*theVec1)[iloop]+(((*theVec2)[iloop]-(*theVec1)[iloop]))*
643 (energy-theEGrid[eBin])/(theEGrid[eBin+1]-theEGrid[eBin]);
644 theTempVec->PutValue(iloop,theXGrid[iloop],val);
645 }
646 }
647 else //first or last bin, no interpolation
648 {
649 for (size_t iloop=0;iloop<nBinsX;iloop++)
650 theTempVec->PutValue(iloop,theXGrid[iloop],(*theVec1)[iloop]);
651 }
652
653 //Start the game
654 G4double pbcut = (*(thePBcut->find(theKey)->second))[eBin];
655
656 if (!firstOrLastBin) //linear interpolation on pbcut as well
657 {
658 pbcut = (*(thePBcut->find(theKey)->second))[eBin] +
659 ((*(thePBcut->find(theKey)->second))[eBin+1]-(*(thePBcut->find(theKey)->second))[eBin])*
660 (energy-theEGrid[eBin])/(theEGrid[eBin+1]-theEGrid[eBin]);
661 }
662
663 G4double pCumulative = (*theTempVec)[nBinsX-1]; //last value
664
665 G4double eGamma = 0;
666 do
667 {
668 G4double pt = pbcut + G4UniformRand()*(pCumulative - pbcut);
669
670 //find where it is
671 size_t ibin = 0;
672 if (pt < (*theTempVec)[0])
673 ibin = 0;
674 else if (pt > (*theTempVec)[nBinsX-1])
675 {
676 //We observed problems due to numerical rounding here (STT).
677 //delta here is a tiny positive number
678 G4double delta = pt-(*theTempVec)[nBinsX-1];
679 if (delta < pt*1e-10) // very small! Numerical rounding only
680 {
681 ibin = nBinsX-2;
683 ed << "Found that (pt > (*theTempVec)[nBinsX-1]) with pt = " << pt <<
684 " , (*theTempVec)[nBinsX-1] = " << (*theTempVec)[nBinsX-1] << " and delta = " <<
685 (pt-(*theTempVec)[nBinsX-1]) << G4endl;
686 ed << "Possible symptom of problem with numerical precision" << G4endl;
687 G4Exception("G4PenelopeBremsstrahlungFS::SampleGammaEnergy()",
688 "em2015",JustWarning,ed);
689 }
690 else //real problem
691 {
693 ed << "Crash at (pt > (*theTempVec)[nBinsX-1]) with pt = " << pt <<
694 " , (*theTempVec)[nBinsX-1]=" << (*theTempVec)[nBinsX-1] << " and nBinsX = " <<
695 nBinsX << G4endl;
696 ed << "Material: " << mat->GetName() << ", energy = " << energy/keV << " keV" <<
697 G4endl;
698 G4Exception("G4PenelopeBremsstrahlungFS::SampleGammaEnergy()",
699 "em2015",FatalException,ed);
700 }
701 }
702 else
703 {
704 size_t i=0;
705 size_t j=nBinsX-1;
706 while ((j-i)>1)
707 {
708 size_t k = (i+j)/2;
709 if (pt > (*theTempVec)[k])
710 i = k;
711 else
712 j = k;
713 }
714 ibin = i;
715 }
716
717 G4double w1 = theXGrid[ibin];
718 G4double w2 = theXGrid[ibin+1];
719
720 G4PhysicsFreeVector* v1 = (G4PhysicsFreeVector*) (*theTableRed)[ibin];
721 G4PhysicsFreeVector* v2 = (G4PhysicsFreeVector*) (*theTableRed)[ibin+1];
722 //Remember: the table theReducedXSTable has a fake first point in energy
723 //so, it contains one more bin than nBinsE.
724 G4double pdf1 = std::exp((*v1)[eBin+1]);
725 G4double pdf2 = std::exp((*v2)[eBin+1]);
726 G4double deltaW = w2-w1;
727 G4double dpdfb = pdf2-pdf1;
728 G4double B = dpdfb/deltaW;
729 G4double A = pdf1-B*w1;
730 //I already made an interpolation in energy, so I can use the actual value for the
731 //calculation of the wbcut, instead of the grid values (except for the last bin)
732 G4double wbcut = (cut < energy) ? cut/energy : 1.0;
733 if (firstOrLastBin) //this is an particular case: no interpolation available
734 wbcut = (cut < theEGrid[eBin]) ? cut/theEGrid[eBin] : 1.0;
735
736 if (w1 < wbcut)
737 w1 = wbcut;
738 if (w2 < w1)
739 {
740 G4cout << "Warning in G4PenelopeBremsstrahlungFS::SampleX()" << G4endl;
741 G4cout << "Conflicting end-point values: w1=" << w1 << "; w2 = " << w2 << G4endl;
742 G4cout << "wbcut = " << wbcut << " energy= " << energy/keV << " keV" << G4endl;
743 G4cout << "cut = " << cut/keV << " keV" << G4endl;
744 return w1*energy;
745 }
746
747 G4double pmax = std::max(A+B*w1,A+B*w2);
748 G4bool loopAgain = false;
749 do
750 {
751 loopAgain = false;
752 eGamma = w1* std::pow((w2/w1),G4UniformRand());
753 if (G4UniformRand()*pmax > (A+B*eGamma))
754 loopAgain = true;
755 }while(loopAgain);
756 eGamma *= energy;
757 }while(eGamma < cut); //repeat if sampled sub-cut!
758
759 return eGamma;
760}
@ JustWarning
bool G4bool
Definition: G4Types.hh:67
G4DLLIMPORT std::ostream G4cout
#define G4UniformRand()
Definition: Randomize.hh:53
const G4String & GetName() const
Definition: G4Material.hh:177
void PutValue(size_t binNumber, G4double binValue, G4double dataValue)

Referenced by G4PenelopeBremsstrahlungModel::SampleSecondaries().


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