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

#include <G4ExtDEDXTable.hh>

+ Inheritance diagram for G4ExtDEDXTable:

Public Member Functions

 G4ExtDEDXTable ()=default
 
 ~G4ExtDEDXTable () override
 
 G4ExtDEDXTable (G4ExtDEDXTable &)=delete
 
const G4ExtDEDXTableoperator= (const G4ExtDEDXTable &)=delete
 
G4bool BuildPhysicsVector (G4int ionZ, const G4String &matName) override
 
G4bool BuildPhysicsVector (G4int ionZ, G4int matZ) override
 
G4bool IsApplicable (G4int atomicNumberIon, G4int atomicNumberElem) override
 
G4bool IsApplicable (G4int atomicNumberIon, const G4String &matIdentifier) override
 
G4PhysicsVectorGetPhysicsVector (G4int atomicNumberIon, G4int atomicNumberElem) override
 
G4PhysicsVectorGetPhysicsVector (G4int atomicNumberIon, const G4String &matIdenfier) override
 
G4double GetDEDX (G4double kinEnergyPerNucleon, G4int atomicNumberIon, G4int atomicNumberElem)
 
G4double GetDEDX (G4double kinEnergyPerNucleon, G4int atomicNumberIon, const G4String &matIdenfier)
 
G4bool AddPhysicsVector (G4PhysicsVector *physicsVector, G4int atomicNumberIon, const G4String &matIdenfier, G4int atomicNumberElem=0)
 
G4bool RemovePhysicsVector (G4int atomicNumberIon, const G4String &matIdentifier)
 
G4bool StorePhysicsTable (const G4String &fileName)
 
G4bool RetrievePhysicsTable (const G4String &fileName)
 
void ClearTable ()
 
void DumpMap ()
 
- Public Member Functions inherited from G4VIonDEDXTable
 G4VIonDEDXTable ()=default
 
virtual ~G4VIonDEDXTable ()=default
 
 G4VIonDEDXTable (G4VIonDEDXTable &)=delete
 
const G4VIonDEDXTableoperator= (const G4VIonDEDXTable &)=delete
 

Detailed Description

Definition at line 61 of file G4ExtDEDXTable.hh.

Constructor & Destructor Documentation

◆ G4ExtDEDXTable() [1/2]

G4ExtDEDXTable::G4ExtDEDXTable ( )
explicitdefault

◆ ~G4ExtDEDXTable()

G4ExtDEDXTable::~G4ExtDEDXTable ( )
override

Definition at line 68 of file G4ExtDEDXTable.cc.

68{ ClearTable(); }

◆ G4ExtDEDXTable() [2/2]

G4ExtDEDXTable::G4ExtDEDXTable ( G4ExtDEDXTable & )
delete

Member Function Documentation

◆ AddPhysicsVector()

G4bool G4ExtDEDXTable::AddPhysicsVector ( G4PhysicsVector * physicsVector,
G4int atomicNumberIon,
const G4String & matIdenfier,
G4int atomicNumberElem = 0 )

Definition at line 166 of file G4ExtDEDXTable.cc.

171{
172 if (physicsVector == nullptr) {
173 G4Exception("G4ExtDEDXTable::AddPhysicsVector() for material", "mat037", FatalException,
174 "Pointer to vector is null-pointer.");
175 return false;
176 }
177
178 if (matIdentifier.empty()) {
179 G4Exception("G4ExtDEDXTable::AddPhysicsVector() for material", "mat038", FatalException,
180 "Invalid name of the material.");
181 return false;
182 }
183
184 if (atomicNumberIon <= 2) {
185 G4Exception("G4ExtDEDXTable::AddPhysicsVector() for material", "mat039", FatalException,
186 "Illegal atomic number.");
187 return false;
188 }
189
190 if (atomicNumberElem > 0) {
191 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
192
193 if (dedxMapElements.count(key) == 1) {
194 G4Exception("G4ExtDEDXTable::AddPhysicsVector() for material", "mat037", FatalException,
195 "Vector already exist, remove it before replacing.");
196 return false;
197 }
198
199 dedxMapElements[key] = physicsVector;
200 }
201
202 G4IonDEDXKeyMat mkey = std::make_pair(atomicNumberIon, matIdentifier);
203
204 if (dedxMapMaterials.count(mkey) == 1) {
205 G4Exception("G4ExtDEDXTable::AddPhysicsVector() for material", "mat037", FatalException,
206 "Vector already exist, remove it before replacing.");
207 return false;
208 }
209
210 dedxMapMaterials[mkey] = physicsVector;
211
212 return true;
213}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)

