Geant4 10.7.0
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 ()
 
virtual ~G4ExtDEDXTable ()
 
virtual G4bool BuildPhysicsVector (G4int ionZ, const G4String &matName)
 
virtual G4bool BuildPhysicsVector (G4int ionZ, G4int matZ)
 
virtual G4bool IsApplicable (G4int atomicNumberIon, G4int atomicNumberElem)
 
virtual G4bool IsApplicable (G4int atomicNumberIon, const G4String &matIdentifier)
 
virtual G4PhysicsVectorGetPhysicsVector (G4int atomicNumberIon, G4int atomicNumberElem)
 
virtual G4PhysicsVectorGetPhysicsVector (G4int atomicNumberIon, const G4String &matIdenfier)
 
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 ()
 
virtual ~G4VIonDEDXTable ()
 
virtual G4bool BuildPhysicsVector (G4int, G4int)=0
 
virtual G4bool BuildPhysicsVector (G4int, const G4String &)=0
 
virtual G4bool IsApplicable (G4int, G4int)=0
 
virtual G4bool IsApplicable (G4int, const G4String &)=0
 
virtual G4PhysicsVectorGetPhysicsVector (G4int, G4int)=0
 
virtual G4PhysicsVectorGetPhysicsVector (G4int, const G4String &)=0
 

Detailed Description

Definition at line 63 of file G4ExtDEDXTable.hh.

Constructor & Destructor Documentation

◆ G4ExtDEDXTable()

G4ExtDEDXTable::G4ExtDEDXTable ( )
explicit

Definition at line 72 of file G4ExtDEDXTable.cc.

72 {
73
74}

◆ ~G4ExtDEDXTable()

G4ExtDEDXTable::~G4ExtDEDXTable ( )
virtual

Definition at line 78 of file G4ExtDEDXTable.cc.

78 {
79
80 ClearTable();
81}

Member Function Documentation

◆ AddPhysicsVector()

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

Definition at line 189 of file G4ExtDEDXTable.cc.

194 {
195
196 if(physicsVector == nullptr) {
197 G4Exception ("G4ExtDEDXTable::AddPhysicsVector() for material",
198 "mat037", FatalException,
199 "Pointer to vector is null-pointer.");
200 return false;
201 }
202
203 if(matIdentifier.empty()) {
204 G4Exception ("G4ExtDEDXTable::AddPhysicsVector() for material",
205 "mat038", FatalException, "Invalid name of the material.");
206 return false;
207 }
208
209 if(atomicNumberIon <= 2) {
210 G4Exception ("G4ExtDEDXTable::AddPhysicsVector() for material",
211 "mat039", FatalException, "Illegal atomic number.");
212 return false;
213 }
214
215 if(atomicNumberElem > 0) {
216
217 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
218
219 if(dedxMapElements.count(key) == 1) {
220 G4Exception ("G4ExtDEDXTable::AddPhysicsVector() for material",
221 "mat037", FatalException,
222 "Vector already exist, remove it before replacing.");
223 return false;
224 }
225
226 dedxMapElements[key] = physicsVector;
227 }
228
229 G4IonDEDXKeyMat mkey = std::make_pair(atomicNumberIon, matIdentifier);
230
231 if(dedxMapMaterials.count(mkey) == 1) {
232 G4Exception ("G4ExtDEDXTable::AddPhysicsVector() for material",
233 "mat037", FatalException,
234 "Vector already exist, remove it before replacing.");
235 return false;
236 }
237
238 dedxMapMaterials[mkey] = physicsVector;
239
240 return true;
241}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35

Referenced by RetrievePhysicsTable().

◆ BuildPhysicsVector() [1/2]

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

Implements G4VIonDEDXTable.

Definition at line 93 of file G4ExtDEDXTable.cc.

94 {
95
96 return IsApplicable( ionZ, matName );
97}
virtual G4bool IsApplicable(G4int atomicNumberIon, G4int atomicNumberElem)

