Geant4 9.6.0
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//
27// $Id$
28//
29//
30// class G4tgbMaterialMgr
31
32// History:
33// - Created. P.Arce, CIEMAT (November 2007)
34// -------------------------------------------------------------------------
35
36#include "G4tgbMaterialMgr.hh"
41
45#include "G4tgrUtils.hh"
46#include "G4tgrMessenger.hh"
47#include "G4NistManager.hh"
48
49
50G4tgbMaterialMgr* G4tgbMaterialMgr::theInstance = 0;
51
52
53// -------------------------------------------------------------------------
54G4tgbMaterialMgr::G4tgbMaterialMgr()
55{
56}
57
58
59// -------------------------------------------------------------------------
61{
62 if( !theInstance )
63 {
64 theInstance = new G4tgbMaterialMgr;
65 theInstance->CopyIsotopes();
66 theInstance->CopyElements();
67 theInstance->CopyMaterials();
68 }
69 return theInstance;
70}
71
72
73// -------------------------------------------------------------------------
75{
76 G4mstgbisot::const_iterator isotcite;
77 for( isotcite = theG4tgbIsotopes.begin();
78 isotcite != theG4tgbIsotopes.end(); isotcite++)
79 {
80 delete (*isotcite).second;
81 }
82 theG4tgbIsotopes.clear();
83
84 G4mstgbelem::const_iterator elemcite;
85 for( elemcite = theG4tgbElements.begin();
86 elemcite != theG4tgbElements.end(); elemcite++)
87 {
88 delete (*elemcite).second;
89 }
90 theG4tgbElements.clear();
91
92 G4mstgbmate::const_iterator matcite;
93 for( matcite = theG4tgbMaterials.begin();
94 matcite != theG4tgbMaterials.end(); matcite++)
95 {
96 delete (*matcite).second;
97 }
98 theG4tgbMaterials.clear();
99
100 delete theInstance;
101}
102
103
104// -------------------------------------------------------------------------
106{
107 const G4mstgrisot tgrIsots
109 G4mstgrisot::const_iterator cite;
110 for( cite = tgrIsots.begin(); cite != tgrIsots.end(); cite++ )
111 {
112 G4tgrIsotope* tgr = (*cite).second;
113 G4tgbIsotope* tgb = new G4tgbIsotope( tgr );
114 theG4tgbIsotopes[tgb->GetName()] = tgb;
115 }
116}
117
118
119// -------------------------------------------------------------------------
121{
122 const G4mstgrelem tgrElems
124 G4mstgrelem::const_iterator cite;
125 for( cite = tgrElems.begin(); cite != tgrElems.end(); cite++ )
126 {
127 G4tgrElement* tgr = (*cite).second;
128 G4tgbElement* tgb = new G4tgbElement( tgr );
129 theG4tgbElements[tgb->GetName()] = tgb;
130 }
131}
132
133
134// -------------------------------------------------------------------------
136{
137 const G4mstgrmate tgrMates
139 G4mstgrmate::const_iterator cite;
140 for( cite = tgrMates.begin(); cite != tgrMates.end(); cite++ )
141 {
142 G4tgrMaterial* tgr = (*cite).second;
143 G4tgbMaterial* tgb = 0;
144 if( tgr->GetType() == "MaterialSimple" ) {
145 tgb = new G4tgbMaterialSimple( tgr );
146 } else if( tgr->GetType() == "MaterialMixtureByWeight" ) {
147 tgb = new G4tgbMaterialMixtureByWeight( tgr );
148 } else if( tgr->GetType() == "MaterialMixtureByNoAtoms" ) {
149 tgb = new G4tgbMaterialMixtureByNoAtoms( tgr );
150 } else if( tgr->GetType() == "MaterialMixtureByVolume" ) {
151 tgb = new G4tgbMaterialMixtureByVolume( tgr );
152 } else {
153 return;
154 }
155 theG4tgbMaterials[tgb->GetName()] = tgb;
156 }
157}
158
159
160// -------------------------------------------------------------------------
162{
163 G4Isotope* g4isot = FindBuiltG4Isotope( name );
164 if( g4isot == 0 )
165 {
166 G4tgbIsotope* tgbisot = FindG4tgbIsotope( name );
167 // FindG4tgbIsotope never returns 0, otherwise if not found, crashes
168 g4isot = tgbisot->BuildG4Isotope();
169 // Register it
170 G4String isotname = g4isot->GetName();
171 theG4Isotopes[isotname] = g4isot;
172 }
173 else
174 {
175#ifdef G4VERBOSE
177 {
178 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Isotope() -"
179 << " G4Isotope already built: " << g4isot->GetName() << G4endl;
180 }
181#endif
182 }
183
184#ifdef G4VERBOSE
186 {
187 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Isotope() - Isotope: "
188 << name << G4endl;
189 }
190#endif
191 return g4isot;
192}
193
194
195// -------------------------------------------------------------------------
197{
198 G4Isotope* g4isot = 0;
199
200 G4msg4isot::const_iterator cite = theG4Isotopes.find( name );
201 if( cite != theG4Isotopes.end() )
202 {
203 g4isot = (*cite).second;
204#ifdef G4VERBOSE
206 {
207 G4cout << " G4tgbMaterialMgr::FindBuiltG4Isotope() - Isotope: "
208 << name << " = " << g4isot << G4endl;
209 }
210#endif
211
212 }
213
214 return g4isot;
215}
216
217
218// -------------------------------------------------------------------------
220 G4bool bMustExist ) const
221{
222 G4tgbIsotope* isot = 0;
223
224 G4mstgbisot::const_iterator cite = theG4tgbIsotopes.find( name );
225 if( cite != theG4tgbIsotopes.end() )
226 {
227#ifdef G4VERBOSE
229 {
230 G4cout << " G4tgbMaterialMgr::FindG4tgbIsotope() -"
231 << " G4tgbIsotope found: " << ( (*cite).second )->GetName()
232 << G4endl;
233 }
234#endif
235 isot = (*cite).second;
236 }
237 if( (isot == 0) && bMustExist )
238 {
239 G4String ErrMessage = "Isotope " + name + " not found !";
240 G4Exception("G4tgbMaterialMgr::FindG4tgbIsotope()",
241 "InvalidSetup", FatalException, ErrMessage);
242 }
243
244 return isot;
245}
246
247
248// -------------------------------------------------------------------------
250 G4bool bMustExist )
251{
252 G4Element* g4elem = FindBuiltG4Element( name );
253 if( g4elem == 0 )
254 {
255 G4tgbElement* tgbelem = FindG4tgbElement( name, false );
256 if( tgbelem == 0)
257 {
258 // If FindG4tgbElement returns 0, look for a G4NISTElement
259 G4cout << " G4NistManager::Instance()->FindOrBuildElement( " << G4endl;
261 }
262 else
263 {
264 if( tgbelem->GetType() == "ElementSimple" )
265 {
266 g4elem = tgbelem->BuildG4ElementSimple();
267 }
268 else if( tgbelem->GetType() == "ElementFromIsotopes" )
269 {
270 g4elem = tgbelem->BuildG4ElementFromIsotopes();
271 }
272 else
273 {
274 G4String ErrMessage = "Element type " + tgbelem->GetType()
275 + " does not exist !";
276 G4Exception("G4tgbMaterialMgr::GetG4Element()",
277 "InvalidSetup", FatalException, ErrMessage);
278 }
279 }
280 // Register it
281 if( (g4elem != 0) )
282 {
283 theG4Elements[g4elem->GetName()] = g4elem;
284#ifdef G4VERBOSE
286 {
287 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Element() - Element: "
288 << name << G4endl;
289 }
290#endif
291 }
292 else
293 {
294 if( bMustExist )
295 {
296 G4String ErrMessage = "Element " + name + " not found !";
297 G4Exception("G4tgbMaterialMgr::FindOrBuildG4Element()",
298 "InvalidSetup", FatalException, ErrMessage);
299 }
300#ifdef G4VERBOSE
302 {
303 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Element() - Element: "
304 << name << " not found " << G4endl;
305 }
306#endif
307 }
308 }
309 else
310 {
311#ifdef G4VERBOSE
313 {
314 G4cout << " G4tgbMaterialMgr::GetG4Element() -"
315 << " G4Element already built: " << g4elem->GetName() << G4endl;
316 }
317#endif
318 }
319
320 return g4elem;
321}
322
323
324// -------------------------------------------------------------------------
326{
327 G4Element* g4elem = 0;
328
329 G4msg4elem::const_iterator cite = theG4Elements.find( name );
330 if( cite != theG4Elements.end() )
331 {
332 g4elem = (*cite).second;
333#ifdef G4VERBOSE
335 {
336 G4cout << " G4tgbMaterialMgr::FindBuiltG4Element() - Element: "
337 << name << " = " << g4elem << G4endl;
338 }
339#endif
340 }
341
342 return g4elem;
343}
344
345
346// -------------------------------------------------------------------------
348 G4bool bMustExist ) const
349{
350 G4tgbElement* elem = 0;
351
352 G4mstgbelem::const_iterator cite = theG4tgbElements.find( name );
353 if( cite != theG4tgbElements.end() )
354 {
355#ifdef G4VERBOSE
357 {
358 G4cout << " G4tgbMaterialMgr::FindG4tgbElement() -"
359 << " G4tgbElement found: " << ( (*cite).second )->GetName()
360 << G4endl;
361 }
362#endif
363 elem = (*cite).second;
364 }
365 if( (elem == 0) && bMustExist )
366 {
367 G4String ErrMessage = "Element " + name + " not found !";
368 G4Exception("G4tgbMaterialMgr::FindG4tgbElement()",
369 "InvalidSetup", FatalException, ErrMessage);
370 }
371
372 return elem;
373}
374
375
376// -------------------------------------------------------------------------
378 G4bool bMustExist )
379{
380 G4Material* g4mate = FindBuiltG4Material( name );
381 if( g4mate == 0)
382 {
383 G4tgbMaterial* tgbmate = FindG4tgbMaterial( name, false );
384
385 if( tgbmate == 0)
386 {
387 // if FindG4tgbMaterial() returns 0, look for a G4NISTMaterial
389 }
390 else
391 {
392 g4mate = tgbmate->BuildG4Material();
393
394 if( tgbmate->GetTgrMate()->GetIonisationMeanExcitationEnergy() != -1. )
395 {
396 g4mate->GetIonisation()->SetMeanExcitationEnergy(tgbmate->
397 GetTgrMate()->GetIonisationMeanExcitationEnergy());
398 }
399 }
400
401 // Register it
402 if( g4mate != 0 )
403 {
404 theG4Materials[g4mate->GetName()] = g4mate;
405#ifdef G4VERBOSE
407 {
408 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Material() - Material: "
409 << name << G4endl;
410 }
411#endif
412 }
413 else
414 {
415 if( bMustExist )
416 {
417 G4String ErrMessage = "Material " + name + " not found !";
418 G4Exception("G4tgbMaterialMgr::FindOrBuildG4Material()",
419 "InvalidSetup", FatalException, ErrMessage);
420 }
421#ifdef G4VERBOSE
423 {
424 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Material() - Element: "
425 << name << " not found " << G4endl;
426 }
427#endif
428 }
429 }
430 else
431 {
432#ifdef G4VERBOSE
434 {
435 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Material() -"
436 << " G4Material already built: " << g4mate->GetName() << G4endl;
437 }
438#endif
439 }
440
441 return g4mate;
442}
443
444
445// -------------------------------------------------------------------------
447{
448 G4Material* g4mate = 0;
449 //---------- look for an existing G4Material
450 G4msg4mate::const_iterator cite = theG4Materials.find( name );
451 if( cite != theG4Materials.end() )
452 {
453 g4mate = (*cite).second;
454#ifdef G4VERBOSE
456 {
457 G4cout << " G4tgbMaterialMgr::FindBuiltG4Material() - Material: "
458 << name << " = " << g4mate << G4endl;
459 }
460#endif
461 }
462
463 return g4mate;
464}
465
466
467// -------------------------------------------------------------------------
469 G4bool bMustExist ) const
470{
471 G4tgbMaterial* mate = 0;
472 G4mstgbmate::const_iterator cite = theG4tgbMaterials.find( name );
473 if( cite != theG4tgbMaterials.end() )
474 {
475 mate = (*cite).second;
476#ifdef G4VERBOSE
478 {
479 G4cout << " G4tgbMaterialMgr::FindG4tgbMaterial() -"
480 << " G4tgbMaterial found: " << ( (*cite).second )->GetName()
481 << " type " << ( (*cite).second )->GetName() << G4endl;
482 }
483#endif
484 }
485
486 if( (mate == 0) && bMustExist )
487 {
488 G4String ErrMessage = "Material " + name + " not found !";
489 G4Exception("G4tgbMaterialMgr::FindG4tgbMaterial()",
490 "InvalidSetup", FatalException, ErrMessage);
491 }
492
493 return mate;
494}
@ FatalException
bool G4bool
Definition: G4Types.hh:67
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
std::map< G4String, G4tgrMaterial * > G4mstgrmate
std::map< G4String, G4tgrIsotope * > G4mstgrisot
std::map< G4String, G4tgrElement * > G4mstgrelem
const G4String & GetName() const
Definition: G4Element.hh:127
void SetMeanExcitationEnergy(G4double value)
const G4String & GetName() const
Definition: G4Isotope.hh:88
G4IonisParamMat * GetIonisation() const
Definition: G4Material.hh:225
const G4String & GetName() const
Definition: G4Material.hh:177
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
Definition: G4tgbElement.hh:68
G4Element * BuildG4ElementFromIsotopes()
Definition: G4tgbElement.cc:83
const G4String & GetType() const
Definition: G4tgbElement.hh:72
G4Element * BuildG4ElementSimple()
Definition: G4tgbElement.cc:52
G4Isotope * BuildG4Isotope()
Definition: G4tgbIsotope.cc:58
const G4String & GetName() const
Definition: G4tgbIsotope.hh:67
G4Material * FindBuiltG4Material(const G4String &name) const
G4tgbIsotope * FindG4tgbIsotope(const G4String &name, G4bool bMustExist=0) const
G4tgbElement * FindG4tgbElement(const G4String &name, G4bool bMustExist=0) const
G4Isotope * FindOrBuildG4Isotope(const G4String &name)
G4Element * FindOrBuildG4Element(const G4String &name, G4bool bMustExist=1)
G4Material * FindOrBuildG4Material(const G4String &name, G4bool bMustExist=1)
G4Element * FindBuiltG4Element(const G4String &name) const
G4tgbMaterial * FindG4tgbMaterial(const G4String &name, G4bool bMustExist=0) const
G4Isotope * FindBuiltG4Isotope(const G4String &name) 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()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41