Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4EnergySplitter Class Reference

#include <G4EnergySplitter.hh>

Public Member Functions

 G4EnergySplitter ()
 
virtual ~G4EnergySplitter ()
 
G4int SplitEnergyInVolumes (const G4Step *aStep)
 
void GetLastVoxelID (G4int &voxelID)
 
void GetFirstVoxelID (G4int &voxelID)
 
void GetVoxelID (G4int stepNo, G4int &voxelID)
 
void GetVoxelIDAndLength (G4int stepNo, G4int &voxelID, G4double &stepLength)
 
void GetLengthAndEnergyDeposited (G4int stepNo, G4int &voxelID, G4double &stepLength, G4double &energyLoss)
 
void GetLengthAndInitialEnergy (G4double &preStepEnergy, G4int stepNo, G4int &voxelID, G4double &stepLength, G4double &initialEnergy)
 
void SetNIterations (G4int niter)
 
G4MaterialGetVoxelMaterial (G4int stepNo)
 

Detailed Description

Definition at line 49 of file G4EnergySplitter.hh.

Constructor & Destructor Documentation

◆ G4EnergySplitter()

G4EnergySplitter::G4EnergySplitter ( )

Definition at line 44 of file G4EnergySplitter.cc.

45{
46 theElossExt = new G4EnergyLossForExtrapolator(0);
47 thePhantomParam = nullptr;
48 theNIterations = 2;
49}

◆ ~G4EnergySplitter()

G4EnergySplitter::~G4EnergySplitter ( )
virtual

Definition at line 51 of file G4EnergySplitter.cc.

52{
53 delete theElossExt;
54}

Member Function Documentation

◆ GetFirstVoxelID()

void G4EnergySplitter::GetFirstVoxelID ( G4int & voxelID)

Definition at line 313 of file G4EnergySplitter.cc.

314{
315 voxelID = (*(G4RegularNavigationHelper::Instance()->GetStepLengths().crbegin())).first;
316}
const std::vector< std::pair< G4int, G4double > > & GetStepLengths()
static G4RegularNavigationHelper * Instance()

◆ GetLastVoxelID()

void G4EnergySplitter::GetLastVoxelID ( G4int & voxelID)

Definition at line 307 of file G4EnergySplitter.cc.

308{
309 voxelID = (*(G4RegularNavigationHelper::Instance()->GetStepLengths().cbegin())).first;
310}

◆ GetLengthAndEnergyDeposited()

void G4EnergySplitter::GetLengthAndEnergyDeposited ( G4int stepNo,
G4int & voxelID,
G4double & stepLength,
G4double & energyLoss )
inline

◆ GetLengthAndInitialEnergy()

void G4EnergySplitter::GetLengthAndInitialEnergy ( G4double & preStepEnergy,
G4int stepNo,
G4int & voxelID,
G4double & stepLength,
G4double & initialEnergy )
inline

◆ GetVoxelID()

void G4EnergySplitter::GetVoxelID ( G4int stepNo,
G4int & voxelID )

Definition at line 319 of file G4EnergySplitter.cc.

320{
321 if (stepNo < 0 || stepNo >= G4int(G4RegularNavigationHelper::Instance()->GetStepLengths().size()))
322 {
323 G4Exception("G4EnergySplitter::GetVoxelID",
324 "Invalid stepNo, smaller than 0 or bigger or equal to number of voxels traversed",
326 G4String("stepNo = " + G4UIcommand::ConvertToString(stepNo)
327 + ", number of voxels = "
329 G4int(G4RegularNavigationHelper::Instance()->GetStepLengths().size())))
330 .c_str());
331 }
333 advance(ite, stepNo);
334 voxelID = (*ite).first;
335}
@ FatalErrorInArgument
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
int G4int
Definition G4Types.hh:85
static G4String ConvertToString(G4bool boolVal)

Referenced by G4ScoreSplittingProcess::PostStepDoIt().

◆ GetVoxelIDAndLength()

void G4EnergySplitter::GetVoxelIDAndLength ( G4int stepNo,
G4int & voxelID,
G4double & stepLength )
inline

◆ GetVoxelMaterial()

G4Material * G4EnergySplitter::GetVoxelMaterial ( G4int stepNo)
inline

◆ SetNIterations()

void G4EnergySplitter::SetNIterations ( G4int niter)
inline

◆ SplitEnergyInVolumes()

G4int G4EnergySplitter::SplitEnergyInVolumes ( const G4Step * aStep)

Definition at line 56 of file G4EnergySplitter.cc.

