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

#include <G4IonDEDXHandler.hh>

Public Member Functions

 G4IonDEDXHandler (G4VIonDEDXTable *tables, G4VIonDEDXScalingAlgorithm *algorithm, const G4String &name, G4int maxCacheSize=5, G4bool splines=true)
 
 ~G4IonDEDXHandler ()
 
G4bool IsApplicable (const G4ParticleDefinition *, const G4Material *)
 
G4double GetDEDX (const G4ParticleDefinition *, const G4Material *, G4double)
 
G4bool BuildDEDXTable (const G4ParticleDefinition *, const G4Material *)
 
G4bool BuildDEDXTable (G4int atomicNumberIon, const G4Material *)
 
void PrintDEDXTable (const G4ParticleDefinition *, const G4Material *, G4double, G4double, G4int, G4bool logScaleEnergy=true)
 
G4double GetLowerEnergyEdge (const G4ParticleDefinition *, const G4Material *)
 
G4double GetUpperEnergyEdge (const G4ParticleDefinition *, const G4Material *)
 
void ClearCache ()
 
G4String GetName ()
 

Detailed Description

Definition at line 82 of file G4IonDEDXHandler.hh.

Constructor & Destructor Documentation

◆ G4IonDEDXHandler()

G4IonDEDXHandler::G4IonDEDXHandler ( G4VIonDEDXTable tables,
G4VIonDEDXScalingAlgorithm algorithm,
const G4String name,
G4int  maxCacheSize = 5,
G4bool  splines = true 
)

Definition at line 67 of file G4IonDEDXHandler.cc.

72 :
73 table(ionTable),
74 algorithm(ionAlgorithm),
75 tableName(name),
76 useSplines(splines),
77 maxCacheEntries(maxCacheSize) {
78
79 if(table == 0) {
80 G4cerr << "G4IonDEDXHandler::G4IonDEDXHandler() "
81 << " Pointer to G4VIonDEDXTable object is null-pointer."
82 << G4endl;
83 }
84
85 if(algorithm == 0) {
86 G4cerr << "G4IonDEDXHandler::G4IonDEDXHandler() "
87 << " Pointer to G4VIonDEDXScalingAlgorithm object is null-pointer."
88 << G4endl;
89 }
90
91 if(maxCacheEntries <= 0) {
92 G4cerr << "G4IonDEDXHandler::G4IonDEDXHandler() "
93 << " Cache size <=0. Resetting to 5."
94 << G4endl;
95 maxCacheEntries = 5;
96 }
97}
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cerr

◆ ~G4IonDEDXHandler()

G4IonDEDXHandler::~G4IonDEDXHandler ( )

Definition at line 101 of file G4IonDEDXHandler.cc.

101 {
102
103 ClearCache();
104
105 // All stopping power vectors built according to Bragg's addivitiy rule
106 // are deleted. All other stopping power vectors are expected to be
107 // deleted by their creator class (sub-class of G4VIonDEDXTable).
108 DEDXTableBraggRule::iterator iter = stoppingPowerTableBragg.begin();
109 DEDXTableBraggRule::iterator iter_end = stoppingPowerTableBragg.end();
110
111 for(;iter != iter_end; iter++) delete iter -> second;
112 stoppingPowerTableBragg.clear();
113
114 stoppingPowerTable.clear();
115
116 if(table != 0) delete table;
117 if(algorithm != 0) delete algorithm;
118}

Member Function Documentation

◆ BuildDEDXTable() [1/2]

G4bool G4IonDEDXHandler::BuildDEDXTable ( const G4ParticleDefinition particle,
const G4Material material 
)

Definition at line 195 of file G4IonDEDXHandler.cc.

197 { // Target material
198
199 G4int atomicNumberIon = particle -> GetAtomicNumber();
200
201 G4bool isApplicable = BuildDEDXTable(atomicNumberIon, material);
202
203 return isApplicable;
204}
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
G4bool BuildDEDXTable(const G4ParticleDefinition *, const G4Material *)

Referenced by BuildDEDXTable().

◆ BuildDEDXTable() [2/2]

