57{
58 theEnergies.clear();
59
60 if (aStep == nullptr) return false;
61
63
64#ifdef VERBOSE_ENERSPLIT
66 if (verbose)
70#endif
73 {
74 return (
G4int)theEnergies.size();
75 }
77 theEnergies.push_back(edep);
78 return (
G4int)theEnergies.size();
79 }
80
81 if (thePhantomParam == nullptr) GetPhantomParam(true);
82
83
84 std::vector<std::pair<G4int, G4double>> rnsl =
86
89 G4double kinEnergyPre = kinEnergyPreOrig;
90
93 unsigned int ii;
94 for (ii = 0; ii < rnsl.size(); ++ii) {
96 slSum += sl;
97#ifdef VERBOSE_ENERSPLIT
98 if (verbose)
99 G4cout <<
"G4EnergySplitter::SplitEnergyInVolumes" << ii <<
" RN: iter1 step length geom "
101#endif
102 }
103
104#ifdef VERBOSE_ENERSPLIT
105 if (verbose)
106 G4cout <<
"G4EnergySplitter RN: step length geom TOTAL " << slSum <<
" true TOTAL "
107 << stepLength << " ratio " << stepLength / slSum << " Energy "
111#endif
112
113
114 if (theNIterations == 0) {
115 for (ii = 0; ii < rnsl.size(); ++ii) {
117 G4double edepStep = edep * sl / slSum;
118
119#ifdef VERBOSE_ENERSPLIT
120 if (verbose)
121 G4cout <<
"G4EnergySplitter::SplitEnergyInVolumes" << ii <<
" edep " << edepStep <<
G4endl;
122#endif
123
124 theEnergies.push_back(edepStep);
125 }
126 }
127 else {
128
129#ifdef VERBOSE_ENERSPLIT
130
131 if (verbose) {
133 for (ii = 0; ii < rnsl.size(); ++ii) {
135 slSum += sl;
136 }
137 for (ii = 0; ii < rnsl.size(); ii++) {
138 G4cout <<
"G4EnergySplitter::SplitEnergyInVolumes " << ii
139 <<
" RN: iter0 corrected energy lost " << edep * rnsl[ii].second / slSum <<
G4endl;
140 }
141 }
142#endif
143
144 G4double slRatio = stepLength / slSum;
145#ifdef VERBOSE_ENERSPLIT
146 if (verbose)
147 G4cout <<
"G4EnergySplitter::SplitEnergyInVolumes RN: iter 0, step ratio " << slRatio
149#endif
150
151
154 std::vector<G4double> stepLengths;
155 for (
G4int iiter = 1; iiter <= theNIterations; ++iiter) {
156
157
158 if (iiter == 1) {
159 for (ii = 0; ii < rnsl.size(); ++ii) {
161 stepLengths.push_back(sl * slRatio);
162#ifdef VERBOSE_ENERSPLIT
163 if (verbose)
164 G4cout <<
"G4EnergySplitter::SplitEnergyInVolumes" << ii <<
" RN: iter" << iiter
165 <<
" corrected step length " << sl * slRatio <<
G4endl;
166#endif
167 }
168
169 for (ii = 0; ii < rnsl.size(); ++ii) {
172 if (kinEnergyPre > 0.) {
173 dEdx = emcalc.
GetDEDX(kinEnergyPre, part, mate);
174 }
175 G4double elost = stepLengths[ii] * dEdx;
176
177#ifdef VERBOSE_ENERSPLIT
178 if (verbose)
179 G4cout <<
"G4EnergySplitter::SplitEnergyInVolumes" << ii <<
" RN: iter1 energy lost "
180 << elost << " energy at interaction " << kinEnergyPre << " = stepLength "
181 << stepLengths[ii] <<
" * dEdx " << dEdx <<
G4endl;
182#endif
183 kinEnergyPre -= elost;
184 theEnergies.push_back(elost);
185 totalELost += elost;
186 }
187 }
188 else {
189
190
191
192 slSum = 0.;
193 kinEnergyPre = kinEnergyPreOrig;
194 for (ii = 0; ii < rnsl.size(); ++ii) {
196 stepLengths[ii] = theElossExt->
TrueStepLength(kinEnergyPre, rnsl[ii].second, mate, part);
197 kinEnergyPre -= theEnergies[ii];
198
199#ifdef VERBOSE_ENERSPLIT
200 if (verbose)
201 G4cout <<
"G4EnergySplitter::SplitEnergyInVolumes" << ii <<
" RN: iter" << iiter
202 << " step length geom " << stepLengths[ii] << " geom2true "
203 << rnsl[ii].second / stepLengths[ii] <<
G4endl;
204#endif
205
206 slSum += stepLengths[ii];
207 }
208
209
211#ifdef VERBOSE_ENERSPLIT
212 if (verbose)
213 G4cout <<
"G4EnergySplitter::SplitEnergyInVolumes" << ii <<
" RN: iter" << iiter
214 <<
" step ratio " << slRatio <<
G4endl;
215#endif
216 for (ii = 0; ii < rnsl.size(); ++ii) {
217 stepLengths[ii] *= slratio;
218#ifdef VERBOSE_ENERSPLIT
219 if (verbose)
220 G4cout <<
"G4EnergySplitter::SplitEnergyInVolumes" << ii <<
" RN: iter" << iiter
221 <<
" corrected step length " << stepLengths[ii] <<
G4endl;
222#endif
223 }
224
225
227 totalELost = 0.;
228 for (ii = 0; ii < rnsl.size(); ++ii) {
231 if (kinEnergyPre > 0.) {
232 dEdx = emcalc.
GetDEDX(kinEnergyPre, part, mate);
233 }
234 G4double elost = stepLengths[ii] * dEdx;
235#ifdef VERBOSE_ENERSPLIT
236 if (verbose)
237 G4cout <<
"G4EnergySplitter::SplitEnergyInVolumes" << ii <<
" RN: iter" << iiter
238 << " energy lost " << elost << " energy at interaction " << kinEnergyPre
239 <<
" = stepLength " << stepLengths[ii] <<
" * dEdx " << dEdx <<
G4endl;
240#endif
241 kinEnergyPre -= elost;
242 theEnergies[ii] = elost;
243 totalELost += elost;
244 }
245 }
246
247
248 G4double enerRatio = (edep / totalELost);
249
250#ifdef VERBOSE_ENERSPLIT
251 if (verbose)
252 G4cout <<
"G4EnergySplitter::SplitEnergyInVolumes" << ii <<
" RN: iter" << iiter
253 <<
" energy ratio " << enerRatio <<
G4endl;
254#endif
255
256#ifdef VERBOSE_ENERSPLIT
258#endif
259 for (ii = 0; ii < theEnergies.size(); ++ii) {
260 theEnergies[ii] *= enerRatio;
261#ifdef VERBOSE_ENERSPLIT
262 elostTot += theEnergies[ii];
263 if (verbose)
264 G4cout <<
"G4EnergySplitter::SplitEnergyInVolumes " << ii <<
" RN: iter" << iiter
265 << " corrected energy lost " << theEnergies[ii] << " orig elost "
266 << theEnergies[ii] / enerRatio << " energy before interaction "
267 << kinEnergyPreOrig - elostTot + theEnergies[ii] << " energy after interaction "
268 << kinEnergyPreOrig - elostTot <<
G4endl;
269#endif
270 }
271 }
272 }
273
274 return (
G4int)theEnergies.size();
275}
G4GLOB_DLL std::ostream G4cout
G4double GetDEDX(G4double kinEnergy, const G4ParticleDefinition *, const G4Material *, const G4Region *r=nullptr)
const G4String & GetName() const
G4double GetPDGCharge() const
G4Material * GetMaterial(std::size_t nx, std::size_t ny, std::size_t nz) const
G4Material * GetMaterial() const
G4double GetKineticEnergy() const
G4Track * GetTrack() const
G4StepPoint * GetPreStepPoint() const
G4double GetStepLength() const
G4double GetTotalEnergyDeposit() const
G4ParticleDefinition * GetDefinition() const