◆ BuildPhysicsVector() [2/2]

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

Implements G4VIonDEDXTable.

Definition at line 85 of file G4ExtDEDXTable.cc.

85 {
86
87 return IsApplicable( ionZ, matZ );
88}

◆ ClearTable()

void G4ExtDEDXTable::ClearTable ( )

Definition at line 519 of file G4ExtDEDXTable.cc.

519 {
520
521 G4IonDEDXMapMat::iterator iterMat = dedxMapMaterials.begin();
522 G4IonDEDXMapMat::iterator iterMat_end = dedxMapMaterials.end();
523
524 for(;iterMat != iterMat_end; iterMat++) {
525
526 G4PhysicsVector* vec = iterMat -> second;
527
528 if(vec != 0) delete vec;
529 }
530
531 dedxMapElements.clear();
532 dedxMapMaterials.clear();
533}

Referenced by ~G4ExtDEDXTable().

◆ DumpMap()

void G4ExtDEDXTable::DumpMap ( )

Definition at line 537 of file G4ExtDEDXTable.cc.

537 {
538
539 G4IonDEDXMapMat::iterator iterMat = dedxMapMaterials.begin();
540 G4IonDEDXMapMat::iterator iterMat_end = dedxMapMaterials.end();
541
542 G4cout << std::setw(15) << std::right
543 << "Atomic nmb ion"
544 << std::setw(25) << std::right
545 << "Material name"
546 << std::setw(25) << std::right
547 << "Atomic nmb material"
548 << G4endl;
549
550 for(;iterMat != iterMat_end; iterMat++) {
551 G4IonDEDXKeyMat key = iterMat -> first;
552 G4PhysicsVector* physicsVector = iterMat -> second;
553
554 G4int atomicNumberIon = key.first;
555 G4String matIdentifier = key.second;
556
557 G4int atomicNumberElem = FindAtomicNumberElement(physicsVector);
558
559 if(physicsVector != 0) {
560 G4cout << std::setw(15) << std::right
561 << atomicNumberIon
562 << std::setw(25) << std::right
563 << matIdentifier
564 << std::setw(25) << std::right;
565
566 if(atomicNumberElem > 0) G4cout << atomicNumberElem;
567 else G4cout << "N/A";
568
569 G4cout << G4endl;
570 }
571 }
572
573}
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout

◆ GetDEDX() [1/2]

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

Definition at line 173 of file G4ExtDEDXTable.cc.

178{
179 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
180
181 G4IonDEDXMapMat::iterator iter = dedxMapMaterials.find(key);
182
183 return (iter != dedxMapMaterials.end()) ?
184 (iter->second)->Value( kinEnergyPerNucleon) : 0.0;
185}

◆ GetDEDX() [2/2]

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

Definition at line 157 of file G4ExtDEDXTable.cc.

162{
163 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
164
165 G4IonDEDXMapElem::iterator iter = dedxMapElements.find(key);
166
167 return ( iter != dedxMapElements.end() ) ?
168 (iter->second)->Value( kinEnergyPerNucleon) : 0.0;
169}

◆ GetPhysicsVector() [1/2]

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

Implements G4VIonDEDXTable.

Definition at line 143 of file G4ExtDEDXTable.cc.

147{
148 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
149
150 G4IonDEDXMapMat::iterator iter = dedxMapMaterials.find(key);
151
152 return (iter != dedxMapMaterials.end()) ? iter->second : nullptr;
153}

◆ GetPhysicsVector() [2/2]

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

Implements G4VIonDEDXTable.

Definition at line 129 of file G4ExtDEDXTable.cc.

133{
134 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
135
136 G4IonDEDXMapElem::iterator iter = dedxMapElements.find(key);
137
138 return (iter != dedxMapElements.end()) ? iter->second : nullptr;
139}

◆ IsApplicable() [1/2]

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

