56 :
G4VEmModel(nam),fParticleChange(0),fParticle(0),isInitialised(false),
57 logAtomicCrossSection(0),atomicFormFactor(0),logFormFactorTable(0),
58 pMaxTable(0),samplingTable(0),fLocalTable(false)
82 G4double logfactor1 = std::log(10.)/250.;
86 if (logenergy < logtransitionenergy)
87 logenergy += logfactor1;
89 logenergy += logfactor2;
91 }
while (logenergy < logmaxenergy);
157 std::map<const G4Material*,G4PenelopeSamplingData*>::iterator ii;
161 if (ii->second)
delete ii->second;
175 G4cout <<
"Calling G4PenelopeRayleighModel::Initialise()" <<
G4endl;
197 pMaxTable =
new std::map<const G4Material*,G4PhysicsFreeVector*>;
199 samplingTable =
new std::map<const G4Material*,G4PenelopeSamplingData*>;
213 G4int iZ = (
G4int) theElementVector->at(j)->GetZ();
234 G4cout <<
"Penelope Rayleigh model v2008 is initialized " << G4endl
253 G4cout <<
"Calling G4PenelopeRayleighModel::InitialiseLocal()" <<
G4endl;
297 G4cout <<
"Calling CrossSectionPerAtom() of G4PenelopeRayleighModel" <<
G4endl;
319 ed <<
"Unable to retrieve the cross section table for Z=" << iZ <<
G4endl;
320 ed <<
"This can happen only in Unit Tests or via G4EmCalculator" <<
G4endl;
321 G4Exception(
"G4PenelopeRayleighModel::ComputeCrossSectionPerAtom()",
336 ed <<
"Unable to find Z=" << iZ <<
" in the atomic cross section table" <<
G4endl;
337 G4Exception(
"G4PenelopeRayleighModel::ComputeCrossSectionPerAtom()",
343 cross = std::exp(logXS);
346 G4cout <<
"Rayleigh cross section at " << energy/
keV <<
" keV for Z=" << Z <<
364 std::vector<G4double> *StechiometricFactors =
new std::vector<G4double>;
365 for (
G4int i=0;i<nElements;i++)
367 G4double fraction = fractionVector[i];
368 G4double atomicWeigth = (*elementVector)[i]->GetA()/(
g/
mole);
369 StechiometricFactors->push_back(fraction/atomicWeigth);
372 G4double MaxStechiometricFactor = 0.;
373 for (
G4int i=0;i<nElements;i++)
375 if ((*StechiometricFactors)[i] > MaxStechiometricFactor)
376 MaxStechiometricFactor = (*StechiometricFactors)[i];
378 if (MaxStechiometricFactor<1e-16)
381 ed <<
"Inconsistent data of atomic composition for " <<
383 G4Exception(
"G4PenelopeRayleighModel::BuildFormFactorTable()",
387 for (
G4int i=0;i<nElements;i++)
388 (*StechiometricFactors)[i] /= MaxStechiometricFactor;
392 for (
G4int i=0;i<nElements;i++)
393 atomsPerMolecule += (*StechiometricFactors)[i];
404 for (
G4int i=0;i<nElements;i++)
406 G4int iZ = (
G4int) (*elementVector)[i]->GetZ();
409 ff2 += f*f*(*StechiometricFactors)[i];
416 delete StechiometricFactors;
444 G4cout <<
"Calling SamplingSecondaries() of G4PenelopeRayleighModel" <<
G4endl;
477 pMaxTable =
new std::map<const G4Material*,G4PhysicsFreeVector*>;
479 samplingTable =
new std::map<const G4Material*,G4PenelopeSamplingData*>;
490 ed <<
"Unable to find the samplingTable data for " <<
492 ed <<
"This can happen only in Unit Tests" <<
G4endl;
493 G4Exception(
"G4PenelopeRayleighModel::SampleSecondaries()",
501 G4int iZ = (
G4int) theElementVector->at(j)->GetZ();
534 G4double qmax = 2.0*photonEnergy0/electron_mass_c2;
543 G4double G = 0.5*(1+cosTheta*cosTheta);
551 G4double LastQ2inTheTable = theDataTable->
GetX(nData-1);
569 cosTheta = 1.0-2.0*xx/q2max;
570 G4double G = 0.5*(1+cosTheta*cosTheta);
576 G4double sinTheta = std::sqrt(1-cosTheta*cosTheta);
580 G4double dirX = sinTheta*std::cos(phi);
581 G4double dirY = sinTheta*std::sin(phi);
587 photonDirection1.rotateUz(photonDirection0);
602 G4cout <<
"G4PenelopeRayleighModel::ReadDataFile()" <<
G4endl;
603 G4cout <<
"Going to read Rayleigh data files for Z=" << Z <<
G4endl;
606 char* path = getenv(
"G4LEDATA");
609 G4String excep =
"G4LEDATA environment variable not set!";
610 G4Exception(
"G4PenelopeRayleighModel::ReadDataFile()",
618 std::ostringstream ost;
620 ost << path <<
"/penelope/rayleigh/pdgra" << Z <<
".p08";
622 ost << path <<
"/penelope/rayleigh/pdgra0" << Z <<
".p08";
623 std::ifstream file(ost.str().c_str());
627 G4Exception(
"G4PenelopeRayleighModel::ReadDataFile()",
632 file >> readZ >> nPoints;
634 if (readZ != Z || nPoints <= 0 || nPoints >= 5000)
637 ed <<
"Corrupted data file for Z=" << Z <<
G4endl;
638 G4Exception(
"G4PenelopeRayleighModel::ReadDataFile()",
644 for (
size_t i=0;i<nPoints;i++)
646 file >> ene >>
f1 >>
f2 >> xs;
650 theVec->
PutValue(i,std::log(ene),std::log(xs));
651 if (file.eof() && i != (nPoints-1))
654 ed <<
"Corrupted data file for Z=" << Z <<
G4endl;
655 ed <<
"Found less than " << nPoints <<
"entries " <<
G4endl;
656 G4Exception(
"G4PenelopeRayleighModel::ReadDataFile()",
662 G4Exception(
"G4PenelopeRayleighModel::ReadDataFile()",
663 "em2044",
FatalException,
"Unable to allocate the atomic cross section table");
673 std::ostringstream ost2;
675 ost2 << path <<
"/penelope/rayleigh/pdaff" << Z <<
".p08";
677 ost2 << path <<
"/penelope/rayleigh/pdaff0" << Z <<
".p08";
678 file.open(ost2.str().c_str());
682 G4Exception(
"G4PenelopeRayleighModel::ReadDataFile()",
685 file >> readZ >> nPoints;
687 if (readZ != Z || nPoints <= 0 || nPoints >= 5000)
690 ed <<
"Corrupted data file for Z=" << Z <<
G4endl;
691 G4Exception(
"G4PenelopeRayleighModel::ReadDataFile()",
701 for (
size_t i=0;i<nPoints;i++)
703 file >> q >> ff >> incoh;
710 if (file.eof() && i != (nPoints-1))
713 ed <<
"Corrupted data file for Z=" << Z <<
G4endl;
714 ed <<
"Found less than " << nPoints <<
"entries " <<
G4endl;
715 G4Exception(
"G4PenelopeRayleighModel::ReadDataFile()",
721 G4Exception(
"G4PenelopeRayleighModel::ReadDataFile()",
723 "Unable to allocate the atomicFormFactor data table");
740 G4double logQSquared = (QSquared>1e-10) ? std::log(QSquared) : -23.;
751 ed <<
"Unable to retrieve F squared table for " << mat->
GetName() <<
G4endl;
752 G4Exception(
"G4PenelopeRayleighModel::GetFSquared()",
756 if (logQSquared < -20)
759 f2 = std::exp(logf2);
761 else if (logQSquared > maxlogQ2)
767 f2 = std::exp(logf2);
773 G4cout <<
"Q^2 = " << QSquared <<
" (units of 1/(m_e*c); F^2 = " << f2 <<
G4endl;
785 const size_t np = 150;
797 size_t nReducedPoints = np/4;
802 G4Exception(
"G4PenelopeRayleighModel::InitializeSamplingAlgorithm()",
804 "Too few points to initialize the sampling algorithm");
806 if (q2min > (q2max-1e-10))
808 G4cout <<
"q2min= " << q2min <<
" q2max= " << q2max <<
G4endl;
809 G4Exception(
"G4PenelopeRayleighModel::InitializeSamplingAlgorithm()",
811 "Too narrow grid to initialize the sampling algorithm");
824 const G4int nip = 51;
828 for (
size_t i=1;i<NUNIF-1;i++)
836 G4cout <<
"Vector x has " << x->size() <<
" points, while NUNIF = " << NUNIF <<
G4endl;
845 for (
size_t i=0;i<NUNIF-1;i++)
854 for (
G4int k=0;k<nip;k++)
858 pdfi->push_back(pdfk);
864 pdfih->push_back(pdfIK);
872 for (
G4int k=1;k<nip;k++)
875 G4double next = previous + cons*((*pdfi)[k-1]+4.0*(*pdfih)[k-1]+(*pdfi)[k]);
876 sumi->push_back(next);
879 G4double lastIntegral = (*sumi)[sumi->size()-1];
880 area->push_back(lastIntegral);
883 for (
size_t k=0;k<sumi->size();k++)
884 (*sumi)[k] *= factor;
887 if ((*pdfi)[0] < 1e-35)
888 (*pdfi)[0] = 1e-5*pdfmax;
889 if ((*pdfi)[pdfi->size()-1] < 1e-35)
890 (*pdfi)[pdfi->size()-1] = 1e-5*pdfmax;
893 G4double pui = (*pdfi)[pdfi->size()-1]*factor;
894 G4double B_temp = 1.0-1.0/(pli*pui*dx*dx);
895 G4double A_temp = (1.0/(pli*dx))-1.0-B_temp;
896 G4double C_temp = 1.0+A_temp+B_temp;
905 a->push_back(A_temp);
906 b->push_back(B_temp);
907 c->push_back(C_temp);
919 for (
G4int k=0;k<nip;k++)
922 G4double pap = (*area)[i]*(1.0+((*a)[i]+(*b)[i]*rr)*rr)*(1.0+((*a)[i]+(*b)[i]*rr)*rr)/
923 ((1.0-(*b)[i]*rr*rr)*(*c)[i]*((*x)[i+1]-(*x)[i]));
924 if (k == 0 || k == nip-1)
925 (*err)[i] += 0.5*std::fabs(pap-(*pdfi)[k]);
927 (*err)[i] += std::fabs(pap-(*pdfi)[k]);
932 if ((*err)[i] > 0.1*(*area)[i] && icase == 1)
948 (*x)[x->size()-1] = q2max;
955 if (x->size() != NUNIF || a->size() != NUNIF ||
956 err->size() != NUNIF || area->size() != NUNIF)
959 ed <<
"Problem in building the Table for Sampling: array dimensions do not match" <<
G4endl;
960 G4Exception(
"G4PenelopeRayleighModel::InitializeSamplingAlgorithm()",
972 for (
size_t i=0;i<err->size()-2;i++)
975 if ((*err)[i] > maxError)
977 maxError = (*err)[i];
983 G4double newx = 0.5*((*x)[iErrMax]+(*x)[iErrMax+1]);
985 x->insert(x->begin()+iErrMax+1,newx);
987 area->insert(area->begin()+iErrMax+1,0.);
988 a->insert(a->begin()+iErrMax+1,0.);
989 b->insert(b->begin()+iErrMax+1,0.);
990 c->insert(c->begin()+iErrMax+1,0.);
991 err->insert(err->begin()+iErrMax+1,0.);
994 for (
size_t i=iErrMax;i<=iErrMax+1;i++)
1001 G4double dxLocal = (*x)[i+1]-(*x)[i];
1004 for (
G4int k=0;k<nip;k++)
1008 pdfi->push_back(pdfk);
1014 pdfih->push_back(pdfIK);
1021 sumi->push_back(0.);
1022 for (
G4int k=1;k<nip;k++)
1025 G4double next = previous + cons*((*pdfi)[k-1]+4.0*(*pdfih)[k-1]+(*pdfi)[k]);
1026 sumi->push_back(next);
1028 G4double lastIntegral = (*sumi)[sumi->size()-1];
1029 (*area)[i] = lastIntegral;
1032 G4double factor = 1.0/lastIntegral;
1033 for (
size_t k=0;k<sumi->size();k++)
1034 (*sumi)[k] *= factor;
1037 if ((*pdfi)[0] < 1e-35)
1038 (*pdfi)[0] = 1e-5*pdfmax;
1039 if ((*pdfi)[pdfi->size()-1] < 1e-35)
1040 (*pdfi)[pdfi->size()-1] = 1e-5*pdfmax;
1043 G4double pui = (*pdfi)[pdfi->size()-1]*factor;
1044 G4double B_temp = 1.0-1.0/(pli*pui*dxLocal*dxLocal);
1045 G4double A_temp = (1.0/(pli*dxLocal))-1.0-B_temp;
1046 G4double C_temp = 1.0+A_temp+B_temp;
1067 for (
G4int k=0;k<nip;k++)
1070 G4double pap = (*area)[i]*(1.0+((*a)[i]+(*b)[i]*rr)*rr)*(1.0+((*a)[i]+(*b)[i]*rr)*rr)/
1071 ((1.0-(*b)[i]*rr*rr)*(*c)[i]*((*x)[i+1]-(*x)[i]));
1072 if (k == 0 || k == nip-1)
1073 (*err)[i] += 0.5*std::fabs(pap-(*pdfi)[k]);
1075 (*err)[i] += std::fabs(pap-(*pdfi)[k]);
1080 if ((*err)[i] > 0.1*(*area)[i] && icase == 1)
1093 }
while(x->size() < np);
1095 if (x->size() != np || a->size() != np ||
1096 err->size() != np || area->size() != np)
1098 G4Exception(
"G4PenelopeRayleighModel::InitializeSamplingAlgorithm()",
1100 "Problem in building the extended Table for Sampling: array dimensions do not match ");
1107 for (
size_t i=0;i<np-1;i++)
1111 for (
size_t i=0;i<np-1;i++)
1115 errMax =
std::max(errMax,(*err)[i]);
1121 for (
size_t i=0;i<np-1;i++)
1124 PAC->push_back(previous+(*area)[i]);
1126 (*PAC)[PAC->size()-1] = 1.;
1133 std::vector<size_t> *ITTL =
new std::vector<size_t>;
1134 std::vector<size_t> *ITTU =
new std::vector<size_t>;
1137 for (
size_t i=0;i<np;i++)
1145 for (
size_t i=1;i<(np-1);i++)
1149 for (
size_t j=(*ITTL)[i-1];j<np && !found;j++)
1151 if ((*PAC)[j] > ptst)
1159 (*ITTU)[ITTU->size()-2] = ITTU->size()-1;
1160 (*ITTU)[ITTU->size()-1] = ITTU->size()-1;
1161 (*ITTL)[ITTL->size()-1] = ITTU->size()-2;
1163 if (ITTU->size() != np || ITTU->size() != np)
1165 G4Exception(
"G4PenelopeRayleighModel::InitializeSamplingAlgorithm()",
1167 "Problem in building the Limit Tables for Sampling: array dimensions do not match");
1175 for (
size_t i=0;i<np;i++)
1177 theTable->
AddPoint((*x)[i],(*PAC)[i],(*a)[i],(*b)[i],(*ITTL)[i],(*ITTU)[i]);
1182 G4cout <<
"*************************************************************************" <<
1184 G4cout <<
"Sampling table for Penelope Rayleigh scattering in " << mat->
GetName() <<
G4endl;
1213 G4cout <<
"G4PenelopeRayleighModel::BuildPMaxTable" <<
G4endl;
1214 G4cout <<
"Going to instanziate the pMaxTable !" <<
G4endl;
1216 pMaxTable =
new std::map<const G4Material*,G4PhysicsFreeVector*>;
1225 G4Exception(
"G4PenelopeRayleighModel::GetPMaxTable()",
1227 "SamplingTable is not properly instantiated");
1240 const size_t nip = 51;
1245 G4double Qm = 2.0*energy/electron_mass_c2;
1256 size_t lowerBound = 0;
1257 size_t upperBound = tablePoints-1;
1258 while (lowerBound <= upperBound)
1260 size_t midBin = (lowerBound + upperBound)/2;
1261 if( Qm2 < theTable->GetX(midBin))
1262 { upperBound = midBin-1; }
1264 { lowerBound = midBin+1; }
1274 for (
size_t k=0;k<nip;k++)
1278 (theTable->
GetX(upperBound+1)-Q1);
1283 if (std::fabs(con1) > 1.0e-16*std::fabs(con2))
1284 etap = con2*(1.0-std::sqrt(1.0-2.0*tau*con1/(con2*con2)))/con1;
1288 (1.0+(theA+theB*etap)*etap)*(1.0+(theA+theB*etap)*etap)/
1289 ((1.0-theB*etap*etap)*ci*(theTable->
GetX(upperBound+1)-Q1));
1290 fun->push_back(theFun);
1298 (5.0*(*fun)[0]+8.0*(*fun)[1]-(*fun)[2])*CONS;
1299 sum->push_back(secondPoint);
1300 for (
size_t hh=2;hh<nip-1;hh++)
1303 G4double next = previous+(13.0*((*fun)[hh-1]+(*fun)[hh])-
1304 (*fun)[hh+1]-(*fun)[hh-2])*HCONS;
1305 sum->push_back(next);
1307 G4double last = (*sum)[nip-2]+(5.0*(*fun)[nip-1]+8.0*(*fun)[nip-2]-
1308 (*fun)[nip-3])*CONS;
1309 sum->push_back(last);
1310 thePMax = thePAC + (*sum)[sum->size()-1];
1321 thePMax = theTable->
GetPAC(0);
1325 theVec->
PutValue(ie,energy,thePMax);
1328 pMaxTable->insert(std::make_pair(mat,theVec));
1337 G4cout <<
"*****************************************************************" <<
G4endl;
1341 G4cout <<
"*****************************************************************" <<
G4endl;
G4double LowEnergyLimit() const
std::vector< G4Element * > G4ElementVector
void PutValue(size_t binNumber, G4double binValue, G4double dataValue)
std::ostringstream G4ExceptionDescription
virtual ~G4PenelopeRayleighModel()
G4double GetKineticEnergy() const
CLHEP::Hep3Vector G4ThreeVector
G4double HighEnergyLimit() const
virtual void Initialise(const G4ParticleDefinition *, const G4DataVector &)
G4double GetB(size_t index)
std::map< const G4Material *, G4PhysicsFreeVector * > * logFormFactorTable
const G4String & GetName() const
virtual void InitialiseLocal(const G4ParticleDefinition *, G4VEmModel *masterModel)
G4double fIntrinsicHighEnergyLimit
G4double GetPAC(size_t index)
size_t GetVectorLength() const
void BuildFormFactorTable(const G4Material *)
G4double GetLowEdgeEnergy(size_t binNumber) const
const G4ElementVector * GetElementVector() const
void ProposeMomentumDirection(G4double Px, G4double Py, G4double Pz)
#define G4MUTEX_INITIALIZER
G4double GetFSquared(const G4Material *, const G4double)
void ProposeLocalEnergyDeposit(G4double anEnergyPart)
void SetHighEnergyLimit(G4double)
size_t GetNumberOfStoredPoints()
G4GLOB_DLL std::ostream G4cout
size_t GetTableSize() const
void GetPMaxTable(const G4Material *)
void InitializeSamplingAlgorithm(const G4Material *)
const G4ThreeVector & GetMomentumDirection() const
std::map< G4int, G4PhysicsFreeVector * > * atomicFormFactor
void DumpFormFactorTable(const G4Material *)
G4double Value(G4double theEnergy, size_t &lastidx) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
static G4ProductionCutsTable * GetProductionCutsTable()
G4double SampleValue(G4double rndm)
const G4MaterialCutsCouple * GetMaterialCutsCouple(G4int i) const
T max(const T t1, const T t2)
brief Return the largest of the two arguments
G4double energy(const ThreeVector &p, const G4double m)
G4double fIntrinsicLowEnergyLimit
G4double GetA(size_t index)
G4DataVector logEnergyGridPMax
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
G4double GetX(size_t index)
std::map< G4int, G4PhysicsFreeVector * > * logAtomicCrossSection
G4ParticleChangeForGamma * fParticleChange
void SetProposedKineticEnergy(G4double proposedKinEnergy)
virtual void SampleSecondaries(std::vector< G4DynamicParticle * > *, const G4MaterialCutsCouple *, const G4DynamicParticle *, G4double tmin, G4double maxEnergy)
std::map< const G4Material *, G4PhysicsFreeVector * > * pMaxTable
size_t GetNumberOfElements() const
void ProposeTrackStatus(G4TrackStatus status)
G4PenelopeRayleighModel(const G4ParticleDefinition *p=0, const G4String &processName="PenRayleigh")
void AddPoint(G4double x0, G4double pac0, G4double a0, G4double b0, size_t ITTL0, size_t ITTU0)
G4ThreeVector G4ParticleMomentum
const G4double * GetFractionVector() const
G4DataVector logQSquareGrid
virtual G4double ComputeCrossSectionPerAtom(const G4ParticleDefinition *, G4double kinEnergy, G4double Z, G4double A=0, G4double cut=0, G4double emax=DBL_MAX)
std::map< const G4Material *, G4PenelopeSamplingData * > * samplingTable
const G4ParticleDefinition * fParticle
G4ParticleChangeForGamma * GetParticleChangeForGamma()
const G4Material * GetMaterial() const
void SetParticle(const G4ParticleDefinition *)