ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4NistManager.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4NistManager.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // -------------------------------------------------------------------
27 //
28 // GEANT4 Class file
29 //
30 //
31 // File name: G4NistManager
32 //
33 // Author: Vladimir Ivanchenko
34 //
35 // Creation date: 23.12.2004
36 //
37 // Modifications:
38 // 27.02.06 V.Ivanchneko add ConstructNewGasMaterial
39 // 18.04.06 V.Ivanchneko add combined creation of materials (NIST + user)
40 // 11.05.06 V.Ivanchneko add warning flag to FindMaterial method
41 // 26.07.07 V.Ivanchneko modify destructor to provide complete destruction
42 // of all elements and materials
43 // 27-07-07, improve destructor (V.Ivanchenko)
44 // 28.07.07 V.Ivanchneko make simple methods inline
45 // 28.07.07 V.Ivanchneko simplify Print methods
46 // 26.10.11, new scheme for G4Exception (mma)
47 //
48 // -------------------------------------------------------------------
49 //
50 // Class Description:
51 //
52 // Element data from the NIST DB on Atomic Weights and Isotope Compositions
53 // http://physics.nist.gov/PhysRefData/Compositions/index.html
54 //
55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
57 
58 #include "G4NistManager.hh"
59 #include "G4NistMessenger.hh"
60 #include "G4Isotope.hh"
61 #include "G4Threading.hh"
62 
64 #ifdef G4MULTITHREADED
65  G4Mutex G4NistManager::nistManagerMutex = G4MUTEX_INITIALIZER;
66 #endif
67 
68 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
69 
71 {
72  if (instance == nullptr) {
73 #ifdef G4MULTITHREADED
74  G4MUTEXLOCK(&nistManagerMutex);
75  if (instance == nullptr) {
76 #endif
77  static G4NistManager manager;
78  instance = &manager;
79 #ifdef G4MULTITHREADED
80  }
81  G4MUTEXUNLOCK(&nistManagerMutex);
82 #endif
83  }
84  return instance;
85 }
86 
87 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
88 
90 {
91  // G4cout << "NistManager: start material destruction" << G4endl;
92  const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
93  size_t nmat = theMaterialTable->size();
94  size_t i;
95  for(i=0; i<nmat; i++) {
96  if((*theMaterialTable)[i]) { delete (*theMaterialTable)[i]; }
97  }
98  // G4cout << "NistManager: start element destruction" << G4endl;
99  const G4ElementTable* theElementTable = G4Element::GetElementTable();
100  size_t nelm = theElementTable->size();
101  for(i=0; i<nelm; i++) {
102  if((*theElementTable)[i]) { delete (*theElementTable)[i]; }
103  }
104  // G4cout << "NistManager: start isotope destruction" << G4endl;
105  const G4IsotopeTable* theIsotopeTable = G4Isotope::GetIsotopeTable();
106  size_t niso = theIsotopeTable->size();
107  for(i=0; i<niso; i++) {
108  if((*theIsotopeTable)[i]) { delete (*theIsotopeTable)[i]; }
109  }
110  // G4cout << "NistManager: end isotope destruction" << G4endl;
111  delete messenger;
112  delete matBuilder;
113  delete elmBuilder;
114  delete fICRU90;
115  // G4cout << "NistManager: end destruction" << G4endl;
116 }
117 
118 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
119 
120 G4Material*
122  const G4String& basename,
123  G4double density,
124  G4double temperature,
125  G4double pressure)
126 {
127  G4Material* bmat = FindOrBuildMaterial(name);
128  if(bmat) {
129  G4cout << "G4NistManager::BuildMaterialWithNewDensity ERROR: " << G4endl;
130  G4cout << " New material <" << name << "> cannot be built because material"
131  << " with the same name already exist" << G4endl;
132  G4Exception("G4NistManager::BuildMaterialWithNewDensity()", "mat101",
133  FatalException, "Wrong material name");
134  return 0;
135  }
136  bmat = FindOrBuildMaterial(basename);
137  if(!bmat) {
138  G4cout << "G4NistManager::BuildMaterialWithNewDensity ERROR: " << G4endl;
139  G4cout << " New material <" << name << "> cannot be built because "
140  << G4endl;
141  G4cout << " base material <" << basename << "> does not exist" << G4endl;
142  G4Exception("G4NistManager::BuildMaterialWithNewDensity()", "mat102",
143  FatalException, "Wrong material name");
144  return 0;
145  }
146  G4double dens = density;
147  G4double temp = temperature;
148  G4double pres = pressure;
149  if(dens == 0.0) {
150  dens = bmat->GetDensity();
151  temp = bmat->GetTemperature();
152  pres = bmat->GetPressure();
153  }
154  G4Material* mat = new G4Material(name, dens, bmat, bmat->GetState(),
155  temp, pres);
156  return mat;
157 }
158 
159 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
160 
161 void G4NistManager::PrintElement(const G4String& symbol) const
162 {
163  if (symbol == "all") { elmBuilder->PrintElement(0); }
164  else { elmBuilder->PrintElement(elmBuilder->GetZ(symbol)); }
165 }
166 
167 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
168 
170 {
171  const G4ElementTable* theElementTable = G4Element::GetElementTable();
172  size_t nelm = theElementTable->size();
173  for(size_t i=0; i<nelm; i++) {
174  G4Element* elm = (*theElementTable)[i];
175  if ( name == elm->GetName() || "all" == name) {
176  G4cout << *elm << G4endl;
177  }
178  }
179 }
180 
181 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
182 
184 {
185  const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
186  size_t nmat = theMaterialTable->size();
187  for(size_t i=0; i<nmat; i++) {
188  G4Material* mat = (*theMaterialTable)[i];
189  if ( name == mat->GetName() || "all" == name) {
190  G4cout << *mat << G4endl;
191  }
192  }
193 }
194 
195 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
196 
198 {
199 #ifdef G4MULTITHREADED
200  G4MUTEXLOCK(&nistManagerMutex);
201 #endif
202  verbose = val;
203  elmBuilder->SetVerbose(val);
204  matBuilder->SetVerbose(val);
205 #ifdef G4MULTITHREADED
206  G4MUTEXUNLOCK(&nistManagerMutex);
207 #endif
208 }
209 
210 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
211 
213 {
214  nElements = 0;
215  nMaterials = 0;
216  verbose = 0;
217 
220 
221  messenger = new G4NistMessenger(this);
223 
224  // compute frequently used values for mean atomic numbers
225  for(G4int j=1; j<101; ++j) {
227  POWERA27[j] = std::pow(A,0.27);
228  LOGAZ[j] = std::log(A);
229  }
230  POWERA27[0] = 1.0;
231  LOGAZ[0] = 0.0;
232  fICRU90 = nullptr;
233 }
234 
235 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
236 
238 {
239  if (!fICRU90) {
240 #ifdef G4MULTITHREADED
241  G4MUTEXLOCK(&nistManagerMutex);
242  if (!fICRU90) {
243 #endif
245 #ifdef G4MULTITHREADED
246  }
247  G4MUTEXUNLOCK(&nistManagerMutex);
248 #endif
249  }
250  return fICRU90;
251 }
252 
253 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
254 
256  G4bool val)
257 {
258 #ifdef G4MULTITHREADED
259  G4MUTEXLOCK(&nistManagerMutex);
260 #endif
261  if(mname == "all") {
262  for(auto mat : materials) {
264  }
265  } else {
266  G4Material* mat = FindMaterial(mname);
268  }
269 #ifdef G4MULTITHREADED
270  G4MUTEXUNLOCK(&nistManagerMutex);
271 #endif
272 }
273 
274 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
275 
277 {
278  if(mat) { mat->ComputeDensityEffectOnFly(val); }
279 }
280 
281 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......