Geant4-11
Public Member Functions | Private Member Functions | Private Attributes
G4EnergySplitter Class Reference

#include <G4EnergySplitter.hh>

Public Member Functions

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

Private Member Functions

void GetPhantomParam (G4bool mustExist)
 
void GetStepLength (G4int stepNo, G4double &stepLength)
 
G4bool IsPhantomVolume (G4VPhysicalVolume *pv)
 

Private Attributes

G4EnergyLossForExtrapolatortheElossExt
 
std::vector< G4doubletheEnergies
 
G4int theNIterations
 
G4PhantomParameterisationthePhantomParam
 

Detailed Description

Definition at line 46 of file G4EnergySplitter.hh.

Constructor & Destructor Documentation

◆ G4EnergySplitter()

G4EnergySplitter::G4EnergySplitter ( )

Definition at line 43 of file G4EnergySplitter.cc.

44{
48}
G4EnergyLossForExtrapolator * theElossExt
G4PhantomParameterisation * thePhantomParam

References theElossExt, theNIterations, and thePhantomParam.

◆ ~G4EnergySplitter()

G4EnergySplitter::~G4EnergySplitter ( )
virtual

Definition at line 50 of file G4EnergySplitter.cc.

51{
52 delete theElossExt;
53}

References theElossExt.

Member Function Documentation

◆ GetFirstVoxelID()

void G4EnergySplitter::GetFirstVoxelID ( G4int voxelID)

Definition at line 308 of file G4EnergySplitter.cc.

309{
310 voxelID = (*(G4RegularNavigationHelper::Instance()->GetStepLengths().rbegin())).first;
311}
const std::vector< std::pair< G4int, G4double > > & GetStepLengths()
static G4RegularNavigationHelper * Instance()

References G4RegularNavigationHelper::GetStepLengths(), and G4RegularNavigationHelper::Instance().

◆ GetLastVoxelID()

void G4EnergySplitter::GetLastVoxelID ( G4int voxelID)

Definition at line 302 of file G4EnergySplitter.cc.

303{
304 voxelID = (*(G4RegularNavigationHelper::Instance()->GetStepLengths().begin())).first;
305}

References G4RegularNavigationHelper::GetStepLengths(), and G4RegularNavigationHelper::Instance().

◆ 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

◆ GetPhantomParam()

void G4EnergySplitter::GetPhantomParam ( G4bool  mustExist)
private

Definition at line 261 of file G4EnergySplitter.cc.

262{
264 std::vector<G4VPhysicalVolume*>::iterator cite;
265 for( cite = pvs->begin(); cite != pvs->end(); cite++ ) {
266 // G4cout << " PV " << (*cite)->GetName() << " " << (*cite)->GetTranslation() << G4endl;
267 if( IsPhantomVolume( *cite ) ) {
268 const G4PVParameterised* pvparam = static_cast<const G4PVParameterised*>(*cite);
269 G4VPVParameterisation* param = pvparam->GetParameterisation();
270 // if( static_cast<const G4PhantomParameterisation*>(param) ){
271 // if( static_cast<const G4PhantomParameterisation*>(param) ){
272 // G4cout << "G4PhantomParameterisation volume found " << (*cite)->GetName() << G4endl;
273 thePhantomParam = static_cast<G4PhantomParameterisation*>(param);
274 }
275 }
276
277 if( !thePhantomParam && mustExist )
278 G4Exception("G4EnergySplitter::GetPhantomParam",
279 "PhantomParamError", FatalException,
280 "No G4PhantomParameterisation found !");
281}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
G4bool IsPhantomVolume(G4VPhysicalVolume *pv)
G4VPVParameterisation * GetParameterisation() const
static G4PhysicalVolumeStore * GetInstance()

References FatalException, G4Exception(), G4PhysicalVolumeStore::GetInstance(), G4PVParameterised::GetParameterisation(), IsPhantomVolume(), and thePhantomParam.

Referenced by SplitEnergyInVolumes().