Referenced by RetrievePhysicsTable().

◆ BuildPhysicsVector() [1/2]

G4bool G4ExtDEDXTable::BuildPhysicsVector ( G4int ionZ,
const G4String & matName )
overridevirtual

Implements G4VIonDEDXTable.

Definition at line 79 of file G4ExtDEDXTable.cc.

80{
81 return IsApplicable(ionZ, matName);
82}
G4bool IsApplicable(G4int atomicNumberIon, G4int atomicNumberElem) override

◆ BuildPhysicsVector() [2/2]

G4bool G4ExtDEDXTable::BuildPhysicsVector ( G4int ionZ,
G4int matZ )
overridevirtual

Implements G4VIonDEDXTable.

Definition at line 72 of file G4ExtDEDXTable.cc.

73{
74 return IsApplicable(ionZ, matZ);
75}

◆ ClearTable()

void G4ExtDEDXTable::ClearTable ( )

Definition at line 464 of file G4ExtDEDXTable.cc.

465{
466 auto iterMat = dedxMapMaterials.begin();
467 auto iterMat_end = dedxMapMaterials.end();
468
469 for (; iterMat != iterMat_end; ++iterMat) {
470 G4PhysicsVector* vec = iterMat->second;
471
472 delete vec;
473 }
474
475 dedxMapElements.clear();
476 dedxMapMaterials.clear();
477}

Referenced by ~G4ExtDEDXTable().

◆ DumpMap()

void G4ExtDEDXTable::DumpMap ( )

Definition at line 481 of file G4ExtDEDXTable.cc.

482{
483 auto iterMat = dedxMapMaterials.begin();
484 auto iterMat_end = dedxMapMaterials.end();
485
486 G4cout << std::setw(15) << std::right << "Atomic nmb ion" << std::setw(25) << std::right
487 << "Material name" << std::setw(25) << std::right << "Atomic nmb material" << G4endl;
488
489 for (; iterMat != iterMat_end; ++iterMat) {
490 G4IonDEDXKeyMat key = iterMat->first;
491 G4PhysicsVector* physicsVector = iterMat->second;
492
493 G4int atomicNumberIon = key.first;
494 G4String matIdentifier = key.second;
495
496 G4int atomicNumberElem = FindAtomicNumberElement(physicsVector);
497
498 if (physicsVector != nullptr) {
499 G4cout << std::setw(15) << std::right << atomicNumberIon << std::setw(25) << std::right
500 << matIdentifier << std::setw(25) << std::right;
501
502 if (atomicNumberElem > 0) {
503 G4cout << atomicNumberElem;
504 }
505 else {
506 G4cout << "N/A";
507 }
508
509 G4cout << G4endl;
510 }
511 }
512}
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout

◆ GetDEDX() [1/2]

G4double G4ExtDEDXTable::GetDEDX ( G4double kinEnergyPerNucleon,
G4int atomicNumberIon,
const G4String & matIdenfier )

Definition at line 152 of file G4ExtDEDXTable.cc.

156{
157 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
158
159 auto iter = dedxMapMaterials.find(key);
160
161 return (iter != dedxMapMaterials.end()) ? (iter->second)->Value(kinEnergyPerNucleon) : 0.0;
162}

◆ GetDEDX() [2/2]

G4double G4ExtDEDXTable::GetDEDX ( G4double kinEnergyPerNucleon,
G4int atomicNumberIon,
G4int atomicNumberElem )

Definition at line 138 of file G4ExtDEDXTable.cc.

142{
143 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
144
145 auto iter = dedxMapElements.find(key);
146
147 return (iter != dedxMapElements.end()) ? (iter->second)->Value(kinEnergyPerNucleon) : 0.0;
148}

◆ GetPhysicsVector() [1/2]

G4PhysicsVector * G4ExtDEDXTable::GetPhysicsVector ( G4int atomicNumberIon,
const G4String & matIdenfier )
overridevirtual

Implements G4VIonDEDXTable.

Definition at line 125 of file G4ExtDEDXTable.cc.

128{
129 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
130
131 auto iter = dedxMapMaterials.find(key);
132
133 return (iter != dedxMapMaterials.end()) ? iter->second : nullptr;
134}

◆ GetPhysicsVector() [2/2]

