Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/materials/src/G4Material.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /materials/src/G4Material.cc (Version 11.3.0) and /materials/src/G4Material.cc (Version 10.4.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25                                                <<  25 //
                                                   >>  26 // $Id: G4Material.cc 106243 2017-09-26 01:56:43Z gcosmo $
                                                   >>  27 //
                                                   >>  28 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
                                                   >>  29 //
 26 // 26-06-96, Code uses operators (+=, *=, ++,      30 // 26-06-96, Code uses operators (+=, *=, ++, -> etc.) correctly, P. Urban
 27 // 10-07-96, new data members added by L.Urban     31 // 10-07-96, new data members added by L.Urban
 28 // 12-12-96, new data memberfFreeElecDensitys  <<  32 // 12-12-96, new data members added by L.Urban
 29 // 20-01-97, aesthetic rearrangement. RadLengt     33 // 20-01-97, aesthetic rearrangement. RadLength calculation modified.
 30 //           Data members Zeff and Aeff REMOVE     34 //           Data members Zeff and Aeff REMOVED (i.e. passed to the Elements).
 31 //           (local definition of Zeff in Dens     35 //           (local definition of Zeff in DensityEffect and FluctModel...)
 32 //           Vacuum defined as a G4State. Mixt <<  36 //           Vacuum defined as a G4State. Mixture flag removed, M.Maire. 
 33 // 29-01-97, State=Vacuum automatically set de     37 // 29-01-97, State=Vacuum automatically set density=0 in the contructors.
 34 //           Subsequent protections have been  <<  38 //           Subsequent protections have been put in the calculation of 
 35 //           MeanExcEnergy, ShellCorrectionVec     39 //           MeanExcEnergy, ShellCorrectionVector, DensityEffect, M.Maire.
 36 // 11-02-97, ComputeDensityEffect() rearranged     40 // 11-02-97, ComputeDensityEffect() rearranged, M.Maire.
 37 // 20-03-97, corrected initialization of point     41 // 20-03-97, corrected initialization of pointers, M.Maire.
 38 // 28-05-98, the kState=kVacuum has been remov     42 // 28-05-98, the kState=kVacuum has been removed.
 39 //           automatic check for a minimal den <<  43 //           automatic check for a minimal density, M.Maire 
 40 // 12-06-98, new method AddMaterial() allowing <<  44 // 12-06-98, new method AddMaterial() allowing mixture of materials, M.Maire  
 41 // 09-07-98, ionisation parameters removed fro     45 // 09-07-98, ionisation parameters removed from the class, M.Maire
 42 // 05-10-98, change names: NumDensity -> NbOfA     46 // 05-10-98, change names: NumDensity -> NbOfAtomsPerVolume
 43 // 18-11-98, new interface to SandiaTable          47 // 18-11-98, new interface to SandiaTable
 44 // 19-01-99  enlarge tolerance on test of cohe     48 // 19-01-99  enlarge tolerance on test of coherence of gas conditions
 45 // 19-07-99, Constructors with chemicalFormula     49 // 19-07-99, Constructors with chemicalFormula added by V.Ivanchenko
 46 // 16-01-01, Nuclear interaction length, M.Mai     50 // 16-01-01, Nuclear interaction length, M.Maire
 47 // 12-03-01, G4bool fImplicitElement;              51 // 12-03-01, G4bool fImplicitElement;
 48 //           copy constructor and assignement      52 //           copy constructor and assignement operator revised (mma)
 49 // 03-05-01, flux.precision(prec) at begin/end     53 // 03-05-01, flux.precision(prec) at begin/end of operator<<
 50 // 17-07-01, migration to STL. M. Verderi.         54 // 17-07-01, migration to STL. M. Verderi.
 51 // 14-09-01, Suppression of the data member fI     55 // 14-09-01, Suppression of the data member fIndexInTable
 52 // 26-02-02, fIndexInTable renewed                 56 // 26-02-02, fIndexInTable renewed
 53 // 16-04-02, G4Exception put in constructor wi     57 // 16-04-02, G4Exception put in constructor with chemical formula
 54 // 06-05-02, remove the check of the ideal gas     58 // 06-05-02, remove the check of the ideal gas state equation
 55 // 06-08-02, remove constructors with chemical     59 // 06-08-02, remove constructors with chemical formula (mma)
 56 // 22-01-04, proper STL handling of theElement     60 // 22-01-04, proper STL handling of theElementVector (Hisaya)
 57 // 30-03-05, warning in GetMaterial(materialNa <<  61 // 30-03-05, warning in GetMaterial(materialName) 
 58 // 09-03-06, minor change of printout (V.Ivanc <<  62 // 09-03-06, minor change of printout (V.Ivanchenko) 
 59 // 10-01-07, compute fAtomVector in the case o <<  63 // 10-01-07, compute fAtomVector in the case of mass fraction (V.Ivanchenko) 
 60 // 27-07-07, improve destructor (V.Ivanchenko) <<  64 // 27-07-07, improve destructor (V.Ivanchenko) 
 61 // 18-10-07, moved definition of mat index to  <<  65 // 18-10-07, move definition of material index to InitialisePointers (V.Ivanchenko) 
 62 // 13-08-08, do not use fixed size arrays (V.I     66 // 13-08-08, do not use fixed size arrays (V.Ivanchenko)
 63 // 26-10-11, new scheme for G4Exception  (mma)     67 // 26-10-11, new scheme for G4Exception  (mma)
 64 // 13-04-12, map<G4Material*,G4double> fMatCom     68 // 13-04-12, map<G4Material*,G4double> fMatComponents, filled in AddMaterial()
 65 // 21-04-12, fMassOfMolecule, computed for Ato     69 // 21-04-12, fMassOfMolecule, computed for AtomsCount (mma)
                                                   >>  70 // 
                                                   >>  71 // 
                                                   >>  72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 66                                                    73 
 67 #include "G4Material.hh"                       <<  74 #include <iomanip>
 68                                                    75 
 69 #include "G4ApplicationState.hh"               <<  76 #include "G4Material.hh"
 70 #include "G4AtomicShells.hh"                   << 
 71 #include "G4ExtendedMaterial.hh"               << 
 72 #include "G4Pow.hh"                            << 
 73 #include "G4NistManager.hh"                        77 #include "G4NistManager.hh"
                                                   >>  78 #include "G4UnitsTable.hh"
 74 #include "G4PhysicalConstants.hh"                  79 #include "G4PhysicalConstants.hh"
 75 #include "G4StateManager.hh"                   << 
 76 #include "G4SystemOfUnits.hh"                      80 #include "G4SystemOfUnits.hh"
 77 #include "G4UnitsTable.hh"                     <<  81 #include "G4Exp.hh"
                                                   >>  82 #include "G4Log.hh"
 78                                                    83 
 79 #include <iomanip>                             <<  84 G4MaterialTable G4Material::theMaterialTable;
                                                   >>  85 
                                                   >>  86 #ifdef G4MULTITHREADED
                                                   >>  87   G4Mutex G4Material::materialMutex = G4MUTEX_INITIALIZER;
                                                   >>  88 #endif
 80                                                    89 
 81 //....oooOO0OOooo........oooOO0OOooo........oo     90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 82                                                    91 
 83 // Constructor to create a material from scrat     92 // Constructor to create a material from scratch
 84                                                    93 
 85 G4Material::G4Material(const G4String& name, G <<  94 G4Material::G4Material(const G4String& name, G4double z,
 86   G4State state, G4double temp, G4double press <<  95                        G4double a, G4double density, 
 87   : fName(name)                                <<  96                        G4State state, G4double temp, G4double pressure)
                                                   >>  97   : fName(name)          
 88 {                                                  98 {
 89   InitializePointers();                            99   InitializePointers();
 90                                                << 100     
 91   if (density < universe_mean_density) {       << 101   if (density < universe_mean_density)
 92     G4cout << " G4Material WARNING:"           << 102     { 
 93            << " define a material with density << 103       G4cout << " G4Material WARNING:"
 94            << " The material " << name << " wi << 104        << " define a material with density=0 is not allowed. \n"
 95            << " default minimal density: " <<  << 105        << " The material " << name << " will be constructed with the"
 96            << G4endl;                          << 106        << " default minimal density: " << universe_mean_density/(g/cm3) 
 97     density = universe_mean_density;           << 107        << "g/cm3" << G4endl;
 98   }                                            << 108       density = universe_mean_density;
 99                                                << 109     } 
100   fDensity = density;                          << 110 
101   fState = state;                              << 111   fDensity  = density;
102   fTemp = temp;                                << 112   fState    = state;
                                                   >> 113   fTemp     = temp;
103   fPressure = pressure;                           114   fPressure = pressure;
104                                                   115 
105   // Initialize theElementVector allocating on    116   // Initialize theElementVector allocating one
106   // element corresponding to this material       117   // element corresponding to this material
107   fNbComponents = fNumberOfElements = 1;       << 118   maxNbComponents        = fNumberOfComponents = fNumberOfElements = 1;
108   theElementVector = new G4ElementVector();    << 119   fArrayLength           = maxNbComponents;
109                                                << 120   theElementVector       = new G4ElementVector();
110   // take element from DB                      << 121 
111   G4NistManager* nist = G4NistManager::Instanc << 122   const std::vector<G4String> elmnames = 
                                                   >> 123     G4NistManager::Instance()->GetNistElementNames();
                                                   >> 124   G4String enam, snam;
112   G4int iz = G4lrint(z);                          125   G4int iz = G4lrint(z);
113   auto elm = nist->FindOrBuildElement(iz);     << 126   if(iz < (G4int)elmnames.size()) { 
114   if (elm == nullptr) {                        << 127     snam = elmnames[iz]; 
115     elm = new G4Element("ELM_" + name, name, z << 128     enam = snam; 
116   }                                            << 129   } else { 
117   theElementVector->push_back(elm);            << 130     enam = "ELM_" + name; 
118                                                << 131     snam = name;
119   fMassFractionVector = new G4double[1];       << 132   }
120   fMassFractionVector[0] = 1.;                 << 133   theElementVector->push_back(new G4Element(enam, snam, z, a));  
121   fMassOfMolecule = a / CLHEP::Avogadro;       << 134 
122                                                << 135   fMassFractionVector    = new G4double[1];
123   if (fState == kStateUndefined) {             << 136   fMassFractionVector[0] = 1. ;
124     if (fDensity > kGasThreshold) {            << 137   fMassOfMolecule        = a/CLHEP::Avogadro;
125       fState = kStateSolid;                    << 138   
126     }                                          << 139   if (fState == kStateUndefined)
127     else {                                     << 140     {
128       fState = kStateGas;                      << 141       if (fDensity > kGasThreshold) { fState = kStateSolid; }
                                                   >> 142       else                          { fState = kStateGas; }
129     }                                             143     }
130   }                                            << 
131                                                   144 
132   ComputeDerivedQuantities();                     145   ComputeDerivedQuantities();
133 }                                                 146 }
134                                                   147 
135 //....oooOO0OOooo........oooOO0OOooo........oo    148 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
136                                                   149 
137 // Constructor to create a material from a Lis    150 // Constructor to create a material from a List of constituents
138 // (elements and/or materials)  added with Add    151 // (elements and/or materials)  added with AddElement or AddMaterial
139                                                   152 
140 G4Material::G4Material(const G4String& name, G << 153 G4Material::G4Material(const G4String& name, G4double density,
141   G4double temp, G4double pressure)            << 154                        G4int nComponents,
142   : fName(name)                                << 155                        G4State state, G4double temp, G4double pressure)
                                                   >> 156   : fName(name)          
143 {                                                 157 {
144   InitializePointers();                           158   InitializePointers();
145                                                << 159     
146   if (density < universe_mean_density) {       << 160   if (density < universe_mean_density)
147     G4cout << "--- Warning from G4Material::G4 << 161     {
148            << " define a material with density << 162       G4cout << "--- Warning from G4Material::G4Material()"
149            << " The material " << name << " wi << 163        << " define a material with density=0 is not allowed. \n"
150            << " default minimal density: " <<  << 164        << " The material " << name << " will be constructed with the"
151            << G4endl;                          << 165        << " default minimal density: " << universe_mean_density/(g/cm3) 
152     density = universe_mean_density;           << 166        << "g/cm3" << G4endl;
153   }                                            << 167       density = universe_mean_density;
154                                                << 168     }
155   fDensity = density;                          << 169         
156   fState = state;                              << 170   fDensity  = density;
157   fTemp = temp;                                << 171   fState    = state;
                                                   >> 172   fTemp     = temp;
158   fPressure = pressure;                           173   fPressure = pressure;
159                                                << 174     
160   fNbComponents = nComponents;                 << 175   maxNbComponents     = nComponents;
161   fMassFraction = true;                        << 176   fArrayLength        = maxNbComponents;
162                                                << 177   fNumberOfComponents = fNumberOfElements = 0;
163   if (fState == kStateUndefined) {             << 178   theElementVector    = new G4ElementVector();
164     if (fDensity > kGasThreshold) {            << 179   theElementVector->reserve(maxNbComponents);  
165       fState = kStateSolid;                    << 180     
166     }                                          << 181   if (fState == kStateUndefined) 
167     else {                                     << 182     {
168       fState = kStateGas;                      << 183       if (fDensity > kGasThreshold) { fState = kStateSolid; }
                                                   >> 184       else                          { fState = kStateGas; }
169     }                                             185     }
170   }                                            << 
171 }                                                 186 }
172                                                   187 
173 //....oooOO0OOooo........oooOO0OOooo........oo    188 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
174                                                   189 
175 // Constructor to create a material from base     190 // Constructor to create a material from base material
176                                                   191 
177 G4Material::G4Material(const G4String& name, G << 192 G4Material::G4Material(const G4String& name, G4double density,
178   G4State state, G4double temp, G4double press << 193                        const G4Material* bmat,
179   : fName(name)                                << 194                        G4State state, G4double temp, G4double pressure)
                                                   >> 195   : fName(name)          
180 {                                                 196 {
181   InitializePointers();                           197   InitializePointers();
                                                   >> 198     
                                                   >> 199   if (density < universe_mean_density)
                                                   >> 200     {
                                                   >> 201       G4cout << "--- Warning from G4Material::G4Material()"
                                                   >> 202        << " define a material with density=0 is not allowed. \n"
                                                   >> 203        << " The material " << name << " will be constructed with the"
                                                   >> 204        << " default minimal density: " << universe_mean_density/(g/cm3) 
                                                   >> 205        << "g/cm3" << G4endl;
                                                   >> 206       density = universe_mean_density;
                                                   >> 207     }
182                                                   208 
183   if (density < universe_mean_density) {       << 209   fDensity  = density;
184     G4cout << "--- Warning from G4Material::G4 << 210   fState    = state;
185            << " define a material with density << 211   fTemp     = temp;
186            << " The material " << name << " wi << 
187            << " default minimal density: " <<  << 
188            << G4endl;                          << 
189     density = universe_mean_density;           << 
190   }                                            << 
191                                                << 
192   fDensity = density;                          << 
193   fState = state;                              << 
194   fTemp = temp;                                << 
195   fPressure = pressure;                           212   fPressure = pressure;
196                                                   213 
197   fBaseMaterial = bmat;                           214   fBaseMaterial = bmat;
198   auto ptr = bmat;                             << 
199   if (nullptr != ptr) {                        << 
200     while (true) {                             << 
201       ptr = ptr->GetBaseMaterial();            << 
202       if (nullptr == ptr) {                    << 
203         break;                                 << 
204       }                                        << 
205       fBaseMaterial = ptr;                     << 
206     }                                          << 
207   }                                            << 
208                                                << 
209   fChemicalFormula = fBaseMaterial->GetChemica    215   fChemicalFormula = fBaseMaterial->GetChemicalFormula();
210   fMassOfMolecule = fBaseMaterial->GetMassOfMo << 216   fMassOfMolecule  = fBaseMaterial->GetMassOfMolecule();
211                                                   217 
212   fNumberOfElements = (G4int)fBaseMaterial->Ge << 218   fNumberOfElements = fBaseMaterial->GetNumberOfElements();     
213   fNbComponents = fNumberOfElements;           << 219   maxNbComponents = fNumberOfElements;
                                                   >> 220   fNumberOfComponents = fNumberOfElements;
214                                                   221 
215   CopyPointersOfBaseMaterial();                   222   CopyPointersOfBaseMaterial();
216 }                                                 223 }
217                                                   224 
218 //....oooOO0OOooo........oooOO0OOooo........oo    225 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
219                                                   226 
                                                   >> 227 // Fake default constructor - sets only member data and allocates memory
                                                   >> 228 //                            for usage restricted to object persistency
                                                   >> 229 
                                                   >> 230 G4Material::G4Material(__void__&)
                                                   >> 231   : fName("")
                                                   >> 232 {
                                                   >> 233   InitializePointers();
                                                   >> 234 }
                                                   >> 235 
                                                   >> 236 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
                                                   >> 237 
220 G4Material::~G4Material()                         238 G4Material::~G4Material()
221 {                                                 239 {
222   if (fBaseMaterial == nullptr) {              << 240   //  G4cout << "### Destruction of material " << fName << " started" <<G4endl;
223     delete theElementVector;                   << 241   if(fBaseMaterial == nullptr) {
224     delete fSandiaTable;                       << 242     delete theElementVector;  
225     delete[] fMassFractionVector;              << 243     delete fSandiaTable; 
226     delete[] fAtomsVector;                     << 244     //delete fMaterialPropertiesTable;
                                                   >> 245     delete [] fMassFractionVector;
                                                   >> 246     delete [] fAtomsVector;
227   }                                               247   }
228   delete fIonisation;                          << 248   delete fIonisation; 
229   delete[] fVecNbOfAtomsPerVolume;             << 249   delete [] VecNbOfAtomsPerVolume; 
230                                                   250 
231   // Remove this material from the MaterialTab << 251   // Remove this material from theMaterialTable.
232   //                                              252   //
233   (*GetMaterialTable())[fIndexInTable] = nullp << 253   theMaterialTable[fIndexInTable] = nullptr;
234 }                                                 254 }
235                                                   255 
236 //....oooOO0OOooo........oooOO0OOooo........oo    256 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
237                                                   257 
238 void G4Material::InitializePointers()             258 void G4Material::InitializePointers()
239 {                                                 259 {
240   fBaseMaterial = nullptr;                     << 260   theElementVector         = nullptr;
                                                   >> 261   fMassFractionVector      = nullptr;
                                                   >> 262   fAtomsVector             = nullptr;
241   fMaterialPropertiesTable = nullptr;             263   fMaterialPropertiesTable = nullptr;
242   theElementVector = nullptr;                  << 264     
243   fAtomsVector = nullptr;                      << 265   VecNbOfAtomsPerVolume    = nullptr;
244   fMassFractionVector = nullptr;               << 266   fBaseMaterial            = nullptr;
245   fVecNbOfAtomsPerVolume = nullptr;            << 267 
                                                   >> 268   fChemicalFormula         = "";
                                                   >> 269 
                                                   >> 270   // initilized data members
                                                   >> 271   fDensity  = 0.0;
                                                   >> 272   fState    = kStateUndefined;
                                                   >> 273   fTemp     = 0.0;
                                                   >> 274   fPressure = 0.0;
                                                   >> 275   maxNbComponents     = 0;
                                                   >> 276   fArrayLength        = 0;
                                                   >> 277   fNumberOfComponents = 0;
                                                   >> 278   fNumberOfElements   = 0;
                                                   >> 279   TotNbOfAtomsPerVolume = 0.0;
                                                   >> 280   TotNbOfElectPerVolume = 0.0; 
                                                   >> 281   fRadlen = 0.0;
                                                   >> 282   fNuclInterLen = 0.0;
                                                   >> 283   fMassOfMolecule = 0.0;
246                                                   284 
247   fIonisation = nullptr;                          285   fIonisation = nullptr;
248   fSandiaTable = nullptr;                         286   fSandiaTable = nullptr;
249                                                   287 
250   fDensity = fFreeElecDensity = fTemp = fPress << 
251   fTotNbOfAtomsPerVolume = 0.0;                << 
252   fTotNbOfElectPerVolume = 0.0;                << 
253   fRadlen = fNuclInterLen = fMassOfMolecule =  << 
254                                                << 
255   fState = kStateUndefined;                    << 
256   fNumberOfElements = fNbComponents = fIdxComp << 
257   fMassFraction = true;                        << 
258   fChemicalFormula = "";                       << 
259                                                << 
260   // Store in the static Table of Materials       288   // Store in the static Table of Materials
261   fIndexInTable = GetMaterialTable()->size();  << 289   fIndexInTable = theMaterialTable.size();
262   for (std::size_t i = 0; i < fIndexInTable; + << 290   for(size_t i=0; i<fIndexInTable; ++i) {
263     if ((*GetMaterialTable())[i]->GetName() == << 291     if(theMaterialTable[i]->GetName() == fName) {
264       G4cout << "G4Material WARNING: duplicate << 292       G4cout << "G4Material WARNING: duplicate name of material "
                                                   >> 293        << fName << G4endl;
265       break;                                      294       break;
266     }                                             295     }
267   }                                               296   }
268   GetMaterialTable()->push_back(this);         << 297   theMaterialTable.push_back(this);
269 }                                                 298 }
270                                                   299 
271 //....oooOO0OOooo........oooOO0OOooo........oo    300 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
272                                                   301 
273 void G4Material::ComputeDerivedQuantities()       302 void G4Material::ComputeDerivedQuantities()
274 {                                                 303 {
275   // Header routine to compute various propert    304   // Header routine to compute various properties of material.
276   //                                           << 305   // 
                                                   >> 306 
277   // Number of atoms per volume (per element),    307   // Number of atoms per volume (per element), total nb of electrons per volume
278   G4double Zi, Ai;                                308   G4double Zi, Ai;
279   fTotNbOfAtomsPerVolume = 0.;                 << 309   TotNbOfAtomsPerVolume = 0.;
280   delete[] fVecNbOfAtomsPerVolume;             << 310   if (VecNbOfAtomsPerVolume) { delete [] VecNbOfAtomsPerVolume; }
281   fVecNbOfAtomsPerVolume = new G4double[fNumbe << 311   VecNbOfAtomsPerVolume = new G4double[fNumberOfElements];
282   fTotNbOfElectPerVolume = 0.;                 << 312   TotNbOfElectPerVolume = 0.;
283   fFreeElecDensity = 0.;                       << 313   for (G4int i=0; i<fNumberOfElements; ++i) {
284   const G4double elecTh = 15. * CLHEP::eV;  // << 314      Zi = (*theElementVector)[i]->GetZ();
285   for (G4int i = 0; i < fNumberOfElements; ++i << 315      Ai = (*theElementVector)[i]->GetA();
286     Zi = (*theElementVector)[i]->GetZ();       << 316      VecNbOfAtomsPerVolume[i] = Avogadro*fDensity*fMassFractionVector[i]/Ai;
287     Ai = (*theElementVector)[i]->GetA();       << 317      TotNbOfAtomsPerVolume += VecNbOfAtomsPerVolume[i];
288     fVecNbOfAtomsPerVolume[i] = Avogadro * fDe << 318      TotNbOfElectPerVolume += VecNbOfAtomsPerVolume[i]*Zi;
289     fTotNbOfAtomsPerVolume += fVecNbOfAtomsPer << 
290     fTotNbOfElectPerVolume += fVecNbOfAtomsPer << 
291     if (fState != kStateGas) {                 << 
292       fFreeElecDensity +=                      << 
293         fVecNbOfAtomsPerVolume[i] * G4AtomicSh << 
294     }                                          << 
295   }                                               319   }
296                                                << 320         
297   ComputeRadiationLength();                       321   ComputeRadiationLength();
298   ComputeNuclearInterLength();                    322   ComputeNuclearInterLength();
299                                                   323 
300   if (fIonisation == nullptr) {                << 324   if (fIonisation) { delete fIonisation; }
301     fIonisation = new G4IonisParamMat(this);   << 325   fIonisation  = new G4IonisParamMat(this);
302   }                                            << 326   if (fSandiaTable) { delete fSandiaTable; }
303   if (fSandiaTable == nullptr) {               << 327   fSandiaTable = new G4SandiaTable(this);
304     fSandiaTable = new G4SandiaTable(this);    << 
305   }                                            << 
306 }                                                 328 }
307                                                   329 
308 //....oooOO0OOooo........oooOO0OOooo........oo    330 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
309                                                   331 
310 void G4Material::CopyPointersOfBaseMaterial()     332 void G4Material::CopyPointersOfBaseMaterial()
311 {                                                 333 {
312   G4double factor = fDensity / fBaseMaterial-> << 334   G4double factor = fDensity/fBaseMaterial->GetDensity();
313   fTotNbOfAtomsPerVolume = factor * fBaseMater << 335   TotNbOfAtomsPerVolume = factor*fBaseMaterial->GetTotNbOfAtomsPerVolume();
314   fTotNbOfElectPerVolume = factor * fBaseMater << 336   TotNbOfElectPerVolume = factor*fBaseMaterial->GetTotNbOfElectPerVolume();
315   fFreeElecDensity = factor * fBaseMaterial->G << 337 
316                                                << 338   if(fState == kStateUndefined) { fState = fBaseMaterial->GetState(); }
317   if (fState == kStateUndefined) {             << 339 
318     fState = fBaseMaterial->GetState();        << 340   theElementVector = 
319   }                                            << 341     const_cast<G4ElementVector*>(fBaseMaterial->GetElementVector());
320                                                << 342   fMassFractionVector = 
321   theElementVector = const_cast<G4ElementVecto << 343     const_cast<G4double*>(fBaseMaterial->GetFractionVector());
322   fMassFractionVector = const_cast<G4double*>( << 
323   fAtomsVector = const_cast<G4int*>(fBaseMater    344   fAtomsVector = const_cast<G4int*>(fBaseMaterial->GetAtomsVector());
324                                                   345 
325   const G4double* v = fBaseMaterial->GetVecNbO    346   const G4double* v = fBaseMaterial->GetVecNbOfAtomsPerVolume();
326   delete[] fVecNbOfAtomsPerVolume;             << 347   if (VecNbOfAtomsPerVolume)  { delete [] VecNbOfAtomsPerVolume; }
327   fVecNbOfAtomsPerVolume = new G4double[fNumbe << 348   VecNbOfAtomsPerVolume = new G4double[fNumberOfElements];
328   for (G4int i = 0; i < fNumberOfElements; ++i << 349   for (G4int i=0; i<fNumberOfElements; ++i) {
329     fVecNbOfAtomsPerVolume[i] = factor * v[i]; << 350     VecNbOfAtomsPerVolume[i] = factor*v[i];
330   }                                               351   }
331   fRadlen = fBaseMaterial->GetRadlen() / facto << 352   fRadlen = fBaseMaterial->GetRadlen()/factor;
332   fNuclInterLen = fBaseMaterial->GetNuclearInt << 353   fNuclInterLen = fBaseMaterial->GetNuclearInterLength()/factor;
333                                                   354 
334   if (fIonisation == nullptr) {                << 355   if (fIonisation) { delete fIonisation; }
335     fIonisation = new G4IonisParamMat(this);   << 356   fIonisation = new G4IonisParamMat(this);
336   }                                            << 
337   fIonisation->SetMeanExcitationEnergy(fBaseMa << 
338   if (fBaseMaterial->GetIonisation()->GetDensi << 
339     ComputeDensityEffectOnFly(true);           << 
340   }                                            << 
341                                                   357 
342   fSandiaTable = fBaseMaterial->GetSandiaTable    358   fSandiaTable = fBaseMaterial->GetSandiaTable();
                                                   >> 359   fIonisation->SetMeanExcitationEnergy(fBaseMaterial->GetIonisation()->GetMeanExcitationEnergy());
                                                   >> 360 
343   fMaterialPropertiesTable = fBaseMaterial->Ge    361   fMaterialPropertiesTable = fBaseMaterial->GetMaterialPropertiesTable();
344 }                                                 362 }
345                                                   363 
346 //....oooOO0OOooo........oooOO0OOooo........oo    364 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
347                                                   365 
348 void G4Material::AddElementByNumberOfAtoms(con << 366 // AddElement -- composition by atom count
349 {                                              << 
350   // perform checks consistency                << 
351   if (0 == fIdxComponent) {                    << 
352     fMassFraction = false;                     << 
353     fAtoms = new std::vector<G4int>;           << 
354     fElm = new std::vector<const G4Element*>;  << 
355   }                                            << 
356   if (fIdxComponent >= fNbComponents) {        << 
357     G4ExceptionDescription ed;                 << 
358     ed << "For material " << fName << " and ad << 
359        << " with Natoms=" << nAtoms            << 
360        << " wrong attempt to add more than the << 
361        << " >= " << fNbComponents;             << 
362     G4Exception("G4Material::AddElementByNumbe << 
363   }                                            << 
364   if (fMassFraction) {                         << 
365     G4ExceptionDescription ed;                 << 
366     ed << "For material " << fName << " and ad << 
367        << " with Natoms=" << nAtoms << " probl << 
368        << "addition of elements by mass fracti << 
369     G4Exception("G4Material::AddElementByNumbe << 
370   }                                            << 
371   if (0 >= nAtoms) {                           << 
372     G4ExceptionDescription ed;                 << 
373     ed << "For material " << fName << " and ad << 
374        << " with Natoms=" << nAtoms << " probl << 
375     G4Exception("G4Material::AddElementByNumbe << 
376   }                                            << 
377                                                << 
378   // filling                                   << 
379   G4bool isAdded = false;                      << 
380   if (! fElm->empty()) {                       << 
381     for (G4int i = 0; i < fNumberOfElements; + << 
382       if (elm == (*fElm)[i]) {                 << 
383         (*fAtoms)[i] += nAtoms;                << 
384         isAdded = true;                        << 
385         break;                                 << 
386       }                                        << 
387     }                                          << 
388   }                                            << 
389   if (! isAdded) {                             << 
390     fElm->push_back(elm);                      << 
391     fAtoms->push_back(nAtoms);                 << 
392     ++fNumberOfElements;                       << 
393   }                                            << 
394   ++fIdxComponent;                             << 
395                                                << 
396   // is filled - complete composition of atoms << 
397   if (fIdxComponent == fNbComponents) {        << 
398     theElementVector = new G4ElementVector();  << 
399     theElementVector->reserve(fNumberOfElement << 
400     fAtomsVector = new G4int[fNumberOfElements << 
401     fMassFractionVector = new G4double[fNumber << 
402                                                   367 
                                                   >> 368 void G4Material::AddElement(G4Element* element, G4int nAtoms)
                                                   >> 369 {   
                                                   >> 370   // initialization
                                                   >> 371   if ( fNumberOfElements == 0 ) {
                                                   >> 372      fAtomsVector        = new G4int   [fArrayLength];
                                                   >> 373      fMassFractionVector = new G4double[fArrayLength];
                                                   >> 374   }
                                                   >> 375 
                                                   >> 376   // filling ...
                                                   >> 377   if ( fNumberOfElements < maxNbComponents ) {
                                                   >> 378      theElementVector->push_back(element);     
                                                   >> 379      fAtomsVector[fNumberOfElements] = nAtoms;
                                                   >> 380      fNumberOfComponents = ++fNumberOfElements;
                                                   >> 381   } else {
                                                   >> 382     G4cout << "G4Material::AddElement ERROR for " << fName << " nElement= " 
                                                   >> 383      <<  fNumberOfElements << G4endl;
                                                   >> 384     G4Exception ("G4Material::AddElement()", "mat031", FatalException, 
                                                   >> 385            "Attempt to add more than the declared number of elements.");
                                                   >> 386   } 
                                                   >> 387   // filled.
                                                   >> 388   if ( fNumberOfElements == maxNbComponents ) {     
                                                   >> 389     // compute proportion by mass
                                                   >> 390     G4int i=0;
403     G4double Amol = 0.;                           391     G4double Amol = 0.;
404     for (G4int i = 0; i < fNumberOfElements; + << 392     for (i=0; i<fNumberOfElements; ++i) {
405       theElementVector->push_back((*fElm)[i]); << 393       G4double w = fAtomsVector[i]*(*theElementVector)[i]->GetA(); 
406       fAtomsVector[i] = (*fAtoms)[i];          << 
407       G4double w = fAtomsVector[i] * (*fElm)[i << 
408       Amol += w;                                  394       Amol += w;
409       fMassFractionVector[i] = w;                 395       fMassFractionVector[i] = w;
410     }                                             396     }
411     for (G4int i = 0; i < fNumberOfElements; + << 397     for (i=0; i<fNumberOfElements; ++i) {
412       fMassFractionVector[i] /= Amol;             398       fMassFractionVector[i] /= Amol;
413     }                                             399     }
414     delete fAtoms;                             << 400 
415     delete fElm;                               << 401     fMassOfMolecule = Amol/Avogadro;
416     fMassOfMolecule = Amol / CLHEP::Avogadro;  << 
417     ComputeDerivedQuantities();                   402     ComputeDerivedQuantities();
418   }                                               403   }
419 }                                                 404 }
420                                                   405 
421 //....oooOO0OOooo........oooOO0OOooo........oo    406 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
422                                                   407 
423 void G4Material::AddElementByMassFraction(cons << 408 // AddElement -- composition by fraction of mass
424 {                                              << 
425   // perform checks consistency                << 
426   if (fraction < 0.0 || fraction > 1.0) {      << 
427     G4ExceptionDescription ed;                 << 
428     ed << "For material " << fName << " and ad << 
429        << " massFraction= " << fraction << " i << 
430     G4Exception("G4Material::AddElementByMassF << 
431   }                                            << 
432   if (! fMassFraction) {                       << 
433     G4ExceptionDescription ed;                 << 
434     ed << "For material " << fName << " and ad << 
435        << ", massFraction= " << fraction << ", << 
436        << " problem: cannot add by mass fracti << 
437        << "addition of elements by number of a << 
438     G4Exception("G4Material::AddElementByMassF << 
439   }                                            << 
440   if (fIdxComponent >= fNbComponents) {        << 
441     G4ExceptionDescription ed;                 << 
442     ed << "For material " << fName << " and ad << 
443        << ", massFraction= " << fraction << ", << 
444        << "; attempt to add more than the decl << 
445        << " >= " << fNbComponents;             << 
446     G4Exception("G4Material::AddElementByMassF << 
447   }                                            << 
448   if (0 == fIdxComponent) {                    << 
449     fElmFrac = new std::vector<G4double>;      << 
450     fElm = new std::vector<const G4Element*>;  << 
451   }                                            << 
452                                                   409 
453   // filling                                   << 410 void G4Material::AddElement(G4Element* element, G4double fraction)
454   G4bool isAdded = false;                      << 411 {
455   if (! fElm->empty()) {                       << 412   if(fraction < 0.0 || fraction > 1.0) {
456     for (G4int i = 0; i < fNumberOfElements; + << 413     G4cout << "G4Material::AddElement ERROR for " << fName << " and " 
457       if (elm == (*fElm)[i]) {                 << 414      << element->GetName() << "  mass fraction= " << fraction 
458         (*fElmFrac)[i] += fraction;            << 415      << " is wrong " << G4endl;
459         isAdded = true;                        << 416     G4Exception ("G4Material::AddElement()", "mat032", FatalException,     
460         break;                                 << 417                  "Attempt to add element with wrong mass fraction");
461       }                                        << 418   }
                                                   >> 419   // initialization
                                                   >> 420   if (fNumberOfComponents == 0) {
                                                   >> 421     fMassFractionVector = new G4double[fArrayLength];
                                                   >> 422     fAtomsVector        = new G4int   [fArrayLength];
                                                   >> 423   }
                                                   >> 424   // filling ...
                                                   >> 425   if (fNumberOfComponents < maxNbComponents) {
                                                   >> 426     G4int el = 0;
                                                   >> 427     // Loop checking, 07-Aug-2015, Vladimir Ivanchenko
                                                   >> 428     while ((el<fNumberOfElements)&&(element!=(*theElementVector)[el])) { ++el; }
                                                   >> 429     if (el<fNumberOfElements) fMassFractionVector[el] += fraction;
                                                   >> 430     else {
                                                   >> 431       theElementVector->push_back(element); 
                                                   >> 432       fMassFractionVector[el] = fraction;
                                                   >> 433       ++fNumberOfElements;
462     }                                             434     }
463   }                                            << 435     ++fNumberOfComponents;  
464   if (! isAdded) {                             << 436   } else {
465     fElm->push_back(elm);                      << 437     G4cout << "G4Material::AddElement ERROR for " << fName << " nElement= " 
466     fElmFrac->push_back(fraction);             << 438      <<  fNumberOfElements << G4endl;
467     ++fNumberOfElements;                       << 439     G4Exception ("G4Material::AddElement()", "mat033", FatalException, 
468   }                                            << 440            "Attempt to add more than the declared number of elements.");
469   ++fIdxComponent;                             << 441   }    
470                                                << 442 
471   // is filled                                 << 443   // filled.
472   if (fIdxComponent == fNbComponents) {        << 444   if (fNumberOfComponents == maxNbComponents) {
473     FillVectors();                             << 445 
                                                   >> 446     G4int i=0;
                                                   >> 447     G4double Zmol(0.), Amol(0.);
                                                   >> 448     // check sum of weights -- OK?
                                                   >> 449     G4double wtSum(0.0);
                                                   >> 450     for (i=0; i<fNumberOfElements; ++i) {
                                                   >> 451       wtSum += fMassFractionVector[i];
                                                   >> 452       Zmol +=  fMassFractionVector[i]*(*theElementVector)[i]->GetZ();
                                                   >> 453       Amol +=  fMassFractionVector[i]*(*theElementVector)[i]->GetA();
                                                   >> 454     }
                                                   >> 455     if (std::fabs(1.-wtSum) > perThousand) {
                                                   >> 456       G4cerr << "WARNING !! for " << fName << " sum of fractional masses "
                                                   >> 457        <<  wtSum << " is not 1 - results may be wrong" 
                                                   >> 458        << G4endl;
                                                   >> 459     }
                                                   >> 460     for (i=0; i<fNumberOfElements; ++i) {
                                                   >> 461       fAtomsVector[i] = 
                                                   >> 462   G4lrint(fMassFractionVector[i]*Amol/(*theElementVector)[i]->GetA());
                                                   >> 463     }
                                                   >> 464      
                                                   >> 465     ComputeDerivedQuantities();
474   }                                               466   }
475 }                                                 467 }
476                                                   468 
477 //....oooOO0OOooo........oooOO0OOooo........oo    469 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
478                                                   470 
479 // composition by fraction of mass             << 471 // AddMaterial -- composition by fraction of mass
                                                   >> 472 
480 void G4Material::AddMaterial(G4Material* mater    473 void G4Material::AddMaterial(G4Material* material, G4double fraction)
481 {                                                 474 {
482   if (fraction < 0.0 || fraction > 1.0) {      << 475   if(fraction < 0.0 || fraction > 1.0) {
483     G4ExceptionDescription ed;                 << 476     G4cout << "G4Material::AddMaterial ERROR for " << fName << " and " 
484     ed << "For material " << fName << " and ad << 477      << material->GetName() << "  mass fraction= " << fraction 
485        << ", massFraction= " << fraction << "  << 478      << " is wrong ";
486     G4Exception("G4Material::AddMaterial()", " << 479     G4Exception ("G4Material::AddMaterial()", "mat034", FatalException,
487   }                                            << 480                  "Attempt to add material with wrong mass fraction");    
488   if (! fMassFraction) {                       << 481   }
489     G4ExceptionDescription ed;                 << 482   // initialization
490     ed << "For material " << fName << " and ad << 483   if (fNumberOfComponents == 0) {
491        << ", massFraction= " << fraction << ", << 484     fMassFractionVector = new G4double[fArrayLength];
492        << " problem: cannot add by mass fracti << 485     fAtomsVector        = new G4int   [fArrayLength];
493        << "addition of elements by number of a << 486   }
494     G4Exception("G4Material::AddMaterial()", " << 487 
495   }                                            << 488   G4int nelm = material->GetNumberOfElements();
496   if (fIdxComponent >= fNbComponents) {        << 489 
497     G4ExceptionDescription ed;                 << 490   // arrays should be extended
498     ed << "For material " << fName << " and ad << 491   if(nelm > 1) {
499        << ", massFraction= " << fraction       << 492     G4int nold    = fArrayLength;
500        << "; attempt to add more than the decl << 493     fArrayLength += nelm - 1;
501        << " >= " << fNbComponents;             << 494     G4double* v1 = new G4double[fArrayLength];
502     G4Exception("G4Material::AddMaterial()", " << 495     G4int* i1    = new G4int[fArrayLength];
503   }                                            << 496     for(G4int i=0; i<nold; ++i) {
504   if (0 == fIdxComponent) {                    << 497       v1[i] = fMassFractionVector[i];
505     fElmFrac = new std::vector<G4double>;      << 498       i1[i] = fAtomsVector[i];
506     fElm = new std::vector<const G4Element*>;  << 499     }
507   }                                            << 500     delete [] fAtomsVector;
508                                                << 501     delete [] fMassFractionVector;
509   // filling                                   << 502     fMassFractionVector = v1;
510   auto nelm = (G4int)material->GetNumberOfElem << 503     fAtomsVector = i1;
511   for (G4int j = 0; j < nelm; ++j) {           << 504   }
512     auto elm = material->GetElement(j);        << 505 
513     auto frac = material->GetFractionVector(); << 506   // filling ...
514     G4bool isAdded = false;                    << 507   if (fNumberOfComponents < maxNbComponents) {
515     if (! fElm->empty()) {                     << 508     for (G4int elm=0; elm<nelm; ++elm)
516       for (G4int i = 0; i < fNumberOfElements; << 509       {
517         if (elm == (*fElm)[i]) {               << 510         G4Element* element = (*(material->GetElementVector()))[elm];
518           (*fElmFrac)[i] += fraction * frac[j] << 511         G4int el = 0;
519           isAdded = true;                      << 512   // Loop checking, 07-Aug-2015, Vladimir Ivanchenko
520           break;                               << 513         while ((el<fNumberOfElements)&&(element!=(*theElementVector)[el])) el++;
                                                   >> 514         if (el < fNumberOfElements) fMassFractionVector[el] += fraction
                                                   >> 515                                           *(material->GetFractionVector())[elm];
                                                   >> 516         else {
                                                   >> 517     theElementVector->push_back(element); 
                                                   >> 518           fMassFractionVector[el] = fraction
                                                   >> 519                                     *(material->GetFractionVector())[elm];
                                                   >> 520           ++fNumberOfElements;
521         }                                         521         }
522       }                                        << 522       } 
523     }                                          << 523     ++fNumberOfComponents;
524     if (! isAdded) {                           << 524     ///store massFraction of material component
525       fElm->push_back(elm);                    << 525     fMatComponents[material] = fraction;
526       fElmFrac->push_back(fraction * frac[j]); << 526       
527       ++fNumberOfElements;                     << 527   } else {
                                                   >> 528     G4cout << "G4Material::AddMaterial ERROR for " << fName << " nElement= " 
                                                   >> 529      <<  fNumberOfElements << G4endl;
                                                   >> 530     G4Exception ("G4Material::AddMaterial()", "mat035", FatalException, 
                                                   >> 531            "Attempt to add more than the declared number of components.");
                                                   >> 532   }    
                                                   >> 533 
                                                   >> 534   // filled.
                                                   >> 535   if (fNumberOfComponents == maxNbComponents) {
                                                   >> 536     G4int i=0;
                                                   >> 537     G4double Zmol(0.), Amol(0.);
                                                   >> 538     // check sum of weights -- OK?
                                                   >> 539     G4double wtSum(0.0);
                                                   >> 540     for (i=0; i<fNumberOfElements; ++i) {
                                                   >> 541       wtSum += fMassFractionVector[i];
                                                   >> 542       Zmol +=  fMassFractionVector[i]*(*theElementVector)[i]->GetZ();
                                                   >> 543       Amol +=  fMassFractionVector[i]*(*theElementVector)[i]->GetA();
                                                   >> 544     }
                                                   >> 545     if (std::fabs(1.-wtSum) > perThousand) {
                                                   >> 546       G4cout << "G4Material::AddMaterial WARNING !! for " << fName 
                                                   >> 547        << " sum of fractional masses "
                                                   >> 548        <<  wtSum << " is not 1 - results may be wrong" 
                                                   >> 549        << G4endl;
                                                   >> 550     }
                                                   >> 551     for (i=0; i<fNumberOfElements; ++i) {
                                                   >> 552       fAtomsVector[i] = 
                                                   >> 553   G4lrint(fMassFractionVector[i]*Amol/(*theElementVector)[i]->GetA());
528     }                                             554     }
                                                   >> 555      
                                                   >> 556     ComputeDerivedQuantities();
529   }                                               557   }
530                                                << 
531   fMatComponents[material] = fraction;         << 
532   ++fIdxComponent;                             << 
533                                                << 
534   // is filled                                 << 
535   if (fIdxComponent == fNbComponents) {        << 
536     FillVectors();                             << 
537   }                                            << 
538 }                                              << 
539                                                << 
540 //....oooOO0OOooo........oooOO0OOooo........oo << 
541                                                << 
542 void G4Material::FillVectors()                 << 
543 {                                              << 
544   // there are material components             << 
545   theElementVector = new G4ElementVector();    << 
546   theElementVector->reserve(fNumberOfElements) << 
547   fAtomsVector = new G4int[fNumberOfElements]; << 
548   fMassFractionVector = new G4double[fNumberOf << 
549                                                << 
550   G4double wtSum(0.0);                         << 
551   for (G4int i = 0; i < fNumberOfElements; ++i << 
552     theElementVector->push_back((*fElm)[i]);   << 
553     fMassFractionVector[i] = (*fElmFrac)[i];   << 
554     wtSum += fMassFractionVector[i];           << 
555   }                                            << 
556   delete fElmFrac;                             << 
557   delete fElm;                                 << 
558                                                << 
559   // check sum of weights -- OK?               << 
560   if (std::abs(1. - wtSum) > perThousand) {    << 
561     G4ExceptionDescription ed;                 << 
562     ed << "For material " << fName << " sum of << 
563        << " is not 1 - results may be wrong";  << 
564     G4Exception("G4Material::FillVectors()", " << 
565   }                                            << 
566   G4double coeff = (wtSum > 0.0) ? 1. / wtSum  << 
567   G4double Amol(0.);                           << 
568   for (G4int i = 0; i < fNumberOfElements; ++i << 
569     fMassFractionVector[i] *= coeff;           << 
570     Amol += fMassFractionVector[i] * (*theElem << 
571   }                                            << 
572   for (G4int i = 0; i < fNumberOfElements; ++i << 
573     fAtomsVector[i] = G4lrint(fMassFractionVec << 
574   }                                            << 
575   ComputeDerivedQuantities();                  << 
576 }                                                 558 }
577                                                   559 
578 //....oooOO0OOooo........oooOO0OOooo........oo    560 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
579                                                   561 
580 void G4Material::ComputeRadiationLength()         562 void G4Material::ComputeRadiationLength()
581 {                                                 563 {
582   G4double radinv = 0.0;                       << 564   G4double radinv = 0.0 ;
583   for (G4int i = 0; i < fNumberOfElements; ++i << 565   for (G4int i=0;i<fNumberOfElements;++i) {
584     radinv += fVecNbOfAtomsPerVolume[i] * ((*t << 566      radinv += VecNbOfAtomsPerVolume[i]*((*theElementVector)[i]->GetfRadTsai());
585   }                                               567   }
586   fRadlen = (radinv <= 0.0 ? DBL_MAX : 1. / ra << 568   fRadlen = (radinv <= 0.0 ? DBL_MAX : 1./radinv);
587 }                                                 569 }
588                                                   570 
589 //....oooOO0OOooo........oooOO0OOooo........oo    571 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
590                                                   572 
591 void G4Material::ComputeNuclearInterLength()      573 void G4Material::ComputeNuclearInterLength()
592 {                                                 574 {
593   const G4double lambda1 = CLHEP::amu*CLHEP::c << 575   static const G4double lambda0  = 35*CLHEP::g/CLHEP::cm2;
                                                   >> 576   static const G4double twothird = 2.0/3.0;
594   G4double NILinv = 0.0;                          577   G4double NILinv = 0.0;
595   for (G4int i = 0; i < fNumberOfElements; ++i << 578   for (G4int i=0; i<fNumberOfElements; ++i) {
596     G4int Z = (*theElementVector)[i]->GetZasIn << 579     G4int Z = G4lrint( (*theElementVector)[i]->GetZ());
597     G4double A = (*theElementVector)[i]->GetN(    580     G4double A = (*theElementVector)[i]->GetN();
598     if (1 == Z) {                              << 581     if(1 == Z) {
599       NILinv += fVecNbOfAtomsPerVolume[i] * A; << 582       NILinv += VecNbOfAtomsPerVolume[i]*A;
600     }                                          << 583     } else {
601     else {                                     << 584       NILinv += VecNbOfAtomsPerVolume[i]*G4Exp(twothird*G4Log(A));
602       NILinv += fVecNbOfAtomsPerVolume[i] * G4 << 585     } 
603     }                                          << 
604   }                                            << 
605   NILinv *= lambda1;                           << 
606   fNuclInterLen = 1.e+20*CLHEP::m;             << 
607   if (fNuclInterLen * NILinv > 1.0) {          << 
608     fNuclInterLen = 1.0 / NILinv;              << 
609   }                                            << 
610 }                                              << 
611                                                << 
612 //....oooOO0OOooo........oooOO0OOooo........oo << 
613                                                << 
614 void G4Material::SetChemicalFormula(const G4St << 
615 {                                              << 
616   if (! IsLocked()) {                          << 
617     fChemicalFormula = chF;                    << 
618   }                                            << 
619 }                                              << 
620                                                << 
621 //....oooOO0OOooo........oooOO0OOooo........oo << 
622                                                << 
623 void G4Material::SetFreeElectronDensity(G4doub << 
624 {                                              << 
625   if (val >= 0. && ! IsLocked()) {             << 
626     fFreeElecDensity = val;                    << 
627   }                                            << 
628 }                                              << 
629                                                << 
630 //....oooOO0OOooo........oooOO0OOooo........oo << 
631                                                << 
632 void G4Material::ComputeDensityEffectOnFly(G4b << 
633 {                                              << 
634   if (! IsLocked()) {                          << 
635     if (nullptr == fIonisation) {              << 
636       fIonisation = new G4IonisParamMat(this); << 
637     }                                          << 
638     fIonisation->ComputeDensityEffectOnFly(val << 
639   }                                               586   }
                                                   >> 587   NILinv *= amu/lambda0; 
                                                   >> 588   fNuclInterLen = (NILinv <= 0.0 ? DBL_MAX : 1./NILinv);
640 }                                                 589 }
641                                                   590 
642 //....oooOO0OOooo........oooOO0OOooo........oo    591 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
643                                                   592 
644 G4MaterialTable* G4Material::GetMaterialTable(    593 G4MaterialTable* G4Material::GetMaterialTable()
645 {                                                 594 {
646   struct Holder {                              << 595   return &theMaterialTable;
647     G4MaterialTable instance;                  << 
648     ~Holder() {                                << 
649       for(auto item : instance)                << 
650         delete item;                           << 
651     }                                          << 
652   };                                           << 
653   static Holder _holder;                       << 
654   return &_holder.instance;                    << 
655 }                                                 596 }
656                                                   597 
657 //....oooOO0OOooo........oooOO0OOooo........oo    598 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
658                                                   599 
659 std::size_t G4Material::GetNumberOfMaterials() << 600 size_t G4Material::GetNumberOfMaterials()
660                                                << 
661 //....oooOO0OOooo........oooOO0OOooo........oo << 
662                                                << 
663 G4Material* G4Material::GetMaterial(const G4St << 
664 {                                                 601 {
665   // search the material by its name           << 602   return theMaterialTable.size();
666   for (auto const & j : *GetMaterialTable()) { << 
667     if (j->GetName() == materialName) {        << 
668       return j;                                << 
669     }                                          << 
670   }                                            << 
671                                                << 
672   // the material does not exist in the table  << 
673   if (warn) {                                  << 
674     G4cout << "G4Material::GetMaterial() WARNI << 
675            << " does not exist in the table. R << 
676   }                                            << 
677   return nullptr;                              << 
678 }                                                 603 }
679                                                   604 
680 //....oooOO0OOooo........oooOO0OOooo........oo    605 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
681                                                   606 
682 G4Material* G4Material::GetMaterial(G4double z << 607 G4Material* 
683 {                                              << 608 G4Material::GetMaterial(const G4String& materialName, G4bool warning)
684   // search the material by its name           << 609 {  
685   for (auto const & mat : *GetMaterialTable()) << 610   // search the material by its name 
686     if (1 == mat->GetNumberOfElements() && z = << 611   for (size_t J=0 ; J<theMaterialTable.size() ; ++J)
687         dens == mat->GetDensity())             << 
688     {                                             612     {
689       return mat;                              << 613       if (theMaterialTable[J]->GetName() == materialName)
                                                   >> 614   { return theMaterialTable[J]; }
690     }                                             615     }
691   }                                            << 616    
692   return nullptr;                              << 617   // the material does not exist in the table
693 }                                              << 618   if (warning) {
694                                                << 619     G4cout << "G4Material::GetMaterial() WARNING: The material: "
695 //....oooOO0OOooo........oooOO0OOooo........oo << 620      << materialName 
696                                                << 621      << " does not exist in the table. Return NULL pointer."
697 G4Material* G4Material::GetMaterial(std::size_ << 622      << G4endl;
698 {                                              << 623   }  
699   // search the material by its name           << 
700   for (auto const & mat : *GetMaterialTable()) << 
701     if (nComp == mat->GetNumberOfElements() && << 
702       return mat;                              << 
703     }                                          << 
704   }                                            << 
705   return nullptr;                                 624   return nullptr;
706 }                                                 625 }
707                                                   626 
708 //....oooOO0OOooo........oooOO0OOooo........oo    627 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
709                                                   628 
710 G4double G4Material::GetZ() const                 629 G4double G4Material::GetZ() const
711 {                                              << 630 { 
712   if (fNumberOfElements > 1) {                    631   if (fNumberOfElements > 1) {
713     G4ExceptionDescription ed;                 << 632      G4cout << "G4Material ERROR in GetZ. The material: " << fName 
714     ed << "For material " << fName << " ERROR  << 633       << " is a mixture.";
715        << " > 1, which is not allowed";        << 634      G4Exception ("G4Material::GetZ()", "mat036", FatalException, 
716     G4Exception("G4Material::GetZ()", "mat036" << 635                   "the Atomic number is not well defined." );
717   }                                            << 636   } 
718   return (*theElementVector)[0]->GetZ();       << 637   return (*theElementVector)[0]->GetZ();      
719 }                                                 638 }
720                                                   639 
721 //....oooOO0OOooo........oooOO0OOooo........oo    640 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
722                                                   641 
723 G4double G4Material::GetA() const                 642 G4double G4Material::GetA() const
724 {                                              << 643 { 
725   if (fNumberOfElements > 1) {                 << 644   if (fNumberOfElements > 1) { 
726     G4ExceptionDescription ed;                 << 645     G4cout << "G4Material ERROR in GetA. The material: " << fName 
727     ed << "For material " << fName << " ERROR  << 646      << " is a mixture.";
728        << " > 1, which is not allowed";        << 647     G4Exception ("G4Material::GetA()", "mat037", FatalException,  
729     G4Exception("G4Material::GetA()", "mat036" << 648      "the Atomic mass is not well defined." );
730   }                                            << 649   } 
731   return (*theElementVector)[0]->GetA();       << 650   return  (*theElementVector)[0]->GetA();      
732 }                                                 651 }
733                                                   652 
734 //....oooOO0OOooo........oooOO0OOooo........oo    653 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
                                                   >> 654 #include "G4ExtendedMaterial.hh"
735                                                   655 
736 std::ostream& operator<<(std::ostream& flux, c    656 std::ostream& operator<<(std::ostream& flux, const G4Material* material)
737 {                                                 657 {
738   std::ios::fmtflags mode = flux.flags();         658   std::ios::fmtflags mode = flux.flags();
739   flux.setf(std::ios::fixed, std::ios::floatfi << 659   flux.setf(std::ios::fixed,std::ios::floatfield);
740   G4long prec = flux.precision(3);                660   G4long prec = flux.precision(3);
741                                                << 661   
742   flux << " Material: " << std::setw(8) << mat << 662   flux
743        << " "                                  << 663     << " Material: "         << std::setw(8) <<  material->fName
744        << "  density: " << std::setw(6) << std << 664     << " " << material->fChemicalFormula << " "
745        << G4BestUnit(material->fDensity, "Volu << 665     << "  density: "         << std::setw(6) << std::setprecision(3)  
746        << std::setprecision(3) << G4BestUnit(m << 666     << G4BestUnit(material->fDensity,"Volumic Mass") 
747        << "  Nucl.Int.Length: " << std::setw(7 << 667     << "  RadL: "            << std::setw(7)  << std::setprecision(3)  
748        << G4BestUnit(material->fNuclInterLen,  << 668     << G4BestUnit(material->fRadlen,"Length")
749        << std::setw(30) << "  Imean: " << std: << 669     << "  Nucl.Int.Length: " << std::setw(7)  << std::setprecision(3)  
750        << G4BestUnit(material->GetIonisation() << 670     << G4BestUnit(material->fNuclInterLen,"Length") 
751        << "  temperature: " << std::setw(6) << << 671     << "\n" << std::setw(30)   
752        << (material->fTemp) / CLHEP::kelvin << << 672     << "  Imean: "           << std::setw(7)  << std::setprecision(3)  
753        << "  pressure: " << std::setw(6) << st << 673     << G4BestUnit(material->GetIonisation()->GetMeanExcitationEnergy(),
754        << (material->fPressure) / CLHEP::atmos << 674       "Energy")
755        << "\n";                                << 675     << "  temperature: " << std::setw(6) << std::setprecision(2)  
756                                                << 676     << (material->fTemp)/kelvin << " K"
757   for (G4int i = 0; i < material->fNumberOfEle << 677     << "  pressure: "    << std::setw(6) << std::setprecision(2)   
758     flux << "\n   ---> " << (*(material->theEl << 678     << (material->fPressure)/atmosphere << " atm" << "\n";
759          << "\n          ElmMassFraction: " << << 679   
760          << (material->fMassFractionVector[i]) << 680   for (G4int i=0; i<material->fNumberOfElements; i++) {
761          << "  ElmAbundance " << std::setw(6)  << 681     flux 
762          << 100 * (material->fVecNbOfAtomsPerV << 682       << "\n   ---> " << (*(material->theElementVector))[i] 
763          << " % \n";                           << 683       << "\n          ElmMassFraction: " 
                                                   >> 684       << std::setw(6)<< std::setprecision(2) 
                                                   >> 685       << (material->fMassFractionVector[i])/perCent << " %" 
                                                   >> 686       << "  ElmAbundance "     << std::setw(6)<< std::setprecision(2) 
                                                   >> 687       << 100*(material->VecNbOfAtomsPerVolume[i])
                                                   >> 688       /(material->TotNbOfAtomsPerVolume)
                                                   >> 689       << " % \n";
764   }                                               690   }
765   flux.precision(prec);                        << 691   flux.precision(prec);    
766   flux.setf(mode, std::ios::floatfield);       << 692   flux.setf(mode,std::ios::floatfield);
767                                                   693 
768   if (material->IsExtended()) {                << 694   if(material->IsExtended())
769     static_cast<const G4ExtendedMaterial*>(mat << 695   { static_cast<const G4ExtendedMaterial*>(material)->Print(flux); }
770   }                                            << 
771                                                   696 
772   return flux;                                    697   return flux;
773 }                                                 698 }
774                                                   699 
775 //....oooOO0OOooo........oooOO0OOooo........oo    700 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
776                                                   701 
777 std::ostream& operator<<(std::ostream& flux, c    702 std::ostream& operator<<(std::ostream& flux, const G4Material& material)
778 {                                                 703 {
779   flux << &material;                           << 704   flux << &material;        
780   return flux;                                    705   return flux;
781 }                                                 706 }
782                                                   707 
783 //....oooOO0OOooo........oooOO0OOooo........oo    708 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
784                                                << 709      
785 std::ostream& operator<<(std::ostream& flux, c << 710 std::ostream& operator<<(std::ostream& flux, G4MaterialTable MaterialTable)
786 {                                                 711 {
787   // Dump info for all known materials         << 712   //Dump info for all known materials
788   flux << "\n***** Table : Nb of materials = " << 713   flux << "\n***** Table : Nb of materials = " << MaterialTable.size() 
789                                                << 714        << " *****\n" << G4endl;
790   for (auto i : MaterialTable) {               << 715         
791     flux << i << G4endl << G4endl;             << 716   for (size_t i=0; i<MaterialTable.size(); ++i) { 
                                                   >> 717     flux << MaterialTable[i] << G4endl << G4endl; 
792   }                                               718   }
793                                                   719 
794   return flux;                                    720   return flux;
795 }                                              << 721 }      
796                                                   722 
797 //....oooOO0OOooo........oooOO0OOooo........oo    723 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
798                                                   724 
799 G4bool G4Material::IsExtended() const { return << 725 G4bool G4Material::IsExtended() const
                                                   >> 726 { return false; }
800                                                   727 
801 //....oooOO0OOooo........oooOO0OOooo........oo    728 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
802                                                   729 
803 void G4Material::SetMaterialPropertiesTable(G4    730 void G4Material::SetMaterialPropertiesTable(G4MaterialPropertiesTable* anMPT)
804 {                                                 731 {
805   if (fMaterialPropertiesTable != anMPT && ! I << 732   if(anMPT && fMaterialPropertiesTable != anMPT) {
                                                   >> 733 #ifdef G4MULTITHREADED
                                                   >> 734     G4MUTEXLOCK(&materialMutex);
                                                   >> 735 #endif
806     delete fMaterialPropertiesTable;              736     delete fMaterialPropertiesTable;
807     fMaterialPropertiesTable = anMPT;             737     fMaterialPropertiesTable = anMPT;
                                                   >> 738 #ifdef G4MULTITHREADED
                                                   >> 739     G4MUTEXUNLOCK(&materialMutex);
                                                   >> 740 #endif
808   }                                               741   }
809 }                                                 742 }
810                                                   743 
811 //....oooOO0OOooo........oooOO0OOooo........oo    744 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
812                                                << 
813 G4bool G4Material::IsLocked()                  << 
814 {                                              << 
815   auto state = G4StateManager::GetStateManager << 
816   return state != G4State_PreInit && state !=  << 
817 }                                              << 
818                                                   745