Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4IonStoppingData.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// ===========================================================================
28// GEANT4 class source file
29//
30// Class: G4IonStoppingData
31//
32// Base class: G4VIonDEDXTable
33//
34// Author: Anton Lechner ([email protected])
35//
36// First implementation: 03. 11. 2009
37//
38// Modifications:
39// 25.10.2010 V.Ivanchenko fixed warnings reported by the Coverity tool
40// 25.10.2011: new scheme for G4Exception (mma)
41//
42//
43// Class description: Class which can read ion stopping power data from
44// $G4LEDATA/ion_stopping_data
45//
46// Comments:
47//
48// ===========================================================================
49//
50
51#include <fstream>
52#include <sstream>
53#include <iomanip>
54
55#include "G4IonStoppingData.hh"
56#include "G4PhysicsVector.hh"
59#include "G4SystemOfUnits.hh"
60
61// #########################################################################
62
64 subDir(dir), fICRU90(val) {
65}
66
67// #########################################################################
68
70 ClearTable();
71}
72
73// #########################################################################
74
76 G4int atomicNumberIon, // Atomic number of ion
77 G4int atomicNumberElem // Atomic number of elemental material
78 )
79{
80 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
81
82 G4IonDEDXMapElem::iterator iter = dedxMapElements.find(key);
83
84 return (iter == dedxMapElements.end()) ? false : true;
85}
86
87// #########################################################################
88
90 G4int atomicNumberIon, // Atomic number of ion
91 const G4String& matIdentifier // Name or chemical formula of material
92 )
93{
94 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
95
96 G4IonDEDXMapMat::iterator iter = dedxMapMaterials.find(key);
97
98 return (iter == dedxMapMaterials.end()) ? false : true;
99}
100
101// #########################################################################
102
104 G4int atomicNumberIon, // Atomic number of ion
105 G4int atomicNumberElem // Atomic number of elemental material
106 )
107{
108 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
109
110 G4IonDEDXMapElem::iterator iter = dedxMapElements.find(key);
111
112 return (iter != dedxMapElements.end()) ? iter->second : nullptr;
113}
114
115// #########################################################################
116
118 G4int atomicNumberIon, // Atomic number of ion
119 const G4String& matIdentifier // Name or chemical formula of material
120 )
121{
122 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
123
124 G4IonDEDXMapMat::iterator iter = dedxMapMaterials.find(key);
125
126 return (iter != dedxMapMaterials.end()) ? iter->second : nullptr;
127}
128
129// #########################################################################
130
132 G4double kinEnergyPerNucleon, // Kinetic energy per nucleon
133 G4int atomicNumberIon, // Atomic number of ion
134 G4int atomicNumberElem // Atomic number of elemental material
135 )
136{
137 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
138
139 G4IonDEDXMapElem::iterator iter = dedxMapElements.find(key);
140
141 return ( iter != dedxMapElements.end()) ?
142 (iter->second)->Value( kinEnergyPerNucleon) : 0.0;
143}
144
145// #########################################################################
146
148 G4double kinEnergyPerNucleon, // Kinetic energy per nucleon
149 G4int atomicNumberIon, // Atomic number of ion
150 const G4String& matIdentifier // Name or chemical formula of material
151 )
152{
153 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
154
155 G4IonDEDXMapMat::iterator iter = dedxMapMaterials.find(key);
156
157 return (iter != dedxMapMaterials.end()) ?
158 (iter->second)->Value(kinEnergyPerNucleon) : 0.0;
159}
160
161// #########################################################################
162
164 G4PhysicsVector* physicsVector, // Physics vector
165 G4int atomicNumberIon, // Atomic number of ion
166 const G4String& matIdentifier // Name of elemental material
167 )
168{
169 if(physicsVector == nullptr) {
170 G4Exception ("G4IonStoppingData::AddPhysicsVector() for material",
171 "mat037", FatalException,
172 "Pointer to vector is null-pointer.");
173 return false;
174 }
175
176 if(matIdentifier.empty()) {
177 G4Exception ("G4IonStoppingData::AddPhysicsVector() for material",
178 "mat038", FatalException, "Invalid name of the material.");
179 return false;
180 }
181
182 if(atomicNumberIon <= 0) {
183 G4Exception ("G4IonStoppingData::AddPhysicsVector() for material",
184 "mat039", FatalException, "Illegal atomic number.");
185 return false;
186 }
187
188 G4IonDEDXKeyMat mkey = std::make_pair(atomicNumberIon, matIdentifier);
189
190 if(dedxMapMaterials.count(mkey) == 1) {
192 ed << "Vector with Z1 = " << atomicNumberIon << ", mat = "
193 << matIdentifier
194 << "already exists. Remove first before replacing.";
195 G4Exception ("G4IonStoppingData::AddPhysicsVector() for material",
196 "mat040", FatalException, ed);
197 return false;
198 }
199
200 dedxMapMaterials[mkey] = physicsVector;
201
202 return true;
203}
204
205// #########################################################################
206
208 G4PhysicsVector* physicsVector, // Physics vector
209 G4int atomicNumberIon, // Atomic number of ion
210 G4int atomicNumberElem // Atomic number of elemental material
211 )
212{
213 if(physicsVector == nullptr) {
214 G4Exception ("G4IonStoppingData::AddPhysicsVector() for element", "mat037",
215 FatalException, "Pointer to vector is null-pointer.");
216 return false;
217 }
218
219 if(atomicNumberIon <= 0) {
220 G4Exception ("G4IonStoppingData::AddPhysicsVector() for element", "mat038",
221 FatalException, "Invalid ion number.");
222 return false;
223 }
224
225 if(atomicNumberElem <= 0) {
226 G4Exception ("G4IonStoppingData::AddPhysicsVector() for element", "mat039",
227 FatalException, "Illegal atomic number.");
228 return false;
229 }
230
231 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
232
233 if(dedxMapElements.count(key) == 1) {
235 ed << "Vector with Z1 = " << atomicNumberIon << ", Z= "
236 << atomicNumberElem
237 << "already exists. Remove first before replacing.";
238 G4Exception ("G4IonStoppingData::AddPhysicsVector() for element", "mat040",
239 FatalException, ed);
240 return false;
241 }
242
243 dedxMapElements[key] = physicsVector;
244
245 return true;
246}
247
248// #########################################################################
249
251 G4int atomicNumberIon, // Atomic number of ion
252 const G4String& matIdentifier // Name or chemical formula of material
253 ) {
254
255 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
256
257 G4IonDEDXMapMat::iterator iter = dedxMapMaterials.find(key);
258
259 if(iter == dedxMapMaterials.end()) {
260 G4Exception ("G4IonStoppingData::RemovePhysicsVector() for material",
261 "mat038", FatalException, "Invalid name of the material.");
262 return false;
263 }
264
265 G4PhysicsVector* physicsVector = (*iter).second;
266
267 // Deleting key of physics vector from material map
268 dedxMapMaterials.erase(key);
269
270 // Deleting physics vector
271 delete physicsVector;
272
273 return true;
274}
275
276// #########################################################################
277
279 G4int atomicNumberIon, // Atomic number of ion
280 G4int atomicNumberElem // Atomic number of elemental material
281 ) {
282 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
283
284 G4IonDEDXMapElem::iterator iter = dedxMapElements.find(key);
285
286 if(iter == dedxMapElements.end()) {
287 G4Exception ("G4IonStoppingData::RemovePhysicsVector() for element",
288 "mat038", FatalException, "Invalid element.");
289 return false;
290 }
291
292 G4PhysicsVector* physicsVector = (*iter).second;
293
294 // Deleting key of physics vector from material map
295 dedxMapElements.erase(key);
296
297 // Deleting physics vector
298 delete physicsVector;
299
300 return true;
301}
302
303// #########################################################################
304
306 G4int atomicNumberIon, // Atomic number of ion
307 const G4String& matname // Name of material
308 ) {
309
310 if( IsApplicable(atomicNumberIon, matname) ) return true;
311
312 const char* path = std::getenv("G4LEDATA");
313 if ( !path ) {
314 G4Exception("G4IonStoppingData::BuildPhysicsVector()", "mat521",
315 FatalException, "G4LEDATA environment variable not set");
316 return false;
317 }
318
319 std::ostringstream file;
320 G4String ww = (fICRU90 && (matname == "G4_WATER" ||
321 matname == "G4_AIR" ||
322 matname == "G4_GRAPHITE")) ? "90" : "73";
323
324 file << path << "/" << subDir << ww << "/z"
325 << atomicNumberIon << "_" << matname << ".dat";
326 G4String fileName = G4String( file.str().c_str() );
327
328 std::ifstream ifilestream( fileName );
329
330 if ( !ifilestream.is_open() ) return false;
331
332 G4LPhysicsFreeVector* physicsVector = new G4LPhysicsFreeVector();
333
334 if( !physicsVector -> Retrieve(ifilestream, true) ) {
335
336 ifilestream.close();
337 return false;
338 }
339
340 physicsVector -> ScaleVector( MeV, MeV * cm2 /( 0.001 * g) );
341 physicsVector -> SetSpline( true );
342 physicsVector -> FillSecondDerivatives();
343
344 // Retrieved vector is added to material store
345 if( !AddPhysicsVector(physicsVector, atomicNumberIon, matname) ) {
346 delete physicsVector;
347 ifilestream.close();
348 return false;
349 }
350
351 ifilestream.close();
352 return true;
353}
354
355// #########################################################################
356
358 G4int ZIon, // Atomic number of ion
359 G4int ZElem // Atomic number of elemental material
360 )
361{
362 if( IsApplicable(ZIon, ZElem) ) return true;
363
364 char* path = std::getenv("G4LEDATA");
365 if ( !path ) {
366 G4Exception("G4IonStoppingData::BuildPhysicsVector()", "mat522",
367 FatalException, "G4LEDATA environment variable not set");
368 return false;
369 }
370 std::ostringstream file;
371 G4String ww = (fICRU90 && ZIon <= 18 &&
372 (ZElem == 1 || ZElem == 6 ||
373 ZElem == 7 || ZElem == 8)) ? "90" : "73";
374
375 file << path << "/" << subDir << ww << "/z"
376 << ZIon << "_" << ZElem << ".dat";
377
378 G4String fileName = G4String( file.str().c_str() );
379 std::ifstream ifilestream( fileName );
380
381 if ( !ifilestream.is_open() ) return false;
382 G4LPhysicsFreeVector* physicsVector = new G4LPhysicsFreeVector();
383
384 if( !physicsVector -> Retrieve(ifilestream, true) ) {
385 ifilestream.close();
386 return false;
387 }
388
389 physicsVector -> ScaleVector( MeV, MeV * cm2 /( 0.001 * g) );
390 physicsVector -> SetSpline( true );
391 physicsVector -> FillSecondDerivatives();
392
393 // Retrieved vector is added to material store
394 if( !AddPhysicsVector(physicsVector, ZIon, ZElem) ) {
395 delete physicsVector;
396 ifilestream.close();
397 return false;
398 }
399
400 ifilestream.close();
401 return true;
402}
403
404// #########################################################################
405
407
408 G4IonDEDXMapMat::iterator iterMat = dedxMapMaterials.begin();
409 G4IonDEDXMapMat::iterator iterMat_end = dedxMapMaterials.end();
410
411 for(;iterMat != iterMat_end; iterMat++) {
412
413 G4PhysicsVector* vec = iterMat -> second;
414
415 if(vec != 0) delete vec;
416 }
417
418 dedxMapMaterials.clear();
419
420 G4IonDEDXMapElem::iterator iterElem = dedxMapElements.begin();
421 G4IonDEDXMapElem::iterator iterElem_end = dedxMapElements.end();
422
423 for(;iterElem != iterElem_end; iterElem++) {
424
425 G4PhysicsVector* vec = iterElem -> second;
426
427 if(vec != 0) delete vec;
428 }
429
430 dedxMapElements.clear();
431}
432
433// #########################################################################
434
436
437 G4IonDEDXMapMat::iterator iterMat = dedxMapMaterials.begin();
438 G4IonDEDXMapMat::iterator iterMat_end = dedxMapMaterials.end();
439
440 G4cout << std::setw(15) << std::right
441 << "Atomic nmb ion"
442 << std::setw(25) << std::right
443 << "Material name"
444 << G4endl;
445
446 for(;iterMat != iterMat_end; iterMat++) {
447 G4IonDEDXKeyMat key = iterMat -> first;
448 G4PhysicsVector* physicsVector = iterMat -> second;
449
450 G4int atomicNumberIon = key.first;
451 G4String matIdentifier = key.second;
452
453 if(physicsVector != 0) {
454 G4cout << std::setw(15) << std::right
455 << atomicNumberIon
456 << std::setw(25) << std::right
457 << matIdentifier
458 << G4endl;
459 }
460 }
461
462 G4IonDEDXMapElem::iterator iterElem = dedxMapElements.begin();
463 G4IonDEDXMapElem::iterator iterElem_end = dedxMapElements.end();
464
465 G4cout << std::setw(15) << std::right
466 << "Atomic nmb ion"
467 << std::setw(25) << std::right
468 << "Atomic nmb material"
469 << G4endl;
470
471 for(;iterElem != iterElem_end; iterElem++) {
472 G4IonDEDXKeyElem key = iterElem -> first;
473 G4PhysicsVector* physicsVector = iterElem -> second;
474
475 G4int atomicNumberIon = key.first;
476 G4int atomicNumberElem = key.second;
477
478 if(physicsVector != 0) {
479 G4cout << std::setw(15) << std::right
480 << atomicNumberIon
481 << std::setw(25) << std::right
482 << atomicNumberElem
483 << G4endl;
484 }
485 }
486
487}
488
489// #########################################################################
490
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4PhysicsVector * GetPhysicsVector(G4int atomicNumberIon, G4int atomicNumberElem)
G4bool IsApplicable(G4int atomicNumberIon, G4int atomicNumberElem)
G4bool RemovePhysicsVector(G4int atomicNumberIon, const G4String &matIdentifier)
G4double GetDEDX(G4double kinEnergyPerNucleon, G4int atomicNumberIon, G4int atomicNumberElem)
G4bool AddPhysicsVector(G4PhysicsVector *physicsVector, G4int atomicNumberIon, const G4String &matIdentifier)
G4IonStoppingData(const G4String &dir, G4bool icru)
G4bool BuildPhysicsVector(G4int ionZ, const G4String &matName)
virtual ~G4IonStoppingData()