Geant4-11
Public Member Functions | Private Types | Private Member Functions | Private Attributes
G4ExtDEDXTable Class Reference

#include <G4ExtDEDXTable.hh>

Inheritance diagram for G4ExtDEDXTable:
G4VIonDEDXTable

Public Member Functions

G4bool AddPhysicsVector (G4PhysicsVector *physicsVector, G4int atomicNumberIon, const G4String &matIdenfier, G4int atomicNumberElem=0)
 
virtual G4bool BuildPhysicsVector (G4int ionZ, const G4String &matName)
 
virtual G4bool BuildPhysicsVector (G4int ionZ, G4int matZ)
 
void ClearTable ()
 
void DumpMap ()
 
 G4ExtDEDXTable ()
 
G4double GetDEDX (G4double kinEnergyPerNucleon, G4int atomicNumberIon, const G4String &matIdenfier)
 
G4double GetDEDX (G4double kinEnergyPerNucleon, G4int atomicNumberIon, G4int atomicNumberElem)
 
virtual G4PhysicsVectorGetPhysicsVector (G4int atomicNumberIon, const G4String &matIdenfier)
 
virtual G4PhysicsVectorGetPhysicsVector (G4int atomicNumberIon, G4int atomicNumberElem)
 
virtual G4bool IsApplicable (G4int atomicNumberIon, const G4String &matIdentifier)
 
virtual G4bool IsApplicable (G4int atomicNumberIon, G4int atomicNumberElem)
 
G4bool RemovePhysicsVector (G4int atomicNumberIon, const G4String &matIdentifier)
 
G4bool RetrievePhysicsTable (const G4String &fileName)
 
G4bool StorePhysicsTable (const G4String &fileName)
 
virtual ~G4ExtDEDXTable ()
 

Private Types

typedef std::pair< G4int, G4intG4IonDEDXKeyElem
 
typedef std::pair< G4int, G4StringG4IonDEDXKeyMat
 
typedef std::map< G4IonDEDXKeyElem, G4PhysicsVector * > G4IonDEDXMapElem
 
typedef std::map< G4IonDEDXKeyMat, G4PhysicsVector * > G4IonDEDXMapMat
 

Private Member Functions

G4PhysicsVectorCreatePhysicsVector (G4int vectorType)
 
G4int FindAtomicNumberElement (G4PhysicsVector *physicsVector)
 
 G4ExtDEDXTable (G4ExtDEDXTable &)=delete
 
const G4ExtDEDXTableoperator= (const G4ExtDEDXTable &)=delete
 

Private Attributes

G4IonDEDXMapElem dedxMapElements
 
G4IonDEDXMapMat dedxMapMaterials
 

Detailed Description

Definition at line 63 of file G4ExtDEDXTable.hh.

Member Typedef Documentation

◆ G4IonDEDXKeyElem

typedef std::pair<G4int, G4int> G4ExtDEDXTable::G4IonDEDXKeyElem
private

Definition at line 161 of file G4ExtDEDXTable.hh.

◆ G4IonDEDXKeyMat

typedef std::pair<G4int, G4String> G4ExtDEDXTable::G4IonDEDXKeyMat
private

Definition at line 162 of file G4ExtDEDXTable.hh.

◆ G4IonDEDXMapElem

Definition at line 164 of file G4ExtDEDXTable.hh.

◆ G4IonDEDXMapMat

Definition at line 165 of file G4ExtDEDXTable.hh.

Constructor & Destructor Documentation

◆ G4ExtDEDXTable() [1/2]

G4ExtDEDXTable::G4ExtDEDXTable ( )
explicit

Definition at line 69 of file G4ExtDEDXTable.cc.

69 {
70
71}

◆ ~G4ExtDEDXTable()

G4ExtDEDXTable::~G4ExtDEDXTable ( )
virtual

Definition at line 75 of file G4ExtDEDXTable.cc.

75 {
76
77 ClearTable();
78}

References ClearTable().

◆ G4ExtDEDXTable() [2/2]

G4ExtDEDXTable::G4ExtDEDXTable ( G4ExtDEDXTable )
privatedelete

Member Function Documentation

◆ AddPhysicsVector()

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

Definition at line 186 of file G4ExtDEDXTable.cc.

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

References dedxMapElements, dedxMapMaterials, FatalException, and G4Exception().

Referenced by RetrievePhysicsTable().

◆ BuildPhysicsVector() [1/2]

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

Implements G4VIonDEDXTable.

Definition at line 90 of file G4ExtDEDXTable.cc.

91 {
92
93 return IsApplicable( ionZ, matName );
94}
virtual G4bool IsApplicable(G4int atomicNumberIon, G4int atomicNumberElem)

References IsApplicable().

◆ BuildPhysicsVector() [2/2]

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

Implements G4VIonDEDXTable.

Definition at line 82 of file G4ExtDEDXTable.cc.

82 {
83
84 return IsApplicable( ionZ, matZ );
85}

References IsApplicable().

◆ ClearTable()

void G4ExtDEDXTable::ClearTable ( )

Definition at line 503 of file G4ExtDEDXTable.cc.

503 {
504
505 G4IonDEDXMapMat::iterator iterMat = dedxMapMaterials.begin();
506 G4IonDEDXMapMat::iterator iterMat_end = dedxMapMaterials.end();
507
508 for(;iterMat != iterMat_end; ++iterMat) {
509
510 G4PhysicsVector* vec = iterMat -> second;
511
512 if(vec != 0) delete vec;
513 }
514
515 dedxMapElements.clear();
516 dedxMapMaterials.clear();
517}
static constexpr double second
Definition: G4SIunits.hh:137

