47 particle_energy = 1.0 * MeV;
48 EnergyDisType =
"Mono";
68 threadLocal_t& data = threadLocalData.
Get();
75 data.particle_energy = 0.;
76 data.particle_definition =
nullptr;
83 if(Arb_grad_cept_flag)
89 if(Arb_alpha_Const_flag)
103 for (
auto it=SplineInt.begin() ; it!=SplineInt.end() ; ++it )
114 EnergyDisType = DisType;
115 if (EnergyDisType ==
"User")
117 UDefEnergyH = IPDFEnergyH = ZeroPhysVector;
118 IPDFEnergyExist =
false;
120 else if (EnergyDisType ==
"Arb")
122 ArbEnergyH = IPDFArbEnergyH = ZeroPhysVector;
123 IPDFArbExist =
false;
125 else if (EnergyDisType ==
"Epn")
127 UDefEnergyH = IPDFEnergyH = ZeroPhysVector;
128 IPDFEnergyExist =
false;
129 EpnEnergyH = ZeroPhysVector;
136 return EnergyDisType;
143 threadLocalData.
Get().Emin = Emin;
148 return threadLocalData.
Get().Emin;
167 threadLocalData.
Get().Emax = Emax;
172 return threadLocalData.
Get().Emax;
178 MonoEnergy = menergy;
190 threadLocalData.
Get().alpha = alpha;
210 threadLocalData.
Get().Ezero = Ezero;
217 threadLocalData.
Get().grad = grad;
224 threadLocalData.
Get().cept = cept;
247 return threadLocalData.
Get().weight;
264 return threadLocalData.
Get().alpha;
269 return threadLocalData.
Get().Ezero;
280 return threadLocalData.
Get().grad;
285 return threadLocalData.
Get().cept;
305 if (verbosityLevel > 1)
312 threadLocalData.
Get().Emax = Emax;
320 if (verbosityLevel > 1)
331 std::ifstream infile(filename, std::ios::in);
334 G4Exception(
"G4SPSEneDistribution::ArbEnergyHistoFile",
"Event0301",
338 while (infile >> ehi >> val)
349 if (verbosityLevel > 1)
356 threadLocalData.
Get().Emax = Emax;
363 if (EnergyDisType ==
"Cdg")
365 CalculateCdgSpectrum();
367 else if (EnergyDisType ==
"Bbody")
373 CalculateBbodySpectrum();
375 else if (EnergyDisType ==
"CPow")
381 CalculateCPowSpectrum();
385void G4SPSEneDistribution::BBInitHists()
387 BBHist =
new std::vector<G4double>(10001, 0.0);
388 Bbody_x =
new std::vector<G4double>(10001, 0.0);
392void G4SPSEneDistribution::CPInitHists()
394 CPHist =
new std::vector<G4double>(10001, 0.0);
395 CP_x =
new std::vector<G4double>(10001, 0.0);
399void G4SPSEneDistribution::CalculateCdgSpectrum()
406 G4double ene_line[3] = { 1. * keV, 18. * keV, 1E6 * keV };
409 ene_line[0] = threadLocalData.
Get().Emin;
410 if (threadLocalData.
Get().Emin < 18 * keV)
413 ene_line[2] = threadLocalData.
Get().Emax;
414 if (threadLocalData.
Get().Emax < 18 * keV)
417 ene_line[1] = threadLocalData.
Get().Emax;
425 ene_line[1] = threadLocalData.
Get().Emax;
435 omalpha = 1. - spind[i];
436 CDGhist[i + 1] = CDGhist[i] + (pfact[i] / omalpha)
437 * (std::pow(ene_line[i + 1] / keV, omalpha)
438 - std::pow(ene_line[i] / keV,omalpha));
447 CDGhist[i + 1] = CDGhist[i + 1] / CDGhist[n_par];
452void G4SPSEneDistribution::CalculateBbodySpectrum()
461 G4double erange = threadLocalData.
Get().Emax - threadLocalData.
Get().Emin;
473 while (count < 10000)
475 Bbody_x->at(count) = threadLocalData.
Get().Emin +
G4double(count * steps);
476 G4double Bbody_y = (2. * std::pow(Bbody_x->at(count), 2.))
477 / (h2*c2*(std::exp(Bbody_x->at(count) / (k*Temp)) - 1.));
479 BBHist->at(count + 1) = BBHist->at(count) + Bbody_y;
483 Bbody_x->at(10000) = threadLocalData.
Get().Emax;
488 while (count < 10001)
490 BBHist->at(count) = BBHist->at(count) / sum;
495void G4SPSEneDistribution::CalculateCPowSpectrum()
504 G4double erange = threadLocalData.
Get().Emax - threadLocalData.
Get().Emin;
506 alpha = threadLocalData.
Get().alpha ;
507 Ezero = threadLocalData.
Get().Ezero ;
513 while (count < 10000)
515 CP_x->at(count) = threadLocalData.
Get().Emin +
G4double(count * steps);
516 G4double CP_y = std::pow(CP_x->at(count), alpha)
517 * std::exp(-CP_x->at(count) / Ezero);
519 CPHist->at(count + 1) = CPHist->at(count) + CP_y;
523 CP_x->at(10000) = threadLocalData.
Get().Emax;
528 while (count < 10001)
530 CPHist->at(count) = CPHist->at(count) / sum;
542 if (verbosityLevel > 1)
544 G4cout <<
"EnergySpec has value " << EnergySpec <<
G4endl;
555 if (verbosityLevel > 1)
571 if (IntType ==
"Lin") LinearInterpolation();
572 if (IntType ==
"Log") LogInterpolation();
573 if (IntType ==
"Exp") ExpInterpolation();
574 if (IntType ==
"Spline") SplineInterpolation();
577void G4SPSEneDistribution::LinearInterpolation()
585 G4double sum = 0., Arb_x[1024], Arb_y[1024], Arb_Cum_Area[1024];
588 for (i = 0; i < maxi; ++i)
591 Arb_y[i] = ArbEnergyH(std::size_t(i));
597 if (DiffSpec ==
false)
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]);
609 if (EnergySpec ==
false)
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;
646 Arb_grad_cept_flag =
true;
651 Arb_Cum_Area[0] = 0.;
656 Arb_grad[i] = (Arb_y[i] - Arb_y[i - 1]) / (Arb_x[i] - Arb_x[i - 1]);
657 if (verbosityLevel == 2)
661 if (Arb_grad[i] > 0.)
663 if (verbosityLevel == 2)
667 Arb_cept[i] = Arb_y[i] - (Arb_grad[i] * Arb_x[i]);
669 else if (Arb_grad[i] < 0.)
671 if (verbosityLevel == 2)
675 Arb_cept[i] = Arb_y[i] + (-Arb_grad[i] * Arb_x[i]);
679 if (verbosityLevel == 2)
683 Arb_cept[i] = Arb_y[i];
686 Area_seg[i] = ((Arb_grad[i] / 2)
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];
691 if (verbosityLevel == 2)
693 G4cout << Arb_x[i] << Arb_y[i] << Area_seg[i] << sum
702 Arb_Cum_Area[i] = Arb_Cum_Area[i] / sum;
711 if (verbosityLevel >= 1)
719void G4SPSEneDistribution::LogInterpolation()
728 G4double sum = 0., Arb_x[1024], Arb_y[1024], Arb_Cum_Area[1024];
731 for (i = 0; i < maxi; ++i)
734 Arb_y[i] = ArbEnergyH(std::size_t(i));
740 if (DiffSpec ==
false)
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]);
752 if (EnergySpec ==
false)
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;
786 if ( Arb_ezero ) {
delete [] Arb_ezero; Arb_ezero = 0; }
787 if ( Arb_Const ) {
delete [] Arb_Const; Arb_Const = 0; }
790 Arb_alpha_Const_flag =
true;
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]));
835 Arb_Const[i] = Arb_y[i] / (std::pow(Arb_x[i], Arb_alpha[i]));
836 alp = Arb_alpha[i] + 1;
839 Area_seg[i] = Arb_Const[i]
840 * (std::log(Arb_x[i]) - std::log(Arb_x[i - 1]));
844 Area_seg[i] = (Arb_Const[i] / alp)
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];
849 if (verbosityLevel == 2)
851 G4cout << Arb_alpha[i] << Arb_Const[i] << Area_seg[i] <<
G4endl;
859 Arb_Cum_Area[i] = Arb_Cum_Area[i] / sum;
868 if (verbosityLevel >= 1)
874void G4SPSEneDistribution::ExpInterpolation()
883 G4double sum = 0., Arb_x[1024], Arb_y[1024], Arb_Cum_Area[1024];
886 for (i = 0; i < maxi; ++i)
889 Arb_y[i] = ArbEnergyH(std::size_t(i));
895 if (DiffSpec ==
false)
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]);
907 if (EnergySpec ==
false)
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;
941 if ( Arb_ezero ) {
delete[] Arb_ezero; Arb_ezero = 0; }
942 if ( Arb_Const ) {
delete[] Arb_Const; Arb_Const = 0; }
945 Arb_ezero_flag =
true;
950 Arb_Cum_Area[0] = 0.;
953 G4double test = std::log(Arb_y[i]) - std::log(Arb_y[i - 1]);
954 if (test > 0. || test < 0.)
956 Arb_ezero[i] = -(Arb_x[i] - Arb_x[i - 1])
957 / (std::log(Arb_y[i]) - std::log(Arb_y[i - 1]));
958 Arb_Const[i] = Arb_y[i] / (std::exp(-Arb_x[i] / Arb_ezero[i]));
959 Area_seg[i] = -(Arb_Const[i] * Arb_ezero[i])
960 * (std::exp(-Arb_x[i] / Arb_ezero[i])
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];
975 if (verbosityLevel == 2)
977 G4cout << Arb_ezero[i] << Arb_Const[i] << Area_seg[i] <<
G4endl;
985 Arb_Cum_Area[i] = Arb_Cum_Area[i] / sum;
994 if (verbosityLevel >= 1)
1000void G4SPSEneDistribution::SplineInterpolation()
1008 G4double sum, Arb_x[1024], Arb_y[1024], Arb_Cum_Area[1024];
1012 for (i = 0; i < maxi; ++i)
1015 Arb_y[i] = ArbEnergyH(std::size_t(i));
1021 if (DiffSpec ==
false)
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]);
1033 if (EnergySpec ==
false)
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.;
1070 for (
auto it = SplineInt.begin(); it!=SplineInt.end() ; ++it)
1076 SplineInt.resize(1024,
nullptr);
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;
1118 IPDFArbEnergyH.
InsertValues(Arb_x[i], Arb_Cum_Area[i]);
1126 if (verbosityLevel > 0)
1132void G4SPSEneDistribution::GenerateMonoEnergetic()
1136 threadLocalData.
Get().particle_energy = MonoEnergy;
1139void G4SPSEneDistribution::GenerateGaussEnergies()
1143 G4double ene = G4RandGauss::shoot(MonoEnergy,SE);
1144 if (ene < 0) ene = 0.;
1145 threadLocalData.
Get().particle_energy = ene;
1148void G4SPSEneDistribution::GenerateLinearEnergies(
G4bool bArb =
false)
1151 threadLocal_t& params = threadLocalData.
Get();
1152 G4double emaxsq = std::pow(params.Emax, 2.);
1153 G4double eminsq = std::pow(params.Emin, 2.);
1154 G4double intersq = std::pow(params.cept, 2.);
1159 G4double bracket = ((params.grad / 2.)
1161 + params.cept * (params.Emax - params.Emin));
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);
1173 G4double root1 = -params.cept + sqbrack;
1174 root1 = root1 / (2. * (params.grad / 2.));
1176 G4double root2 = -params.cept - sqbrack;
1177 root2 = root2 / (2. * (params.grad / 2.));
1179 if (root1 > params.Emin && root1 < params.Emax)
1181 params.particle_energy = root1;
1183 if (root2 > params.Emin && root2 < params.Emax)
1185 params.particle_energy = root2;
1188 else if (params.grad == 0.)
1192 params.particle_energy = bracket / params.cept;
1195 if (params.particle_energy < 0.)
1197 params.particle_energy = -params.particle_energy;
1200 if (verbosityLevel >= 1)
1202 G4cout <<
"Energy is " << params.particle_energy <<
G4endl;
1206void G4SPSEneDistribution::GeneratePowEnergies(
G4bool bArb =
false)
1213 threadLocal_t& params = threadLocalData.
Get();
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.)));
1225 params.particle_energy = ene;
1229 G4double ene = (std::log(params.Emin)
1230 + rndm * (std::log(params.Emax) - std::log(params.Emin)));
1231 params.particle_energy = std::exp(ene);
1233 if (verbosityLevel >= 1)
1235 G4cout <<
"Energy is " << params.particle_energy <<
G4endl;
1239void G4SPSEneDistribution::GenerateCPowEnergies()
1250 G4int nabove = 10001, nbelow = 0, middle;
1253 G4bool done = CPhistCalcd;
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);
1295 y1 = CPHist->at(nbelow);
1296 if(nbelow+1 ==
static_cast<G4int>(CPHist->size()))
1299 y2 = CPHist->back();
1303 y2 = CPHist->at(nbelow + 1);
1305 t = (y2 - y1) / (x2 - x1);
1308 threadLocalData.
Get().particle_energy = (rndm - q) / t;
1310 if (verbosityLevel >= 1)
1312 G4cout <<
"Energy is " << threadLocalData.
Get().particle_energy <<
G4endl;
1316void G4SPSEneDistribution::GenerateBiasPowEnergies()
1321 threadLocal_t& params = threadLocalData.
Get();
1333 if (biasalpha != -1.)
1335 emina = std::pow(emin, biasalpha + 1);
1336 emaxa = std::pow(emax, biasalpha + 1);
1337 G4double ee = ((rndm * (emaxa - emina)) + emina);
1338 params.particle_energy = std::pow(ee, (1. / (biasalpha + 1.)));
1339 normal = 1./(1+biasalpha) * (emaxa - emina);
1343 G4double ee = (std::log(emin) + rndm * (std::log(emax) - std::log(emin)));
1344 params.particle_energy = std::exp(ee);
1345 normal = std::log(emax) - std::log(emin);
1348 / (std::pow(params.particle_energy,biasalpha)/normal);
1350 if (verbosityLevel >= 1)
1352 G4cout <<
"Energy is " << params.particle_energy <<
G4endl;
1356void G4SPSEneDistribution::GenerateExpEnergies(
G4bool bArb =
false)
1366 threadLocal_t& params = threadLocalData.
Get();
1367 params.particle_energy = -params.Ezero
1368 * (std::log(rndm * (std::exp(-params.Emax
1370 - std::exp(-params.Emin
1372 + std::exp(-params.Emin / params.Ezero)));
1373 if (verbosityLevel >= 1)
1375 G4cout <<
"Energy is " << params.particle_energy <<
G4endl;
1379void G4SPSEneDistribution::GenerateBremEnergies()
1392 threadLocal_t& params = threadLocalData.
Get();
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");
1413 G4double tempvar = rndm * ((-k) * Temp * (params.Emax * expmax
1414 - params.Emin * expmin)
1415 - (ksq * Tsq * (expmax - expmin)));
1417 G4double bigc = (tempvar - k * Temp * params.Emin * expmin
1418 - ksq * Tsq * expmin) / (-k * Temp);
1424 G4double erange = params.Emax - params.Emin;
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;
1443 params.particle_energy = etest;
1446 if (verbosityLevel >= 1)
1448 G4cout <<
"Energy is " << params.particle_energy <<
G4endl;
1452void G4SPSEneDistribution::GenerateBbodyEnergies()
1460 G4int nabove = 10001, nbelow = 0, middle;
1463 G4bool done = BBhistCalcd;
1476 while (nabove - nbelow > 1)
1478 middle = (nabove + nbelow) / 2;
1479 if (rndm == BBHist->at(middle))
1483 if (rndm < BBHist->at(middle))
1496 x1 = Bbody_x->at(nbelow);
1498 if(nbelow+1 ==
static_cast<G4int>(Bbody_x->size()))
1500 x2 = Bbody_x->back();
1504 x2 = Bbody_x->at(nbelow + 1);
1506 y1 = BBHist->at(nbelow);
1507 if(nbelow+1 ==
static_cast<G4int>(BBHist->size()))
1510 y2 = BBHist->back();
1514 y2 = BBHist->at(nbelow + 1);
1516 t = (y2 - y1) / (x2 - x1);
1519 threadLocalData.
Get().particle_energy = (rndm - q) / t;
1521 if (verbosityLevel >= 1)
1523 G4cout <<
"Energy is " << threadLocalData.
Get().particle_energy <<
G4endl;
1527void G4SPSEneDistribution::GenerateCdgEnergies()
1536 threadLocal_t& params = threadLocalData.
Get();
1537 if (params.Emin < 18 * keV && params.Emax < 18 * keV)
1539 omalpha[0] = 1. - 1.4;
1540 ene_line[0] = params.Emin;
1541 ene_line[1] = params.Emax;
1543 if (params.Emin < 18 * keV && params.Emax > 18 * keV)
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;
1551 if (params.Emin > 18 * keV)
1553 omalpha[0] = 1. - 2.3;
1554 ene_line[0] = params.Emin;
1555 ene_line[1] = params.Emax;
1561 while (rndm >= CDGhist[i])
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);
1571 params.particle_energy = std::pow(ene, (1. / omalpha[i - 1]));
1573 if (verbosityLevel >= 1)
1575 G4cout <<
"Energy is " << params.particle_energy <<
G4endl;
1579void G4SPSEneDistribution::GenUserHistEnergies()
1585 if (IPDFEnergyExist ==
false)
1589 G4double bins[1024], vals[1024], sum;
1590 for ( ii = 0 ; ii<1024 ; ++ii ) { bins[ii]=0; vals[ii]=0; }
1593 if ( (EnergySpec ==
false)
1594 && (threadLocalData.
Get().particle_definition ==
nullptr))
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");
1609 if (DiffSpec ==
false)
1616 vals[0] = UDefEnergyH(std::size_t(0));
1618 for (ii = 1; ii < maxbin; ++ii)
1621 vals[ii] = UDefEnergyH(std::size_t(ii)) + vals[ii - 1];
1622 sum = sum + UDefEnergyH(std::size_t(ii));
1626 if (EnergySpec ==
false)
1628 G4double mass = threadLocalData.
Get().particle_definition->GetPDGMass();
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;
1660 IPDFEnergyExist =
true;
1661 if (verbosityLevel > 1)
1671 threadLocalData.
Get().particle_energy= IPDFEnergyH.
GetEnergy(rndm);
1673 if (verbosityLevel >= 1)
1686 auto gr = Arb_grad[nbelow + 1];
1687 auto ce = Arb_cept[nbelow + 1];
1690 else if(IntType==
"Log")
1692 auto alp = Arb_alpha[nbelow + 1];
1693 auto cns = Arb_Const[nbelow + 1];
1694 wei = cns * std::pow(ene,alp);
1696 else if(IntType==
"Exp")
1698 auto e0 = Arb_ezero[nbelow + 1];
1699 auto cns = Arb_Const[nbelow + 1];
1700 wei = cns * std::exp(-ene/e0);
1702 else if(IntType==
"Spline")
1704 wei = SplineInt[nbelow+1]->CubicSplineInterpolation(ene);
1709void G4SPSEneDistribution::GenArbPointEnergies()
1711 if (verbosityLevel > 0)
1724 while (nabove - nbelow > 1)
1726 middle = (nabove + nbelow) / 2;
1727 if (rndm == IPDFArbEnergyH(std::size_t(middle)))
1731 if (rndm < IPDFArbEnergyH(std::size_t(middle)))
1740 threadLocal_t& params = threadLocalData.
Get();
1741 if (IntType ==
"Lin")
1747 params.grad = Arb_grad[nbelow + 1];
1748 params.cept = Arb_cept[nbelow + 1];
1749 GenerateLinearEnergies(
true);
1751 else if (IntType ==
"Log")
1755 params.alpha = Arb_alpha[nbelow + 1];
1756 GeneratePowEnergies(
true);
1758 else if (IntType ==
"Exp")
1762 params.Ezero = Arb_ezero[nbelow + 1];
1763 GenerateExpEnergies(
true);
1765 else if (IntType ==
"Spline")
1769 params.particle_energy = -1e100;
1771 while (params.particle_energy < params.Emin
1772 || params.particle_energy > params.Emax)
1774 params.particle_energy =
1775 SplineInt[nbelow+1]->CubicSplineInterpolation(rndm);
1778 if (verbosityLevel >= 1)
1780 G4cout <<
"Energy is " << params.particle_energy <<
G4endl;
1785 G4Exception(
"G4SPSEneDistribution::GenArbPointEnergies",
"Event0302",
1790void G4SPSEneDistribution::GenEpnHistEnergies()
1796 if (Epnflag ==
true)
1800 ConvertEPNToEnergy();
1802 if (IPDFEnergyExist ==
false)
1806 G4double bins[1024], vals[1024], sum;
1810 vals[0] = UDefEnergyH(std::size_t(0));
1812 for (ii = 1; ii < maxbin; ++ii)
1815 vals[ii] = UDefEnergyH(std::size_t(ii)) + vals[ii - 1];
1816 sum = sum + UDefEnergyH(std::size_t(ii));
1820 for (ii = 0; ii < maxbin; ++ii)
1822 vals[ii] = vals[ii] / sum;
1825 IPDFEnergyExist =
true;
1833 threadLocalData.
Get().particle_energy = IPDFEnergyH.
GetEnergy(rndm);
1835 if (verbosityLevel >= 1)
1837 G4cout <<
"Energy is " << threadLocalData.
Get().particle_energy <<
G4endl;
1841void G4SPSEneDistribution::ConvertEPNToEnergy()
1846 threadLocal_t& params = threadLocalData.
Get();
1847 if (params.particle_definition ==
nullptr)
1856 G4int Bary = params.particle_definition->GetBaryonNumber();
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")
1919 UDefEnergyH = IPDFEnergyH = ZeroPhysVector;
1920 IPDFEnergyExist =
false;
1924 else if (atype ==
"arb")
1926 ArbEnergyH = IPDFArbEnergyH = ZeroPhysVector;
1927 IPDFArbExist =
false;
1929 else if (atype ==
"epn")
1931 UDefEnergyH = IPDFEnergyH = ZeroPhysVector;
1932 IPDFEnergyExist =
false;
1933 EpnEnergyH = ZeroPhysVector;
1945 threadLocal_t& params = threadLocalData.
Get();
1946 params.particle_definition=a;
1947 params.particle_energy=-1;
1948 if(applyEvergyWeight)
1950 params.Emax = ArbEmax;
1951 params.Emin = ArbEmin;
1958 params.alpha = alpha;
1959 params.Ezero = Ezero;
1962 params.weight = weight;
1965 if((EnergyDisType ==
"Mono") && ((MonoEnergy>Emax)||(MonoEnergy<Emin)))
1968 ed <<
"MonoEnergy " <<
G4BestUnit(MonoEnergy,
"Energy")
1969 <<
" is outside of [Emin,Emax] = ["
1971 <<
G4BestUnit(Emax,
"Energy") <<
". MonoEnergy is used anyway.";
1972 G4Exception(
"G4SPSEneDistribution::GenerateOne()",
1974 params.particle_energy=MonoEnergy;
1975 return params.particle_energy;
1977 while ( (EnergyDisType ==
"Arb")
1978 ? (params.particle_energy < ArbEmin
1979 || params.particle_energy > ArbEmax)
1980 : (params.particle_energy < params.Emin
1981 || params.particle_energy > params.Emax) )
1985 GenerateBiasPowEnergies();
1989 if (EnergyDisType ==
"Mono")
1991 GenerateMonoEnergetic();
1993 else if (EnergyDisType ==
"Lin")
1995 GenerateLinearEnergies(
false);
1997 else if (EnergyDisType ==
"Pow")
1999 GeneratePowEnergies(
false);
2001 else if (EnergyDisType ==
"CPow")
2003 GenerateCPowEnergies();
2005 else if (EnergyDisType ==
"Exp")
2007 GenerateExpEnergies(
false);
2009 else if (EnergyDisType ==
"Gauss")
2011 GenerateGaussEnergies();
2013 else if (EnergyDisType ==
"Brem")
2015 GenerateBremEnergies();
2017 else if (EnergyDisType ==
"Bbody")
2019 GenerateBbodyEnergies();
2021 else if (EnergyDisType ==
"Cdg")
2023 GenerateCdgEnergies();
2025 else if (EnergyDisType ==
"User")
2027 GenUserHistEnergies();
2029 else if (EnergyDisType ==
"Arb")
2031 GenArbPointEnergies();
2033 else if (EnergyDisType ==
"Epn")
2035 GenEpnHistEnergies();
2039 G4cout <<
"Error: EnergyDisType has unusual value" <<
G4endl;
2043 return params.particle_energy;
2050 threadLocal_t& params = threadLocalData.
Get();
2051 if (EnergyDisType ==
"Lin")
2053 if (prob_norm == 1.)
2055 prob_norm = 0.5*params.grad*params.Emax*params.Emax
2056 + params.cept*params.Emax
2057 - 0.5*params.grad*params.Emin*params.Emin
2058 - params.cept*params.Emin;
2060 prob = params.cept + params.grad * ene;
2063 else if (EnergyDisType ==
"Pow")
2065 if (prob_norm == 1.)
2069 G4double emina = std::pow(params.Emin, params.alpha + 1);
2070 G4double emaxa = std::pow(params.Emax, params.alpha + 1);
2071 prob_norm = 1./(1.+alpha) * (emaxa - emina);
2075 prob_norm = std::log(params.Emax) - std::log(params.Emin) ;
2078 prob = std::pow(ene, params.alpha)/prob_norm;
2080 else if (EnergyDisType ==
"Exp")
2082 if (prob_norm == 1.)
2084 prob_norm = -params.Ezero*(std::exp(-params.Emax/params.Ezero)
2085 - std::exp(params.Emin/params.Ezero));
2087 prob = std::exp(-ene / params.Ezero);
2090 else if (EnergyDisType ==
"Arb")
2092 prob = ArbEnergyH.
Value(ene);
2096 G4cout <<
" Warning:G4SPSEneDistribution::GetProbability: prob<= 0. "
2097 << prob <<
" " << ene <<
G4endl;
2103 G4cout <<
"Error: EnergyDisType not supported" <<
G4endl;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
#define G4MUTEXDESTROY(mutex)
#define G4MUTEXINIT(mutex)
G4GLOB_DLL std::ostream G4cout
G4double CubicSplineInterpolation(G4double pX) const
G4double GetPDGMass() const
void InsertValues(G4double energy, G4double value)
G4double GetMinLowEdgeEnergy()
G4double GetMaxLowEdgeEnergy()
G4double GetEnergy(G4double aValue)
G4double Value(G4double theEnergy, std::size_t &lastidx) const
std::size_t FindBin(const G4double energy, const std::size_t idx) const
virtual void ScaleVector(G4double factorE, G4double factorV)
G4double GetLowEdgeEnergy(std::size_t binNumber) const
std::size_t GetVectorLength() const
void DumpValues(G4double unitE=1.0, G4double unitV=1.0) const
G4double GetProbability(G4double)
G4double GetArbEneWeight(G4double)
G4double GenerateOne(G4ParticleDefinition *)
void InputEnergySpectra(G4bool)
G4double GetWeight() const
G4PhysicsOrderedFreeVector GetArbEnergyHisto()
void ArbInterpolate(const G4String &)
void SetVerbosity(G4int a)
const G4String & GetEnergyDisType()
void SetBeamSigmaInE(G4double)
void SetBiasAlpha(G4double)
void SetEnergyDisType(const G4String &)
void EpnEnergyHisto(const G4ThreeVector &)
G4double GetEzero() const
void ArbEnergyHistoFile(const G4String &)
void SetGradient(G4double)
G4double Getalpha() const
void ReSetHist(const G4String &)
void InputDifferentialSpectra(G4bool)
void SetMonoEnergy(G4double)
void SetBiasRndm(G4SPSRandomGenerator *a)
G4PhysicsOrderedFreeVector GetUserDefinedEnergyHisto()
const G4String & GetIntType()
void UserEnergyHisto(const G4ThreeVector &)
void SetInterCept(G4double)
void ArbEnergyHisto(const G4ThreeVector &)