G4bool G4IonDEDXHandler::BuildDEDXTable ( G4int  atomicNumberIon,
const G4Material material 
)

Definition at line 209 of file G4IonDEDXHandler.cc.

211 { // Target material
212
213 G4bool isApplicable = true;
214
215 if(table == 0 || algorithm == 0) {
216 isApplicable = false;
217 return isApplicable;
218 }
219
220 G4int atomicNumberBase =
221 algorithm -> AtomicNumberBaseIon(atomicNumberIon, material);
222
223 // Checking if vector is already built, and returns if this is indeed
224 // the case
225 G4IonKey key = std::make_pair(atomicNumberBase, material);
226
227 DEDXTable::iterator iter = stoppingPowerTable.find(key);
228 if(iter != stoppingPowerTable.end()) return isApplicable;
229
230 // Checking if table contains stopping power vector for given material name
231 // or chemical formula
232 const G4String& chemFormula = material -> GetChemicalFormula();
233 const G4String& materialName = material -> GetName();
234
235 isApplicable = table -> BuildPhysicsVector(atomicNumberBase, chemFormula);
236
237 if(isApplicable) {
238 stoppingPowerTable[key] =
239 table -> GetPhysicsVector(atomicNumberBase, chemFormula);
240 return isApplicable;
241 }
242
243 isApplicable = table -> BuildPhysicsVector(atomicNumberBase, materialName);
244 if(isApplicable) {
245 stoppingPowerTable[key] =
246 table -> GetPhysicsVector(atomicNumberBase, materialName);
247 return isApplicable;
248 }
249
250 // Building the stopping power vector based on Bragg's additivity rule
251 const G4ElementVector* elementVector = material -> GetElementVector() ;
252
253 std::vector<G4PhysicsVector*> dEdxTable;
254
255 size_t nmbElements = material -> GetNumberOfElements();
256
257 for(size_t i = 0; i < nmbElements; i++) {
258
259 G4int atomicNumberMat = G4int((*elementVector)[i] -> GetZ());
260
261 isApplicable = table -> BuildPhysicsVector(atomicNumberBase, atomicNumberMat);
262
263 if(isApplicable) {
264
265 G4PhysicsVector* dEdx =
266 table -> GetPhysicsVector(atomicNumberBase, atomicNumberMat);
267 dEdxTable.push_back(dEdx);
268 }
269 else {
270
271 dEdxTable.clear();
272 break;
273 }
274 }
275
276 if(isApplicable) {
277
278 if(dEdxTable.size() > 0) {
279
280 size_t nmbdEdxBins = dEdxTable[0] -> GetVectorLength();
281 G4double lowerEdge = dEdxTable[0] -> GetLowEdgeEnergy(0);
282 G4double upperEdge = dEdxTable[0] -> GetLowEdgeEnergy(nmbdEdxBins-1);
283
284 G4LPhysicsFreeVector* dEdxBragg =
285 new G4LPhysicsFreeVector(nmbdEdxBins,
286 lowerEdge,
287 upperEdge);
288 dEdxBragg -> SetSpline(useSplines);
289
290 const G4double* massFractionVector = material -> GetFractionVector();
291
292 G4bool b;
293 for(size_t j = 0; j < nmbdEdxBins; j++) {
294
295 G4double edge = dEdxTable[0] -> GetLowEdgeEnergy(j);
296
297 G4double value = 0.0;
298 for(size_t i = 0; i < nmbElements; i++) {
299
300 value += (dEdxTable[i] -> GetValue(edge ,b)) *
301 massFractionVector[i];
302 }
303
304 dEdxBragg -> PutValues(j, edge, value);
305 }
306
307#ifdef PRINT_DEBUG
308 G4cout << "G4IonDEDXHandler::BuildPhysicsVector() for ion with Z="
309 << atomicNumberBase << " in "
310 << material -> GetName()
311 << G4endl;
312
313 G4cout << *dEdxBragg;
314#endif
315
316 stoppingPowerTable[key] = dEdxBragg;
317 stoppingPowerTableBragg[key] = dEdxBragg;
318 }
319 }
320
321 ClearCache();
322
323 return isApplicable;
324}
std::vector< G4Element * > G4ElementVector
double G4double
Definition: G4Types.hh:64
G4DLLIMPORT std::ostream G4cout

◆ ClearCache()

void G4IonDEDXHandler::ClearCache ( )

Definition at line 424 of file G4IonDEDXHandler.cc.

424 {
425
426 CacheIterPointerMap::iterator iter = cacheKeyPointers.begin();
427 CacheIterPointerMap::iterator iter_end = cacheKeyPointers.end();
428
429 for(;iter != iter_end; iter++) {
430 void* pointerIter = iter -> second;
431 CacheEntryList::iterator* listPointerIter =
432 (CacheEntryList::iterator*) pointerIter;
433
434 delete listPointerIter;
435 }
436
437 cacheEntries.clear();
438 cacheKeyPointers.clear();
439}

Referenced by BuildDEDXTable(), and ~G4IonDEDXHandler().

◆ GetDEDX()

G4double G4IonDEDXHandler::GetDEDX ( const G4ParticleDefinition particle,
const G4Material material,
G4double  kineticEnergy 
)

Definition at line 148 of file G4IonDEDXHandler.cc.

151 { // Kinetic energy of projectile
152
153 G4double dedx = 0.0;
154
155 G4CacheValue value = GetCacheValue(particle, material);
156
157 if(kineticEnergy <= 0.0) dedx = 0.0;
158 else if(value.dedxVector != 0) {
159
160 G4bool b;
161 G4double factor = value.density;
162
163 factor *= algorithm -> ScalingFactorDEDX(particle,
164 material,
165 kineticEnergy);
166 G4double scaledKineticEnergy = kineticEnergy * value.energyScaling;
167
168 if(scaledKineticEnergy < value.lowerEnergyEdge) {
169
170 factor *= std::sqrt(scaledKineticEnergy / value.lowerEnergyEdge);
171 scaledKineticEnergy = value.lowerEnergyEdge;
172 }
173
174 dedx = factor * value.dedxVector -> GetValue(scaledKineticEnergy, b);
175
176 if(dedx < 0.0) dedx = 0.0;
177 }
178 else dedx = 0.0;
179
180#ifdef PRINT_DEBUG
181 G4cout << "G4IonDEDXHandler::GetDEDX() E = "
182 << kineticEnergy / MeV << " MeV * "
183 << value.energyScaling << " = "
184 << kineticEnergy * value.energyScaling / MeV
185 << " MeV, dE/dx = " << dedx / MeV * cm << " MeV/cm"
186 << ", material = " << material -> GetName()
187 << G4endl;
188#endif
189
190 return dedx;
191}
G4double lowerEnergyEdge
G4double density
G4PhysicsVector * dedxVector
G4double energyScaling

Referenced by PrintDEDXTable().

◆ GetLowerEnergyEdge()

G4double G4IonDEDXHandler::GetLowerEnergyEdge ( const G4ParticleDefinition particle,
const G4Material material 
)

Definition at line 516 of file G4IonDEDXHandler.cc.

518 { // Target material
519
520 G4double edge = 0.0;
521
522 G4CacheValue value = GetCacheValue(particle, material);
523
524 if(value.energyScaling > 0)
525 edge = value.lowerEnergyEdge / value.energyScaling;
526
527 return edge;
528}

Referenced by PrintDEDXTable().

◆ GetName()

G4String G4IonDEDXHandler::GetName ( )

Definition at line 548 of file G4IonDEDXHandler.cc.

548 {
549
550 return tableName;
551}

Referenced by BuildDEDXTable(), GetDEDX(), and PrintDEDXTable().

◆ GetUpperEnergyEdge()

G4double G4IonDEDXHandler::GetUpperEnergyEdge ( const G4ParticleDefinition particle,
const G4Material material 
)

Definition at line 532 of file G4IonDEDXHandler.cc.

534 { // Target material
535
536 G4double edge = 0.0;
537
538 G4CacheValue value = GetCacheValue(particle, material);
539
540 if(value.energyScaling > 0)
541 edge = value.upperEnergyEdge / value.energyScaling;
542
543 return edge;
544}
G4double upperEnergyEdge

Referenced by PrintDEDXTable().