57{
58 theEnergies.clear();
59
60 if (aStep == nullptr) return false; // it is 0 when called by GmScoringMgr after last event
61
62 G4double edep = aStep->GetTotalEnergyDeposit();
63
64#ifdef VERBOSE_ENERSPLIT
65 G4bool verbose = 1;
66 if (verbose)
67 G4cout << "G4EnergySplitter::SplitEnergyInVolumes totalEdepo " << aStep->GetTotalEnergyDeposit()
68 << " Nsteps " << G4RegularNavigationHelper::Instance()->GetStepLengths().size()
69 << G4endl;
70#endif
71 if (G4RegularNavigationHelper::Instance()->GetStepLengths().empty()
72 || aStep->GetTrack()->GetDefinition()->GetPDGCharge() == 0)
73 { // we are only counting dose deposit
74 return (G4int)theEnergies.size();
75 }
76 if (G4RegularNavigationHelper::Instance()->GetStepLengths().size() == 1) {
77 theEnergies.push_back(edep);
78 return (G4int)theEnergies.size();
79 }
80
81 if (thePhantomParam == nullptr) GetPhantomParam(true);
82
83 //----- Distribute energy deposited in voxels
84 std::vector<std::pair<G4int, G4double>> rnsl =
86
87 const G4ParticleDefinition* part = aStep->GetTrack()->GetDefinition();
88 G4double kinEnergyPreOrig = aStep->GetPreStepPoint()->GetKineticEnergy();
89 G4double kinEnergyPre = kinEnergyPreOrig;
90
91 G4double stepLength = aStep->GetStepLength();
92 G4double slSum = 0.;
93 unsigned int ii;
94 for (ii = 0; ii < rnsl.size(); ++ii) {
95 G4double sl = rnsl[ii].second;
96 slSum += sl;
97#ifdef VERBOSE_ENERSPLIT
98 if (verbose)
99 G4cout << "G4EnergySplitter::SplitEnergyInVolumes" << ii << " RN: iter1 step length geom "
100 << sl << G4endl;
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 "
108 << aStep->GetPreStepPoint()->GetKineticEnergy() << " Material "
109 << aStep->GetPreStepPoint()->GetMaterial()->GetName() << " Number of geom steps "
110 << rnsl.size() << G4endl;
111#endif
112 //----- No iterations to correct elost and msc => distribute energy deposited according to
113 // geometrical step length in each voxel
114 if (theNIterations == 0) {
115 for (ii = 0; ii < rnsl.size(); ++ii) {
116 G4double sl = rnsl[ii].second;
117 G4double edepStep = edep * sl / slSum; // divide edep along steps, proportional to step
118 // length
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 { // 1 or more iterations demanded
128
129#ifdef VERBOSE_ENERSPLIT
130 // print corrected energy at iteration 0
131 if (verbose) {
132 G4double slSum = 0.;
133 for (ii = 0; ii < rnsl.size(); ++ii) {
134 G4double sl = rnsl[ii].second;
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
148 << G4endl;
149#endif
150
151 //--- energy at each interaction
152 G4EmCalculator emcalc;
153 G4double totalELost = 0.;
154 std::vector<G4double> stepLengths;
155 for (G4int iiter = 1; iiter <= theNIterations; ++iiter) {
156 //--- iter1: distribute true step length in each voxel: geom SL in each voxel is multiplied by
157 // a constant so that the sum gives the total true step length
158 if (iiter == 1) {
159 for (ii = 0; ii < rnsl.size(); ++ii) {
160 G4double sl = rnsl[ii].second;
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) {
170 const G4Material* mate = thePhantomParam->GetMaterial(rnsl[ii].first);
171 G4double dEdx = 0.;
172 if (kinEnergyPre > 0.) { // t check this
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 //------ 2nd and other iterations
190 //----- Get step lengths corrected by changing geom2true correction
191 //-- Get ratios for each energy
192 slSum = 0.;
193 kinEnergyPre = kinEnergyPreOrig;
194 for (ii = 0; ii < rnsl.size(); ++ii) {
195 const G4Material* mate = thePhantomParam->GetMaterial(rnsl[ii].first);
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 // Correct step lengths so that they sum the total step length
210 G4double slratio = aStep->GetStepLength() / slSum;
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 //---- Recalculate energy lost with this new step lengths
226 kinEnergyPre = aStep->GetPreStepPoint()->GetKineticEnergy();
227 totalELost = 0.;
228 for (ii = 0; ii < rnsl.size(); ++ii) {
229 const G4Material* mate = thePhantomParam->GetMaterial(rnsl[ii].first);
230 G4double dEdx = 0.;
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 // correct energies so that they reproduce the real step energy lost
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
257 G4double elostTot = 0.;
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}
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
G4double GetDEDX(G4double kinEnergy, const G4ParticleDefinition *, const G4Material *, const G4Region *r=nullptr)
G4double TrueStepLength(G4double kinEnergy, G4double step, const G4Material *, const G4ParticleDefinition *part)
const G4String & GetName() 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

Referenced by G4ScoreSplittingProcess::PostStepDoIt().


The documentation for this class was generated from the following files: