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);
100 std::map <G4int,G4PhysicsFreeVector*>::iterator i;
104 if (i->second)
delete i->second;
112 if (i->second)
delete i->second;
131 std::map <const G4Material*,G4PhysicsFreeVector*>::iterator i;
136 if (i->second)
delete i->second;
144 if (i->second)
delete i->second;
149 std::map<const G4Material*,G4PenelopeSamplingData*>::iterator ii;
153 if (ii->second)
delete ii->second;
167 G4cout <<
"Calling G4PenelopeRayleighModel::Initialise()" <<
G4endl;
178 G4cout <<
"Calling G4PenelopeRayleighModel::Initialise() [master]" <<
G4endl;
192 pMaxTable =
new std::map<const G4Material*,G4PhysicsFreeVector*>;
194 samplingTable =
new std::map<const G4Material*,G4PenelopeSamplingData*>;
208 G4int iZ = (
G4int) theElementVector->at(j)->GetZ();
229 G4cout <<
"Penelope Rayleigh model v2008 is initialized " << G4endl
248 G4cout <<
"Calling G4PenelopeRayleighModel::InitialiseLocal()" <<
G4endl;
292 G4cout <<
"Calling CrossSectionPerAtom() of G4PenelopeRayleighModel" <<
G4endl;
314 ed <<
"Unable to retrieve the cross section table for Z=" << iZ <<
G4endl;
315 ed <<
"This can happen only in Unit Tests or via G4EmCalculator" <<
G4endl;
316 G4Exception(
"G4PenelopeRayleighModel::ComputeCrossSectionPerAtom()",
331 ed <<
"Unable to find Z=" << iZ <<
" in the atomic cross section table" <<
G4endl;
332 G4Exception(
"G4PenelopeRayleighModel::ComputeCrossSectionPerAtom()",
338 cross =
G4Exp(logXS);
342 G4cout <<
"Rayleigh cross section at " << energy/
keV <<
" keV for Z=" << Z <<
362 std::vector<G4double> *StechiometricFactors =
new std::vector<G4double>;
363 for (
G4int i=0;i<nElements;i++)
365 G4double fraction = fractionVector[i];
366 G4double atomicWeigth = (*elementVector)[i]->GetA()/(
g/
mole);
367 StechiometricFactors->push_back(fraction/atomicWeigth);
370 G4double MaxStechiometricFactor = 0.;
371 for (
G4int i=0;i<nElements;i++)
373 if ((*StechiometricFactors)[i] > MaxStechiometricFactor)
374 MaxStechiometricFactor = (*StechiometricFactors)[i];
376 if (MaxStechiometricFactor<1e-16)
379 ed <<
"Inconsistent data of atomic composition for " <<
381 G4Exception(
"G4PenelopeRayleighModel::BuildFormFactorTable()",
385 for (
G4int i=0;i<nElements;i++)
386 (*StechiometricFactors)[i] /= MaxStechiometricFactor;
390 for (
G4int i=0;i<nElements;i++)
391 atomsPerMolecule += (*StechiometricFactors)[i];
402 for (
G4int i=0;i<nElements;i++)
404 G4int iZ = (
G4int) (*elementVector)[i]->GetZ();
407 ff2 += f*f*(*StechiometricFactors)[i];
414 delete StechiometricFactors;
442 G4cout <<
"Calling SamplingSecondaries() of G4PenelopeRayleighModel" <<
G4endl;
475 pMaxTable =
new std::map<const G4Material*,G4PhysicsFreeVector*>;
477 samplingTable =
new std::map<const G4Material*,G4PenelopeSamplingData*>;
488 ed <<
"Unable to find the samplingTable data for " <<
490 ed <<
"This can happen only in Unit Tests" <<
G4endl;
491 G4Exception(
"G4PenelopeRayleighModel::SampleSecondaries()",
499 G4int iZ = (
G4int) theElementVector->at(j)->GetZ();
530 G4double qmax = 2.0*photonEnergy0/electron_mass_c2;
539 G4double G = 0.5*(1+cosTheta*cosTheta);
547 G4double LastQ2inTheTable = theDataTable->
GetX(nData-1);
565 cosTheta = 1.0-2.0*xx/q2max;
566 G4double G = 0.5*(1+cosTheta*cosTheta);
572 G4double sinTheta = std::sqrt(1-cosTheta*cosTheta);
576 G4double dirX = sinTheta*std::cos(phi);
577 G4double dirY = sinTheta*std::sin(phi);
583 photonDirection1.rotateUz(photonDirection0);
598 G4cout <<
"G4PenelopeRayleighModel::ReadDataFile()" <<
G4endl;
599 G4cout <<
"Going to read Rayleigh data files for Z=" << Z <<
G4endl;
602 char* path = getenv(
"G4LEDATA");
605 G4String excep =
"G4LEDATA environment variable not set!";
606 G4Exception(
"G4PenelopeRayleighModel::ReadDataFile()",
614 std::ostringstream ost;
616 ost << path <<
"/penelope/rayleigh/pdgra" << Z <<
".p08";
618 ost << path <<
"/penelope/rayleigh/pdgra0" << Z <<
".p08";
619 std::ifstream file(ost.str().c_str());
623 G4Exception(
"G4PenelopeRayleighModel::ReadDataFile()",
628 file >> readZ >> nPoints;
630 if (readZ != Z || nPoints <= 0 || nPoints >= 5000)
633 ed <<
"Corrupted data file for Z=" << Z <<
G4endl;
634 G4Exception(
"G4PenelopeRayleighModel::ReadDataFile()",
640 for (
size_t i=0;i<nPoints;i++)
642 file >> ene >>
f1 >>
f2 >> xs;
646 theVec->
PutValue(i,std::log(ene),std::log(xs));
647 if (file.eof() && i != (nPoints-1))
650 ed <<
"Corrupted data file for Z=" << Z <<
G4endl;
651 ed <<
"Found less than " << nPoints <<
"entries " <<
G4endl;
652 G4Exception(
"G4PenelopeRayleighModel::ReadDataFile()",
658 G4Exception(
"G4PenelopeRayleighModel::ReadDataFile()",
659 "em2044",
FatalException,
"Unable to allocate the atomic cross section table");
669 std::ostringstream ost2;
671 ost2 << path <<
"/penelope/rayleigh/pdaff" << Z <<
".p08";
673 ost2 << path <<
"/penelope/rayleigh/pdaff0" << Z <<
".p08";
674 file.open(ost2.str().c_str());
678 G4Exception(
"G4PenelopeRayleighModel::ReadDataFile()",
681 file >> readZ >> nPoints;
683 if (readZ != Z || nPoints <= 0 || nPoints >= 5000)
686 ed <<
"Corrupted data file for Z=" << Z <<
G4endl;
687 G4Exception(
"G4PenelopeRayleighModel::ReadDataFile()",
697 for (
size_t i=0;i<nPoints;i++)
699 file >> q >> ff >> incoh;
706 if (file.eof() && i != (nPoints-1))
709 ed <<
"Corrupted data file for Z=" << Z <<
G4endl;
710 ed <<
"Found less than " << nPoints <<
"entries " <<
G4endl;
711 G4Exception(
"G4PenelopeRayleighModel::ReadDataFile()",
717 G4Exception(
"G4PenelopeRayleighModel::ReadDataFile()",
719 "Unable to allocate the atomicFormFactor data table");
736 G4double logQSquared = (QSquared>1e-10) ? std::log(QSquared) : -23.;
747 ed <<
"Unable to retrieve F squared table for " << mat->
GetName() <<
G4endl;
748 G4Exception(
"G4PenelopeRayleighModel::GetFSquared()",
752 if (logQSquared < -20)
757 else if (logQSquared > maxlogQ2)
769 G4cout <<
"Q^2 = " << QSquared <<
" (units of 1/(m_e*c); F^2 = " << f2 <<
G4endl;
781 const size_t np = 150;
793 size_t nReducedPoints = np/4;
798 G4Exception(
"G4PenelopeRayleighModel::InitializeSamplingAlgorithm()",
800 "Too few points to initialize the sampling algorithm");
802 if (q2min > (q2max-1e-10))
804 G4cout <<
"q2min= " << q2min <<
" q2max= " << q2max <<
G4endl;
805 G4Exception(
"G4PenelopeRayleighModel::InitializeSamplingAlgorithm()",
807 "Too narrow grid to initialize the sampling algorithm");
820 const G4int nip = 51;
824 for (
size_t i=1;i<NUNIF-1;i++)
832 G4cout <<
"Vector x has " << x->size() <<
" points, while NUNIF = " << NUNIF <<
G4endl;
841 for (
size_t i=0;i<NUNIF-1;i++)
850 for (
G4int k=0;k<nip;k++)
854 pdfi->push_back(pdfk);
860 pdfih->push_back(pdfIK);
868 for (
G4int k=1;k<nip;k++)
871 G4double next = previous + cons*((*pdfi)[k-1]+4.0*(*pdfih)[k-1]+(*pdfi)[k]);
872 sumi->push_back(next);
875 G4double lastIntegral = (*sumi)[sumi->size()-1];
876 area->push_back(lastIntegral);
879 for (
size_t k=0;k<sumi->size();k++)
883 if ((*pdfi)[0] < 1e-35)
884 (*pdfi)[0] = 1e-5*pdfmax;
885 if ((*pdfi)[pdfi->size()-1] < 1e-35)
886 (*pdfi)[pdfi->size()-1] = 1e-5*pdfmax;
890 G4double B_temp = 1.0-1.0/(pli*pui*dx*dx);
891 G4double A_temp = (1.0/(pli*dx))-1.0-B_temp;
892 G4double C_temp = 1.0+A_temp+B_temp;
901 a->push_back(A_temp);
902 b->push_back(B_temp);
903 c->push_back(C_temp);
915 for (
G4int k=0;k<nip;k++)
918 G4double pap = (*area)[i]*(1.0+((*a)[i]+(*b)[i]*rr)*rr)*(1.0+((*a)[i]+(*b)[i]*rr)*rr)/
919 ((1.0-(*b)[i]*rr*rr)*(*c)[i]*((*x)[i+1]-(*x)[i]));
920 if (k == 0 || k == nip-1)
921 (*err)[i] += 0.5*std::fabs(pap-(*pdfi)[k]);
923 (*err)[i] += std::fabs(pap-(*pdfi)[k]);
928 if ((*err)[i] > 0.1*(*area)[i] && icase == 1)
944 (*x)[x->size()-1] = q2max;
951 if (x->size() != NUNIF || a->size() != NUNIF ||
952 err->size() != NUNIF || area->size() != NUNIF)
955 ed <<
"Problem in building the Table for Sampling: array dimensions do not match" <<
G4endl;
956 G4Exception(
"G4PenelopeRayleighModel::InitializeSamplingAlgorithm()",
968 for (
size_t i=0;i<err->size()-2;i++)
971 if ((*err)[i] > maxError)
973 maxError = (*err)[i];
979 G4double newx = 0.5*((*x)[iErrMax]+(*x)[iErrMax+1]);
981 x->insert(x->begin()+iErrMax+1,newx);
983 area->insert(area->begin()+iErrMax+1,0.);
984 a->insert(a->begin()+iErrMax+1,0.);
985 b->insert(b->begin()+iErrMax+1,0.);
986 c->insert(c->begin()+iErrMax+1,0.);
987 err->insert(err->begin()+iErrMax+1,0.);
990 for (
size_t i=iErrMax;i<=iErrMax+1;i++)
997 G4double dxLocal = (*x)[i+1]-(*x)[i];
1000 for (
G4int k=0;k<nip;k++)
1004 pdfi->push_back(pdfk);
1010 pdfih->push_back(pdfIK);
1017 sumi->push_back(0.);
1018 for (
G4int k=1;k<nip;k++)
1021 G4double next = previous + cons*((*pdfi)[k-1]+4.0*(*pdfih)[k-1]+(*pdfi)[k]);
1022 sumi->push_back(next);
1024 G4double lastIntegral = (*sumi)[sumi->size()-1];
1025 (*area)[i] = lastIntegral;
1029 for (
size_t k=0;k<sumi->size();k++)
1033 if ((*pdfi)[0] < 1e-35)
1034 (*pdfi)[0] = 1e-5*pdfmax;
1035 if ((*pdfi)[pdfi->size()-1] < 1e-35)
1036 (*pdfi)[pdfi->size()-1] = 1e-5*pdfmax;
1040 G4double B_temp = 1.0-1.0/(pli*pui*dxLocal*dxLocal);
1041 G4double A_temp = (1.0/(pli*dxLocal))-1.0-B_temp;
1042 G4double C_temp = 1.0+A_temp+B_temp;
1063 for (
G4int k=0;k<nip;k++)
1066 G4double pap = (*area)[i]*(1.0+((*a)[i]+(*b)[i]*rr)*rr)*(1.0+((*a)[i]+(*b)[i]*rr)*rr)/
1067 ((1.0-(*b)[i]*rr*rr)*(*c)[i]*((*x)[i+1]-(*x)[i]));
1068 if (k == 0 || k == nip-1)
1069 (*err)[i] += 0.5*std::fabs(pap-(*pdfi)[k]);
1071 (*err)[i] += std::fabs(pap-(*pdfi)[k]);
1076 if ((*err)[i] > 0.1*(*area)[i] && icase == 1)
1089 }
while(x->size() < np);
1091 if (x->size() != np || a->size() != np ||
1092 err->size() != np || area->size() != np)
1094 G4Exception(
"G4PenelopeRayleighModel::InitializeSamplingAlgorithm()",
1096 "Problem in building the extended Table for Sampling: array dimensions do not match ");
1103 for (
size_t i=0;i<np-1;i++)
1107 for (
size_t i=0;i<np-1;i++)
1111 errMax =
std::max(errMax,(*err)[i]);
1117 for (
size_t i=0;i<np-1;i++)
1120 PAC->push_back(previous+(*area)[i]);
1122 (*PAC)[PAC->size()-1] = 1.;
1129 std::vector<size_t> *ITTL =
new std::vector<size_t>;
1130 std::vector<size_t> *ITTU =
new std::vector<size_t>;
1133 for (
size_t i=0;i<np;i++)
1141 for (
size_t i=1;i<(np-1);i++)
1145 for (
size_t j=(*ITTL)[i-1];j<np && !found;j++)
1147 if ((*PAC)[j] > ptst)
1155 (*ITTU)[ITTU->size()-2] = ITTU->size()-1;
1156 (*ITTU)[ITTU->size()-1] = ITTU->size()-1;
1157 (*ITTL)[ITTL->size()-1] = ITTU->size()-2;
1159 if (ITTU->size() != np || ITTU->size() != np)
1161 G4Exception(
"G4PenelopeRayleighModel::InitializeSamplingAlgorithm()",
1163 "Problem in building the Limit Tables for Sampling: array dimensions do not match");
1171 for (
size_t i=0;i<np;i++)
1173 theTable->
AddPoint((*x)[i],(*PAC)[i],(*a)[i],(*b)[i],(*ITTL)[i],(*ITTU)[i]);
1178 G4cout <<
"*************************************************************************" <<
1180 G4cout <<
"Sampling table for Penelope Rayleigh scattering in " << mat->
GetName() <<
G4endl;
1209 G4cout <<
"G4PenelopeRayleighModel::BuildPMaxTable" <<
G4endl;
1210 G4cout <<
"Going to instanziate the pMaxTable !" <<
G4endl;
1212 pMaxTable =
new std::map<const G4Material*,G4PhysicsFreeVector*>;
1221 G4Exception(
"G4PenelopeRayleighModel::GetPMaxTable()",
1223 "SamplingTable is not properly instantiated");
1231 ed <<
"Sampling table for material " << mat->
GetName() <<
" not found";
1232 G4Exception(
"G4PenelopeRayleighModel::GetPMaxTable()",
1244 const size_t nip = 51;
1249 G4double Qm = 2.0*energy/electron_mass_c2;
1260 size_t lowerBound = 0;
1261 size_t upperBound = tablePoints-1;
1262 while (lowerBound <= upperBound)
1264 size_t midBin = (lowerBound + upperBound)/2;
1265 if( Qm2 < theTable->GetX(midBin))
1266 { upperBound = midBin-1; }
1268 { lowerBound = midBin+1; }
1278 for (
size_t k=0;k<nip;k++)
1282 (theTable->
GetX(upperBound+1)-Q1);
1287 if (std::fabs(con1) > 1.0e-16*std::fabs(con2))
1288 etap = con2*(1.0-std::sqrt(1.0-2.0*tau*con1/(con2*con2)))/con1;
1292 (1.0+(theA+theB*etap)*etap)*(1.0+(theA+theB*etap)*etap)/
1293 ((1.0-theB*etap*etap)*ci*(theTable->
GetX(upperBound+1)-Q1));
1294 fun->push_back(theFun);
1302 (5.0*(*fun)[0]+8.0*(*fun)[1]-(*fun)[2])*CONS;
1303 sum->push_back(secondPoint);
1304 for (
size_t hh=2;hh<nip-1;hh++)
1307 G4double next = previous+(13.0*((*fun)[hh-1]+(*fun)[hh])-
1308 (*fun)[hh+1]-(*fun)[hh-2])*HCONS;
1309 sum->push_back(next);
1311 G4double last = (*sum)[nip-2]+(5.0*(*fun)[nip-1]+8.0*(*fun)[nip-2]-
1312 (*fun)[nip-3])*CONS;
1313 sum->push_back(last);
1314 thePMax = thePAC + (*sum)[sum->size()-1];
1325 thePMax = theTable->
GetPAC(0);
1329 theVec->
PutValue(ie,energy,thePMax);
1332 pMaxTable->insert(std::make_pair(mat,theVec));
1341 G4cout <<
"*****************************************************************" <<
G4endl;
1345 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
static const double twopi
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)
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
static G4ProductionCutsTable * GetProductionCutsTable()
G4double SampleValue(G4double rndm)
static const G4double factor
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
const G4double x[NPOINTSGL]
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 *)