Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4tgbMaterialMgr.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4tgbMaterialMgr implementation
27//
28// Author: P.Arce, CIEMAT (November 2007)
29// --------------------------------------------------------------------
30
31#include "G4tgbMaterialMgr.hh"
36
40#include "G4tgrUtils.hh"
41#include "G4tgrMessenger.hh"
42#include "G4NistManager.hh"
43
44G4ThreadLocal G4tgbMaterialMgr* G4tgbMaterialMgr::theInstance = nullptr;
45
46// --------------------------------------------------------------------
47G4tgbMaterialMgr::G4tgbMaterialMgr()
48{
49}
50
51// --------------------------------------------------------------------
53{
54 if(theInstance == nullptr)
55 {
56 theInstance = new G4tgbMaterialMgr;
57 theInstance->CopyIsotopes();
58 theInstance->CopyElements();
59 theInstance->CopyMaterials();
60 }
61 return theInstance;
62}
63
64// --------------------------------------------------------------------
66{
67 for(auto isotcite = theG4tgbIsotopes.cbegin();
68 isotcite != theG4tgbIsotopes.cend(); ++isotcite)
69 {
70 delete(*isotcite).second;
71 }
72 theG4tgbIsotopes.clear();
73
74 for(auto elemcite = theG4tgbElements.cbegin();
75 elemcite != theG4tgbElements.cend(); ++elemcite)
76 {
77 delete(*elemcite).second;
78 }
79 theG4tgbElements.clear();
80
81 for(auto matcite = theG4tgbMaterials.cbegin();
82 matcite != theG4tgbMaterials.cend(); ++matcite)
83 {
84 delete(*matcite).second;
85 }
86 theG4tgbMaterials.clear();
87
88 delete theInstance;
89}
90
91// --------------------------------------------------------------------
93{
94 const G4mstgrisot tgrIsots =
96 for(auto cite = tgrIsots.cbegin(); cite != tgrIsots.cend(); ++cite)
97 {
98 G4tgrIsotope* tgr = (*cite).second;
99 G4tgbIsotope* tgb = new G4tgbIsotope(tgr);
100 theG4tgbIsotopes[tgb->GetName()] = tgb;
101 }
102}
103
104// --------------------------------------------------------------------
106{
107 const G4mstgrelem tgrElems =
109 for(auto cite = tgrElems.cbegin(); cite != tgrElems.cend(); ++cite)
110 {
111 G4tgrElement* tgr = (*cite).second;
112 G4tgbElement* tgb = new G4tgbElement(tgr);
113 theG4tgbElements[tgb->GetName()] = tgb;
114 }
115}
116
117// --------------------------------------------------------------------
119{
120 const G4mstgrmate tgrMates =
122 for(auto cite = tgrMates.cbegin(); cite != tgrMates.cend(); ++cite)
123 {
124 G4tgrMaterial* tgr = (*cite).second;
125 G4tgbMaterial* tgb = nullptr;
126 if(tgr->GetType() == "MaterialSimple")
127 {
128 tgb = new G4tgbMaterialSimple(tgr);
129 }
130 else if(tgr->GetType() == "MaterialMixtureByWeight")
131 {
132 tgb = new G4tgbMaterialMixtureByWeight(tgr);
133 }
134 else if(tgr->GetType() == "MaterialMixtureByNoAtoms")
135 {
136 tgb = new G4tgbMaterialMixtureByNoAtoms(tgr);
137 }
138 else if(tgr->GetType() == "MaterialMixtureByVolume")
139 {
140 tgb = new G4tgbMaterialMixtureByVolume(tgr);
141 }
142 else
143 {
144 return;
145 }
146 theG4tgbMaterials[tgb->GetName()] = tgb;
147 }
148}
149
150// --------------------------------------------------------------------
152{
153 G4Isotope* g4isot = FindBuiltG4Isotope(name);
154 if(g4isot == nullptr)
155 {
156 G4tgbIsotope* tgbisot = FindG4tgbIsotope(name);
157 // FindG4tgbIsotope never returns nullptr, otherwise if not found, crashes
158 g4isot = tgbisot->BuildG4Isotope();
159 // Register it
160 G4String isotname = g4isot->GetName();
161 theG4Isotopes[isotname] = g4isot;
162 }
163 else
164 {
165#ifdef G4VERBOSE
167 {
168 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Isotope() -"
169 << " G4Isotope already built: " << g4isot->GetName() << G4endl;
170 }
171#endif
172 }
173
174#ifdef G4VERBOSE
176 {
177 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Isotope() - Isotope: " << name
178 << G4endl;
179 }
180#endif
181 return g4isot;
182}
183
184// --------------------------------------------------------------------
186{
187 G4Isotope* g4isot = nullptr;
188
189 G4msg4isot::const_iterator cite = theG4Isotopes.find(name);
190 if(cite != theG4Isotopes.cend())
191 {
192 g4isot = (*cite).second;
193#ifdef G4VERBOSE
195 {
196 G4cout << " G4tgbMaterialMgr::FindBuiltG4Isotope() - Isotope: " << name
197 << " = " << g4isot << G4endl;
198 }
199#endif
200 }
201
202 return g4isot;
203}
204
205// --------------------------------------------------------------------
207 G4bool bMustExist) const
208{
209 G4tgbIsotope* isot = nullptr;
210
211 G4mstgbisot::const_iterator cite = theG4tgbIsotopes.find(name);
212 if(cite != theG4tgbIsotopes.cend())
213 {
214#ifdef G4VERBOSE
216 {
217 G4cout << " G4tgbMaterialMgr::FindG4tgbIsotope() -"
218 << " G4tgbIsotope found: " << ((*cite).second)->GetName()
219 << G4endl;
220 }
221#endif
222 isot = (*cite).second;
223 }
224 if((isot == nullptr) && bMustExist)
225 {
226 G4String ErrMessage = "Isotope " + name + " not found !";
227 G4Exception("G4tgbMaterialMgr::FindG4tgbIsotope()", "InvalidSetup",
228 FatalException, ErrMessage);
229 }
230
231 return isot;
232}
233
234// --------------------------------------------------------------------
236 G4bool bMustExist)
237{
238 G4Element* g4elem = FindBuiltG4Element(name);
239 if(g4elem == nullptr)
240 {
241 G4tgbElement* tgbelem = FindG4tgbElement(name, false);
242 if(tgbelem == nullptr)
243 {
244 // If FindG4tgbElement returns nullptr, look for a G4NISTElement
245 G4cout << " G4NistManager::Instance()->FindOrBuildElement( " << G4endl;
247 }
248 else
249 {
250 if(tgbelem->GetType() == "ElementSimple")
251 {
252 g4elem = tgbelem->BuildG4ElementSimple();
253 }
254 else if(tgbelem->GetType() == "ElementFromIsotopes")
255 {
256 g4elem = tgbelem->BuildG4ElementFromIsotopes();
257 }
258 else
259 {
260 G4String ErrMessage =
261 "Element type " + tgbelem->GetType() + " does not exist !";
262 G4Exception("G4tgbMaterialMgr::GetG4Element()", "InvalidSetup",
263 FatalException, ErrMessage);
264 }
265 }
266 // Register it
267 if((g4elem != nullptr))
268 {
269 theG4Elements[g4elem->GetName()] = g4elem;
270#ifdef G4VERBOSE
272 {
273 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Element() - Element: "
274 << name << G4endl;
275 }
276#endif
277 }
278 else
279 {
280 if(bMustExist)
281 {
282 G4String ErrMessage = "Element " + name + " not found !";
283 G4Exception("G4tgbMaterialMgr::FindOrBuildG4Element()", "InvalidSetup",
284 FatalException, ErrMessage);
285 }
286#ifdef G4VERBOSE
288 {
289 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Element() - Element: "
290 << name << " not found " << G4endl;
291 }
292#endif
293 }
294 }
295 else
296 {
297#ifdef G4VERBOSE
299 {
300 G4cout << " G4tgbMaterialMgr::GetG4Element() -"
301 << " G4Element already built: " << g4elem->GetName() << G4endl;
302 }
303#endif
304 }
305
306 return g4elem;
307}
308
309// --------------------------------------------------------------------
311{
312 G4Element* g4elem = nullptr;
313
314 G4msg4elem::const_iterator cite = theG4Elements.find(name);
315 if(cite != theG4Elements.cend())
316 {
317 g4elem = (*cite).second;
318#ifdef G4VERBOSE
320 {
321 G4cout << " G4tgbMaterialMgr::FindBuiltG4Element() - Element: " << name
322 << " = " << g4elem << G4endl;
323 }
324#endif
325 }
326
327 return g4elem;
328}
329
330// --------------------------------------------------------------------
332 G4bool bMustExist) const
333{
334 G4tgbElement* elem = nullptr;
335
336 G4mstgbelem::const_iterator cite = theG4tgbElements.find(name);
337 if(cite != theG4tgbElements.cend())
338 {
339#ifdef G4VERBOSE
341 {
342 G4cout << " G4tgbMaterialMgr::FindG4tgbElement() -"
343 << " G4tgbElement found: " << ((*cite).second)->GetName()
344 << G4endl;
345 }
346#endif
347 elem = (*cite).second;
348 }
349 if((elem == nullptr) && bMustExist)
350 {
351 G4String ErrMessage = "Element " + name + " not found !";
352 G4Exception("G4tgbMaterialMgr::FindG4tgbElement()", "InvalidSetup",
353 FatalException, ErrMessage);
354 }
355
356 return elem;
357}
358
359// --------------------------------------------------------------------
361 G4bool bMustExist)
362{
363 G4Material* g4mate = FindBuiltG4Material(name);
364 if(g4mate == nullptr)
365 {
366 G4tgbMaterial* tgbmate = FindG4tgbMaterial(name, false);
367
368 if(tgbmate == nullptr)
369 {
370 // if FindG4tgbMaterial() returns 0, look for a G4NISTMaterial
372 }
373 else
374 {
375 g4mate = tgbmate->BuildG4Material();
376
377 if(tgbmate->GetTgrMate()->GetIonisationMeanExcitationEnergy() != -1.)
378 {
381 }
382 }
383
384 // Register it
385 if(g4mate != nullptr)
386 {
387 theG4Materials[g4mate->GetName()] = g4mate;
388#ifdef G4VERBOSE
390 {
391 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Material() - Material: "
392 << name << G4endl;
393 }
394#endif
395 }
396 else
397 {
398 if(bMustExist)
399 {
400 G4String ErrMessage = "Material " + name + " not found !";
401 G4Exception("G4tgbMaterialMgr::FindOrBuildG4Material()", "InvalidSetup",
402 FatalException, ErrMessage);
403 }
404#ifdef G4VERBOSE
406 {
407 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Material() - Element: "
408 << name << " not found " << G4endl;
409 }
410#endif
411 }
412 }
413 else
414 {
415#ifdef G4VERBOSE
417 {
418 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Material() -"
419 << " G4Material already built: " << g4mate->GetName() << G4endl;
420 }
421#endif
422 }
423
424 return g4mate;
425}
426
427// --------------------------------------------------------------------
429{
430 G4Material* g4mate = nullptr;
431 //---------- look for an existing G4Material
432 G4msg4mate::const_iterator cite = theG4Materials.find(name);
433 if(cite != theG4Materials.cend())
434 {
435 g4mate = (*cite).second;
436#ifdef G4VERBOSE
438 {
439 G4cout << " G4tgbMaterialMgr::FindBuiltG4Material() - Material: " << name
440 << " = " << g4mate << G4endl;
441 }
442#endif
443 }
444
445 return g4mate;
446}
447
448// -------------------------------------------------------------------------
450 G4bool bMustExist) const
451{
452 G4tgbMaterial* mate = nullptr;
453 G4mstgbmate::const_iterator cite = theG4tgbMaterials.find(name);
454 if(cite != theG4tgbMaterials.cend())
455 {
456 mate = (*cite).second;
457#ifdef G4VERBOSE
459 {
460 G4cout << " G4tgbMaterialMgr::FindG4tgbMaterial() -"
461 << " G4tgbMaterial found: " << ((*cite).second)->GetName()
462 << " type " << ((*cite).second)->GetName() << G4endl;
463 }
464#endif
465 }
466
467 if((mate == nullptr) && bMustExist)
468 {
469 G4String ErrMessage = "Material " + name + " not found !";
470 G4Exception("G4tgbMaterialMgr::FindG4tgbMaterial()", "InvalidSetup",
471 FatalException, ErrMessage);
472 }
473
474 return mate;
475}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
#define elem(i, j)
bool G4bool
Definition G4Types.hh:86
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
std::map< G4String, G4tgrElement * > G4mstgrelem
std::map< G4String, G4tgrMaterial * > G4mstgrmate
std::map< G4String, G4tgrIsotope * > G4mstgrisot
const G4String & GetName() const
Definition G4Element.hh:115
void SetMeanExcitationEnergy(G4double value)
const G4String & GetName() const
Definition G4Isotope.hh:77
G4IonisParamMat * GetIonisation() const
const G4String & GetName() const
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
static G4NistManager * Instance()
G4Element * FindOrBuildElement(G4int Z, G4bool isotopes=true)
const G4String & GetName() const
G4Element * BuildG4ElementFromIsotopes()
const G4String & GetType() const
G4Element * BuildG4ElementSimple()
G4Isotope * BuildG4Isotope()
const G4String & GetName() const
G4Material * FindBuiltG4Material(const G4String &name) const
G4Isotope * FindOrBuildG4Isotope(const G4String &name)
G4tgbIsotope * FindG4tgbIsotope(const G4String &name, G4bool bMustExist=false) const
G4tgbElement * FindG4tgbElement(const G4String &name, G4bool bMustExist=false) const
G4Element * FindBuiltG4Element(const G4String &name) const
G4Isotope * FindBuiltG4Isotope(const G4String &name) const
G4Element * FindOrBuildG4Element(const G4String &name, G4bool bMustExist=true)
G4Material * FindOrBuildG4Material(const G4String &name, G4bool bMustExist=true)
G4tgbMaterial * FindG4tgbMaterial(const G4String &name, G4bool bMustExist=false) const
static G4tgbMaterialMgr * GetInstance()
const G4String & GetName() const
G4tgrMaterial * GetTgrMate() const
virtual G4Material * BuildG4Material()=0
const G4mstgrelem & GetElementList() const
const G4mstgrmate & GetMaterialList() const
static G4tgrMaterialFactory * GetInstance()
const G4mstgrisot & GetIsotopeList() const
const G4String & GetType() const
G4double GetIonisationMeanExcitationEnergy() const
static G4int GetVerboseLevel()
#define G4ThreadLocal
Definition tls.hh:77