Geant4 11.1.1
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
 
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
 
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
 
 G4VIonDEDXTable (G4VIonDEDXTable &)=delete
 
const G4VIonDEDXTableoperator= (const G4VIonDEDXTable &)=delete
 

Detailed Description

Definition at line 63 of file G4ExtDEDXTable.hh.

Constructor & Destructor Documentation

◆ G4ExtDEDXTable()

G4ExtDEDXTable::G4ExtDEDXTable ( )
explicitdefault

◆ ~G4ExtDEDXTable()

G4ExtDEDXTable::~G4ExtDEDXTable ( )
override

Definition at line 68 of file G4ExtDEDXTable.cc.

68 {
69
70 ClearTable();
71}

Member Function Documentation

◆ AddPhysicsVector()

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

Definition at line 179 of file G4ExtDEDXTable.cc.

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

Referenced by RetrievePhysicsTable().

◆ BuildPhysicsVector() [1/2]

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

Implements G4VIonDEDXTable.

Definition at line 83 of file G4ExtDEDXTable.cc.

84 {
85
86 return IsApplicable( ionZ, matName );
87}
G4bool IsApplicable(G4int atomicNumberIon, G4int atomicNumberElem) override

◆ BuildPhysicsVector() [2/2]

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

Implements G4VIonDEDXTable.

Definition at line 75 of file G4ExtDEDXTable.cc.

75 {
76
77 return IsApplicable( ionZ, matZ );
78}

◆ ClearTable()

void G4ExtDEDXTable::ClearTable ( )

Definition at line 502 of file G4ExtDEDXTable.cc.

502 {
503 auto iterMat = dedxMapMaterials.begin();
504 auto iterMat_end = dedxMapMaterials.end();
505
506 for(;iterMat != iterMat_end; ++iterMat) {
507
508 G4PhysicsVector* vec = iterMat -> second;
509
510 delete vec;
511 }
512
513 dedxMapElements.clear();
514 dedxMapMaterials.clear();
515}

Referenced by ~G4ExtDEDXTable().

◆ DumpMap()

void G4ExtDEDXTable::DumpMap ( )

Definition at line 519 of file G4ExtDEDXTable.cc.

519 {
520 auto iterMat = dedxMapMaterials.begin();
521 auto iterMat_end = dedxMapMaterials.end();
522
523 G4cout << std::setw(15) << std::right
524 << "Atomic nmb ion"
525 << std::setw(25) << std::right
526 << "Material name"
527 << std::setw(25) << std::right
528 << "Atomic nmb material"
529 << G4endl;
530
531 for(;iterMat != iterMat_end; ++iterMat) {
532 G4IonDEDXKeyMat key = iterMat -> first;
533 G4PhysicsVector* physicsVector = iterMat -> second;
534
535 G4int atomicNumberIon = key.first;
536 G4String matIdentifier = key.second;
537
538 G4int atomicNumberElem = FindAtomicNumberElement(physicsVector);
539
540 if(physicsVector != nullptr)
541 {
542 G4cout << std::setw(15) << std::right << atomicNumberIon
543 << std::setw(25) << std::right << matIdentifier << std::setw(25)
544 << std::right;
545
546 if(atomicNumberElem > 0)
547 {
548 G4cout << atomicNumberElem;
549 }
550 else
551 {
552 G4cout << "N/A";
553 }
554
555 G4cout << G4endl;
556 }
557 }
558
559}
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 163 of file G4ExtDEDXTable.cc.

168{
169 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
170
171 auto iter = dedxMapMaterials.find(key);
172
173 return (iter != dedxMapMaterials.end()) ?
174 (iter->second)->Value( kinEnergyPerNucleon) : 0.0;
175}

◆ GetDEDX() [2/2]

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

Definition at line 147 of file G4ExtDEDXTable.cc.

152{
153 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
154
155 auto iter = dedxMapElements.find(key);
156
157 return ( iter != dedxMapElements.end() ) ?
158 (iter->second)->Value( kinEnergyPerNucleon) : 0.0;
159}

◆ GetPhysicsVector() [1/2]

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

Implements G4VIonDEDXTable.

Definition at line 133 of file G4ExtDEDXTable.cc.

137{
138 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
139
140 auto iter = dedxMapMaterials.find(key);
141
142 return (iter != dedxMapMaterials.end()) ? iter->second : nullptr;
143}

◆ GetPhysicsVector() [2/2]

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

Implements G4VIonDEDXTable.

Definition at line 119 of file G4ExtDEDXTable.cc.

123{
124 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
125
126 auto iter = dedxMapElements.find(key);
127
128 return (iter != dedxMapElements.end()) ? iter->second : nullptr;
129}

◆ IsApplicable() [1/2]

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

Implements G4VIonDEDXTable.

Definition at line 105 of file G4ExtDEDXTable.cc.

109{
110 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
111
112 auto iter = dedxMapMaterials.find(key);
113
114 return iter != dedxMapMaterials.end();
115}

◆ IsApplicable() [2/2]

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

Implements G4VIonDEDXTable.

Definition at line 91 of file G4ExtDEDXTable.cc.

95{
96 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
97
98 auto iter = dedxMapElements.find(key);
99
100 return iter != dedxMapElements.end();
101}

Referenced by BuildPhysicsVector().

◆ RemovePhysicsVector()

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

Definition at line 235 of file G4ExtDEDXTable.cc.

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

◆ RetrievePhysicsTable()

G4bool G4ExtDEDXTable::RetrievePhysicsTable ( const G4String fileName)

Definition at line 344 of file G4ExtDEDXTable.cc.

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

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

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