References dedxMapElements, dedxMapMaterials, and second.

Referenced by ~G4ExtDEDXTable().

◆ CreatePhysicsVector()

G4PhysicsVector * G4ExtDEDXTable::CreatePhysicsVector ( G4int  vectorType)
private

Definition at line 454 of file G4ExtDEDXTable.cc.

454 {
455
456 G4PhysicsVector* physicsVector = nullptr;
457
458 switch (vectorType) {
459
461 physicsVector = new G4PhysicsLinearVector(true);
462 break;
463
465 physicsVector = new G4PhysicsLogVector(true);
466 break;
467
469 physicsVector = new G4PhysicsFreeVector(true);
470 break;
471
472 default:
473 break;
474 }
475 return physicsVector;
476}
@ T_G4PhysicsFreeVector
@ T_G4PhysicsLinearVector
@ T_G4PhysicsLogVector

References T_G4PhysicsFreeVector, T_G4PhysicsLinearVector, and T_G4PhysicsLogVector.

Referenced by RetrievePhysicsTable().

◆ DumpMap()

void G4ExtDEDXTable::DumpMap ( )

Definition at line 521 of file G4ExtDEDXTable.cc.

521 {
522
523 G4IonDEDXMapMat::iterator iterMat = dedxMapMaterials.begin();
524 G4IonDEDXMapMat::iterator iterMat_end = dedxMapMaterials.end();
525
526 G4cout << std::setw(15) << std::right
527 << "Atomic nmb ion"
528 << std::setw(25) << std::right
529 << "Material name"
530 << std::setw(25) << std::right
531 << "Atomic nmb material"
532 << G4endl;
533
534 for(;iterMat != iterMat_end; ++iterMat) {
535 G4IonDEDXKeyMat key = iterMat -> first;
536 G4PhysicsVector* physicsVector = iterMat -> second;
537
538 G4int atomicNumberIon = key.first;
539 G4String matIdentifier = key.second;
540
541 G4int atomicNumberElem = FindAtomicNumberElement(physicsVector);
542
543 if(physicsVector != 0) {
544 G4cout << std::setw(15) << std::right
545 << atomicNumberIon
546 << std::setw(25) << std::right
547 << matIdentifier
548 << std::setw(25) << std::right;
549
550 if(atomicNumberElem > 0) G4cout << atomicNumberElem;
551 else G4cout << "N/A";
552
553 G4cout << G4endl;
554 }
555 }
556
557}
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4int FindAtomicNumberElement(G4PhysicsVector *physicsVector)

References dedxMapMaterials, FindAtomicNumberElement(), G4cout, G4endl, and second.

◆ FindAtomicNumberElement()

G4int G4ExtDEDXTable::FindAtomicNumberElement ( G4PhysicsVector physicsVector)
private

Definition at line 480 of file G4ExtDEDXTable.cc.

482 {
483
484 G4int atomicNumber = 0;
485
486 G4IonDEDXMapElem::iterator iter = dedxMapElements.begin();
487 G4IonDEDXMapElem::iterator iter_end = dedxMapElements.end();
488
489 for(;iter != iter_end; ++iter) {
490
491 if( (*iter).second == physicsVector ) {
492
493 G4IonDEDXKeyElem key = (*iter).first;
494 atomicNumber = key.second;
495 }
496 }
497
498 return atomicNumber;
499}

References dedxMapElements.

Referenced by DumpMap(), and StorePhysicsTable().

◆ GetDEDX() [1/2]

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

Definition at line 170 of file G4ExtDEDXTable.cc.

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

References dedxMapMaterials.

◆ GetDEDX() [2/2]

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

Definition at line 154 of file G4ExtDEDXTable.cc.

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

References dedxMapElements.

◆ GetPhysicsVector() [1/2]

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

Implements G4VIonDEDXTable.

Definition at line 140 of file G4ExtDEDXTable.cc.

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

References dedxMapMaterials.

◆ GetPhysicsVector() [2/2]

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

Implements G4VIonDEDXTable.

Definition at line 126 of file G4ExtDEDXTable.cc.

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

References dedxMapElements.

◆ IsApplicable() [1/2]

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

Implements G4VIonDEDXTable.

Definition at line 112 of file G4ExtDEDXTable.cc.

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

References dedxMapMaterials.

◆ IsApplicable() [2/2]

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

Implements G4VIonDEDXTable.

Definition at line 98 of file G4ExtDEDXTable.cc.

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

References dedxMapElements.

Referenced by BuildPhysicsVector().

◆ operator=()

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

◆ RemovePhysicsVector()

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

Definition at line 242 of file G4ExtDEDXTable.cc.

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

References dedxMapElements, dedxMapMaterials, FatalException, and G4Exception().

◆ RetrievePhysicsTable()

G4bool G4ExtDEDXTable::RetrievePhysicsTable ( const G4String fileName)

Definition at line 345 of file G4ExtDEDXTable.cc.

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

References AddPhysicsVector(), CreatePhysicsVector(), FatalException, G4cout, G4endl, G4Exception(), and pos.

◆ StorePhysicsTable()

G4bool G4ExtDEDXTable::StorePhysicsTable ( const G4String fileName)

Definition at line 283 of file G4ExtDEDXTable.cc.

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

References dedxMapMaterials, FatalException, FindAtomicNumberElement(), G4endl, G4Exception(), and second.

Field Documentation

◆ dedxMapElements

G4IonDEDXMapElem G4ExtDEDXTable::dedxMapElements
private

◆ dedxMapMaterials

G4IonDEDXMapMat G4ExtDEDXTable::dedxMapMaterials
private

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