41 fPrimaryEnergy.reserve(npoints);
42 fSecEnergy.reserve(npoints);
43 for (
G4int i=0; i<5; ++i) { (fPDF[i]).reserve(npoints); }
48 for (
auto & p : fSecEnergy) {
delete p; }
49 for (
G4int i=0; i<5; ++i) {
50 for (
auto & p : fPDF[i]) {
delete p; }
57 std::ostringstream ost;
59 std::ifstream fin(ost.str().c_str());
62 ed <<
"File <" << ost.str().c_str() <<
"> is not opened!";
63 G4Exception(
"G4DNASamplingTable::LoadDifferential ",
"em0003",
72 std::vector<G4double>* v =
nullptr;
73 std::vector<G4double>* vPDF[5];
76 if (fin.eof()) {
break; }
77 if (e != e0 ||
nullptr == v) {
78 fPrimaryEnergy.push_back(e*factE);
81 v =
new std::vector<G4double>;
82 fSecEnergy.push_back(v);
83 for (
G4int i=0; i<5; ++i) {
84 vPDF[i] =
new std::vector<G4double>;
85 (fPDF[i]).push_back(vPDF[i]);
87 ntmax = std::max(ntmax, nt);
91 v->push_back(t*factE);
93 for (
G4int i=0; i<5; ++i) {
96 (vPDF[i])->push_back(sig);
98 if (fin.eof()) {
break; }
101 G4cout <<
"G4DNASamplingTable::LoadData from file:" <<
G4endl;
103 G4cout <<
" Nenergy= " << fNpoints <<
" NmaxT= " << ntmax <<
G4endl;
105 if (fNpoints > 0) { --fNpoints; }
111 std::vector<G4double>* e1{
nullptr};
112 std::vector<G4double>* e2{
nullptr};
113 std::vector<G4double>* s1{
nullptr};
114 std::vector<G4double>* s2{
nullptr};
115 G4int idx = GetIndex(fPrimaryEnergy, ekinPrimary);
118 s1 = (fPDF[shell])[0];
119 }
else if (idx > fNpoints) {
120 e1 = fSecEnergy[fNpoints];
121 s1 = (fPDF[shell])[fNpoints];
123 e1 = fSecEnergy[idx];
124 s1 = (fPDF[shell])[idx];
125 e2 = fSecEnergy[idx + 1];
126 s2 = (fPDF[shell])[idx + 1];
129 G4double res1 = VecInterpolation(e1, s1, ekinSec);
130 if (
nullptr == e2) {
return res1; }
133 G4double res2 = VecInterpolation(e2, s2, ekinSec);
134 G4double res = Interpolate(fPrimaryEnergy[idx], fPrimaryEnergy[idx + 1],
135 ekinPrimary, res1, res2);
139G4int G4DNASamplingTable::GetIndex(
const std::vector<G4double>& v,
G4double x)
const
142 if (x <= v[0]) { idx = -1; }
143 else if (x >= v.back()) { idx = (
G4int)v.size(); }
145 std::size_t i = std::upper_bound(v.cbegin(), v.cend(), x) - v.cbegin() - 1;
151G4double G4DNASamplingTable::VecInterpolation(
const std::vector<G4double>* ener,
152 const std::vector<G4double>* val,
155 G4int idx = GetIndex(*ener, e);
157 if (idx == -1) { res = (*val)[0]; }
158 else if (e >= ener->back()) { res = val->back(); }
160 res = Interpolate((*ener)[idx], (*ener)[idx + 1], e, (*val)[idx], (*val)[idx + 1]);
171 res = 0.5 * (xs1 + xs2);
174 }
else if (e1 > 0.0 && e2 > 0.0 && xs1 > 0.0 && xs2 > 0.0) {
179 }
else if (xs1 > 0.0 && xs2 > 0.0) {
185 res = xs1 + (e - e1) * (xs2 - xs1)/(e2 - e1);
193 std::vector<G4double>* e1{
nullptr};
194 std::vector<G4double>* e2{
nullptr};
195 std::vector<G4double>* s1{
nullptr};
196 std::vector<G4double>* s2{
nullptr};
197 G4int idx = GetIndex(fPrimaryEnergy, ekinPrimary);
200 s1 = (fPDF[shell])[0];
201 }
else if (idx > fNpoints) {
202 e1 = fSecEnergy[fNpoints];
203 s1 = (fPDF[shell])[fNpoints];
205 e1 = fSecEnergy[idx];
206 s1 = (fPDF[shell])[idx];
207 e2 = fSecEnergy[idx + 1];
208 s2 = (fPDF[shell])[idx + 1];
213 G4double res1 = VecInterpolation(s1, e1, q);
214 if (
nullptr == e2) {
return res1; }
217 G4double res2 = VecInterpolation(s2, e2, q);
218 G4double res = Interpolate(fPrimaryEnergy[idx], fPrimaryEnergy[idx + 1],
219 ekinPrimary, res1, res2);
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
G4double G4Log(G4double x)
G4GLOB_DLL std::ostream G4cout
G4DNASamplingTable(std::size_t npoint)
G4double SampleCumulative(G4double ekinPrimary, G4int shell) const
G4double GetValue(G4double ekinPrimary, G4double ekinSecondary, G4int shell) const
void LoadData(const G4String &filename, G4double factorE, G4double scaleFactor, G4bool verbose)
static G4EmParameters * Instance()
const G4String & GetDirLEDATA() const