66 particle_energy = 1.0 *
MeV;
67 EnergyDisType =
"Mono";
84 IPDFEnergyExist =
false;
98 Arb_grad_cept_flag =
false;
99 Arb_alpha_Const_flag =
false;
100 Arb_ezero_flag =
false;
107 threadLocal_t&
data = threadLocalData.
Get();
114 data.particle_energy = 0;
115 data.particle_definition = NULL;
116 data.weight = weight;
122 if(Arb_grad_cept_flag)
128 if(Arb_alpha_Const_flag)
140 for ( std::vector<G4DataInterpolation*>::iterator it = SplineInt.begin() ; it!=SplineInt.end() ; ++it)
150 EnergyDisType = DisType;
151 if (EnergyDisType ==
"User")
153 UDefEnergyH = IPDFEnergyH = ZeroPhysVector;
154 IPDFEnergyExist =
false;
156 else if (EnergyDisType ==
"Arb")
158 ArbEnergyH = IPDFArbEnergyH = ZeroPhysVector;
159 IPDFArbExist =
false;
161 else if (EnergyDisType ==
"Epn")
163 UDefEnergyH = IPDFEnergyH = ZeroPhysVector;
164 IPDFEnergyExist =
false;
165 EpnEnergyH = ZeroPhysVector;
172 return EnergyDisType;
178 threadLocalData.
Get().Emin = Emin;
183 return threadLocalData.
Get().Emin;
201 threadLocalData.
Get().Emax = Emax;
206 return threadLocalData.
Get().Emax;
212 MonoEnergy = menergy;
222 threadLocalData.
Get().alpha = alpha;
239 threadLocalData.
Get().Ezero = Ezero;
245 threadLocalData.
Get().grad = grad;
251 threadLocalData.
Get().cept = cept;
274 return threadLocalData.
Get().weight;
291 return threadLocalData.
Get().alpha;
296 return threadLocalData.
Get().Ezero;
307 return threadLocalData.
Get().grad;
312 return threadLocalData.
Get().cept;
332 if (verbosityLevel > 1) {
338 threadLocalData.
Get().Emax = Emax;
347 if (verbosityLevel > 1)
358 std::ifstream infile(filename, std::ios::in);
361 G4Exception(
"G4SPSEneDistribution::ArbEnergyHistoFile",
"Event0301",
FatalException,
"Unable to open the histo ASCII file");
364 while (infile >> ehi >> val)
376 if (verbosityLevel > 1)
383 threadLocalData.
Get().Emax = Emax;
390 if (EnergyDisType ==
"Cdg")
392 CalculateCdgSpectrum();
394 else if (EnergyDisType ==
"Bbody")
400 CalculateBbodySpectrum();
405 void G4SPSEneDistribution::InitHists()
407 BBHist =
new std::vector<G4double>(10001, 0.0);
408 Bbody_x =
new std::vector<G4double>(10001, 0.0);
414 void G4SPSEneDistribution::CalculateCdgSpectrum()
423 ene_line[0] = threadLocalData.
Get().Emin;
424 if (threadLocalData.
Get().Emin < 18 *
keV)
427 ene_line[2] = threadLocalData.
Get().Emax;
428 if (threadLocalData.
Get().Emax < 18 *
keV)
431 ene_line[1] = threadLocalData.
Get().Emax;
439 ene_line[1] = threadLocalData.
Get().Emax;
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));
458 CDGhist[i + 1] = CDGhist[i + 1] / CDGhist[n_par];
465 void G4SPSEneDistribution::CalculateBbodySpectrum()
474 G4double erange = threadLocalData.
Get().Emax - threadLocalData.
Get().Emin;
486 while (count < 10000) {
487 Bbody_x->at(count) = threadLocalData.
Get().Emin +
G4double(count * steps);
488 G4double Bbody_y = (2. * std::pow(Bbody_x->at(count), 2.)) / (h2 * c2 * (std::exp(Bbody_x->at(count) / (k * Temp)) - 1.));
490 BBHist->at(count + 1) = BBHist->at(count) + Bbody_y;
494 Bbody_x->at(10000) = threadLocalData.
Get().Emax;
497 while (count < 10001) {
498 BBHist->at(count) = BBHist->at(count) / sum;
507 if (verbosityLevel > 1)
508 G4cout <<
"EnergySpec has value " << EnergySpec <<
G4endl;
515 if (verbosityLevel > 1)
521 if (EnergyDisType !=
"Arb")
522 G4Exception(
"G4SPSEneDistribution::ArbInterpolate",
524 "Error: this is for arbitrary distributions");
530 if (IntType ==
"Lin")
531 LinearInterpolation();
532 if (IntType ==
"Log")
534 if (IntType ==
"Exp")
536 if (IntType ==
"Spline")
537 SplineInterpolation();
541 void G4SPSEneDistribution::LinearInterpolation() {
548 G4double sum = 0., Arb_x[1024], Arb_y[1024], Arb_Cum_Area[1024];
551 for (i = 0; i < maxi; i++)
554 Arb_y[i] = ArbEnergyH(
size_t(i));
558 if (DiffSpec ==
false)
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]);
569 if (EnergySpec ==
false)
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;
605 Arb_grad_cept_flag =
true;
610 Arb_Cum_Area[0] = 0.;
614 Arb_grad[i] = (Arb_y[i] - Arb_y[i - 1]) / (Arb_x[i] - Arb_x[i - 1]);
615 if (verbosityLevel == 2)
619 if (Arb_grad[i] > 0.)
621 if (verbosityLevel == 2)
625 Arb_cept[i] = Arb_y[i] - (Arb_grad[i] * Arb_x[i]);
627 else if (Arb_grad[i] < 0.)
629 if (verbosityLevel == 2)
633 Arb_cept[i] = Arb_y[i] + (-Arb_grad[i] * Arb_x[i]);
637 if (verbosityLevel == 2)
641 Arb_cept[i] = Arb_y[i];
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];
647 if (verbosityLevel == 2)
649 G4cout << Arb_x[i] << Arb_y[i] << Area_seg[i] << sum << Arb_grad[i] <<
G4endl;
657 Arb_Cum_Area[i] = Arb_Cum_Area[i] / sum;
665 if (verbosityLevel >= 1)
674 void G4SPSEneDistribution::LogInterpolation()
682 G4double sum = 0., Arb_x[1024], Arb_y[1024], Arb_Cum_Area[1024];
685 for (i = 0; i < maxi; i++)
688 Arb_y[i] = ArbEnergyH(
size_t(i));
692 if (DiffSpec ==
false)
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]);
702 if (EnergySpec ==
false)
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;
735 if ( Arb_ezero ) {
delete[] Arb_ezero; Arb_ezero = 0; }
736 if ( Arb_Const ) {
delete[] Arb_Const; Arb_Const = 0; }
739 Arb_alpha_Const_flag =
true;
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]));
779 Arb_Const[i] = Arb_y[i] / (std::pow(Arb_x[i], Arb_alpha[i]));
780 alp = Arb_alpha[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];
791 if (verbosityLevel == 2)
793 G4cout << Arb_alpha[i] << Arb_Const[i] << Area_seg[i] <<
G4endl;
801 Arb_Cum_Area[i] = Arb_Cum_Area[i] / sum;
809 if (verbosityLevel >= 1)
816 void G4SPSEneDistribution::ExpInterpolation()
824 G4double sum = 0., Arb_x[1024], Arb_y[1024], Arb_Cum_Area[1024];
827 for (i = 0; i < maxi; i++)
830 Arb_y[i] = ArbEnergyH(
size_t(i));
834 if (DiffSpec ==
false)
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]);
845 if (EnergySpec ==
false)
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;
876 if ( Arb_ezero ) {
delete[] Arb_ezero; Arb_ezero = 0; }
877 if ( Arb_Const ) {
delete[] Arb_Const; Arb_Const = 0; }
880 Arb_ezero_flag =
true;
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]));
892 Arb_Const[i] = Arb_y[i] / (std::exp(-Arb_x[i] / Arb_ezero[i]));
893 Area_seg[i] = -(Arb_Const[i] * Arb_ezero[i]) * (std::exp(-Arb_x[i] / Arb_ezero[i]) - std::exp(-Arb_x[i - 1] / Arb_ezero[i]));
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];
907 if (verbosityLevel == 2)
909 G4cout << Arb_ezero[i] << Arb_Const[i] << Area_seg[i] <<
G4endl;
917 Arb_Cum_Area[i] = Arb_Cum_Area[i] / sum;
925 if (verbosityLevel >= 1)
932 void G4SPSEneDistribution::SplineInterpolation()
941 G4double sum, Arb_x[1024], Arb_y[1024], Arb_Cum_Area[1024];
945 for (i = 0; i < maxi; i++) {
947 Arb_y[i] = ArbEnergyH(
size_t(i));
951 if (DiffSpec ==
false) {
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]);
960 if (EnergySpec ==
false) {
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)
997 SplineInt.resize(1024,NULL);
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;
1028 IPDFArbEnergyH.
InsertValues(Arb_x[i], Arb_Cum_Area[i]);
1034 if (verbosityLevel > 0)
1038 void G4SPSEneDistribution::GenerateMonoEnergetic() {
1040 threadLocalData.
Get().particle_energy = MonoEnergy;
1043 void G4SPSEneDistribution::GenerateGaussEnergies() {
1046 if (ene < 0) ene = 0.;
1047 threadLocalData.
Get().particle_energy = ene;
1050 void G4SPSEneDistribution::GenerateLinearEnergies(
G4bool bArb =
false) {
1052 threadLocal_t& params = threadLocalData.
Get();
1053 G4double emaxsq = std::pow(params.Emax, 2.);
1054 G4double eminsq = std::pow(params.Emin, 2.);
1055 G4double intersq = std::pow(params.cept, 2.);
1062 G4double bracket = ((params.grad / 2.) * (emaxsq - eminsq) + params.cept * (params.Emax - params.Emin));
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);
1073 G4double root1 = -params.cept + sqbrack;
1074 root1 = root1 / (2. * (params.grad / 2.));
1076 G4double root2 = -params.cept - sqbrack;
1077 root2 = root2 / (2. * (params.grad / 2.));
1081 if (root1 > params.Emin && root1 < params.Emax)
1083 params.particle_energy = root1;
1085 if (root2 > params.Emin && root2 < params.Emax)
1087 params.particle_energy = root2;
1090 else if (params.grad == 0.)
1093 params.particle_energy = bracket / params.cept;
1096 if (params.particle_energy < 0.)
1098 params.particle_energy = -params.particle_energy;
1101 if (verbosityLevel >= 1)
1103 G4cout <<
"Energy is " << params.particle_energy <<
G4endl;
1107 void G4SPSEneDistribution::GeneratePowEnergies(
G4bool bArb =
false)
1115 threadLocal_t& params = threadLocalData.
Get();
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.)));
1133 params.particle_energy = ene;
1137 G4double ene = (std::log(params.Emin) + rndm * (std::log(params.Emax) - std::log(params.Emin)));
1138 params.particle_energy = std::exp(ene);
1140 if (verbosityLevel >= 1)
1142 G4cout <<
"Energy is " << params.particle_energy <<
G4endl;
1146 void G4SPSEneDistribution::GenerateBiasPowEnergies()
1151 threadLocal_t& params = threadLocalData.
Get();
1167 if (biasalpha != -1.)
1169 emina = std::pow(emin, biasalpha + 1);
1170 emaxa = std::pow(emax, biasalpha + 1);
1171 G4double ee = ((rndm * (emaxa - emina)) + emina);
1172 params.particle_energy = std::pow(ee, (1. / (biasalpha + 1.)));
1173 normal = 1./(1+biasalpha) * (emaxa - emina);
1177 G4double ee = (std::log(emin) + rndm * (std::log(emax) - std::log(emin)));
1178 params.particle_energy = std::exp(ee);
1179 normal = std::log(emax) - std::log(emin) ;
1182 / (std::pow(params.particle_energy,biasalpha)/
normal);
1184 if (verbosityLevel >= 1)
1186 G4cout <<
"Energy is " << params.particle_energy <<
G4endl;
1190 void G4SPSEneDistribution::GenerateExpEnergies(
G4bool bArb =
false)
1205 threadLocal_t& params = threadLocalData.
Get();
1206 params.particle_energy = -params.Ezero * (std::log(rndm * (std::exp(-params.Emax / params.Ezero) - std::exp(-params.Emin / params.Ezero)) + std::exp(-params.Emin / params.Ezero)));
1207 if (verbosityLevel >= 1)
1209 G4cout <<
"Energy is " << params.particle_energy <<
G4endl;
1213 void G4SPSEneDistribution::GenerateBremEnergies()
1227 threadLocal_t& params = threadLocalData.
Get();
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);
1256 G4double erange = params.Emax - params.Emin;
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;
1277 params.particle_energy = etest;
1280 if (verbosityLevel >= 1)
1282 G4cout <<
"Energy is " << params.particle_energy <<
G4endl;
1286 void G4SPSEneDistribution::GenerateBbodyEnergies()
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))
1327 x1 = Bbody_x->at(nbelow);
1328 if(nbelow+1 == static_cast<G4int>(Bbody_x->size()))
1330 x2 = Bbody_x->back();
1334 x2 = Bbody_x->at(nbelow + 1);
1336 y1 = BBHist->at(nbelow);
1337 if(nbelow+1 == static_cast<G4int>(BBHist->size()))
1340 y2 = BBHist->back();
1344 y2 = BBHist->at(nbelow + 1);
1346 t = (y2 - y1) / (x2 - x1);
1349 threadLocalData.
Get().particle_energy = (rndm - q) / t;
1351 if (verbosityLevel >= 1) {
1352 G4cout <<
"Energy is " << threadLocalData.
Get().particle_energy <<
G4endl;
1356 void G4SPSEneDistribution::GenerateCdgEnergies() {
1366 threadLocal_t& params = threadLocalData.
Get();
1367 if (params.Emin < 18 *
keV && params.Emax < 18 *
keV)
1369 omalpha[0] = 1. - 1.4;
1370 ene_line[0] = params.Emin;
1371 ene_line[1] = params.Emax;
1373 if (params.Emin < 18 *
keV && params.Emax > 18 *
keV)
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;
1381 if (params.Emin > 18 *
keV)
1383 omalpha[0] = 1. - 2.3;
1384 ene_line[0] = params.Emin;
1385 ene_line[1] = params.Emax;
1391 while (rndm >= CDGhist[i])
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);
1397 params.particle_energy = std::pow(ene, (1. / omalpha[i - 1]));
1399 if (verbosityLevel >= 1)
1401 G4cout <<
"Energy is " << params.particle_energy <<
G4endl;
1405 void G4SPSEneDistribution::GenUserHistEnergies()
1410 if (IPDFEnergyExist ==
false)
1414 G4double bins[1024], vals[1024], sum;
1415 for ( ii = 0 ; ii<1024 ; ++ii ) { bins[ii]=0; vals[ii]=0; }
1418 if ((EnergySpec ==
false) && (threadLocalData.
Get().particle_definition == NULL))
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");
1432 if (DiffSpec ==
false)
1439 vals[0] = UDefEnergyH(
size_t(0));
1441 for (ii = 1; ii < maxbin; ii++)
1444 vals[ii] = UDefEnergyH(
size_t(ii)) + vals[ii - 1];
1445 sum = sum + UDefEnergyH(
size_t(ii));
1449 if (EnergySpec ==
false)
1451 G4double mass = threadLocalData.
Get().particle_definition->GetPDGMass();
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;
1479 IPDFEnergyExist =
true;
1480 if (verbosityLevel > 1)
1489 threadLocalData.
Get().particle_energy= IPDFEnergyH.
GetEnergy(rndm);
1491 if (verbosityLevel >= 1)
1497 void G4SPSEneDistribution::GenArbPointEnergies()
1499 if (verbosityLevel > 0)
1508 G4int nabove, nbelow = 0, middle;
1512 while (nabove - nbelow > 1)
1514 middle = (nabove + nbelow) / 2;
1515 if (rndm == IPDFArbEnergyH(
size_t(middle)))
1519 if (rndm < IPDFArbEnergyH(
size_t(middle)))
1528 threadLocal_t& params = threadLocalData.
Get();
1529 if (IntType ==
"Lin")
1534 params.grad = Arb_grad[nbelow + 1];
1535 params.cept = Arb_cept[nbelow + 1];
1537 GenerateLinearEnergies(
true);
1539 else if (IntType ==
"Log")
1543 params.alpha = Arb_alpha[nbelow + 1];
1545 GeneratePowEnergies(
true);
1547 else if (IntType ==
"Exp")
1551 params.Ezero = Arb_ezero[nbelow + 1];
1553 GenerateExpEnergies(
true);
1555 else if (IntType ==
"Spline")
1559 params.particle_energy = -1e100;
1561 while (params.particle_energy < params.Emin || params.particle_energy > params.Emax)
1563 params.particle_energy = SplineInt[nbelow+1]->CubicSplineInterpolation(rndm);
1566 if (verbosityLevel >= 1)
1568 G4cout <<
"Energy is " << params.particle_energy <<
G4endl;
1573 G4Exception(
"G4SPSEneDistribution::GenArbPointEnergies",
"Event0302",
1578 void G4SPSEneDistribution::GenEpnHistEnergies() {
1583 if (Epnflag ==
true)
1587 ConvertEPNToEnergy();
1591 if (IPDFEnergyExist ==
false)
1594 G4double bins[1024], vals[1024], sum;
1598 vals[0] = UDefEnergyH(
size_t(0));
1600 for (ii = 1; ii < maxbin; ii++)
1603 vals[ii] = UDefEnergyH(
size_t(ii)) + vals[ii - 1];
1604 sum = sum + UDefEnergyH(
size_t(ii));
1608 for (ii = 0; ii < maxbin; ii++)
1610 vals[ii] = vals[ii] / sum;
1614 IPDFEnergyExist =
true;
1621 threadLocalData.
Get().particle_energy = IPDFEnergyH.
GetEnergy(rndm);
1623 if (verbosityLevel >= 1)
1625 G4cout <<
"Energy is " << threadLocalData.
Get().particle_energy <<
G4endl;
1630 void G4SPSEneDistribution::ConvertEPNToEnergy()
1636 threadLocal_t& params = threadLocalData.
Get();
1637 if (params.particle_definition == NULL)
1645 G4int Bary = params.particle_definition->GetBaryonNumber();
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++)
1667 evals[count] = EpnEnergyH(
size_t(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")
1701 UDefEnergyH = IPDFEnergyH = ZeroPhysVector;
1702 IPDFEnergyExist =
false;
1706 else if (atype ==
"arb")
1708 ArbEnergyH = IPDFArbEnergyH = ZeroPhysVector;
1709 IPDFArbExist =
false;
1711 else if (atype ==
"epn")
1713 UDefEnergyH = IPDFEnergyH = ZeroPhysVector;
1714 IPDFEnergyExist =
false;
1715 EpnEnergyH = ZeroPhysVector;
1726 threadLocal_t& params = threadLocalData.
Get();
1727 params.particle_definition=a;
1728 params.particle_energy=-1;
1731 params.alpha = alpha;
1732 params.Ezero = Ezero;
1735 params.weight = weight;
1737 while ((EnergyDisType ==
"Arb") ? (params.particle_energy < ArbEmin || params.particle_energy > ArbEmax) : (params.particle_energy < params.Emin|| params.particle_energy > params.Emax))
1741 GenerateBiasPowEnergies();
1745 if (EnergyDisType ==
"Mono")
1747 GenerateMonoEnergetic();
1749 else if (EnergyDisType ==
"Lin")
1751 GenerateLinearEnergies(
false);
1753 else if (EnergyDisType ==
"Pow")
1755 GeneratePowEnergies(
false);
1757 else if (EnergyDisType ==
"Exp")
1759 GenerateExpEnergies(
false);
1761 else if (EnergyDisType ==
"Gauss")
1763 GenerateGaussEnergies();
1765 else if (EnergyDisType ==
"Brem")
1767 GenerateBremEnergies();
1769 else if (EnergyDisType ==
"Bbody")
1771 GenerateBbodyEnergies();
1773 else if (EnergyDisType ==
"Cdg")
1775 GenerateCdgEnergies();
1777 else if (EnergyDisType ==
"User")
1779 GenUserHistEnergies();
1781 else if (EnergyDisType ==
"Arb")
1783 GenArbPointEnergies();
1785 else if (EnergyDisType ==
"Epn")
1787 GenEpnHistEnergies();
1791 G4cout <<
"Error: EnergyDisType has unusual value" <<
G4endl;
1795 return params.particle_energy;
1802 threadLocal_t& params = threadLocalData.
Get();
1803 if (EnergyDisType ==
"Lin")
1805 if (prob_norm == 1.)
1807 prob_norm = 0.5*params.grad*params.Emax*params.Emax + params.cept*params.Emax - 0.5*params.grad*params.Emin*params.Emin - params.cept*params.Emin;
1809 prob = params.cept + params.grad * ene;
1812 else if (EnergyDisType ==
"Pow")
1814 if (prob_norm == 1.)
1818 G4double emina = std::pow(params.Emin, params.alpha + 1);
1819 G4double emaxa = std::pow(params.Emax, params.alpha + 1);
1820 prob_norm = 1./(1.+alpha) * (emaxa - emina);
1824 prob_norm = std::log(params.Emax) - std::log(params.Emin) ;
1827 prob = std::pow(ene, params.alpha)/prob_norm;
1829 else if (EnergyDisType ==
"Exp")
1831 if (prob_norm == 1.)
1833 prob_norm = -params.Ezero*(std::exp(-params.Emax/params.Ezero) - std::exp(params.Emin/params.Ezero));
1835 prob = std::exp(-ene / params.Ezero);
1838 else if (EnergyDisType ==
"Arb")
1840 prob = ArbEnergyH.
Value(ene);
1847 G4cout <<
" Warning:G4SPSEneDistribution::GetProbability: prob<= 0. "<<prob <<
" "<<ene <<
G4endl;
1854 G4cout <<
"Error: EnergyDisType not supported" <<
G4endl;
void SetBeamSigmaInE(G4double)
ThreeVector shoot(const G4int Ap, const G4int Af)
void DumpValues(G4double unitE=1.0, G4double unitV=1.0) const
std::ostringstream G4ExceptionDescription
void ArbEnergyHisto(G4ThreeVector)
G4PhysicsOrderedFreeVector GetUserDefinedEnergyHisto()
void SetVerbosity(G4int a)
#define G4MUTEXINIT(mutex)
void InsertValues(G4double energy, G4double value)
size_t GetVectorLength() const
G4double GetLowEdgeEnergy(size_t binNumber) const
G4PhysicsOrderedFreeVector GetArbEnergyHisto()
G4double CubicSplineInterpolation(G4double pX) const
G4double GetMaxLowEdgeEnergy()
const XML_Char const XML_Char * data
static double normal(HepRandomEngine *eptr)
G4GLOB_DLL std::ostream G4cout
const XML_Char int const XML_Char * value
void SetEnergyDisType(G4String)
G4String GetEnergyDisType()
G4double GetProbability(G4double)
G4double GenerateOne(G4ParticleDefinition *)
virtual void ScaleVector(G4double factorE, G4double factorV)
void SetBiasRndm(G4SPSRandomGenerator *a)
G4double Value(G4double theEnergy, size_t &lastidx) const
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)
void InputEnergySpectra(G4bool)
G4double GetPDGMass() const
void SetGradient(G4double)
void UserEnergyHisto(G4ThreeVector)
void SetInterCept(G4double)
void InputDifferentialSpectra(G4bool)
void SetBiasAlpha(G4double)
static constexpr double MeV
void ArbEnergyHistoFile(G4String)
G4double GetMinLowEdgeEnergy()
static constexpr double keV
#define G4MUTEXDESTROY(mutex)
void SetMonoEnergy(G4double)