140 for ( std::vector<G4DataInterpolation*>::iterator it =
SplineInt.begin() ; it!=
SplineInt.end() ; ++it)
361 G4Exception(
"G4SPSEneDistribution::ArbEnergyHistoFile",
"Event0301",
FatalException,
"Unable to open the histo ASCII file");
364 while (infile >> ehi >> val)
407 BBHist =
new std::vector<G4double>(10001, 0.0);
408 Bbody_x =
new std::vector<G4double>(10001, 0.0);
449 omalpha = 1. - spind[i];
450 CDGhist[i + 1] =
CDGhist[i] + (pfact[i] / omalpha) * (std::pow(ene_line[i + 1] / keV, omalpha) - std::pow(ene_line[i] / keV,omalpha));
486 while (count < 10000) {
497 while (count < 10001) {
522 G4Exception(
"G4SPSEneDistribution::ArbInterpolate",
524 "Error: this is for arbitrary distributions");
548 G4double sum = 0., Arb_x[1024], Arb_y[1024], Arb_Cum_Area[1024];
551 for (i = 0; i < maxi; i++)
561 for (count = 0; count < maxi - 1; count++)
563 Arb_y[count] = (Arb_y[count] - Arb_y[count + 1])
564 / (Arb_x[count + 1] - Arb_x[count]);
576 G4Exception(
"G4SPSEneDistribution::LinearInterpolation",
578 "Error: particle not defined");
588 for (count = 0; count < maxi; count++)
590 total_energy = std::sqrt((Arb_x[count] * Arb_x[count]) + (mass
593 Arb_y[count] = Arb_y[count] * Arb_x[count] / total_energy;
594 Arb_x[count] = total_energy - mass;
610 Arb_Cum_Area[0] = 0.;
614 Arb_grad[i] = (Arb_y[i] - Arb_y[i - 1]) / (Arb_x[i] - Arb_x[i - 1]);
644 Area_seg[i] = ((
Arb_grad[i] / 2) * (Arb_x[i] * Arb_x[i] - Arb_x[i - 1] * Arb_x[i - 1]) +
Arb_cept[i] * (Arb_x[i] - Arb_x[i - 1]));
645 Arb_Cum_Area[i] = Arb_Cum_Area[i - 1] + Area_seg[i];
646 sum = sum + Area_seg[i];
657 Arb_Cum_Area[i] = Arb_Cum_Area[i] / sum;
682 G4double sum = 0., Arb_x[1024], Arb_y[1024], Arb_Cum_Area[1024];
685 for (i = 0; i < maxi; i++)
695 for (count = 0; count < maxi - 1; count++)
697 Arb_y[count] = (Arb_y[count] - Arb_y[count + 1]) / (Arb_x[count + 1] - Arb_x[count]);
709 G4Exception(
"G4SPSEneDistribution::LogInterpolation",
711 "Error: particle not defined");
721 for (count = 0; count < maxi; count++)
723 total_energy = std::sqrt((Arb_x[count] * Arb_x[count]) + (mass
726 Arb_y[count] = Arb_y[count] * Arb_x[count] / total_energy;
727 Arb_x[count] = total_energy - mass;
745 Arb_Cum_Area[0] = 0.;
746 if (Arb_x[0] <= 0. || Arb_y[0] <= 0.)
748 G4cout <<
"You should not use log interpolation with points <= 0." <<
G4endl;
749 G4cout <<
"These will be changed to 1e-20, which may cause problems" <<
G4endl;
764 if (Arb_x[i] <= 0. || Arb_y[i] <= 0.)
766 G4cout <<
"You should not use log interpolation with points <= 0." <<
G4endl;
767 G4cout <<
"These will be changed to 1e-20, which may cause problems" <<
G4endl;
778 Arb_alpha[i] = (std::log10(Arb_y[i]) - std::log10(Arb_y[i - 1])) / (std::log10(Arb_x[i]) - std::log10(Arb_x[i - 1]));
783 Area_seg[i] =
Arb_Const[i] * (std::log(Arb_x[i]) - std::log(Arb_x[i - 1]));
787 Area_seg[i] = (
Arb_Const[i] / alp) * (std::pow(Arb_x[i], alp) - std::pow(Arb_x[i - 1], alp));
789 sum = sum + Area_seg[i];
790 Arb_Cum_Area[i] = Arb_Cum_Area[i - 1] + Area_seg[i];
801 Arb_Cum_Area[i] = Arb_Cum_Area[i] / sum;
824 G4double sum = 0., Arb_x[1024], Arb_y[1024], Arb_Cum_Area[1024];
827 for (i = 0; i < maxi; i++)
837 for (count = 0; count < maxi - 1; count++)
839 Arb_y[count] = (Arb_y[count] - Arb_y[count + 1])
840 / (Arb_x[count + 1] - Arb_x[count]);
852 G4Exception(
"G4SPSEneDistribution::ExpInterpolation",
854 "Error: particle not defined");
864 for (count = 0; count < maxi; count++)
866 total_energy = std::sqrt((Arb_x[count] * Arb_x[count]) + (mass * mass));
867 Arb_y[count] = Arb_y[count] * Arb_x[count] / total_energy;
868 Arb_x[count] = total_energy - mass;
885 Arb_Cum_Area[0] = 0.;
888 G4double test = std::log(Arb_y[i]) - std::log(Arb_y[i - 1]);
889 if (test > 0. || test < 0.)
891 Arb_ezero[i] = -(Arb_x[i] - Arb_x[i - 1]) / (std::log(Arb_y[i]) - std::log(Arb_y[i - 1]));
897 G4Exception(
"G4SPSEneDistribution::ExpInterpolation",
899 "Flat line segment: problem, setting to zero parameters.");
905 sum = sum + Area_seg[i];
906 Arb_Cum_Area[i] = Arb_Cum_Area[i - 1] + Area_seg[i];
917 Arb_Cum_Area[i] = Arb_Cum_Area[i] / sum;
941 G4double sum, Arb_x[1024], Arb_y[1024], Arb_Cum_Area[1024];
945 for (i = 0; i < maxi; i++) {
953 for (count = 0; count < maxi - 1; count++)
955 Arb_y[count] = (Arb_y[count] - Arb_y[count + 1]) / (Arb_x[count + 1] - Arb_x[count]);
965 G4Exception(
"G4SPSEneDistribution::SplineInterpolation",
967 "Error: particle not defined");
975 for (count = 0; count < maxi; count++) {
976 total_energy = std::sqrt((Arb_x[count] * Arb_x[count]) + (mass
979 Arb_y[count] = Arb_y[count] * Arb_x[count] / total_energy;
980 Arb_x[count] = total_energy - mass;
987 Arb_Cum_Area[0] = 0.;
991 for ( std::vector<G4DataInterpolation*>::iterator it =
SplineInt.begin() ; it!=
SplineInt.end() ; ++it)
1000 G4double de = (Arb_x[i] - Arb_x[i - 1])/100.;
1003 for (count = 0; count < 101; count++) {
1004 ei[count] = Arb_x[i - 1] + de*count ;
1006 if (prob[count] < 0.) {
1008 ED <<
"Warning: G4DataInterpolation returns value < 0 " << prob[count] <<
" "<<ei[count]<<
G4endl;
1009 G4Exception(
"G4SPSEneDistribution::SplineInterpolation",
"Event0303",
1012 area += prob[count]*de;
1014 Arb_Cum_Area[i] = Arb_Cum_Area[i - 1] + area;
1017 prob[0] = prob[0]/(area/de);
1018 for (count = 1; count < 100; count++)
1019 prob[count] = prob[count-1] + prob[count]/(area/de);
1027 Arb_Cum_Area[i] = Arb_Cum_Area[i] / sum;
1046 if (ene < 0) ene = 0.;
1063 bracket = bracket * rndm;
1064 bracket = bracket + (params.
grad / 2.) * eminsq + params.
cept * params.
Emin;
1068 if (params.
grad != 0.)
1070 G4double sqbrack = (intersq - 4 * (params.
grad / 2.) * (bracket));
1072 sqbrack = std::sqrt(sqbrack);
1074 root1 = root1 / (2. * (params.
grad / 2.));
1077 root2 = root2 / (2. * (params.
grad / 2.));
1081 if (root1 > params.
Emin && root1 < params.
Emax)
1085 if (root2 > params.
Emin && root2 < params.
Emax)
1090 else if (params.
grad == 0.)
1117 emina = std::pow(params.
Emin, params.
alpha + 1);
1118 emaxa = std::pow(params.
Emax, params.
alpha + 1);
1129 if (params.
alpha != -1.)
1131 G4double ene = ((rndm * (emaxa - emina)) + emina);
1132 ene = std::pow(ene, (1. / (params.
alpha + 1.)));
1137 G4double ene = (std::log(params.
Emin) + rndm * (std::log(params.
Emax) - std::log(params.
Emin)));
1171 G4double ee = ((rndm * (emaxa - emina)) + emina);
1173 normal = 1./(1+
biasalpha) * (emaxa - emina);
1177 G4double ee = (std::log(emin) + rndm * (std::log(emax) - std::log(emin)));
1179 normal = std::log(emax) - std::log(emin) ;
1229 expmax = std::exp(-params.
Emax / (k *
Temp));
1230 expmin = std::exp(-params.
Emin / (k * Temp));
1237 G4Exception(
"G4SPSEneDistribution::GenerateBremEnergies",
1239 "*****EXPMAX=0. Choose different E's or Temp");
1243 G4Exception(
"G4SPSEneDistribution::GenerateBremEnergies",
1245 "*****EXPMIN=0. Choose different E's or Temp");
1248 G4double tempvar = rndm * ((-k) * Temp * (params.
Emax * expmax - params.
Emin * expmin) - (ksq * Tsq * (expmax - expmin)));
1250 G4double bigc = (tempvar - k * Temp * params.
Emin * expmin - ksq * Tsq * expmin) / (-k * Temp);
1263 for (i = 1; i < 1000; i++)
1265 etest = params.
Emin + (i - 1) * steps;
1267 diff = etest * (std::exp(-etest / (k * Temp))) + k * Temp * (std::exp(-etest / (k * Temp))) - bigc;
1293 G4int nabove, nbelow = 0, middle;
1308 while (nabove - nbelow > 1)
1310 middle = (nabove + nbelow) / 2;
1311 if (rndm ==
BBHist->at(middle))
1315 if (rndm < BBHist->at(middle))
1328 if(nbelow+1 == static_cast<G4int>(
Bbody_x->size()))
1337 if(nbelow+1 == static_cast<G4int>(
BBHist->size()))
1344 y2 =
BBHist->at(nbelow + 1);
1346 t = (y2 -
y1) / (x2 - x1);
1369 omalpha[0] = 1. - 1.4;
1370 ene_line[0] = params.
Emin;
1371 ene_line[1] = params.
Emax;
1375 omalpha[0] = 1. - 1.4;
1376 omalpha[1] = 1. - 2.3;
1377 ene_line[0] = params.
Emin;
1378 ene_line[1] = 18. *
keV;
1379 ene_line[2] = params.
Emax;
1383 omalpha[0] = 1. - 2.3;
1384 ene_line[0] = params.
Emin;
1385 ene_line[1] = params.
Emax;
1396 G4double ene = (std::pow(ene_line[i - 1], omalpha[i - 1]) + (std::pow(ene_line[i], omalpha[i - 1]) - std::pow(ene_line[i - 1], omalpha[i- 1])) * rndm2);
1414 G4double bins[1024], vals[1024], sum;
1415 for ( ii = 0 ; ii<1024 ; ++ii ) { bins[ii]=0; vals[ii]=0; }
1420 G4Exception(
"G4SPSEneDistribution::GenUserHistEnergies",
1422 "Error: particle definition is NULL");
1427 G4Exception(
"G4SPSEneDistribution::GenUserHistEnergies",
1428 "Event0302",
JustWarning,
"Maxbin>1024\n Setting maxbin to 1024, other bins are lost");
1441 for (ii = 1; ii < maxbin; ii++)
1444 vals[ii] =
UDefEnergyH(
size_t(ii)) + vals[ii - 1];
1455 for (ii = 1; ii < maxbin; ii++)
1457 vals[ii] = vals[ii] * (bins[ii] - bins[ii - 1]);
1461 for (ii = 0; ii < maxbin; ii++)
1463 bins[ii] = std::sqrt((bins[ii] * bins[ii]) + (mass * mass))- mass;
1465 for (ii = 1; ii < maxbin; ii++)
1467 vals[ii] = vals[ii] / (bins[ii] - bins[ii - 1]);
1469 sum = vals[maxbin - 1];
1472 for (ii = 0; ii < maxbin; ii++)
1474 vals[ii] = vals[ii] / sum;
1508 G4int nabove, nbelow = 0, middle;
1512 while (nabove - nbelow > 1)
1514 middle = (nabove + nbelow) / 2;
1573 G4Exception(
"G4SPSEneDistribution::GenArbPointEnergies",
"Event0302",
1594 G4double bins[1024], vals[1024], sum;
1600 for (ii = 1; ii < maxbin; ii++)
1603 vals[ii] =
UDefEnergyH(
size_t(ii)) + vals[ii - 1];
1608 for (ii = 0; ii < maxbin; ii++)
1610 vals[ii] = vals[ii] / sum;
1648 G4int count, maxcount;
1652 if (maxcount > 1024)
1655 "Histogram contains more than 1024 bins!\nThose above 1024 will be ignored");
1660 G4Exception(
"G4SPSEneDistribution::ConvertEPNToEnergy()",
"gps001",
FatalException,
"Histogram contains less than 1 bin!\nRedefine the histogram");
1663 for (count = 0; count < maxcount; count++)
1671 for (count = 0; count < maxcount; count++)
1673 ebins[count] = ebins[count] * Bary;
1677 params.
Emin = ebins[0];
1680 params.
Emax = ebins[maxcount - 1];
1684 params.
Emax = ebins[0];
1687 for (count = 0; count < maxcount; count++)
1699 if (atype ==
"energy")
1706 else if (atype ==
"arb")
1711 else if (atype ==
"epn")
1791 G4cout <<
"Error: EnergyDisType has unusual value" <<
G4endl;
1809 prob = params.
cept + params.
grad * ene;
1835 prob = std::exp(-ene / params.
Ezero);
1847 G4cout <<
" Warning:G4SPSEneDistribution::GetProbability: prob<= 0. "<<prob <<
" "<<ene <<
G4endl;
1854 G4cout <<
"Error: EnergyDisType not supported" <<
G4endl;
void SetBeamSigmaInE(G4double)
G4bool Arb_alpha_Const_flag
ThreeVector shoot(const G4int Ap, const G4int Af)
std::vector< G4DataInterpolation * > SplineInt
void CalculateBbodySpectrum()
void LinearInterpolation()
void GenEpnHistEnergies()
void CalculateCdgSpectrum()
G4double CubicSplineInterpolation(G4double pX) const
G4int GetBaryonNumber() const
std::ostringstream G4ExceptionDescription
void ArbEnergyHisto(G4ThreeVector)
G4PhysicsOrderedFreeVector GetUserDefinedEnergyHisto()
void SetVerbosity(G4int a)
G4bool Arb_grad_cept_flag
void ConvertEPNToEnergy()
#define G4MUTEXINIT(mutex)
void GenerateCdgEnergies()
void InsertValues(G4double energy, G4double value)
void GenArbPointEnergies()
std::vector< G4double > * Bbody_x
G4PhysicsOrderedFreeVector GetArbEnergyHisto()
G4ParticleDefinition * particle_definition
void GenerateGaussEnergies()
G4PhysicsOrderedFreeVector IPDFEnergyH
G4double GetMaxLowEdgeEnergy()
static double normal(HepRandomEngine *eptr)
G4double GetLowEdgeEnergy(size_t binNumber) const
G4GLOB_DLL std::ostream G4cout
void SetEnergyDisType(G4String)
G4String GetEnergyDisType()
void GenerateBremEnergies()
G4double GetProbability(G4double)
G4DataInterpolation * Splinetemp
void GenerateMonoEnergetic()
G4double GenerateOne(G4ParticleDefinition *)
virtual void ScaleVector(G4double factorE, G4double factorV)
void SetBiasRndm(G4SPSRandomGenerator *a)
size_t GetVectorLength() const
G4double Value(G4double theEnergy, size_t &lastidx) const
std::vector< G4double > * BBHist
G4double GetEnergy(G4double aValue)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
void ArbInterpolate(G4String)
static const G4double emax
void EpnEnergyHisto(G4ThreeVector)
G4PhysicsOrderedFreeVector ArbEnergyH
void InputEnergySpectra(G4bool)
G4SPSRandomGenerator * eneRndm
G4PhysicsOrderedFreeVector UDefEnergyH
void SetGradient(G4double)
void UserEnergyHisto(G4ThreeVector)
void GenUserHistEnergies()
void GenerateBbodyEnergies()
void GenerateExpEnergies(G4bool)
G4double GetPDGMass() const
void SetInterCept(G4double)
void InputDifferentialSpectra(G4bool)
G4PhysicsOrderedFreeVector EpnEnergyH
void GeneratePowEnergies(G4bool)
void SetBiasAlpha(G4double)
void ArbEnergyHistoFile(G4String)
G4double GetMinLowEdgeEnergy()
G4PhysicsOrderedFreeVector IPDFArbEnergyH
#define G4MUTEXDESTROY(mutex)
void GenerateBiasPowEnergies()
void GenerateLinearEnergies(G4bool)
void SplineInterpolation()
G4Cache< threadLocal_t > threadLocalData
void SetMonoEnergy(G4double)
G4PhysicsOrderedFreeVector ZeroPhysVector