67 :
G4VEmModel(nam),fParticleChange(0),fParticle(0),
68 isInitialised(false),fAtomDeexcitation(0),logAtomicShellXS(0),fLocalTable(false)
70 fIntrinsicLowEnergyLimit = 100.0*eV;
71 fIntrinsicHighEnergyLimit = 100.0*GeV;
101 for (
auto& item : (*logAtomicShellXS))
108 delete logAtomicShellXS;
117 if (verboseLevel > 3)
118 G4cout <<
"Calling G4PenelopePhotoElectricModel::Initialise()" <<
G4endl;
122 if (!fAtomDeexcitation)
125 G4cout <<
"WARNING from G4PenelopePhotoElectricModel " <<
G4endl;
126 G4cout <<
"Atomic de-excitation module is not instantiated, so there will not be ";
128 G4cout <<
"Please make sure this is intended" <<
G4endl;
131 SetParticle(particle);
138 if (!logAtomicShellXS)
139 logAtomicShellXS =
new std::map<G4int,G4PhysicsTable*>;
152 G4int iZ = theElementVector->at(j)->GetZasInt();
154 if (!logAtomicShellXS->count(iZ))
162 if (verboseLevel > 0) {
163 G4cout <<
"Penelope Photo-Electric model v2008 is initialized " <<
G4endl
170 if(isInitialised)
return;
172 isInitialised =
true;
179 if (verboseLevel > 3)
180 G4cout <<
"Calling G4PenelopePhotoElectricModel::InitialiseLocal()" <<
G4endl;
194 logAtomicShellXS = theModel->logAtomicShellXS;
197 verboseLevel = theModel->verboseLevel;
215 if (verboseLevel > 3)
216 G4cout <<
"Calling ComputeCrossSectionPerAtom() of G4PenelopePhotoElectricModel" <<
G4endl;
222 if (!logAtomicShellXS)
227 logAtomicShellXS =
new std::map<G4int,G4PhysicsTable*>;
231 if (!logAtomicShellXS->count(iZ))
235 if (verboseLevel > 0)
239 ed <<
"Unable to retrieve the shell cross section table for Z=" << iZ <<
G4endl;
240 ed <<
"This can happen only in Unit Tests or via G4EmCalculator" <<
G4endl;
241 G4Exception(
"G4PenelopePhotoElectricModel::ComputeCrossSectionPerAtom()",
245 G4AutoLock lock(&PenelopePhotoElectricModelMutex);
258 G4Exception(
"G4PenelopePhotoElectricModel::ComputeCrossSectionPerAtom()",
260 "Unable to retrieve the total cross section table");
265 cross =
G4Exp(logXS);
267 if (verboseLevel > 2)
268 G4cout <<
"Photoelectric cross section at " << energy/MeV <<
" MeV for Z=" << Z <<
269 " = " << cross/barn <<
" barn" <<
G4endl;
295 if (verboseLevel > 3)
296 G4cout <<
"Calling SamplingSecondaries() of G4PenelopePhotoElectricModel" <<
G4endl;
304 if (photonEnergy <= fIntrinsicLowEnergyLimit)
313 if (verboseLevel > 2)
320 if (verboseLevel > 2)
329 size_t shellIndex = SelectRandomShell(Z,photonEnergy);
331 if (verboseLevel > 2)
332 G4cout <<
"Selected shell " << shellIndex <<
" of element " << anElement->
GetName() <<
G4endl;
343 size_t numberOfShells = (size_t) transitionManager->
NumberOfShells(Z);
344 if (shellIndex >= numberOfShells)
345 shellIndex = numberOfShells-1;
357 bindingEnergy = 0.*eV;
364 G4double eKineticEnergy = photonEnergy - bindingEnergy;
368 if (eKineticEnergy > 0.)
372 cosTheta = SampleElectronDirection(eKineticEnergy);
373 G4double sinTheta = std::sqrt(1-cosTheta*cosTheta);
375 G4double dirx = sinTheta * std::cos(phi);
376 G4double diry = sinTheta * std::sin(phi);
379 electronDirection.
rotateUz(photonDirection);
383 fvect->push_back(electron);
386 bindingEnergy = photonEnergy;
395 if (fAtomDeexcitation && shellIndex<9)
400 size_t nBefore = fvect->size();
402 size_t nAfter = fvect->size();
404 if (nAfter > nBefore)
406 for (
size_t j=nBefore;j<nAfter;j++)
408 G4double itsEnergy = ((*fvect)[j])->GetKineticEnergy();
409 if (itsEnergy < bindingEnergy)
411 bindingEnergy -= itsEnergy;
413 energyInFluorescence += itsEnergy;
415 energyInAuger += itsEnergy;
420 (*fvect)[j] =
nullptr;
428 localEnergyDeposit += bindingEnergy;
430 if (localEnergyDeposit < 0)
432 G4Exception(
"G4PenelopePhotoElectricModel::SampleSecondaries()",
433 "em2099",
JustWarning,
"WARNING: Negative local energy deposit");
434 localEnergyDeposit = 0;
439 if (verboseLevel > 1)
441 G4cout <<
"-----------------------------------------------------------" <<
G4endl;
442 G4cout <<
"Energy balance from G4PenelopePhotoElectric" <<
G4endl;
443 G4cout <<
"Selected shell: " << WriteTargetShell(shellIndex) <<
" of element " <<
445 G4cout <<
"Incoming photon energy: " << photonEnergy/keV <<
" keV" <<
G4endl;
446 G4cout <<
"-----------------------------------------------------------" <<
G4endl;
448 G4cout <<
"Outgoing electron " << eKineticEnergy/keV <<
" keV" <<
G4endl;
449 if (energyInFluorescence)
450 G4cout <<
"Fluorescence x-rays: " << energyInFluorescence/keV <<
" keV" <<
G4endl;
452 G4cout <<
"Auger electrons: " << energyInAuger/keV <<
" keV" <<
G4endl;
453 G4cout <<
"Local energy deposit " << localEnergyDeposit/keV <<
" keV" <<
G4endl;
454 G4cout <<
"Total final state: " <<
455 (eKineticEnergy+energyInFluorescence+localEnergyDeposit+energyInAuger)/keV <<
457 G4cout <<
"-----------------------------------------------------------" <<
G4endl;
459 if (verboseLevel > 0)
462 std::fabs(eKineticEnergy+energyInFluorescence+localEnergyDeposit+energyInAuger-photonEnergy);
463 if (energyDiff > 0.05*keV)
465 G4cout <<
"Warning from G4PenelopePhotoElectric: problem with energy conservation: " <<
466 (eKineticEnergy+energyInFluorescence+localEnergyDeposit+energyInAuger)/keV
467 <<
" keV (final) vs. " <<
468 photonEnergy/keV <<
" keV (initial)" <<
G4endl;
469 G4cout <<
"-----------------------------------------------------------" <<
G4endl;
470 G4cout <<
"Energy balance from G4PenelopePhotoElectric" <<
G4endl;
471 G4cout <<
"Selected shell: " << WriteTargetShell(shellIndex) <<
" of element " <<
473 G4cout <<
"Incoming photon energy: " << photonEnergy/keV <<
" keV" <<
G4endl;
474 G4cout <<
"-----------------------------------------------------------" <<
G4endl;
476 G4cout <<
"Outgoing electron " << eKineticEnergy/keV <<
" keV" <<
G4endl;
477 if (energyInFluorescence)
478 G4cout <<
"Fluorescence x-rays: " << energyInFluorescence/keV <<
" keV" <<
G4endl;
480 G4cout <<
"Auger electrons: " << energyInAuger/keV <<
" keV" <<
G4endl;
481 G4cout <<
"Local energy deposit " << localEnergyDeposit/keV <<
" keV" <<
G4endl;
482 G4cout <<
"Total final state: " <<
483 (eKineticEnergy+energyInFluorescence+localEnergyDeposit+energyInAuger)/keV <<
485 G4cout <<
"-----------------------------------------------------------" <<
G4endl;
492G4double G4PenelopePhotoElectricModel::SampleElectronDirection(
G4double energy)
495 if (energy>1*GeV)
return costheta;
500 G4double gamma = 1.0 + energy/electron_mass_c2;
502 G4double beta = std::sqrt((gamma2-1.0)/gamma2);
507 G4double a1 = 0.5*beta*gamma*(gamma-1.0)*(gamma-2.0);
519 tsam = 2.0*ac * (2.0*rand + a2*std::sqrt(rand)) / (a2*a2 - 4.0*rand);
520 gtr = (2.0 - tsam) * (a1 + 1.0/(ac+tsam));
530void G4PenelopePhotoElectricModel::ReadDataFile(
G4int Z)
534 G4Exception(
"G4PenelopePhotoElectricModel::ReadDataFile()",
537 if (verboseLevel > 2)
539 G4cout <<
"G4PenelopePhotoElectricModel::ReadDataFile()" <<
G4endl;
540 G4cout <<
"Going to read PhotoElectric data files for Z=" << Z <<
G4endl;
543 char* path = std::getenv(
"G4LEDATA");
546 G4String excep =
"G4PenelopePhotoElectricModel - G4LEDATA environment variable not set!";
547 G4Exception(
"G4PenelopePhotoElectricModel::ReadDataFile()",
555 std::ostringstream ost;
557 ost << path <<
"/penelope/photoelectric/pdgph" << Z <<
".p08";
559 ost << path <<
"/penelope/photoelectric/pdgph0" << Z <<
".p08";
560 std::ifstream file(ost.str().c_str());
563 G4String excep =
"G4PenelopePhotoElectricModel - data file " +
G4String(ost.str()) +
" not found!";
564 G4Exception(
"G4PenelopePhotoElectricModel::ReadDataFile()",
571 while( getline(file, line) )
578 file.open(ost.str().c_str());
582 file >> readZ >> nShells;
584 if (verboseLevel > 3)
585 G4cout <<
"Element Z=" << Z <<
" , nShells = " << nShells <<
G4endl;
588 if (readZ != Z || nShells <= 0 || nShells > 50)
591 ed <<
"Corrupted data file for Z=" << Z <<
G4endl;
592 G4Exception(
"G4PenelopePhotoElectricModel::ReadDataFile()",
604 for (
size_t i=0;i<nShells+1;i++)
608 for (k=0;k<ndata && !file.eof();k++)
616 for (
size_t i=0;i<nShells+1;i++)
621 if (aValue < 1e-40*cm2)
627 if (verboseLevel > 2)
629 G4cout <<
"G4PenelopePhotoElectricModel: read " << k <<
" points for element Z = "
633 logAtomicShellXS->insert(std::make_pair(Z,thePhysicsTable));
645 G4Exception(
"G4PenelopePhotoElectricModel::GetNumberOfShellXS()",
649 if (!logAtomicShellXS->count(Z))
652 if (!logAtomicShellXS->count(Z))
655 ed <<
"Cannot find shell cross section data for Z=" << Z <<
G4endl;
656 G4Exception(
"G4PenelopePhotoElectricModel::GetNumberOfShellXS()",
660 size_t nEntries = logAtomicShellXS->find(Z)->second->entries();
671 if (shellID >= entries)
673 G4cout <<
"Element Z=" << Z <<
" has data for " << entries <<
" shells only" <<
G4endl;
674 G4cout <<
"so shellID should be from 0 to " << entries-1 <<
G4endl;
684 G4Exception(
"G4PenelopePhotoElectricModel::GetShellCrossSection()",
686 "Unable to retrieve the total cross section table");
692 if (cross < 2e-40*cm2) cross = 0;
698G4String G4PenelopePhotoElectricModel::WriteTargetShell(
size_t shellID)
703 else if (shellID == 1)
705 else if (shellID == 2)
707 else if (shellID == 3)
709 else if (shellID == 4)
711 else if (shellID == 5)
713 else if (shellID == 6)
715 else if (shellID == 7)
717 else if (shellID == 8)
734size_t G4PenelopePhotoElectricModel::SelectRandomShell(
G4int Z,
G4double energy)
739 if (!logAtomicShellXS->count(Z))
742 ed <<
"Cannot find shell cross section data for Z=" << Z <<
G4endl;
743 G4Exception(
"G4PenelopePhotoElectricModel::SelectRandomShell()",
765 for (
size_t k=1;k<theTable->
entries();k++)
std::vector< G4Element * > G4ElementVector
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
G4double G4Log(G4double x)
#define G4MUTEX_INITIALIZER
G4GLOB_DLL std::ostream G4cout
Hep3Vector & rotateUz(const Hep3Vector &)
G4double BindingEnergy() const
G4AtomicShell * Shell(G4int Z, size_t shellIndex) const
G4int NumberOfShells(G4int Z) const
static G4AtomicTransitionManager * Instance()
const G4ThreeVector & GetMomentumDirection() const
G4double GetKineticEnergy() const
static G4Electron * Definition()
static G4Electron * Electron()
const G4String & GetName() const
static G4Gamma * GammaDefinition()
static G4Gamma * Definition()
static G4LossTableManager * Instance()
G4VAtomDeexcitation * AtomDeexcitation()
const G4Material * GetMaterial() const
const G4ElementVector * GetElementVector() const
size_t GetNumberOfElements() const
const G4String & GetName() const
void SetProposedKineticEnergy(G4double proposedKinEnergy)
virtual void Initialise(const G4ParticleDefinition *, const G4DataVector &)
G4PenelopePhotoElectricModel(const G4ParticleDefinition *p=0, const G4String &processName="PenPhotoElec")
virtual void InitialiseLocal(const G4ParticleDefinition *, G4VEmModel *masterModel)
virtual G4double ComputeCrossSectionPerAtom(const G4ParticleDefinition *, G4double kinEnergy, G4double Z, G4double A=0, G4double cut=0, G4double emax=DBL_MAX)
G4double GetShellCrossSection(G4int Z, size_t shellID, G4double energy)
size_t GetNumberOfShellXS(G4int)
G4ParticleChangeForGamma * fParticleChange
virtual void SampleSecondaries(std::vector< G4DynamicParticle * > *, const G4MaterialCutsCouple *, const G4DynamicParticle *, G4double tmin, G4double maxEnergy)
virtual ~G4PenelopePhotoElectricModel()
const G4ParticleDefinition * fParticle
void PutValue(std::size_t index, G4double energy, G4double dValue)
void push_back(G4PhysicsVector *)
std::size_t entries() const
G4double Value(G4double theEnergy, std::size_t &lastidx) const
const G4MaterialCutsCouple * GetMaterialCutsCouple(G4int i) const
std::size_t GetTableSize() const
static G4ProductionCutsTable * GetProductionCutsTable()
G4bool CheckDeexcitationActiveRegion(G4int coupleIndex)
void GenerateParticles(std::vector< G4DynamicParticle * > *secVect, const G4AtomicShell *, G4int Z, G4int coupleIndex)
void SetHighEnergyLimit(G4double)
void SetElementSelectors(std::vector< G4EmElementSelector * > *)
G4ParticleChangeForGamma * GetParticleChangeForGamma()
G4double LowEnergyLimit() const
std::vector< G4EmElementSelector * > * GetElementSelectors()
G4double HighEnergyLimit() const
const G4Element * SelectRandomAtom(const G4MaterialCutsCouple *, const G4ParticleDefinition *, G4double kineticEnergy, G4double cutEnergy=0.0, G4double maxEnergy=DBL_MAX)
void SetDeexcitationFlag(G4bool val)
void InitialiseElementSelectors(const G4ParticleDefinition *, const G4DataVector &)
void ProposeTrackStatus(G4TrackStatus status)
void ProposeLocalEnergyDeposit(G4double anEnergyPart)
G4double energy(const ThreeVector &p, const G4double m)