331 std::ifstream infile(filename, std::ios::in);
334 G4Exception(
"G4SPSEneDistribution::ArbEnergyHistoFile",
"Event0301",
338 while (infile >> ehi >> val)
387 BBHist =
new std::vector<G4double>(10001, 0.0);
388 Bbody_x =
new std::vector<G4double>(10001, 0.0);
394 CPHist =
new std::vector<G4double>(10001, 0.0);
395 CP_x =
new std::vector<G4double>(10001, 0.0);
435 omalpha = 1. - spind[i];
437 * (std::pow(ene_line[i + 1] /
keV, omalpha)
438 - std::pow(ene_line[i] /
keV,omalpha));
473 while (count < 10000)
477 / (h2*c2*(std::exp(
Bbody_x->at(count) / (k*
Temp)) - 1.));
488 while (count < 10001)
513 while (count < 10000)
528 while (count < 10001)
585 G4double sum = 0., Arb_x[1024], Arb_y[1024], Arb_Cum_Area[1024];
588 for (i = 0; i < maxi; ++i)
601 for (count = 0; count < maxi-1; ++count)
603 Arb_y[count] = (Arb_y[count] - Arb_y[count + 1])
604 / (Arb_x[count + 1] - Arb_x[count]);
617 G4Exception(
"G4SPSEneDistribution::LinearInterpolation",
619 "Error: particle not defined");
632 for (count = 0; count < maxi; ++count)
634 total_energy = std::sqrt((Arb_x[count] * Arb_x[count])
636 Arb_y[count] = Arb_y[count] * Arb_x[count] / total_energy;
637 Arb_x[count] = total_energy - mass;
651 Arb_Cum_Area[0] = 0.;
656 Arb_grad[i] = (Arb_y[i] - Arb_y[i - 1]) / (Arb_x[i] - Arb_x[i - 1]);
687 * (Arb_x[i] * Arb_x[i] - Arb_x[i - 1] * Arb_x[i - 1])
688 +
Arb_cept[i] * (Arb_x[i] - Arb_x[i - 1]));
689 Arb_Cum_Area[i] = Arb_Cum_Area[i - 1] + Area_seg[i];
690 sum = sum + Area_seg[i];
693 G4cout << Arb_x[i] << Arb_y[i] << Area_seg[i] << sum
702 Arb_Cum_Area[i] = Arb_Cum_Area[i] / sum;
728 G4double sum = 0., Arb_x[1024], Arb_y[1024], Arb_Cum_Area[1024];
731 for (i = 0; i < maxi; ++i)
744 for (count = 0; count < maxi-1; ++count)
746 Arb_y[count] = (Arb_y[count] - Arb_y[count + 1])
747 / (Arb_x[count + 1] - Arb_x[count]);
760 G4Exception(
"G4SPSEneDistribution::LogInterpolation",
762 "Error: particle not defined");
775 for (count = 0; count < maxi; ++count)
777 total_energy = std::sqrt((Arb_x[count] * Arb_x[count]) + (mass * mass));
778 Arb_y[count] = Arb_y[count] * Arb_x[count] / total_energy;
779 Arb_x[count] = total_energy - mass;
795 Arb_Cum_Area[0] = 0.;
796 if (Arb_x[0] <= 0. || Arb_y[0] <= 0.)
798 G4cout <<
"You should not use log interpolation with points <= 0."
800 G4cout <<
"These will be changed to 1e-20, which may cause problems"
817 if (Arb_x[i] <= 0. || Arb_y[i] <= 0.)
819 G4cout <<
"You should not use log interpolation with points <= 0."
821 G4cout <<
"These will be changed to 1e-20, which may cause problems"
833 Arb_alpha[i] = (std::log10(Arb_y[i]) - std::log10(Arb_y[i - 1]))
834 / (std::log10(Arb_x[i]) - std::log10(Arb_x[i - 1]));
840 * (std::log(Arb_x[i]) - std::log(Arb_x[i - 1]));
845 * (std::pow(Arb_x[i], alp) - std::pow(Arb_x[i - 1], alp));
847 sum = sum + Area_seg[i];
848 Arb_Cum_Area[i] = Arb_Cum_Area[i - 1] + Area_seg[i];
859 Arb_Cum_Area[i] = Arb_Cum_Area[i] / sum;
883 G4double sum = 0., Arb_x[1024], Arb_y[1024], Arb_Cum_Area[1024];
886 for (i = 0; i < maxi; ++i)
899 for (count = 0; count < maxi - 1; ++count)
901 Arb_y[count] = (Arb_y[count] - Arb_y[count + 1])
902 / (Arb_x[count + 1] - Arb_x[count]);
915 G4Exception(
"G4SPSEneDistribution::ExpInterpolation",
917 "Error: particle not defined");
930 for (count = 0; count < maxi; ++count)
932 total_energy = std::sqrt((Arb_x[count] * Arb_x[count]) + (mass * mass));
933 Arb_y[count] = Arb_y[count] * Arb_x[count] / total_energy;
934 Arb_x[count] = total_energy - mass;
950 Arb_Cum_Area[0] = 0.;
953 G4double test = std::log(Arb_y[i]) - std::log(Arb_y[i - 1]);
956 Arb_ezero[i] = -(Arb_x[i] - Arb_x[i - 1])
957 / (std::log(Arb_y[i]) - std::log(Arb_y[i - 1]));
961 - std::exp(-Arb_x[i - 1] /
Arb_ezero[i]));
965 G4Exception(
"G4SPSEneDistribution::ExpInterpolation",
967 "Flat line segment: problem, setting to zero parameters.");
973 sum = sum + Area_seg[i];
974 Arb_Cum_Area[i] = Arb_Cum_Area[i - 1] + Area_seg[i];
985 Arb_Cum_Area[i] = Arb_Cum_Area[i] / sum;
1008 G4double sum, Arb_x[1024], Arb_y[1024], Arb_Cum_Area[1024];
1012 for (i = 0; i < maxi; ++i)
1025 for (count = 0; count < maxi - 1; ++count)
1027 Arb_y[count] = (Arb_y[count] - Arb_y[count + 1])
1028 / (Arb_x[count + 1] - Arb_x[count]);
1039 if (pdef ==
nullptr)
1041 G4Exception(
"G4SPSEneDistribution::SplineInterpolation",
1043 "Error: particle not defined");
1056 for (count = 0; count < maxi; ++count)
1058 total_energy = std::sqrt((Arb_x[count] * Arb_x[count]) + (mass * mass));
1059 Arb_y[count] = Arb_y[count] * Arb_x[count] / total_energy;
1060 Arb_x[count] = total_energy - mass;
1066 Arb_Cum_Area[0] = 0.;
1081 G4double de = (Arb_x[i] - Arb_x[i - 1])/100.;
1084 for (count = 0; count < 101; ++count)
1086 ei[count] = Arb_x[i - 1] + de*count ;
1088 if (prob[count] < 0.)
1091 ED <<
"Warning: G4DataInterpolation returns value < 0 " << prob[count]
1092 <<
" " << ei[count] <<
G4endl;
1093 G4Exception(
"G4SPSEneDistribution::SplineInterpolation",
"Event0303",
1096 area += prob[count]*de;
1098 Arb_Cum_Area[i] = Arb_Cum_Area[i - 1] + area;
1101 prob[0] = prob[0]/(area/de);
1102 for (count = 1; count < 100; ++count)
1104 prob[count] = prob[count-1] + prob[count]/(area/de);
1117 Arb_Cum_Area[i] = Arb_Cum_Area[i] / sum;
1144 if (ene < 0) ene = 0.;
1162 bracket = bracket * rndm;
1163 bracket = bracket + (params.
grad / 2.) * eminsq + params.
cept * params.
Emin;
1169 if (params.
grad != 0.)
1171 G4double sqbrack = (intersq - 4 * (params.
grad / 2.) * (bracket));
1172 sqbrack = std::sqrt(sqbrack);
1174 root1 = root1 / (2. * (params.
grad / 2.));
1177 root2 = root2 / (2. * (params.
grad / 2.));
1179 if (root1 > params.
Emin && root1 < params.
Emax)
1183 if (root2 > params.
Emin && root2 < params.
Emax)
1188 else if (params.
grad == 0.)
1215 emina = std::pow(params.
Emin, params.
alpha + 1);
1216 emaxa = std::pow(params.
Emax, params.
alpha + 1);
1221 if (params.
alpha != -1.)
1223 G4double ene = ((rndm * (emaxa - emina)) + emina);
1224 ene = std::pow(ene, (1. / (params.
alpha + 1.)));
1230 + rndm * (std::log(params.
Emax) - std::log(params.
Emin)));
1250 G4int nabove = 10001, nbelow = 0, middle;
1266 while (nabove - nbelow > 1)
1268 middle = (nabove + nbelow) / 2;
1269 if (rndm ==
CPHist->at(middle))
1273 if (rndm < CPHist->at(middle))
1286 x1 =
CP_x->at(nbelow);
1287 if(nbelow+1 ==
static_cast<G4int>(
CP_x->size()))
1293 x2 =
CP_x->at(nbelow + 1);
1296 if(nbelow+1 ==
static_cast<G4int>(
CPHist->size()))
1303 y2 =
CPHist->at(nbelow + 1);
1305 t = (y2 - y1) / (x2 - x1);
1337 G4double ee = ((rndm * (emaxa - emina)) + emina);
1343 G4double ee = (std::log(emin) + rndm * (std::log(
emax) - std::log(emin)));
1368 * (std::log(rndm * (std::exp(-params.
Emax
1370 - std::exp(-params.
Emin
1372 + std::exp(-params.
Emin / params.
Ezero)));
1394 expmax = std::exp(-params.
Emax / (k *
Temp));
1395 expmin = std::exp(-params.
Emin / (k *
Temp));
1402 G4Exception(
"G4SPSEneDistribution::GenerateBremEnergies",
1404 "*****EXPMAX=0. Choose different E's or Temp");
1408 G4Exception(
"G4SPSEneDistribution::GenerateBremEnergies",
1410 "*****EXPMIN=0. Choose different E's or Temp");
1414 - params.
Emin * expmin)
1415 - (ksq * Tsq * (expmax - expmin)));
1418 - ksq * Tsq * expmin) / (-k *
Temp);
1427 G4double etest, diff, err = 100000.;
1429 for (i = 1; i < 1000; ++i)
1431 etest = params.
Emin + (i - 1) * steps;
1432 diff = etest * (std::exp(-etest / (k *
Temp)))
1433 + k *
Temp * (std::exp(-etest / (k *
Temp))) - bigc;
1460 G4int nabove = 10001, nbelow = 0, middle;
1476 while (nabove - nbelow > 1)
1478 middle = (nabove + nbelow) / 2;
1479 if (rndm ==
BBHist->at(middle))
1483 if (rndm < BBHist->at(middle))
1507 if(nbelow+1 ==
static_cast<G4int>(
BBHist->size()))
1514 y2 =
BBHist->at(nbelow + 1);
1516 t = (y2 - y1) / (x2 - x1);
1539 omalpha[0] = 1. - 1.4;
1540 ene_line[0] = params.
Emin;
1541 ene_line[1] = params.
Emax;
1545 omalpha[0] = 1. - 1.4;
1546 omalpha[1] = 1. - 2.3;
1547 ene_line[0] = params.
Emin;
1548 ene_line[1] = 18. *
keV;
1549 ene_line[2] = params.
Emax;
1553 omalpha[0] = 1. - 2.3;
1554 ene_line[0] = params.
Emin;
1555 ene_line[1] = params.
Emax;
1568 G4double ene = (std::pow(ene_line[i - 1], omalpha[i - 1])
1569 + (std::pow(ene_line[i], omalpha[i - 1])
1570 - std::pow(ene_line[i - 1], omalpha[i- 1])) * rndm2);
1590 for ( ii = 0 ; ii<1024 ; ++ii ) {
bins[ii]=0; vals[ii]=0; }
1596 G4Exception(
"G4SPSEneDistribution::GenUserHistEnergies",
1598 "Error: particle definition is NULL");
1603 G4Exception(
"G4SPSEneDistribution::GenUserHistEnergies",
1605 "Maxbin>1024\n Setting maxbin to 1024, other bins are lost");
1618 for (ii = 1; ii < maxbin; ++ii)
1621 vals[ii] =
UDefEnergyH(std::size_t(ii)) + vals[ii - 1];
1633 for (ii = 1; ii < maxbin; ++ii)
1635 vals[ii] = vals[ii] * (
bins[ii] -
bins[ii - 1]);
1641 for (ii = 0; ii < maxbin; ++ii)
1645 bins[ii] = std::sqrt((
bins[ii]*
bins[ii])+(mass*mass))-mass;
1647 for (ii = 1; ii < maxbin; ++ii)
1649 vals[ii] = vals[ii] / (
bins[ii] -
bins[ii - 1]);
1651 sum = vals[maxbin - 1];
1654 for (ii = 0; ii < maxbin; ++ii)
1656 vals[ii] = vals[ii] / sum;
1694 wei = cns * std::pow(ene,alp);
1700 wei = cns * std::exp(-ene/e0);
1704 wei =
SplineInt[nbelow+1]->CubicSplineInterpolation(ene);
1724 while (nabove - nbelow > 1)
1726 middle = (nabove + nbelow) / 2;
1775 SplineInt[nbelow+1]->CubicSplineInterpolation(rndm);
1785 G4Exception(
"G4SPSEneDistribution::GenArbPointEnergies",
"Event0302",
1812 for (ii = 1; ii < maxbin; ++ii)
1815 vals[ii] =
UDefEnergyH(std::size_t(ii)) + vals[ii - 1];
1820 for (ii = 0; ii < maxbin; ++ii)
1822 vals[ii] = vals[ii] / sum;
1860 G4int count, maxcount;
1863 if (maxcount > 1024)
1865 G4Exception(
"G4SPSEneDistribution::ConvertEPNToEnergy()",
1867 "Histogram contains more than 1024 bins!\n\
1868 Those above 1024 will be ignored");
1873 G4Exception(
"G4SPSEneDistribution::ConvertEPNToEnergy()",
1875 "Histogram contains less than 1 bin!\nRedefine the histogram");
1878 for (count = 0; count < maxcount; ++count)
1882 evals[count] =
EpnEnergyH(std::size_t(count));
1887 for (count = 0; count < maxcount; ++count)
1889 ebins[count] = ebins[count] * Bary;
1894 params.
Emin = ebins[0];
1897 params.
Emax = ebins[maxcount - 1];
1901 params.
Emax = ebins[0];
1906 for (count = 0; count < maxcount; ++count)
1917 if (atype ==
"energy")
1924 else if (atype ==
"arb")
1929 else if (atype ==
"epn")
1969 <<
" is outside of [Emin,Emax] = ["
1972 G4Exception(
"G4SPSEneDistribution::GenerateOne()",
2039 G4cout <<
"Error: EnergyDisType has unusual value" <<
G4endl;
2060 prob = params.
cept + params.
grad * ene;
2087 prob = std::exp(-ene / params.
Ezero);
2096 G4cout <<
" Warning:G4SPSEneDistribution::GetProbability: prob<= 0. "
2097 << prob <<
" " << ene <<
G4endl;
2103 G4cout <<
"Error: EnergyDisType not supported" <<
G4endl;
static const G4double emax
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
static constexpr double keV
static constexpr double MeV
#define G4MUTEXDESTROY(mutex)
#define G4MUTEXINIT(mutex)
G4GLOB_DLL std::ostream G4cout
G4double CubicSplineInterpolation(G4double pX) const
G4double GetPDGMass() const
G4int GetBaryonNumber() const
void InsertValues(const G4double energy, const G4double value)
G4double GetEnergy(const G4double value) const
G4double GetLowEdgeEnergy(const std::size_t index) const
G4double GetMaxEnergy() const
void ScaleVector(const G4double factorE, const G4double factorV)
G4double Energy(const std::size_t index) const
G4double Value(const G4double energy, std::size_t &lastidx) const
std::size_t GetVectorLength() const
void DumpValues(G4double unitE=1.0, G4double unitV=1.0) const
std::size_t FindBin(const G4double energy, std::size_t idx) const
G4double GetProbability(G4double)
void LinearInterpolation()
void GenUserHistEnergies()
G4bool Arb_grad_cept_flag
G4double GetArbEneWeight(G4double)
G4double GenerateOne(G4ParticleDefinition *)
void InputEnergySpectra(G4bool)
void GenerateCdgEnergies()
G4double GetWeight() const
G4Cache< threadLocal_t > threadLocalData
void ArbInterpolate(const G4String &)
void SetVerbosity(G4int a)
void GenerateMonoEnergetic()
void GenerateLinearEnergies(G4bool)
void GenerateCPowEnergies()
G4PhysicsFreeVector GetUserDefinedEnergyHisto()
G4PhysicsFreeVector IPDFArbEnergyH
void GenerateExpEnergies(G4bool)
const G4String & GetEnergyDisType()
void SetBeamSigmaInE(G4double)
void GenEpnHistEnergies()
std::vector< G4DataInterpolation * > SplineInt
G4SPSRandomGenerator * eneRndm
void SetBiasAlpha(G4double)
void GenArbPointEnergies()
G4PhysicsFreeVector ArbEnergyH
void SetEnergyDisType(const G4String &)
G4PhysicsFreeVector IPDFEnergyH
void EpnEnergyHisto(const G4ThreeVector &)
G4double GetEzero() const
void ArbEnergyHistoFile(const G4String &)
void SplineInterpolation()
std::vector< G4double > * CPHist
void GeneratePowEnergies(G4bool)
void SetGradient(G4double)
G4double Getalpha() const
void ReSetHist(const G4String &)
void InputDifferentialSpectra(G4bool)
void CalculateCPowSpectrum()
void ConvertEPNToEnergy()
void GenerateBiasPowEnergies()
void CalculateBbodySpectrum()
G4DataInterpolation * Splinetemp
void CalculateCdgSpectrum()
void SetMonoEnergy(G4double)
G4PhysicsFreeVector GetArbEnergyHisto()
std::vector< G4double > * Bbody_x
void SetBiasRndm(G4SPSRandomGenerator *a)
void GenerateBbodyEnergies()
G4PhysicsFreeVector EpnEnergyH
void GenerateBremEnergies()
std::vector< G4double > * BBHist
G4bool Arb_alpha_Const_flag
const G4String & GetIntType()
void UserEnergyHisto(const G4ThreeVector &)
void SetInterCept(G4double)
G4PhysicsFreeVector UDefEnergyH
void GenerateGaussEnergies()
G4PhysicsFreeVector ZeroPhysVector
void ArbEnergyHisto(const G4ThreeVector &)
std::vector< G4double > * CP_x
static double normal(HepRandomEngine *eptr)
ThreeVector shoot(const G4int Ap, const G4int Af)
static const G4double bins[31]
G4ParticleDefinition * particle_definition