◆ GetStepLength()

void G4EnergySplitter::GetStepLength ( G4int  stepNo,
G4double stepLength 
)
private

Definition at line 330 of file G4EnergySplitter.cc.

331{
332 std::vector< std::pair<G4int,G4double> >::const_iterator ite = G4RegularNavigationHelper::Instance()->GetStepLengths().begin();
333 advance( ite, stepNo );
334 stepLength = (*ite).second;
335}

References G4RegularNavigationHelper::GetStepLengths(), and G4RegularNavigationHelper::Instance().

◆ GetVoxelID()

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

Definition at line 314 of file G4EnergySplitter.cc.

315{
316 if( stepNo < 0 || stepNo >= G4int(G4RegularNavigationHelper::Instance()->GetStepLengths().size()) ) {
317 G4Exception("G4EnergySplitter::GetVoxelID",
318 "Invalid stepNo, smaller than 0 or bigger or equal to number of voxels traversed",
320 G4String("stepNo = " + G4UIcommand::ConvertToString(stepNo) + ", number of voxels = " + G4UIcommand::ConvertToString(G4int(G4RegularNavigationHelper::Instance()->GetStepLengths().size())) ).c_str());
321 }
322 std::vector< std::pair<G4int,G4double> >::const_iterator ite = G4RegularNavigationHelper::Instance()->GetStepLengths().begin();
323 advance( ite, stepNo );
324 voxelID = (*ite).first;
325
326}
@ FatalErrorInArgument
int G4int
Definition: G4Types.hh:85
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:445

References G4UIcommand::ConvertToString(), FatalErrorInArgument, G4Exception(), G4RegularNavigationHelper::GetStepLengths(), and G4RegularNavigationHelper::Instance().

Referenced by G4ScoreSplittingProcess::PostStepDoIt().

◆ GetVoxelIDAndLength()

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

◆ GetVoxelMaterial()

G4Material * G4EnergySplitter::GetVoxelMaterial ( G4int  stepNo)
inline

◆ IsPhantomVolume()

G4bool G4EnergySplitter::IsPhantomVolume ( G4VPhysicalVolume pv)
private

Definition at line 285 of file G4EnergySplitter.cc.

286{
287 EAxis axis;
288 G4int nReplicas;
289 G4double width,offset;
290 G4bool consuming;
291 pv->GetReplicationData(axis,nReplicas,width,offset,consuming);
292 EVolume type = (consuming) ? kReplica : kParameterised;
293 if( type == kParameterised && pv->GetRegularStructureId() == 1 ) {
294 return TRUE;
295 } else {
296 return FALSE;
297 }
298
299}
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
#define TRUE
Definition: Globals.hh:27
#define FALSE
Definition: Globals.hh:23
virtual void GetReplicationData(EAxis &axis, G4int &nReplicas, G4double &width, G4double &offset, G4bool &consuming) const =0
virtual G4int GetRegularStructureId() const =0
EAxis
Definition: geomdefs.hh:54
EVolume
Definition: geomdefs.hh:83
@ kParameterised
Definition: geomdefs.hh:86
@ kReplica
Definition: geomdefs.hh:85

References FALSE, G4VPhysicalVolume::GetRegularStructureId(), G4VPhysicalVolume::GetReplicationData(), kParameterised, kReplica, and TRUE.

Referenced by GetPhantomParam().

◆ SetNIterations()

void G4EnergySplitter::SetNIterations ( G4int  niter)
inline

◆ SplitEnergyInVolumes()

G4int G4EnergySplitter::SplitEnergyInVolumes ( const G4Step aStep)

Definition at line 55 of file G4EnergySplitter.cc.

