72 algorithm(ionAlgorithm),
75 maxCacheEntries(maxCacheSize) {
77 if(table ==
nullptr) {
78 G4cerr <<
"G4IonDEDXHandler::G4IonDEDXHandler() "
79 <<
" Pointer to G4VIonDEDXTable object is null-pointer."
83 if(algorithm ==
nullptr) {
84 G4cerr <<
"G4IonDEDXHandler::G4IonDEDXHandler() "
85 <<
" Pointer to G4VIonDEDXScalingAlgorithm object is null-pointer."
89 if(maxCacheEntries <= 0) {
90 G4cerr <<
"G4IonDEDXHandler::G4IonDEDXHandler() "
91 <<
" Cache size <=0. Resetting to 5."
110 stoppingPowerTableBragg.clear();
112 stoppingPowerTable.clear();
116 if(algorithm !=
nullptr)
126 G4bool isApplicable =
true;
128 if(table ==
nullptr || algorithm ==
nullptr) {
129 isApplicable =
false;
133 G4int atomicNumberIon = particle -> GetAtomicNumber();
134 G4int atomicNumberBase =
135 algorithm -> AtomicNumberBaseIon(atomicNumberIon, material);
137 G4IonKey key = std::make_pair(atomicNumberBase, material);
139 DEDXTable::iterator iter = stoppingPowerTable.find(key);
140 if(iter == stoppingPowerTable.end()) isApplicable =
false;
157 if(kineticEnergy <= 0.0) dedx = 0.0;
163 factor *= algorithm -> ScalingFactorDEDX(particle,
174 dedx = factor * value.
dedxVector -> GetValue(scaledKineticEnergy, b);
176 if(dedx < 0.0) dedx = 0.0;
181 G4cout <<
"G4IonDEDXHandler::GetDEDX() E = "
182 << kineticEnergy / MeV <<
" MeV * "
185 <<
" MeV, dE/dx = " << dedx / MeV * cm <<
" MeV/cm"
186 <<
", material = " << material ->
GetName()
199 G4int atomicNumberIon = particle -> GetAtomicNumber();
210 G4int atomicNumberIon,
213 G4bool isApplicable =
true;
215 if(table == 0 || algorithm == 0) {
216 isApplicable =
false;
220 G4int atomicNumberBase =
221 algorithm -> AtomicNumberBaseIon(atomicNumberIon, material);
225 G4IonKey key = std::make_pair(atomicNumberBase, material);
227 auto iter = stoppingPowerTable.find(key);
228 if(iter != stoppingPowerTable.end())
return isApplicable;
232 const G4String& chemFormula = material -> GetChemicalFormula();
235 isApplicable = table -> BuildPhysicsVector(atomicNumberBase, chemFormula);
238 stoppingPowerTable[key] =
239 table -> GetPhysicsVector(atomicNumberBase, chemFormula);
243 isApplicable = table -> BuildPhysicsVector(atomicNumberBase, materialName);
245 stoppingPowerTable[key] =
246 table -> GetPhysicsVector(atomicNumberBase, materialName);
251 const G4ElementVector* elementVector = material -> GetElementVector() ;
253 std::vector<G4PhysicsVector*> dEdxTable;
255 size_t nmbElements = material -> GetNumberOfElements();
257 for(
size_t i = 0; i < nmbElements; i++) {
259 G4int atomicNumberMat =
G4int((*elementVector)[i] -> GetZ());
261 isApplicable = table -> BuildPhysicsVector(atomicNumberBase, atomicNumberMat);
266 table -> GetPhysicsVector(atomicNumberBase, atomicNumberMat);
267 dEdxTable.push_back(dEdx);
278 if(dEdxTable.size() > 0) {
280 size_t nmbdEdxBins = dEdxTable[0] -> GetVectorLength();
281 G4double lowerEdge = dEdxTable[0] -> GetLowEdgeEnergy(0);
282 G4double upperEdge = dEdxTable[0] -> GetLowEdgeEnergy(nmbdEdxBins-1);
290 const G4double* massFractionVector = material -> GetFractionVector();
293 for(
size_t j = 0; j < nmbdEdxBins; j++) {
295 G4double edge = dEdxTable[0] -> GetLowEdgeEnergy(j);
298 for(
size_t i = 0; i < nmbElements; i++) {
300 value += (dEdxTable[i] -> GetValue(edge ,b)) *
301 massFractionVector[i];
304 dEdxBragg -> PutValues(j, edge, value);
307 dEdxBragg -> FillSecondDerivatives();
310 G4cout <<
"G4IonDEDXHandler::BuildPhysicsVector() for ion with Z="
311 << atomicNumberBase <<
" in "
318 stoppingPowerTable[key] = dEdxBragg;
319 stoppingPowerTableBragg[key] = dEdxBragg;
336 G4int atomicNumberIon = particle -> GetAtomicNumber();
337 G4int atomicNumberBase =
338 algorithm -> AtomicNumberBaseIon(atomicNumberIon, material);
340 G4IonKey key = std::make_pair(atomicNumberBase, material);
342 DEDXTable::iterator iter = stoppingPowerTable.find(key);
344 if(iter != stoppingPowerTable.end()) {
349 algorithm -> ScalingFactorEnergy(particle, material) / nmbNucleons;
351 size_t nmbdEdxBins = value.
dedxVector -> GetVectorLength();
355 value.
dedxVector -> GetLowEdgeEnergy(nmbdEdxBins-1);
356 value.
density = material -> GetDensity();
367 G4cout <<
"G4IonDEDXHandler::UpdateCacheValue() for "
368 << particle -> GetParticleName() <<
" in "
382 G4CacheKey key = std::make_pair(particle, material);
385 CacheEntryList::iterator* pointerIter =
386 (CacheEntryList::iterator*) cacheKeyPointers[key];
389 entry.value = UpdateCacheValue(particle, material);
392 cacheEntries.push_front(entry);
394 CacheEntryList::iterator* pointerIter1 =
395 new CacheEntryList::iterator();
396 *pointerIter1 = cacheEntries.begin();
397 cacheKeyPointers[key] = pointerIter1;
399 if(
G4int(cacheEntries.size()) > maxCacheEntries) {
401 G4CacheEntry lastEntry = cacheEntries.back();
403 void* pointerIter2 = cacheKeyPointers[lastEntry.key];
404 CacheEntryList::iterator* listPointerIter =
405 (CacheEntryList::iterator*) pointerIter2;
407 cacheEntries.erase(*listPointerIter);
409 delete listPointerIter;
410 cacheKeyPointers.erase(lastEntry.key);
414 entry = *(*pointerIter);
428 CacheIterPointerMap::iterator iter = cacheKeyPointers.begin();
429 CacheIterPointerMap::iterator iter_end = cacheKeyPointers.end();
431 for(;iter != iter_end; iter++) {
432 void* pointerIter = iter -> second;
433 CacheEntryList::iterator* listPointerIter =
434 (CacheEntryList::iterator*) pointerIter;
436 delete listPointerIter;
439 cacheEntries.clear();
440 cacheKeyPointers.clear();
453 G4double atomicMassNumber = particle -> GetAtomicMass();
454 G4double materialDensity = material -> GetDensity();
456 G4cout <<
"# dE/dx table for " << particle -> GetParticleName()
457 <<
" in material " << material ->
GetName()
458 <<
" of density " << materialDensity / g * cm3
461 <<
"# Projectile mass number A1 = " << atomicMassNumber
463 <<
"# Energy range (per nucleon) of tabulation: "
469 <<
"# ------------------------------------------------------"
472 << std::setw(13) << std::right <<
"E"
473 << std::setw(14) <<
"E/A1"
474 << std::setw(14) <<
"dE/dx"
475 << std::setw(14) <<
"1/rho*dE/dx"
478 << std::setw(13) << std::right <<
"(MeV)"
479 << std::setw(14) <<
"(MeV)"
480 << std::setw(14) <<
"(MeV/cm)"
481 << std::setw(14) <<
"(MeV*cm2/mg)"
483 <<
"# ------------------------------------------------------"
488 G4double energyLowerBoundary = lowerBoundary * atomicMassNumber;
489 G4double energyUpperBoundary = upperBoundary * atomicMassNumber;
493 energyLowerBoundary = std::log(energyLowerBoundary);
494 energyUpperBoundary = std::log(energyUpperBoundary);
497 G4double deltaEnergy = (energyUpperBoundary - energyLowerBoundary) /
501 for(
int i = 0; i < nmbBins + 1; i++) {
503 G4double energy = energyLowerBoundary + i * deltaEnergy;
504 if(logScaleEnergy) energy =
G4Exp(energy);
508 G4cout << std::setw(14) << std::right << energy / MeV
509 << std::setw(14) << energy / atomicMassNumber / MeV
510 << std::setw(14) << loss / MeV * cm
511 << std::setw(14) << loss / materialDensity / (MeV*cm2/(0.001*g))
std::vector< const G4Element * > G4ElementVector
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
void PrintDEDXTable(const G4ParticleDefinition *, const G4Material *, G4double, G4double, G4int, G4bool logScaleEnergy=true)
G4bool BuildDEDXTable(const G4ParticleDefinition *, const G4Material *)
G4IonDEDXHandler(G4VIonDEDXTable *tables, G4VIonDEDXScalingAlgorithm *algorithm, const G4String &name, G4int maxCacheSize=5, G4bool splines=true)
G4bool IsApplicable(const G4ParticleDefinition *, const G4Material *)
G4double GetLowerEnergyEdge(const G4ParticleDefinition *, const G4Material *)
G4double GetUpperEnergyEdge(const G4ParticleDefinition *, const G4Material *)
G4double GetDEDX(const G4ParticleDefinition *, const G4Material *, G4double)
G4PhysicsVector * dedxVector