Geant4  10.00.p03
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 //
27 // $Id: G4Element.cc 81839 2014-06-06 08:47:44Z gcosmo $
28 //
29 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
30 
31 // 26-06-96: Code uses operators (+=, *=, ++, -> etc.) correctly, P. Urban
32 // 09-07-96: new data members added by L.Urban
33 // 17-01-97: aesthetic rearrangement, M.Maire
34 // 20-01-97: Compute Tsai's formula for the rad length, M.Maire
35 // 21-01-97: remove mixture flag, M.Maire
36 // 24-01-97: ComputeIonisationParameters().
37 // new data member: fTaul, M.Maire
38 // 29-01-97: Forbidden to create Element with Z<1 or N<Z, M.Maire
39 // 20-03-97: corrected initialization of pointers, M.Maire
40 // 28-04-98: atomic subshell binding energies stuff, V. Grichine
41 // 09-07-98: Ionisation parameters removed from the class, M.Maire
42 // 16-11-98: name Subshell -> Shell; GetBindingEnergy() (mma)
43 // 09-03-01: assignement operator revised (mma)
44 // 02-05-01: check identical Z in AddIsotope (marc)
45 // 03-05-01: flux.precision(prec) at begin/end of operator<<
46 // 13-09-01: suppression of the data member fIndexInTable
47 // 14-09-01: fCountUse: nb of materials which use this element
48 // 26-02-02: fIndexInTable renewed
49 // 30-03-05: warning in GetElement(elementName)
50 // 15-11-05: GetElement(elementName, G4bool warning=true)
51 // 17-10-06: Add fNaturalAbundances (V.Ivanchenko)
52 // 27-07-07: improve destructor (V.Ivanchenko)
53 // 18-10-07: move definition of material index to ComputeDerivedQuantities (VI)
54 // 25.10.11: new scheme for G4Exception (mma)
55 // 05-03-12: always create isotope vector (V.Ivanchenko)
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 
59 #include <iomanip>
60 #include <sstream>
61 
62 #include "G4Element.hh"
63 #include "G4AtomicShells.hh"
64 #include "G4NistManager.hh"
65 #include "G4PhysicalConstants.hh"
66 #include "G4SystemOfUnits.hh"
67 
69 
70 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
71 
72 // Constructor to Generate an element from scratch
73 
75  G4double zeff, G4double aeff)
76  : fName(name), fSymbol(symbol)
77 {
78  G4int iz = G4lrint(zeff);
79  if (iz < 1) {
81  ed << "Fail to create G4Element " << name
82  << " Z= " << zeff << " < 1 !";
83  G4Exception ("G4Element::G4Element()", "mat011", FatalException, ed);
84  }
85  if (std::abs(zeff - iz) > perMillion) {
87  ed << "G4Element Warning: " << name << " Z= " << zeff
88  << " A= " << aeff/(g/mole);
89  G4Exception("G4Element::G4Element()", "mat017", JustWarning, ed);
90  }
91 
93 
94  fZeff = zeff;
95  fNeff = aeff/(g/mole);
96  fAeff = aeff;
97 
98  if(fNeff < 1.0) fNeff = 1.0;
99 
100  if (fNeff < zeff) {
102  ed << "Fail to create G4Element " << name
103  << " with Z= " << zeff << " N= " << fNeff
104  << " N < Z is not allowed" << G4endl;
105  G4Exception("G4Element::G4Element()", "mat012", FatalException, ed);
106  }
107 
111 
113 
114  for (G4int i=0;i<fNbOfAtomicShells;i++)
115  {
118  }
120 }
121 
122 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
123 
124 // Constructor to Generate element from a List of 'nIsotopes' isotopes, added
125 // via AddIsotope
126 
128  const G4String& symbol, G4int nIsotopes)
129  : fName(name),fSymbol(symbol)
130 {
132 
133  size_t n = size_t(nIsotopes);
134 
135  if(0 >= nIsotopes) {
137  ed << "Fail to create G4Element " << name
138  << " <" << symbol << "> with " << nIsotopes
139  << " isotopes";
140  G4Exception ("G4Element::G4Element()", "mat012", FatalException, ed);
141  } else {
143  fRelativeAbundanceVector = new G4double[nIsotopes];
144  }
145 }
146 
147 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
148 
149 // Add an isotope to the element
150 
151 void G4Element::AddIsotope(G4Isotope* isotope, G4double abundance)
152 {
153  if (theIsotopeVector == 0) {
155  ed << "Fail to add Isotope to G4Element " << fName
156  << " with Z= " << fZeff << " N= " << fNeff;
157  G4Exception ("G4Element::AddIsotope()", "mat013", FatalException, ed);
158  return;
159  }
160  G4int iz = isotope->GetZ();
161 
162  // filling ...
163  if ( fNumberOfIsotopes < theIsotopeVector->size() ) {
164  // check same Z
165  if (fNumberOfIsotopes==0) { fZeff = G4double(iz); }
166  else if (G4double(iz) != fZeff) {
168  ed << "Fail to add Isotope Z= " << iz << " to G4Element " << fName
169  << " with different Z= " << fZeff << fNeff;
170  G4Exception ("G4Element::AddIsotope()", "mat014", FatalException, ed);
171  return;
172  }
173  //Z ok
175  (*theIsotopeVector)[fNumberOfIsotopes] = isotope;
177 
178  } else {
180  ed << "Fail to add Isotope Z= " << iz << " to G4Element " << fName
181  << " - more isotopes than declaired ";
182  G4Exception ("G4Element::AddIsotope()", "mat015", FatalException, ed);
183  return;
184  }
185 
186  // filled.
187  if ( fNumberOfIsotopes == theIsotopeVector->size() ) {
188  // Compute Neff, Aeff
189  G4double wtSum=0.0;
190 
191  G4double aeff = 0.0;
192  G4double neff = 0.0;
193  for (size_t i=0;i<fNumberOfIsotopes;i++) {
194  aeff += fRelativeAbundanceVector[i]*(*theIsotopeVector)[i]->GetA();
195  neff += fRelativeAbundanceVector[i]*(*theIsotopeVector)[i]->GetN();
196  wtSum += fRelativeAbundanceVector[i];
197  }
198  aeff /= wtSum;
199  neff /= wtSum;
200  if(0.0 == fAeff) {
201  fAeff = aeff;
202  fNeff = neff;
203  }
204 
205  if(wtSum != 1.0) {
206  for(size_t i=0; i<fNumberOfIsotopes; ++i) {
207  fRelativeAbundanceVector[i] /= wtSum;
208  }
209  }
210 
214 
215  for ( G4int j = 0; j < fNbOfAtomicShells; j++ )
216  {
219  }
221 
222  }
223 }
224 
225 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
226 
228 {
229  theIsotopeVector = 0;
231  fAtomicShells = 0;
233  fIonisation = 0;
234  fNumberOfIsotopes = 0;
235  fNaturalAbundance = false;
236 
237  // add initialisation of all remaining members
238  fZeff = 0;
239  fNeff = 0;
240  fAeff = 0;
241  fNbOfAtomicShells = 0;
242  fIndexInTable = 0;
243  fCoulomb = 0.0;
244  fRadTsai = 0.0;
245 }
246 
247 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
248 
249 // Fake default constructor - sets only member data and allocates memory
250 // for usage restricted to object persistency
251 
253  : fZeff(0), fNeff(0), fAeff(0)
254 {
256 }
257 
258 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
259 
261 {
262  // G4cout << "### Destruction of element " << fName << " started" <<G4endl;
263 
264  if (theIsotopeVector) { delete theIsotopeVector; }
266  if (fAtomicShells) { delete [] fAtomicShells; }
267  if (fNbOfShellElectrons) { delete [] fNbOfShellElectrons; }
268  if (fIonisation) { delete fIonisation; }
269 
270  //remove this element from theElementTable
272 }
273 
274 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
275 
277 {
278  // some basic functions of the atomic number
279 
280  // Store in table
281  theElementTable.push_back(this);
282  fIndexInTable = theElementTable.size() - 1;
283 
284  // Radiation Length
287 
288  // parameters for energy loss by ionisation
289  if (fIonisation) { delete fIonisation; }
291 }
292 
293 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
294 
296 {
297  //
298  // Compute Coulomb correction factor (Phys Rev. D50 3-1 (1994) page 1254)
299 
300  static const G4double k1 = 0.0083 , k2 = 0.20206 ,k3 = 0.0020 , k4 = 0.0369 ;
301 
302  G4double az2 = (fine_structure_const*fZeff)*(fine_structure_const*fZeff);
303  G4double az4 = az2 * az2;
304 
305  fCoulomb = (k1*az4 + k2 + 1./(1.+az2))*az2 - (k3*az4 + k4)*az4;
306 }
307 
308 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
309 
311 {
312  //
313  // Compute Tsai's Expression for the Radiation Length
314  // (Phys Rev. D50 3-1 (1994) page 1254)
315 
316  static const G4double Lrad_light[] = {5.31 , 4.79 , 4.74 , 4.71} ;
317  static const G4double Lprad_light[] = {6.144 , 5.621 , 5.805 , 5.924} ;
318 
319  const G4double logZ3 = std::log(fZeff)/3.;
320 
321  G4double Lrad, Lprad;
322  G4int iz = (G4int)(fZeff+0.5) - 1 ;
323  if (iz <= 3) { Lrad = Lrad_light[iz] ; Lprad = Lprad_light[iz] ; }
324  else { Lrad = std::log(184.15) - logZ3 ; Lprad = std::log(1194.) - 2*logZ3;}
325 
326  fRadTsai = 4*alpha_rcl2*fZeff*(fZeff*(Lrad-fCoulomb) + Lprad);
327 }
328 
329 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
330 
332 {
333  G4int Z = G4lrint(fZeff);
335  G4int n = nist->GetNumberOfNistIsotopes(Z);
336  G4int N0 = nist->GetNistFirstIsotopeN(Z);
337 
338  if("" == fSymbol) {
339  const std::vector<G4String> elmnames =
341  if(Z < (G4int)elmnames.size()) { fSymbol = elmnames[Z]; }
342  else { fSymbol = fName; }
343  }
344 
345  fNumberOfIsotopes = 0;
346  for(G4int i=0; i<n; ++i) {
347  if(nist->GetIsotopeAbundance(Z, N0+i) > 0.0) { ++fNumberOfIsotopes; }
348  }
351  G4int idx = 0;
352  G4double xsum = 0.0;
353  for(G4int i=0; i<n; ++i) {
354  G4int N = N0 + i;
355  G4double x = nist->GetIsotopeAbundance(Z, N);
356  if(x > 0.0) {
357  std::ostringstream strm;
358  strm << fSymbol << N;
359  (*theIsotopeVector)[idx] = new G4Isotope(strm.str(), Z, N, 0.0, 0);
360  fRelativeAbundanceVector[idx] = x;
361  xsum += x;
362  ++idx;
363  }
364  }
365  if(xsum != 0.0 && xsum != 1.0) {
366  for(G4int i=0; i<idx; ++i) { fRelativeAbundanceVector[i] /= xsum; }
367  }
368  fNaturalAbundance = true;
369 }
370 
371 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
372 
374 {
375  if (i<0 || i>=fNbOfAtomicShells) {
377  ed << "Invalid argument " << i << " in for G4Element " << fName
378  << " with Z= " << fZeff
379  << " and Nshells= " << fNbOfAtomicShells;
380  G4Exception("G4Element::GetAtomicShell()", "mat016", FatalException, ed);
381  return 0.0;
382  }
383  return fAtomicShells[i];
384 }
385 
386 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
387 
389 {
390  if (i<0 || i>=fNbOfAtomicShells) {
392  ed << "Invalid argument " << i << " for G4Element " << fName
393  << " with Z= " << fZeff
394  << " and Nshells= " << fNbOfAtomicShells;
395  G4Exception("G4Element::GetNbOfShellElectrons()", "mat016", FatalException, ed);
396  return 0;
397  }
398  return fNbOfShellElectrons[i];
399 }
400 
401 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
402 
404 {
405  return &theElementTable;
406 }
407 
408 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
409 
411 {
412  return theElementTable.size();
413 }
414 
415 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
416 
418 {
419  // search the element by its name
420  for (size_t J=0 ; J<theElementTable.size() ; J++)
421  {
422  if (theElementTable[J]->GetName() == elementName)
423  return theElementTable[J];
424  }
425 
426  // the element does not exist in the table
427  if (warning) {
428  G4cout << "\n---> warning from G4Element::GetElement(). The element: "
429  << elementName << " does not exist in the table. Return NULL pointer."
430  << G4endl;
431  }
432  return 0;
433 }
434 
435 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
436 
438 {
440  *this = right;
441 
442  // Store this new element in table and set the index
443  theElementTable.push_back(this);
444  fIndexInTable = theElementTable.size() - 1;
445 }
446 
447 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
448 
450 {
451  if (this != &right)
452  {
453  fName = right.fName;
454  fSymbol = right.fSymbol;
455  fZeff = right.fZeff;
456  fNeff = right.fNeff;
457  fAeff = right.fAeff;
458 
459  if (fAtomicShells) delete [] fAtomicShells;
462 
466 
467  for ( G4int i = 0; i < fNbOfAtomicShells; i++ )
468  {
469  fAtomicShells[i] = right.fAtomicShells[i];
471  }
474 
476  if (fNumberOfIsotopes > 0)
477  {
480  for (size_t i=0;i<fNumberOfIsotopes;i++)
481  {
482  (*theIsotopeVector)[i] = (*right.theIsotopeVector)[i];
484  }
485  }
487  }
488  return *this;
489 }
490 
491 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
492 
494 {
495  return (this == (G4Element*) &right);
496 }
497 
498 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
499 
501 {
502  return (this != (G4Element*) &right);
503 }
504 
505 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
506 
507 std::ostream& operator<<(std::ostream& flux, G4Element* element)
508 {
509  std::ios::fmtflags mode = flux.flags();
510  flux.setf(std::ios::fixed,std::ios::floatfield);
511  G4long prec = flux.precision(3);
512 
513  flux
514  << " Element: " << element->fName << " (" << element->fSymbol << ")"
515  << " Z = " << std::setw(4) << std::setprecision(1) << element->fZeff
516  << " N = " << std::setw(5) << std::setprecision(1) << element->fNeff
517  << " A = " << std::setw(6) << std::setprecision(2)
518  << (element->fAeff)/(g/mole) << " g/mole";
519 
520  for (size_t i=0; i<element->fNumberOfIsotopes; i++)
521  flux
522  << "\n ---> " << (*(element->theIsotopeVector))[i]
523  << " abundance: " << std::setw(6) << std::setprecision(2)
524  << (element->fRelativeAbundanceVector[i])/perCent << " %";
525 
526  flux.precision(prec);
527  flux.setf(mode,std::ios::floatfield);
528  return flux;
529 }
530 
531 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
532 
533  std::ostream& operator<<(std::ostream& flux, G4Element& element)
534 {
535  flux << &element;
536  return flux;
537 }
538 
539 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
540 
541 std::ostream& operator<<(std::ostream& flux, G4ElementTable ElementTable)
542 {
543  //Dump info for all known elements
544  flux << "\n***** Table : Nb of elements = " << ElementTable.size()
545  << " *****\n" << G4endl;
546 
547  for (size_t i=0; i<ElementTable.size(); i++) flux << ElementTable[i]
548  << G4endl << G4endl;
549 
550  return flux;
551 }
552 
553 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4double fRadTsai
Definition: G4Element.hh:259
G4String symbol
Definition: TRTMaterials.hh:40
const G4Element & operator=(const G4Element &)
Definition: G4Element.cc:449
std::vector< G4Isotope * > G4IsotopeVector
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4String fName
Definition: G4AttUtils.hh:55
static G4Element * GetElement(G4String name, G4bool warning=true)
Definition: G4Element.cc:417
void ComputeCoulombFactor()
Definition: G4Element.cc:295
void AddNaturalIsotopes()
Definition: G4Element.cc:331
static G4ElementTable theElementTable
Definition: G4Element.hh:251
G4double fCoulomb
Definition: G4Element.hh:258
G4String name
Definition: TRTMaterials.hh:40
const std::vector< G4String > & GetNistElementNames() const
G4int * fNbOfShellElectrons
Definition: G4Element.hh:242
G4IsotopeVector * theIsotopeVector
Definition: G4Element.hh:246
long G4long
Definition: G4Types.hh:80
G4double * fAtomicShells
Definition: G4Element.hh:241
G4IonisParamElm * fIonisation
Definition: G4Element.hh:260
G4int GetNbOfShellElectrons(G4int index) const
Definition: G4Element.cc:388
int G4int
Definition: G4Types.hh:78
static G4NistManager * Instance()
G4int GetNistFirstIsotopeN(G4int Z) const
G4bool fNaturalAbundance
Definition: G4Element.hh:253
static const double prec
Definition: RanecuEngine.cc:51
void ComputeLradTsaiFactor()
Definition: G4Element.cc:310
std::ostream & operator<<(std::ostream &flux, G4Element *element)
Definition: G4Element.cc:507
G4GLOB_DLL std::ostream G4cout
static size_t GetNumberOfElements()
Definition: G4Element.cc:410
void InitializePointers()
Definition: G4Element.cc:227
bool G4bool
Definition: G4Types.hh:79
static G4double GetBindingEnergy(G4int Z, G4int SubshellNb)
G4double iz
Definition: TRTMaterials.hh:39
void AddIsotope(G4Isotope *isotope, G4double RelativeAbundance)
Definition: G4Element.cc:151
G4Element(const G4String &name, const G4String &symbol, G4double Zeff, G4double Aeff)
Definition: G4Element.cc:74
static const double perCent
Definition: G4SIunits.hh:296
G4double GetIsotopeAbundance(G4int Z, G4int N) const
G4int GetNumberOfNistIsotopes(G4int Z) const
const G4int n
G4String fSymbol
Definition: G4Element.hh:235
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4int operator==(const G4Element &) const
Definition: G4Element.cc:493
G4double fNeff
Definition: G4Element.hh:237
G4int GetZ() const
Definition: G4Isotope.hh:91
static const double perMillion
Definition: G4SIunits.hh:298
int G4lrint(double ad)
Definition: templates.hh:163
G4int operator!=(const G4Element &) const
Definition: G4Element.cc:500
size_t fIndexInTable
Definition: G4Element.hh:252
static const double g
Definition: G4SIunits.hh:162
static G4int GetNumberOfElectrons(G4int Z, G4int SubshellNb)
G4String fName
Definition: G4Element.hh:234
virtual ~G4Element()
Definition: G4Element.cc:260
static const double mole
Definition: G4SIunits.hh:265
#define G4endl
Definition: G4ios.hh:61
G4int fNbOfAtomicShells
Definition: G4Element.hh:240
G4double fZeff
Definition: G4Element.hh:236
G4double * fRelativeAbundanceVector
Definition: G4Element.hh:247
G4double GetAtomicShell(G4int index) const
Definition: G4Element.cc:373
std::vector< G4Element * > G4ElementTable
double G4double
Definition: G4Types.hh:76
const G4String & GetName() const
Definition: G4Element.hh:127
size_t fNumberOfIsotopes
Definition: G4Element.hh:245
static G4ElementTable * GetElementTable()
Definition: G4Element.cc:403
G4double fAeff
Definition: G4Element.hh:238
static G4int GetNumberOfShells(G4int Z)
void ComputeDerivedQuantities()
Definition: G4Element.cc:276