Implements G4VIonDEDXTable.

Definition at line 115 of file G4ExtDEDXTable.cc.

119{
120 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
121
122 G4IonDEDXMapMat::iterator iter = dedxMapMaterials.find(key);
123
124 return (iter == dedxMapMaterials.end()) ? false : true;
125}

◆ IsApplicable() [2/2]

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

Implements G4VIonDEDXTable.

Definition at line 101 of file G4ExtDEDXTable.cc.

105{
106 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
107
108 G4IonDEDXMapElem::iterator iter = dedxMapElements.find(key);
109
110 return (iter == dedxMapElements.end()) ? false : true;
111}

Referenced by BuildPhysicsVector().

◆ RemovePhysicsVector()

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

Definition at line 245 of file G4ExtDEDXTable.cc.

248 {
249
250 G4PhysicsVector* physicsVector = nullptr;
251
252 // Deleting key of physics vector from material map
253 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
254
255 G4IonDEDXMapMat::iterator iter = dedxMapMaterials.find(key);
256
257 if(iter == dedxMapMaterials.end()) {
258 G4Exception ("G4ExtDEDXTable::RemovePhysicsVector() for material",
259 "mat037", FatalException,
260 "Pointer to vector is null-pointer.");
261 return false;
262 }
263
264 physicsVector = (*iter).second;
265 dedxMapMaterials.erase(key);
266
267 // Deleting key of physics vector from elemental material map (if it exists)
268 G4IonDEDXMapElem::iterator it;
269
270 for(it=dedxMapElements.begin(); it!=dedxMapElements.end(); ++it) {
271
272 if( (*it).second == physicsVector ) {
273 dedxMapElements.erase(it);
274 break;
275 }
276 }
277
278 // Deleting physics vector
279 delete physicsVector;
280
281 return true;
282}

◆ RetrievePhysicsTable()

G4bool G4ExtDEDXTable::RetrievePhysicsTable ( const G4String fileName)

Definition at line 348 of file G4ExtDEDXTable.cc.

349{
350 std::ifstream ifilestream;
351 ifilestream.open( fileName, std::ios::in|std::ios::binary );
352 if( ! ifilestream ) {
354 ed << "Cannot open file " << fileName;
355 G4Exception ("G4IonStoppingData::RetrievePhysicsTable()",
356 "mat030", FatalException, ed);
357 return false;
358 }
359
360 //std::string::size_type nmbVectors;
361 G4int nmbVectors = 0;
362 ifilestream >> nmbVectors;
363 if( ifilestream.fail() || nmbVectors <= 0) {
364 G4cout << "G4ExtDEDXTable::RetrievePhysicsTable() "
365 << " File content of " << fileName << " ill-formated."
366 << " Nvectors= " << nmbVectors
367 << G4endl;
368 ifilestream.close();
369 return false;
370 }
371
372 for(G4int i = 0; i<nmbVectors; ++i) {
373
374 G4String line = "";
375 // Loop checking, 07-Aug-2015, Vladimir Ivanchenko
376 while( line.empty() ) {
377
378 getline( ifilestream, line );
379 if( ifilestream.fail() ) {
380 G4cout << "G4ExtDEDXTable::RetrievePhysicsTable() "
381 << " File content of " << fileName << " ill-formated."
382 << G4endl;
383 ifilestream.close();
384 return false;
385 }
386
387 std::string::size_type pos = line.find_first_of("#");
388 if(pos != std::string::npos && pos > 0) {
389 line = line.substr(0, pos);
390 }
391 }
392
393 std::istringstream headerstream( line );
394
395 std::string::size_type atomicNumberIon;
396 headerstream >> atomicNumberIon;
397
398 G4String materialName;
399 headerstream >> materialName;
400
401 if( headerstream.fail() || std::string::npos == atomicNumberIon) {
402 G4cout << "G4ExtDEDXTable::RetrievePhysicsTable() "
403 << " File content of " << fileName << " ill-formated "
404 << " (vector header)."
405 << G4endl;
406 ifilestream.close();
407 return false;
408 }
409
410 std::string::size_type atomicNumberMat;
411 headerstream >> atomicNumberMat;
412
413 if( headerstream.eof() || std::string::npos == atomicNumberMat) {
414 atomicNumberMat = 0;
415 }
416
417 G4int vectorType;
418 ifilestream >> vectorType;
419
420 G4PhysicsVector* physicsVector = CreatePhysicsVector(vectorType);
421
422 if(physicsVector == nullptr) {
423 G4cout << "G4ExtDEDXTable::RetrievePhysicsTable "
424 << " illegal physics Vector type " << vectorType
425 << " in " << fileName
426 << G4endl;
427 ifilestream.close();
428 return false;
429 }
430
431 if( !physicsVector -> Retrieve(ifilestream, true) ) {
432 G4cout << "G4ExtDEDXTable::RetrievePhysicsTable() "
433 << " File content of " << fileName << " ill-formated."
434 << G4endl;
435 ifilestream.close();
436 return false;
437 }
438
439 physicsVector -> SetSpline(true);
440
441 // Retrieved vector is added to material store
442 if( !AddPhysicsVector(physicsVector, (G4int)atomicNumberIon,
443 materialName, (G4int)atomicNumberMat) ) {
444
445 delete physicsVector;
446 ifilestream.close();
447 return false;
448 }
449 }
450
451 ifilestream.close();
452
453 return true;
454}
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
G4bool AddPhysicsVector(G4PhysicsVector *physicsVector, G4int atomicNumberIon, const G4String &matIdenfier, G4int atomicNumberElem=0)