G4PhysicsVector * G4ExtDEDXTable::GetPhysicsVector ( G4int atomicNumberIon,
G4int atomicNumberElem )
overridevirtual

Implements G4VIonDEDXTable.

Definition at line 112 of file G4ExtDEDXTable.cc.

115{
116 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
117
118 auto iter = dedxMapElements.find(key);
119
120 return (iter != dedxMapElements.end()) ? iter->second : nullptr;
121}

◆ IsApplicable() [1/2]

G4bool G4ExtDEDXTable::IsApplicable ( G4int atomicNumberIon,
const G4String & matIdentifier )
overridevirtual

Implements G4VIonDEDXTable.

Definition at line 99 of file G4ExtDEDXTable.cc.

102{
103 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
104
105 auto iter = dedxMapMaterials.find(key);
106
107 return iter != dedxMapMaterials.end();
108}

◆ IsApplicable() [2/2]

G4bool G4ExtDEDXTable::IsApplicable ( G4int atomicNumberIon,
G4int atomicNumberElem )
overridevirtual

Implements G4VIonDEDXTable.

Definition at line 86 of file G4ExtDEDXTable.cc.

89{
90 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
91
92 auto iter = dedxMapElements.find(key);
93
94 return iter != dedxMapElements.end();
95}

Referenced by BuildPhysicsVector(), and BuildPhysicsVector().

◆ operator=()

const G4ExtDEDXTable & G4ExtDEDXTable::operator= ( const G4ExtDEDXTable & )
delete

◆ RemovePhysicsVector()

G4bool G4ExtDEDXTable::RemovePhysicsVector ( G4int atomicNumberIon,
const G4String & matIdentifier )

Definition at line 217 of file G4ExtDEDXTable.cc.

220{
221 G4PhysicsVector* physicsVector = nullptr;
222
223 // Deleting key of physics vector from material map
224 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
225
226 auto iter = dedxMapMaterials.find(key);
227
228 if (iter == dedxMapMaterials.end()) {
229 G4Exception("G4ExtDEDXTable::RemovePhysicsVector() for material", "mat037", FatalException,
230 "Pointer to vector is null-pointer.");
231 return false;
232 }
233
234 physicsVector = (*iter).second;
235 dedxMapMaterials.erase(key);
236
237 // Deleting key of physics vector from elemental material map (if it exists)
238 G4IonDEDXMapElem::iterator it;
239
240 for (it = dedxMapElements.begin(); it != dedxMapElements.end(); ++it) {
241 if ((*it).second == physicsVector) {
242 dedxMapElements.erase(it);
243 break;
244 }
245 }
246
247 // Deleting physics vector
248 delete physicsVector;
249
250 return true;
251}

◆ RetrievePhysicsTable()

G4bool G4ExtDEDXTable::RetrievePhysicsTable ( const G4String & fileName)

Definition at line 320 of file G4ExtDEDXTable.cc.

