75 algorithm(ionAlgorithm),
78 maxCacheEntries(maxCacheSize) {
81 G4cerr <<
"G4IonDEDXHandler::G4IonDEDXHandler() "
82 <<
" Pointer to G4VIonDEDXTable object is null-pointer."
87 G4cerr <<
"G4IonDEDXHandler::G4IonDEDXHandler() "
88 <<
" Pointer to G4VIonDEDXScalingAlgorithm object is null-pointer."
92 if(maxCacheEntries <= 0) {
93 G4cerr <<
"G4IonDEDXHandler::G4IonDEDXHandler() "
94 <<
" Cache size <=0. Resetting to 5."
113 stoppingPowerTableBragg.clear();
115 stoppingPowerTable.clear();
117 if(table != 0)
delete table;
118 if(algorithm != 0)
delete algorithm;
127 G4bool isApplicable =
true;
129 if(table == 0 || algorithm == 0) {
130 isApplicable =
false;
134 G4int atomicNumberIon = particle -> GetAtomicNumber();
135 G4int atomicNumberBase =
136 algorithm -> AtomicNumberBaseIon(atomicNumberIon, material);
138 G4IonKey key = std::make_pair(atomicNumberBase, material);
140 DEDXTable::iterator iter = stoppingPowerTable.find(key);
141 if(iter == stoppingPowerTable.end()) isApplicable =
false;
158 if(kineticEnergy <= 0.0) dedx = 0.0;
164 factor *= algorithm -> ScalingFactorDEDX(particle,
175 dedx = factor * value.
dedxVector -> GetValue(scaledKineticEnergy, b);
177 if(dedx < 0.0) dedx = 0.0;
182 G4cout <<
"G4IonDEDXHandler::GetDEDX() E = "
183 << kineticEnergy / MeV <<
" MeV * "
186 <<
" MeV, dE/dx = " << dedx / MeV * cm <<
" MeV/cm"
187 <<
", material = " << material ->
GetName()
200 G4int atomicNumberIon = particle -> GetAtomicNumber();
211 G4int atomicNumberIon,
214 G4bool isApplicable =
true;
216 if(table == 0 || algorithm == 0) {
217 isApplicable =
false;
221 G4int atomicNumberBase =
222 algorithm -> AtomicNumberBaseIon(atomicNumberIon, material);
226 G4IonKey key = std::make_pair(atomicNumberBase, material);
228 DEDXTable::iterator iter = stoppingPowerTable.find(key);
229 if(iter != stoppingPowerTable.end())
return isApplicable;
233 const G4String& chemFormula = material -> GetChemicalFormula();
236 isApplicable = table -> BuildPhysicsVector(atomicNumberBase, chemFormula);
239 stoppingPowerTable[key] =
240 table -> GetPhysicsVector(atomicNumberBase, chemFormula);
244 isApplicable = table -> BuildPhysicsVector(atomicNumberBase, materialName);
246 stoppingPowerTable[key] =
247 table -> GetPhysicsVector(atomicNumberBase, materialName);
252 const G4ElementVector* elementVector = material -> GetElementVector() ;
254 std::vector<G4PhysicsVector*> dEdxTable;
256 size_t nmbElements = material -> GetNumberOfElements();
258 for(
size_t i = 0; i < nmbElements; i++) {
260 G4int atomicNumberMat =
G4int((*elementVector)[i] -> GetZ());
262 isApplicable = table -> BuildPhysicsVector(atomicNumberBase, atomicNumberMat);
267 table -> GetPhysicsVector(atomicNumberBase, atomicNumberMat);
268 dEdxTable.push_back(dEdx);
279 if(dEdxTable.size() > 0) {
281 size_t nmbdEdxBins = dEdxTable[0] -> GetVectorLength();
282 G4double lowerEdge = dEdxTable[0] -> GetLowEdgeEnergy(0);
283 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);
306 dEdxBragg -> SetSpline(useSplines);
309 G4cout <<
"G4IonDEDXHandler::BuildPhysicsVector() for ion with Z="
310 << atomicNumberBase <<
" in "
317 stoppingPowerTable[key] = dEdxBragg;
318 stoppingPowerTableBragg[key] = dEdxBragg;
335 G4int atomicNumberIon = particle -> GetAtomicNumber();
336 G4int atomicNumberBase =
337 algorithm -> AtomicNumberBaseIon(atomicNumberIon, material);
339 G4IonKey key = std::make_pair(atomicNumberBase, material);
341 DEDXTable::iterator iter = stoppingPowerTable.find(key);
343 if(iter != stoppingPowerTable.end()) {
348 algorithm -> ScalingFactorEnergy(particle, material) / nmbNucleons;
350 size_t nmbdEdxBins = value.
dedxVector -> GetVectorLength();
354 value.
dedxVector -> GetLowEdgeEnergy(nmbdEdxBins-1);
355 value.
density = material -> GetDensity();
366 G4cout <<
"G4IonDEDXHandler::UpdateCacheValue() for "
367 << particle -> GetParticleName() <<
" in "
381 G4CacheKey key = std::make_pair(particle, material);
384 CacheEntryList::iterator* pointerIter =
385 (CacheEntryList::iterator*) cacheKeyPointers[key];
388 entry.value = UpdateCacheValue(particle, material);
391 cacheEntries.push_front(entry);
393 CacheEntryList::iterator* pointerIter1 =
394 new CacheEntryList::iterator();
395 *pointerIter1 = cacheEntries.begin();
396 cacheKeyPointers[key] = pointerIter1;
398 if(
G4int(cacheEntries.size()) > maxCacheEntries) {
400 G4CacheEntry lastEntry = cacheEntries.back();
402 void* pointerIter2 = cacheKeyPointers[lastEntry.key];
403 CacheEntryList::iterator* listPointerIter =
404 (CacheEntryList::iterator*) pointerIter2;
406 cacheEntries.erase(*listPointerIter);
408 delete listPointerIter;
409 cacheKeyPointers.erase(lastEntry.key);
413 entry = *(*pointerIter);
427 CacheIterPointerMap::iterator iter = cacheKeyPointers.begin();
428 CacheIterPointerMap::iterator iter_end = cacheKeyPointers.end();
430 for(;iter != iter_end; iter++) {
431 void* pointerIter = iter -> second;
432 CacheEntryList::iterator* listPointerIter =
433 (CacheEntryList::iterator*) pointerIter;
435 delete listPointerIter;
438 cacheEntries.clear();
439 cacheKeyPointers.clear();
452 G4double atomicMassNumber = particle -> GetAtomicMass();
453 G4double materialDensity = material -> GetDensity();
455 G4cout <<
"# dE/dx table for " << particle -> GetParticleName()
456 <<
" in material " << material ->
GetName()
457 <<
" of density " << materialDensity / g * cm3
460 <<
"# Projectile mass number A1 = " << atomicMassNumber
462 <<
"# Energy range (per nucleon) of tabulation: "
468 <<
"# ------------------------------------------------------"
471 << std::setw(13) << std::right <<
"E"
472 << std::setw(14) <<
"E/A1"
473 << std::setw(14) <<
"dE/dx"
474 << std::setw(14) <<
"1/rho*dE/dx"
477 << std::setw(13) << std::right <<
"(MeV)"
478 << std::setw(14) <<
"(MeV)"
479 << std::setw(14) <<
"(MeV/cm)"
480 << std::setw(14) <<
"(MeV*cm2/mg)"
482 <<
"# ------------------------------------------------------"
487 G4double energyLowerBoundary = lowerBoundary * atomicMassNumber;
488 G4double energyUpperBoundary = upperBoundary * atomicMassNumber;
492 energyLowerBoundary = std::log(energyLowerBoundary);
493 energyUpperBoundary = std::log(energyUpperBoundary);
496 G4double deltaEnergy = (energyUpperBoundary - energyLowerBoundary) /
500 for(
int i = 0; i < nmbBins + 1; i++) {
502 G4double energy = energyLowerBoundary + i * deltaEnergy;
503 if(logScaleEnergy) energy =
G4Exp(energy);
507 G4cout << std::setw(14) << std::right << energy / MeV
508 << std::setw(14) << energy / atomicMassNumber / MeV
509 << std::setw(14) << loss / MeV * cm
510 << std::setw(14) << loss / materialDensity / (MeV*cm2/(0.001*g))
std::vector< 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