56{
57 theEnergies.clear();
58
59 G4double edep = aStep->GetTotalEnergyDeposit();
60
61#ifdef VERBOSE_ENERSPLIT
62 G4bool verbose = 1;
63 if( verbose ) G4cout << "G4EnergySplitter::SplitEnergyInVolumes totalEdepo " << aStep->GetTotalEnergyDeposit()
64 << " Nsteps " << G4RegularNavigationHelper::Instance()->GetStepLengths().size() << G4endl;
65#endif
66 if( G4RegularNavigationHelper::Instance()->GetStepLengths().size() == 0 ||
67 aStep->GetTrack()->GetDefinition()->GetPDGCharge() == 0) { // we are only counting dose deposit
68 return theEnergies.size();
69 }
70 if( G4RegularNavigationHelper::Instance()->GetStepLengths().size() == 1 ) {
71 theEnergies.push_back(edep);
72 return theEnergies.size();
73 }
74
76
77 if( aStep == 0 ) return FALSE; // it is 0 when called by GmScoringMgr after last event
78
79 //----- Distribute energy deposited in voxels
80 std::vector< std::pair<G4int,G4double> > rnsl = G4RegularNavigationHelper::Instance()->GetStepLengths();
81
82 const G4ParticleDefinition* part = aStep->GetTrack()->GetDefinition();
83 G4double kinEnergyPreOrig = aStep->GetPreStepPoint()->GetKineticEnergy();
84 G4double kinEnergyPre = kinEnergyPreOrig;
85
86 G4double stepLength = aStep->GetStepLength();
87 G4double slSum = 0.;
88 unsigned int ii;
89 for( ii = 0; ii < rnsl.size(); ii++ ){
90 G4double sl = rnsl[ii].second;
91 slSum += sl;
92#ifdef VERBOSE_ENERSPLIT
93 if(verbose) G4cout << "G4EnergySplitter::SplitEnergyInVolumes"<< ii << " RN: iter1 step length geom " << sl << G4endl;
94#endif
95 }
96
97#ifdef VERBOSE_ENERSPLIT
98 if( verbose )
99 G4cout << "G4EnergySplitter RN: step length geom TOTAL " << slSum
100 << " true TOTAL " << stepLength
101 << " ratio " << stepLength/slSum
102 << " Energy " << aStep->GetPreStepPoint()->GetKineticEnergy()
103 << " Material " << aStep->GetPreStepPoint()->GetMaterial()->GetName()
104 << " Number of geom steps " << rnsl.size() << G4endl;
105#endif
106 //----- No iterations to correct elost and msc => distribute energy deposited according to geometrical step length in each voxel
107 if( theNIterations == 0 ) {
108 for( ii = 0; ii < rnsl.size(); ii++ ){
109 G4double sl = rnsl[ii].second;
110 G4double edepStep = edep * sl/slSum; //divide edep along steps, proportional to step length
111#ifdef VERBOSE_ENERSPLIT
112 if(verbose) G4cout << "G4EnergySplitter::SplitEnergyInVolumes"<< ii
113 << " edep " << edepStep << G4endl;
114#endif
115
116 theEnergies.push_back(edepStep);
117
118 }
119 } else { // 1 or more iterations demanded
120
121#ifdef VERBOSE_ENERSPLIT
122 // print corrected energy at iteration 0
123 if(verbose) {
124 G4double slSum = 0.;
125 for( ii = 0; ii < rnsl.size(); ii++ ){
126 G4double sl = rnsl[ii].second;
127 slSum += sl;
128 }
129 for( ii = 0; ii < rnsl.size(); ii++ ){
130 G4cout << "G4EnergySplitter::SplitEnergyInVolumes "<< ii
131 << " RN: iter0 corrected energy lost " << edep*rnsl[ii].second/slSum
132 << G4endl;
133 }
134 }
135#endif
136
137 G4double slRatio = stepLength/slSum;
138#ifdef VERBOSE_ENERSPLIT
139 if(verbose) G4cout << "G4EnergySplitter::SplitEnergyInVolumes RN: iter 0, step ratio " << slRatio << G4endl;
140#endif
141
142 //--- energy at each interaction
143 G4EmCalculator emcalc;
144 G4double totalELost = 0.;
145 std::vector<G4double> stepLengths;
146 for( int iiter = 1; iiter <= theNIterations; iiter++ ) {
147 //--- iter1: distribute true step length in each voxel: geom SL in each voxel is multiplied by a constant so that the sum gives the total true step length
148 if( iiter == 1 ) {
149 for( ii = 0; ii < rnsl.size(); ii++ ){
150 G4double sl = rnsl[ii].second;
151 stepLengths.push_back( sl * slRatio );
152#ifdef VERBOSE_ENERSPLIT
153 if(verbose) G4cout << "G4EnergySplitter::SplitEnergyInVolumes"<< ii << " RN: iter" << iiter << " corrected step length " << sl*slRatio << G4endl;
154#endif
155 }
156
157 for( ii = 0; ii < rnsl.size(); ii++ ){
158 const G4Material* mate = thePhantomParam->GetMaterial( rnsl[ii].first );
159 G4double dEdx = 0.;
160 if( kinEnergyPre > 0. ) { //t check this
161 dEdx = emcalc.GetDEDX(kinEnergyPre, part, mate);
162 }
163 G4double elost = stepLengths[ii] * dEdx;
164
165#ifdef VERBOSE_ENERSPLIT
166 if(verbose) G4cout << "G4EnergySplitter::SplitEnergyInVolumes"<< ii << " RN: iter1 energy lost " << elost
167 << " energy at interaction " << kinEnergyPre
168 << " = stepLength " << stepLengths[ii]
169 << " * dEdx " << dEdx << G4endl;
170#endif
171 kinEnergyPre -= elost;
172 theEnergies.push_back( elost );
173 totalELost += elost;
174 }
175
176 } else{
177 //------ 2nd and other iterations
178 //----- Get step lengths corrected by changing geom2true correction
179 //-- Get ratios for each energy
180 slSum = 0.;
181 kinEnergyPre = kinEnergyPreOrig;
182 for( ii = 0; ii < rnsl.size(); ii++ ){
183 const G4Material* mate = thePhantomParam->GetMaterial( rnsl[ii].first );
184 stepLengths[ii] = theElossExt->TrueStepLength( kinEnergyPre, rnsl[ii].second , mate, part );
185 kinEnergyPre -= theEnergies[ii];
186
187#ifdef VERBOSE_ENERSPLIT
188 if(verbose) G4cout << "G4EnergySplitter::SplitEnergyInVolumes" << ii
189 << " RN: iter" << iiter << " step length geom " << stepLengths[ii]
190 << " geom2true " << rnsl[ii].second / stepLengths[ii] << G4endl;
191#endif
192
193 slSum += stepLengths[ii];
194 }
195
196 //Correct step lengths so that they sum the total step length
197 G4double slratio = aStep->GetStepLength()/slSum;
198#ifdef VERBOSE_ENERSPLIT
199 if(verbose) G4cout << "G4EnergySplitter::SplitEnergyInVolumes" << ii << " RN: iter" << iiter << " step ratio " << slRatio << G4endl;
200#endif
201 for( ii = 0; ii < rnsl.size(); ii++ ){
202 stepLengths[ii] *= slratio;
203#ifdef VERBOSE_ENERSPLIT
204 if(verbose) G4cout << "G4EnergySplitter::SplitEnergyInVolumes"<< ii << " RN: iter" << iiter << " corrected step length " << stepLengths[ii] << G4endl;
205#endif
206 }
207
208 //---- Recalculate energy lost with this new step lengths
209 kinEnergyPre = aStep->GetPreStepPoint()->GetKineticEnergy();
210 totalELost = 0.;
211 for( ii = 0; ii < rnsl.size(); ii++ ){
212 const G4Material* mate = thePhantomParam->GetMaterial( rnsl[ii].first );
213 G4double dEdx = 0.;
214 if( kinEnergyPre > 0. ) {
215 dEdx = emcalc.GetDEDX(kinEnergyPre, part, mate);
216 }
217 G4double elost = stepLengths[ii] * dEdx;
218#ifdef VERBOSE_ENERSPLIT
219 if(verbose) G4cout << "G4EnergySplitter::SplitEnergyInVolumes"<< ii << " RN: iter" << iiter << " energy lost " << elost
220 << " energy at interaction " << kinEnergyPre
221 << " = stepLength " << stepLengths[ii]
222 << " * dEdx " << dEdx << G4endl;
223#endif
224 kinEnergyPre -= elost;
225 theEnergies[ii] = elost;
226 totalELost += elost;
227 }
228
229 }
230
231 //correct energies so that they reproduce the real step energy lost
232 G4double enerRatio = (edep/totalELost);
233
234#ifdef VERBOSE_ENERSPLIT
235 if(verbose) G4cout << "G4EnergySplitter::SplitEnergyInVolumes"<< ii << " RN: iter" << iiter << " energy ratio " << enerRatio << G4endl;
236#endif
237
238#ifdef VERBOSE_ENERSPLIT
239 G4double elostTot = 0.;
240#endif
241 for( ii = 0; ii < theEnergies.size(); ii++ ){
242 theEnergies[ii] *= enerRatio;
243#ifdef VERBOSE_ENERSPLIT
244 elostTot += theEnergies[ii];
245 if(verbose) G4cout << "G4EnergySplitter::SplitEnergyInVolumes "<< ii << " RN: iter" << iiter << " corrected energy lost " << theEnergies[ii]
246 << " orig elost " << theEnergies[ii]/enerRatio
247 << " energy before interaction " << kinEnergyPreOrig-elostTot+theEnergies[ii]
248 << " energy after interaction " << kinEnergyPreOrig-elostTot
249 << G4endl;
250#endif
251 }
252 }
253
254 }
255
256 return theEnergies.size();
257}
static constexpr double second
Definition: G4SIunits.hh:137
#define G4endl
Definition: G4ios.hh:57
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)
std::vector< G4double > theEnergies
void GetPhantomParam(G4bool mustExist)
const G4String & GetName() const
Definition: G4Material.hh:173
G4double GetPDGCharge() const
G4Material * GetMaterial(size_t nx, size_t ny, 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

References FALSE, G4cout, G4endl, G4EmCalculator::GetDEDX(), G4Track::GetDefinition(), G4StepPoint::GetKineticEnergy(), G4StepPoint::GetMaterial(), G4PhantomParameterisation::GetMaterial(), G4Material::GetName(), G4ParticleDefinition::GetPDGCharge(), GetPhantomParam(), G4Step::GetPreStepPoint(), G4Step::GetStepLength(), G4RegularNavigationHelper::GetStepLengths(), G4Step::GetTotalEnergyDeposit(), G4Step::GetTrack(), G4RegularNavigationHelper::Instance(), second, theElossExt, theEnergies, theNIterations, thePhantomParam, TRUE, and G4EnergyLossForExtrapolator::TrueStepLength().

Referenced by G4ScoreSplittingProcess::PostStepDoIt().

Field Documentation

◆ theElossExt

G4EnergyLossForExtrapolator* G4EnergySplitter::theElossExt
private

Definition at line 71 of file G4EnergySplitter.hh.

Referenced by G4EnergySplitter(), SplitEnergyInVolumes(), and ~G4EnergySplitter().

◆ theEnergies

std::vector<G4double> G4EnergySplitter::theEnergies
private

Definition at line 75 of file G4EnergySplitter.hh.

Referenced by SplitEnergyInVolumes().

◆ theNIterations

G4int G4EnergySplitter::theNIterations
private

Definition at line 73 of file G4EnergySplitter.hh.

Referenced by G4EnergySplitter(), and SplitEnergyInVolumes().

◆ thePhantomParam

G4PhantomParameterisation* G4EnergySplitter::thePhantomParam
private

Definition at line 77 of file G4EnergySplitter.hh.

Referenced by G4EnergySplitter(), GetPhantomParam(), and SplitEnergyInVolumes().


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