Geant4-11
G4IonICRU73Data.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 file
29//
30// Description: Data on stopping power
31//
32// Author: Vladimir Ivanchenko
33//
34// Creation date: 23.10.2021
35//
36//----------------------------------------------------------------------------
37//
38
39//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
40
41#include <fstream>
42#include <sstream>
43
44#include "G4IonICRU73Data.hh"
45#include "G4SystemOfUnits.hh"
46#include "G4PhysicsLogVector.hh"
48#include "G4EmParameters.hh"
51#include "G4Material.hh"
52#include "G4Element.hh"
53
54const G4String namesICRU73[31] = {
55"G4_A-150_TISSUE"
56"G4_ADIPOSE_TISSUE_ICRP"
57"G4_AIR"
58"G4_ALUMINUM_OXIDE"
59"G4_BONE_COMPACT_ICRU"
60"G4_BONE_CORTICAL_ICRP"
61"G4_C-552"
62"G4_CALCIUM_FLUORIDE"
63"G4_CARBON_DIOXIDE"
64"G4_KAPTON"
65"G4_LITHIUM_FLUORIDE"
66"G4_LITHIUM_TETRABORATE"
67"G4_LUCITE"
68"G4_METHANE"
69"G4_MUSCLE_STRIATED_ICRU"
70"G4_MYLAR"
71"G4_NYLON-6-6"
72"G4_PHOTO_EMULSION"
73"G4_PLASTIC_SC_VINYLTOLUENE"
74"G4_POLYCARBONATE"
75"G4_POLYETHYLENE"
76"G4_POLYSTYRENE"
77"G4_PROPANE"
78"G4_Pyrex_Glass"
79"G4_SILICON_DIOXIDE"
80"G4_SODIUM_IODIDE"
81"G4_TEFLON"
82"G4_TISSUE-METHANE"
83"G4_TISSUE-PROPANE"
84"G4_WATER"
85"G4_WATER_VAPOR"};
86const G4String namesICRU90[3] = {"G4_AIR","G4_GRAPHITE","G4_WATER"};
87
88//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
89
91{
92 fEmin = 0.025*CLHEP::MeV;
93 fEmax = 2.5*CLHEP::MeV;
94 fNbins = fNbinsPerDecade*G4lrint(std::log10(fEmax/fEmin) + 0.000001);
96 for(G4int i=0; i<81; ++i) {
97 fMatData[i] = new std::vector<G4PhysicsLogVector*>;
98 }
99}
100
101//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
102
104{
105 delete fVector;
106 for(G4int i=0; i<81; ++i) {
107 auto v = fMatData[i];
108 for(G4int j=0; j<fNmat; ++j) {
109 delete (*v)[j];
110 }
111 delete v;
112 for(G4int j=0; j<81; ++j) { delete fElmData[i][j]; }
113 }
114}
115
116//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
117
119 const G4double e, const G4double loge) const
120{
121 G4PhysicsLogVector* v = nullptr;
122 if(1 == mat->GetNumberOfElements()) {
123 G4int Z1 = (*(mat->GetElementVector()))[0]->GetZasInt();
124 if(Z <= 80 && Z1 <= 80) {
125 v = fElmData[Z][Z1];
126 }
127 } else {
128 G4int idx = fMatIndex[mat->GetIndex()];
129 if(idx < fNmat && Z <= 80) {
130 v = (*(fMatData[Z]))[idx];
131 }
132 }
133 G4double res = (nullptr != v) ? v->LogVectorValue(e, loge) : 0.0;
134 return res;
135}
136
137//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
138
140{
141 // fill directory path
142 if(fDataDirectory.empty()) {
143 char* path = std::getenv("G4LEDATA");
144 if (nullptr != path) {
145 std::ostringstream ost;
146 ost << path << "/ion_stopping_data/";
147 fDataDirectory = ost.str();
148 } else {
149 G4Exception("G4IonICRU73Data::Initialise(..)","em013",
151 "Environment variable G4LEDATA is not defined");
152 }
153 }
154
156 size_t nmat = G4Material::GetNumberOfMaterials();
157 fMatIndex.resize(nmat, -1);
158
159 const G4ProductionCutsTable* theCoupleTable=
161 size_t numOfCouples = theCoupleTable->GetTableSize();
162
163 for(size_t i=0; i<numOfCouples; ++i) {
164 const G4MaterialCutsCouple* couple =
165 theCoupleTable->GetMaterialCutsCouple(i);
166 const G4Material* mat = couple->GetMaterial();
167 G4int idx = mat->GetIndex();
168 if(fMatIndex[idx] == -1) {
169 G4String matname = mat->GetName();
170 G4bool isOK = false;
171 if(1 == mat->GetNumberOfElements()) {
172 ReadElementData(mat, useICRU90);
173 isOK = true;
174 }
175 if(!isOK && useICRU90) {
176 for(G4int j=0; j<3; ++j) {
177 if(matname == namesICRU90[j]) {
178 ReadMaterialData(matname, true);
179 isOK = true;
180 fMatIndex[idx] = fNmat;
181 ++fNmat;
182 break;
183 }
184 }
185 }
186 if(!isOK) {
187 for(G4int j=0; j<31; ++j) {
188 if(matname == namesICRU73[j]) {
189 ReadMaterialData(matname, false);
190 isOK = true;
191 fMatIndex[idx] = fNmat;
192 ++fNmat;
193 break;
194 }
195 }
196 }
197 if(!isOK) {
198 ReadElementData(mat, useICRU90);
199 fMatIndex[idx] = fNmat;
200 ++fNmat;
201 }
202 }
203 }
204}
205
206//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
207
209{
210 for(G4int Z=3; Z<81; ++Z) {
211 std::ostringstream ost;
212 ost << fDataDirectory << "icru";
213 if(isICRU90 && Z <= 18) { ost << "90"; }
214 else { ost << "73"; }
215 ost << "/z" << Z << "_" << name << ".dat";
216 G4PhysicsLogVector* v = RetrieveVector(ost, false);
217 (fMatData[Z])->push_back(v);
218 }
219}
220
221//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
222
224{
225 const G4ElementVector* elmv = mat->GetElementVector();
226 const G4double* dens = mat->GetFractionVector();
227 const G4int nelm = mat->GetNumberOfElements();
228 for(G4int Z=3; Z<81; ++Z) {
229 if(1 == nelm) {
230 FindOrBuildElementData(Z, (*elmv)[0]->GetZasInt(), useICRU90);
231 } else {
232 G4PhysicsLogVector* v2 = nullptr;
233 for(G4int j=0; j<nelm; ++j) {
234 v2 = FindOrBuildElementData(Z, (*elmv)[j]->GetZasInt(), useICRU90);
235 if(nullptr == v2) { break; }
236 }
237 // for one or more elements there is no data
238 if(nullptr == v2) {
239 fMatData[Z]->push_back(v2);
240 continue;
241 }
244 for(G4int i=0; i<=fNbins; ++i) {
245 G4double dedx = 0;
246 for(G4int j=0; j<nelm; ++j) {
247 G4PhysicsLogVector* v1 =
248 FindOrBuildElementData(Z, (*elmv)[j]->GetZasInt(), useICRU90);
249 dedx += (*v1)[i]*dens[j];
250 }
251 v->PutValue(i, dedx);
252 }
253 if(fSpline) { v->FillSecondDerivatives(); }
254 fMatData[Z]->push_back(v);
255 }
256 }
257}
258
259//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
260
263 G4bool useICRU90)
264{
265 G4PhysicsLogVector* v = nullptr;
266 if(Z <= 80 && Z1 <= 80) {
267 v = fElmData[Z][Z1];
268 if(nullptr == v) {
269 G4bool isICRU90 = (useICRU90 && Z <= 18 &&
270 (Z1 == 1 || Z1 == 6 || Z1 == 7 || Z1 == 8));
271 std::ostringstream ost;
272 ost << fDataDirectory << "icru";
273 if(isICRU90) { ost << "90"; }
274 else { ost << "73"; }
275 ost << "/z" << Z << "_" << Z1 << ".dat";
276 v = RetrieveVector(ost, false);
277 fElmData[Z][Z1] = v;
278 }
279 }
280 return v;
281}
282
283//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
284
286G4IonICRU73Data::RetrieveVector(std::ostringstream& ost, G4bool warn)
287{
288 G4PhysicsLogVector* v = nullptr;
289 std::ifstream filein(ost.str().c_str());
290 if (!filein.is_open()) {
291 if(warn) {
293 ed << "Data file <" << ost.str().c_str()
294 << "> is not opened";
295 G4Exception("G4IonICRU73Data::RetrieveVector(..)","em013",
296 FatalException, ed, "Check G4LEDATA");
297 }
298 } else {
299 if(fVerbose > 0) {
300 G4cout << "File " << ost.str()
301 << " is opened by G4IonICRU73Data" << G4endl;
302 }
303 // retrieve data from DB
304 if(!fVector->Retrieve(filein, true)) {
306 ed << "Data file <" << ost.str().c_str()
307 << "> is not retrieved!";
308 G4Exception("G4IonICRU73Data::RetrieveVector(..)","had015",
309 FatalException, ed, "Check G4LEDATA");
310 } else {
313 for(G4int i=0; i<=fNbins; ++i) {
314 G4double e = v->Energy(i);
315 G4double dedx = fVector->Value(e);
316 v->PutValue(i, dedx);
317 }
318 const G4double fact = CLHEP::MeV * CLHEP::cm2 /( 0.001 * CLHEP::g);
319 v->ScaleVector(CLHEP::MeV, fact);
320 if(fSpline) { v->FillSecondDerivatives(); }
321 if(fVerbose > 1) { G4cout << *v << G4endl; }
322 }
323 }
324 return v;
325}
326
327//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
std::vector< const G4Element * > G4ElementVector
@ 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
const G4String namesICRU73[31]
const G4String namesICRU90[3]
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
const G4int Z[17]
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static G4EmParameters * Instance()
G4bool UseICRU90Data() const
G4PhysicsFreeVector * fVector
std::vector< G4PhysicsLogVector * > * fMatData[81]
G4PhysicsLogVector * RetrieveVector(std::ostringstream &in, G4bool warn)
std::vector< G4int > fMatIndex
G4PhysicsLogVector * fElmData[81][81]
G4double GetDEDX(const G4Material *, const G4int Z, const G4double e, const G4double loge) const
void ReadElementData(const G4Material *mat, G4bool type)
void ReadMaterialData(const G4String &name, G4bool type)
G4PhysicsLogVector * FindOrBuildElementData(const G4int Z, const G4int Z1, G4bool useICRU90)
const G4Material * GetMaterial() const
const G4ElementVector * GetElementVector() const
Definition: G4Material.hh:186
static size_t GetNumberOfMaterials()
Definition: G4Material.cc:679
const G4double * GetFractionVector() const
Definition: G4Material.hh:190
size_t GetNumberOfElements() const
Definition: G4Material.hh:182
const G4String & GetName() const
Definition: G4Material.hh:173
size_t GetIndex() const
Definition: G4Material.hh:256
void PutValue(const std::size_t index, const G4double value)
void ScaleVector(const G4double factorE, const G4double factorV)
G4double Energy(const std::size_t index) const
G4double LogVectorValue(const G4double energy, const G4double theLogEnergy) const
G4bool Retrieve(std::ifstream &fIn, G4bool ascii=false)
G4double Value(const G4double energy, std::size_t &lastidx) const
void FillSecondDerivatives(const G4SplineType=G4SplineType::Base, const G4double dir1=0.0, const G4double dir2=0.0)
const G4MaterialCutsCouple * GetMaterialCutsCouple(G4int i) const
std::size_t GetTableSize() const
static G4ProductionCutsTable * GetProductionCutsTable()
static constexpr double MeV
static constexpr double g
static constexpr double cm2
const char * name(G4int ptype)
static const G4double Z1[5]
Definition: paraMaker.cc:41
int G4lrint(double ad)
Definition: templates.hh:134