321{
322 std::ifstream ifilestream;
323 ifilestream.open(fileName, std::ios::in | std::ios::binary);
324 if (! ifilestream) {
326 ed << "Cannot open file " << fileName;
327 G4Exception("G4IonStoppingData::RetrievePhysicsTable()", "mat030", FatalException, ed);
328 return false;
329 }
330
331 // std::string::size_type nmbVectors;
332 G4int nmbVectors = 0;
333 ifilestream >> nmbVectors;
334 if (ifilestream.fail() || nmbVectors <= 0) {
335 G4cout << "G4ExtDEDXTable::RetrievePhysicsTable() "
336 << " File content of " << fileName << " ill-formated."
337 << " Nvectors= " << nmbVectors << G4endl;
338 ifilestream.close();
339 return false;
340 }
341
342 for (G4int i = 0; i < nmbVectors; ++i) {
343 G4String line = "";
344 // Loop checking, 07-Aug-2015, Vladimir Ivanchenko
345 while (line.empty()) {
346 getline(ifilestream, line);
347 if (ifilestream.fail()) {
348 G4cout << "G4ExtDEDXTable::RetrievePhysicsTable() "
349 << " File content of " << fileName << " ill-formated." << G4endl;
350 ifilestream.close();
351 return false;
352 }
353
354 std::string::size_type pos = line.find_first_of('#');
355 if (pos != std::string::npos && pos > 0) {
356 line = line.substr(0, pos);
357 }
358 }
359
360 std::istringstream headerstream(line);
361
362 std::string::size_type atomicNumberIon;
363 headerstream >> atomicNumberIon;
364
365 G4String materialName;
366 headerstream >> materialName;
367
368 if (headerstream.fail() || std::string::npos == atomicNumberIon) {
369 G4cout << "G4ExtDEDXTable::RetrievePhysicsTable() "
370 << " File content of " << fileName << " ill-formated "
371 << " (vector header)." << G4endl;
372 ifilestream.close();
373 return false;
374 }
375
376 std::string::size_type atomicNumberMat;
377 headerstream >> atomicNumberMat;
378
379 if (headerstream.eof() || std::string::npos == atomicNumberMat) {
380 atomicNumberMat = 0;
381 }
382
383 G4int vectorType;
384 ifilestream >> vectorType;
385
386 G4PhysicsVector* physicsVector = CreatePhysicsVector(vectorType);
387
388 if (physicsVector == nullptr) {
389 G4cout << "G4ExtDEDXTable::RetrievePhysicsTable "
390 << " illegal physics Vector type " << vectorType << " in " << fileName << G4endl;
391 ifilestream.close();
392 return false;
393 }
394
395 if (! physicsVector->Retrieve(ifilestream, true)) {
396 G4cout << "G4ExtDEDXTable::RetrievePhysicsTable() "
397 << " File content of " << fileName << " ill-formated." << G4endl;
398 ifilestream.close();
399 return false;
400 }
401 physicsVector->FillSecondDerivatives();
402
403 // Retrieved vector is added to material store
404 if (! AddPhysicsVector(
405 physicsVector, (G4int)atomicNumberIon, materialName, (G4int)atomicNumberMat))
406 {
407 delete physicsVector;
408 ifilestream.close();
409 return false;
410 }
411 }
412
413 ifilestream.close();
414
415 return true;
416}
std::ostringstream G4ExceptionDescription
G4bool AddPhysicsVector(G4PhysicsVector *physicsVector, G4int atomicNumberIon, const G4String &matIdenfier, G4int atomicNumberElem=0)
G4bool Retrieve(std::ifstream &fIn, G4bool ascii=false)
void FillSecondDerivatives(const G4SplineType=G4SplineType::Base, const G4double dir1=0.0, const G4double dir2=0.0)

◆ StorePhysicsTable()

G4bool G4ExtDEDXTable::StorePhysicsTable ( const G4String & fileName)

Definition at line 255 of file G4ExtDEDXTable.cc.

257{
258 G4bool success = true;
259
260 std::ofstream ofilestream;
261
262 ofilestream.open(fileName, std::ios::out);
263
264 if (! ofilestream) {
266 ed << "Cannot open file " << fileName;
267 G4Exception("G4IonStoppingData::StorePhysicsTable()", "mat030", FatalException, ed);
268 success = false;
269 }
270 else {
271 size_t nmbMatTables = dedxMapMaterials.size();
272
273 ofilestream << nmbMatTables << G4endl << G4endl;
274
275 auto iterMat = dedxMapMaterials.begin();
276 auto iterMat_end = dedxMapMaterials.end();
277
278 for (; iterMat != iterMat_end; iterMat++) {
279 G4IonDEDXKeyMat key = iterMat->first;
280 G4PhysicsVector* physicsVector = iterMat->second;
281
282 G4int atomicNumberIon = key.first;
283 G4String matIdentifier = key.second;
284
285 G4int atomicNumberElem = FindAtomicNumberElement(physicsVector);
286
287 if (physicsVector != nullptr) {
288 ofilestream << atomicNumberIon << " " << matIdentifier;
289
290 if (atomicNumberElem > 0) {
291 ofilestream << " " << atomicNumberElem;
292 }
293
294 ofilestream << " # <Atomic number ion> <Material name> ";
295
296 if (atomicNumberElem > 0) {
297 ofilestream << "<Atomic number element>";
298 }
299
300 ofilestream << G4endl << physicsVector->GetType() << G4endl;
301
302 physicsVector->Store(ofilestream, true);
303
304 ofilestream << G4endl;
305 }
306 else {
307 G4Exception("G4IonStoppingData::StorePhysicsTable()", "mat030", FatalException,
308 "Cannot store vector.");
309 }
310 }
311 }
312
313 ofilestream.close();
314
315 return success;
316}
bool G4bool
Definition G4Types.hh:86
G4bool Store(std::ofstream &fOut, G4bool ascii=false) const
G4PhysicsVectorType GetType() const

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