Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4ExtDEDXTable Class Reference

#include <G4ExtDEDXTable.hh>

Inheritance diagram for G4ExtDEDXTable:
Collaboration 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 ()
 

Detailed Description

Definition at line 64 of file G4ExtDEDXTable.hh.

Constructor & Destructor Documentation

G4ExtDEDXTable::G4ExtDEDXTable ( )
explicit

Definition at line 73 of file G4ExtDEDXTable.cc.

73  {
74 
75 }
G4ExtDEDXTable::~G4ExtDEDXTable ( )
virtual

Definition at line 79 of file G4ExtDEDXTable.cc.

79  {
80 
81  ClearTable();
82 }

Here is the call graph for this function:

Member Function Documentation

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

Definition at line 190 of file G4ExtDEDXTable.cc.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Implements G4VIonDEDXTable.

Definition at line 94 of file G4ExtDEDXTable.cc.

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

Here is the call graph for this function:

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

Implements G4VIonDEDXTable.

Definition at line 86 of file G4ExtDEDXTable.cc.

86  {
87 
88  return IsApplicable( ionZ, matZ );
89 }
virtual G4bool IsApplicable(G4int atomicNumberIon, G4int atomicNumberElem)

Here is the call graph for this function:

void G4ExtDEDXTable::ClearTable ( )

Definition at line 520 of file G4ExtDEDXTable.cc.

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

Here is the caller graph for this function:

void G4ExtDEDXTable::DumpMap ( )

Definition at line 538 of file G4ExtDEDXTable.cc.

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

Definition at line 158 of file G4ExtDEDXTable.cc.

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

Definition at line 174 of file G4ExtDEDXTable.cc.

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

Implements G4VIonDEDXTable.

Definition at line 130 of file G4ExtDEDXTable.cc.

134 {
135  G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
136 
137  G4IonDEDXMapElem::iterator iter = dedxMapElements.find(key);
138 
139  return (iter != dedxMapElements.end()) ? iter->second : nullptr;
140 }
G4PhysicsVector * G4ExtDEDXTable::GetPhysicsVector ( G4int  atomicNumberIon,
const G4String matIdenfier 
)
virtual

Implements G4VIonDEDXTable.

Definition at line 144 of file G4ExtDEDXTable.cc.

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

Implements G4VIonDEDXTable.

Definition at line 102 of file G4ExtDEDXTable.cc.

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

Here is the caller graph for this function:

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

Implements G4VIonDEDXTable.

Definition at line 116 of file G4ExtDEDXTable.cc.

120 {
121  G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
122 
123  G4IonDEDXMapMat::iterator iter = dedxMapMaterials.find(key);
124 
125  return (iter == dedxMapMaterials.end()) ? false : true;
126 }
G4bool G4ExtDEDXTable::RemovePhysicsVector ( G4int  atomicNumberIon,
const G4String matIdentifier 
)

Definition at line 246 of file G4ExtDEDXTable.cc.

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

Here is the call graph for this function:

G4bool G4ExtDEDXTable::RetrievePhysicsTable ( const G4String fileName)

Definition at line 349 of file G4ExtDEDXTable.cc.

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

Here is the call graph for this function:

G4bool G4ExtDEDXTable::StorePhysicsTable ( const G4String fileName)

Definition at line 287 of file G4ExtDEDXTable.cc.

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

Here is the call graph for this function:


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