◆ IsApplicable()

G4bool G4IonDEDXHandler::IsApplicable ( const G4ParticleDefinition particle,
const G4Material material 
)

Definition at line 122 of file G4IonDEDXHandler.cc.

124 { // Target material
125
126 G4bool isApplicable = true;
127
128 if(table == 0 || algorithm == 0) {
129 isApplicable = false;
130 }
131 else {
132
133 G4int atomicNumberIon = particle -> GetAtomicNumber();
134 G4int atomicNumberBase =
135 algorithm -> AtomicNumberBaseIon(atomicNumberIon, material);
136
137 G4IonKey key = std::make_pair(atomicNumberBase, material);
138
139 DEDXTable::iterator iter = stoppingPowerTable.find(key);
140 if(iter == stoppingPowerTable.end()) isApplicable = false;
141 }
142
143 return isApplicable;
144}

◆ PrintDEDXTable()

void G4IonDEDXHandler::PrintDEDXTable ( const G4ParticleDefinition particle,
const G4Material material,
G4double  lowerBoundary,
G4double  upperBoundary,
G4int  nmbBins,
G4bool  logScaleEnergy = true 
)

Definition at line 443 of file G4IonDEDXHandler.cc.

449 { // Logarithmic scaling of energy
450
451 G4double atomicMassNumber = particle -> GetAtomicMass();
452 G4double materialDensity = material -> GetDensity();
453
454 G4cout << "# dE/dx table for " << particle -> GetParticleName()
455 << " in material " << material -> GetName()
456 << " of density " << materialDensity / g * cm3
457 << " g/cm3"
458 << G4endl
459 << "# Projectile mass number A1 = " << atomicMassNumber
460 << G4endl
461 << "# Energy range (per nucleon) of tabulation: "
462 << GetLowerEnergyEdge(particle, material) / atomicMassNumber / MeV
463 << " - "
464 << GetUpperEnergyEdge(particle, material) / atomicMassNumber / MeV
465 << " MeV"
466 << G4endl
467 << "# ------------------------------------------------------"
468 << G4endl;
469 G4cout << "#"
470 << std::setw(13) << std::right << "E"
471 << std::setw(14) << "E/A1"
472 << std::setw(14) << "dE/dx"
473 << std::setw(14) << "1/rho*dE/dx"
474 << G4endl;
475 G4cout << "#"
476 << std::setw(13) << std::right << "(MeV)"
477 << std::setw(14) << "(MeV)"
478 << std::setw(14) << "(MeV/cm)"
479 << std::setw(14) << "(MeV*cm2/mg)"
480 << G4endl
481 << "# ------------------------------------------------------"
482 << G4endl;
483
484 //G4CacheValue value = GetCacheValue(particle, material);
485
486 G4double energyLowerBoundary = lowerBoundary * atomicMassNumber;
487 G4double energyUpperBoundary = upperBoundary * atomicMassNumber;
488
489 if(logScaleEnergy) {
490
491 energyLowerBoundary = std::log(energyLowerBoundary);
492 energyUpperBoundary = std::log(energyUpperBoundary);
493 }
494
495 G4double deltaEnergy = (energyUpperBoundary - energyLowerBoundary) /
496 G4double(nmbBins);
497
498 G4cout.precision(6);
499 for(int i = 0; i < nmbBins + 1; i++) {
500
501 G4double energy = energyLowerBoundary + i * deltaEnergy;
502 if(logScaleEnergy) energy = std::exp(energy);
503
504 G4double loss = GetDEDX(particle, material, energy);
505
506 G4cout << std::setw(14) << std::right << energy / MeV
507 << std::setw(14) << energy / atomicMassNumber / MeV
508 << std::setw(14) << loss / MeV * cm
509 << std::setw(14) << loss / materialDensity / (MeV*cm2/(0.001*g))
510 << G4endl;
511 }
512}
G4double GetLowerEnergyEdge(const G4ParticleDefinition *, const G4Material *)
G4double GetUpperEnergyEdge(const G4ParticleDefinition *, const G4Material *)
G4double GetDEDX(const G4ParticleDefinition *, const G4Material *, G4double)

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