Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Element.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// 26-06-96: Code uses operators (+=, *=, ++, -> etc.) correctly, P. Urban
27// 09-07-96: new data members added by L.Urban
28// 17-01-97: aesthetic rearrangement, M.Maire
29// 20-01-97: Compute Tsai's formula for the rad length, M.Maire
30// 21-01-97: remove mixture flag, M.Maire
31// 24-01-97: ComputeIonisationParameters().
32// new data member: fTaul, M.Maire
33// 29-01-97: Forbidden to create Element with Z<1 or N<Z, M.Maire
34// 20-03-97: corrected initialization of pointers, M.Maire
35// 28-04-98: atomic subshell binding energies stuff, V. Grichine
36// 09-07-98: Ionisation parameters removed from the class, M.Maire
37// 16-11-98: name Subshell -> Shell; GetBindingEnergy() (mma)
38// 09-03-01: assignement operator revised (mma)
39// 02-05-01: check identical Z in AddIsotope (marc)
40// 03-05-01: flux.precision(prec) at begin/end of operator<<
41// 13-09-01: suppression of the data member fIndexInTable
42// 14-09-01: fCountUse: nb of materials which use this element
43// 26-02-02: fIndexInTable renewed
44// 30-03-05: warning in GetElement(elementName)
45// 15-11-05: GetElement(elementName, G4bool warning=true)
46// 17-10-06: Add fNaturalAbundances (V.Ivanchenko)
47// 27-07-07: improve destructor (V.Ivanchenko)
48// 18-10-07: move definition of material index to ComputeDerivedQuantities (VI)
49// 25.10.11: new scheme for G4Exception (mma)
50// 05-03-12: always create isotope vector (V.Ivanchenko)
51
52#include "G4Element.hh"
53
54#include "G4AtomicShells.hh"
55#include "G4Log.hh"
56#include "G4NistManager.hh"
58#include "G4SystemOfUnits.hh"
59
60#include <iomanip>
61#include <sstream>
62#include <utility>
63
64G4ElementTable G4Element::theElementTable;
65
66// Constructor to Generate an element from scratch
67
68G4Element::G4Element(const G4String& name, const G4String& symbol, G4double zeff, G4double aeff)
69 : fName(name), fSymbol(symbol)
70{
71 G4int iz = G4lrint(zeff);
72 if (iz < 1) {
74 ed << "Failed to create G4Element " << name << " Z= " << zeff << " < 1 !";
75 G4Exception("G4Element::G4Element()", "mat011", FatalException, ed);
76 }
77 if (std::abs(zeff - iz) > perMillion) {
79 ed << "G4Element Warning: " << name << " Z= " << zeff << " A= " << aeff / (g / mole);
80 G4Exception("G4Element::G4Element()", "mat017", JustWarning, ed);
81 }
82
83 InitializePointers();
84
85 fZeff = zeff;
86 fAeff = aeff;
87 fNeff = fAeff / (g / mole);
88
89 if (fNeff < 1.0) {
90 fNeff = 1.0;
91 }
92
93 if (fNeff < zeff) {
95 ed << "Failed to create G4Element " << name << " with Z= " << zeff << " N= " << fNeff
96 << " N < Z is not allowed" << G4endl;
97 G4Exception("G4Element::G4Element()", "mat012", FatalException, ed);
98 }
99
100 fNbOfAtomicShells = G4AtomicShells::GetNumberOfShells(iz);
101 fAtomicShells = new G4double[fNbOfAtomicShells];
102 fNbOfShellElectrons = new G4int[fNbOfAtomicShells];
103
104 AddNaturalIsotopes();
105
106 for (G4int i = 0; i < fNbOfAtomicShells; ++i) {
107 fAtomicShells[i] = G4AtomicShells::GetBindingEnergy(iz, i);
108 fNbOfShellElectrons[i] = G4AtomicShells::GetNumberOfElectrons(iz, i);
109 }
110 ComputeDerivedQuantities();
111}
112
113//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
114
115// Constructor to Generate element from a List of 'nIsotopes' isotopes, added
116// via AddIsotope
117
118G4Element::G4Element(const G4String& name, const G4String& symbol, G4int nIsotopes)
119 : fName(name), fSymbol(symbol)
120{
121 InitializePointers();
122
123 auto n = size_t(nIsotopes);
124
125 if (0 >= nIsotopes) {
127 ed << "Failed to create G4Element " << name << " <" << symbol << "> with " << nIsotopes
128 << " isotopes.";
129 G4Exception("G4Element::G4Element()", "mat012", FatalException, ed);
130 }
131 else {
132 theIsotopeVector = new G4IsotopeVector(n, nullptr);
133 fRelativeAbundanceVector = new G4double[nIsotopes];
134 }
135}
136
137//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
138
139// Add an isotope to the element
140
141void G4Element::AddIsotope(G4Isotope* isotope, G4double abundance)
142{
143 if (theIsotopeVector == nullptr) {
145 ed << "Failed to add Isotope to G4Element " << fName << " with Z= " << fZeff
146 << " N= " << fNeff;
147 G4Exception("G4Element::AddIsotope()", "mat013", FatalException, ed);
148 return;
149 }
150 G4int iz = isotope->GetZ();
151
152 // filling ...
153 if (fNumberOfIsotopes < (G4int)theIsotopeVector->size()) {
154 // check same Z
155 if (fNumberOfIsotopes == 0) {
156 fZeff = G4double(iz);
157 }
158 else if (G4double(iz) != fZeff) {
160 ed << "Failed to add Isotope Z= " << iz << " to G4Element " << fName
161 << " with different Z= " << fZeff << fNeff;
162 G4Exception("G4Element::AddIsotope()", "mat014", FatalException, ed);
163 return;
164 }
165 // Z ok
166 fRelativeAbundanceVector[fNumberOfIsotopes] = abundance;
167 (*theIsotopeVector)[fNumberOfIsotopes] = isotope;
168 ++fNumberOfIsotopes;
169 }
170 else {
172 ed << "Failed to add Isotope Z= " << iz << " to G4Element " << fName
173 << " - more isotopes than declared.";
174 G4Exception("G4Element::AddIsotope()", "mat015", FatalException, ed);
175 return;
176 }
177
178 // filled.
179 if (fNumberOfIsotopes == (G4int)theIsotopeVector->size()) {
180 G4double wtSum = 0.0;
181 fAeff = 0.0;
182 for (G4int i = 0; i < fNumberOfIsotopes; ++i) {
183 fAeff += fRelativeAbundanceVector[i] * (*theIsotopeVector)[i]->GetA();
184 wtSum += fRelativeAbundanceVector[i];
185 }
186 if (wtSum > 0.0) {
187 fAeff /= wtSum;
188 }
189 fNeff = fAeff / (g / mole);
190
191 if (wtSum != 1.0) {
192 for (G4int i = 0; i < fNumberOfIsotopes; ++i) {
193 fRelativeAbundanceVector[i] /= wtSum;
194 }
195 }
196
197 fNbOfAtomicShells = G4AtomicShells::GetNumberOfShells(iz);
198 fAtomicShells = new G4double[fNbOfAtomicShells];
199 fNbOfShellElectrons = new G4int[fNbOfAtomicShells];
200
201 for (G4int j = 0; j < fNbOfAtomicShells; ++j) {
202 fAtomicShells[j] = G4AtomicShells::GetBindingEnergy(iz, j);
203 fNbOfShellElectrons[j] = G4AtomicShells::GetNumberOfElectrons(iz, j);
204 }
205 ComputeDerivedQuantities();
206 }
207}
208
209//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
210
211void G4Element::InitializePointers()
212{
213 theIsotopeVector = nullptr;
214 fRelativeAbundanceVector = nullptr;
215 fAtomicShells = nullptr;
216 fNbOfShellElectrons = nullptr;
217 fIonisation = nullptr;
218 fNumberOfIsotopes = 0;
219 fNaturalAbundance = false;
220
221 // add initialisation of all remaining members
222 fZeff = 0;
223 fNeff = 0;
224 fAeff = 0;
225 fNbOfAtomicShells = 0;
226 fIndexInTable = 0;
227 fCoulomb = 0.0;
228 fRadTsai = 0.0;
229 fZ = 0;
230}
231
232//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
233
235{
236 delete theIsotopeVector;
237 delete[] fRelativeAbundanceVector;
238 delete[] fAtomicShells;
239 delete[] fNbOfShellElectrons;
240 delete fIonisation;
241
242 // remove this element from theElementTable
243 theElementTable[fIndexInTable] = nullptr;
244}
245
246//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
247
248void G4Element::ComputeDerivedQuantities()
249{
250 // some basic functions of the atomic number
251
252 // Store in table
253 theElementTable.push_back(this);
254 fIndexInTable = theElementTable.size() - 1;
255
256 // Radiation Length
257 ComputeCoulombFactor();
258 ComputeLradTsaiFactor();
259
260 // parameters for energy loss by ionisation
261 delete fIonisation;
262 fIonisation = new G4IonisParamElm(fZeff);
263 fZ = G4lrint(fZeff);
264}
265
266//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
267
268void G4Element::ComputeCoulombFactor()
269{
270 //
271 // Compute Coulomb correction factor (Phys Rev. D50 3-1 (1994) page 1254)
272
273 static const G4double k1 = 0.0083, k2 = 0.20206, k3 = 0.0020, k4 = 0.0369;
274
275 G4double az2 = (fine_structure_const * fZeff) * (fine_structure_const * fZeff);
276 G4double az4 = az2 * az2;
277
278 fCoulomb = (k1 * az4 + k2 + 1. / (1. + az2)) * az2 - (k3 * az4 + k4) * az4;
279}
280
281//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
282
283void G4Element::ComputeLradTsaiFactor()
284{
285 //
286 // Compute Tsai's Expression for the Radiation Length
287 // (Phys Rev. D50 3-1 (1994) page 1254)
288
289 static const G4double Lrad_light[] = {5.31, 4.79, 4.74, 4.71};
290 static const G4double Lprad_light[] = {6.144, 5.621, 5.805, 5.924};
291
292 const G4double logZ3 = G4Log(fZeff) / 3.;
293
294 G4double Lrad, Lprad;
295 G4int iz = G4lrint(fZeff) - 1;
296 static const G4double log184 = G4Log(184.15);
297 static const G4double log1194 = G4Log(1194.);
298 if (iz <= 3) {
299 Lrad = Lrad_light[iz];
300 Lprad = Lprad_light[iz];
301 }
302 else {
303 Lrad = log184 - logZ3;
304 Lprad = log1194 - 2 * logZ3;
305 }
306
307 fRadTsai = 4 * alpha_rcl2 * fZeff * (fZeff * (Lrad - fCoulomb) + Lprad);
308}
309
310//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
311
312void G4Element::AddNaturalIsotopes()
313{
314 G4int Z = G4lrint(fZeff);
317 G4int N0 = nist->GetNistFirstIsotopeN(Z);
318
319 if (fSymbol.empty()) {
320 const std::vector<G4String> elmnames = G4NistManager::Instance()->GetNistElementNames();
321 if (Z < (G4int)elmnames.size()) {
322 fSymbol = elmnames[Z];
323 }
324 else {
325 fSymbol = fName;
326 }
327 }
328
329 fNumberOfIsotopes = 0;
330 for (G4int i = 0; i < n; ++i) {
331 if (nist->GetIsotopeAbundance(Z, N0 + i) > 0.0) {
332 ++fNumberOfIsotopes;
333 }
334 }
335 theIsotopeVector = new G4IsotopeVector((unsigned int)fNumberOfIsotopes, nullptr);
336 fRelativeAbundanceVector = new G4double[fNumberOfIsotopes];
337 G4int idx = 0;
338 G4double xsum = 0.0;
339 for (G4int i = 0; i < n; ++i) {
340 G4int N = N0 + i;
341 G4double x = nist->GetIsotopeAbundance(Z, N);
342 if (x > 0.0) {
343 std::ostringstream strm;
344 strm << fSymbol << N;
345 (*theIsotopeVector)[idx] = new G4Isotope(strm.str(), Z, N, 0.0, 0);
346 fRelativeAbundanceVector[idx] = x;
347 xsum += x;
348 ++idx;
349 }
350 }
351 if (xsum != 0.0 && xsum != 1.0) {
352 for (G4int i = 0; i < idx; ++i) {
353 fRelativeAbundanceVector[i] /= xsum;
354 }
355 }
356 fNaturalAbundance = true;
357}
358
359//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
360
362{
363 if (i < 0 || i >= fNbOfAtomicShells) {
365 ed << "Invalid argument " << i << " in for G4Element " << fName << " with Z= " << fZeff
366 << " and Nshells= " << fNbOfAtomicShells;
367 G4Exception("G4Element::GetAtomicShell()", "mat016", FatalException, ed);
368 return 0.0;
369 }
370 return fAtomicShells[i];
371}
372
373//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
374
376{
377 if (i < 0 || i >= fNbOfAtomicShells) {
379 ed << "Invalid argument " << i << " for G4Element " << fName << " with Z= " << fZeff
380 << " and Nshells= " << fNbOfAtomicShells;
381 G4Exception("G4Element::GetNbOfShellElectrons()", "mat016", FatalException, ed);
382 return 0;
383 }
384 return fNbOfShellElectrons[i];
385}
386
387//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
388
389G4ElementTable* G4Element::GetElementTable() { return &theElementTable; }
390
391//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
392
393size_t G4Element::GetNumberOfElements() { return theElementTable.size(); }
394
395//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
396
397G4Element* G4Element::GetElement(const G4String& elementName, G4bool warning)
398{
399 // search the element by its name
400 for (auto J : theElementTable) {
401 if (J->GetName() == elementName) {
402 return J;
403 }
404 }
405
406 // the element does not exist in the table
407 if (warning) {
408 G4cout << "\n---> warning from G4Element::GetElement(). The element: " << elementName
409 << " does not exist in the table. Return NULL pointer." << G4endl;
410 }
411 return nullptr;
412}
413
414//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
415
416std::ostream& operator<<(std::ostream& flux, const G4Element* element)
417{
418 std::ios::fmtflags mode = flux.flags();
419 flux.setf(std::ios::fixed, std::ios::floatfield);
420 G4long prec = flux.precision(3);
421
422 flux << " Element: " << element->fName << " (" << element->fSymbol << ")"
423 << " Z = " << std::setw(4) << std::setprecision(1) << element->fZeff
424 << " N = " << std::setw(5) << std::setprecision(1) << G4lrint(element->fNeff)
425 << " A = " << std::setw(6) << std::setprecision(3) << (element->fAeff) / (g / mole)
426 << " g/mole";
427
428 for (G4int i = 0; i < element->fNumberOfIsotopes; i++) {
429 flux << "\n ---> " << (*(element->theIsotopeVector))[i]
430 << " abundance: " << std::setw(6) << std::setprecision(3)
431 << (element->fRelativeAbundanceVector[i]) / perCent << " %";
432 }
433
434 flux.precision(prec);
435 flux.setf(mode, std::ios::floatfield);
436 return flux;
437}
438
439//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
440
441std::ostream& operator<<(std::ostream& flux, const G4Element& element)
442{
443 flux << &element;
444 return flux;
445}
446
447//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
448
449std::ostream& operator<<(std::ostream& flux, const G4ElementTable& ElementTable)
450{
451 // Dump info for all known elements
452 flux << "\n***** Table : Nb of elements = " << ElementTable.size() << " *****\n" << G4endl;
453
454 for (auto i : ElementTable) {
455 flux << i << G4endl << G4endl;
456 }
457
458 return flux;
459}
460
461//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
462
463std::ostream& operator<<(std::ostream& flux, const G4ElementVector& ElementVector)
464{
465 // Dump info for all known elements
466 flux << "\n***** Vector : Nb of elements = " << ElementVector.size() << " *****\n" << G4endl;
467
468 for (auto i : ElementVector) {
469 flux << i << G4endl << G4endl;
470 }
471
472 return flux;
473}
std::vector< G4Element * > G4ElementTable
std::vector< const G4Element * > G4ElementVector
std::ostream & operator<<(std::ostream &flux, const G4Element *element)
Definition G4Element.cc:416
@ JustWarning
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
std::vector< G4Isotope * > G4IsotopeVector
G4double G4Log(G4double x)
Definition G4Log.hh:227
double G4double
Definition G4Types.hh:83
long G4long
Definition G4Types.hh:87
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
static G4int GetNumberOfElectrons(G4int Z, G4int SubshellNb)
static G4double GetBindingEnergy(G4int Z, G4int SubshellNb)
static G4int GetNumberOfShells(G4int Z)
static G4ElementTable * GetElementTable()
Definition G4Element.cc:389
virtual ~G4Element()
Definition G4Element.cc:234
static size_t GetNumberOfElements()
Definition G4Element.cc:393
void AddIsotope(G4Isotope *isotope, G4double RelativeAbundance)
Definition G4Element.cc:141
G4Element(const G4String &name, const G4String &symbol, G4double Zeff, G4double Aeff)
Definition G4Element.cc:68
G4int GetNbOfShellElectrons(G4int index) const
Definition G4Element.cc:375
static G4Element * GetElement(const G4String &name, G4bool warning=true)
Definition G4Element.cc:397
G4double GetAtomicShell(G4int index) const
Definition G4Element.cc:361
G4int GetZ() const
Definition G4Isotope.hh:80
G4int GetNumberOfNistIsotopes(G4int Z) const
const std::vector< G4String > & GetNistElementNames() const
G4int GetNistFirstIsotopeN(G4int Z) const
static G4NistManager * Instance()
G4double GetIsotopeAbundance(G4int Z, G4int N) const
#define N
Definition crc32.c:57
int G4lrint(double ad)
Definition templates.hh:134