◆ StorePhysicsTable()

G4bool G4ExtDEDXTable::StorePhysicsTable ( const G4String fileName)

Definition at line 286 of file G4ExtDEDXTable.cc.

288 {
289 G4bool success = true;
290
291 std::ofstream ofilestream;
292
293 ofilestream.open( fileName, std::ios::out );
294
295 if( !ofilestream ) {
297 ed << "Cannot open file " << fileName;
298 G4Exception ("G4IonStoppingData::StorePhysicsTable()",
299 "mat030", FatalException, ed);
300 success = false;
301 }
302 else {
303
304 size_t nmbMatTables = dedxMapMaterials.size();
305
306 ofilestream << nmbMatTables << G4endl << G4endl;
307
308 G4IonDEDXMapMat::iterator iterMat = dedxMapMaterials.begin();
309 G4IonDEDXMapMat::iterator iterMat_end = dedxMapMaterials.end();
310
311 for(;iterMat != iterMat_end; iterMat++) {
312 G4IonDEDXKeyMat key = iterMat -> first;
313 G4PhysicsVector* physicsVector = iterMat -> second;
314
315 G4int atomicNumberIon = key.first;
316 G4String matIdentifier = key.second;
317
318 G4int atomicNumberElem = FindAtomicNumberElement(physicsVector);
319
320 if(physicsVector != nullptr) {
321 ofilestream << atomicNumberIon << " " << matIdentifier;
322
323 if(atomicNumberElem > 0) ofilestream << " " << atomicNumberElem;
324
325 ofilestream << " # <Atomic number ion> <Material name> ";
326
327 if(atomicNumberElem > 0) ofilestream << "<Atomic number element>";
328
329 ofilestream << G4endl << physicsVector -> GetType() << G4endl;
330
331 physicsVector -> Store(ofilestream, true);
332
333 ofilestream << G4endl;
334 } else {
335 G4Exception ("G4IonStoppingData::StorePhysicsTable()",
336 "mat030", FatalException,"Cannot store vector.");
337 }
338 }
339 }
340
341 ofilestream.close();
342
343 return success;
344}
bool G4bool
Definition: G4Types.hh:86

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