ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4tgbMaterialMgr.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4tgbMaterialMgr.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 //
29 // class G4tgbMaterialMgr
30 
31 // History:
32 // - Created. P.Arce, CIEMAT (November 2007)
33 // -------------------------------------------------------------------------
34 
35 #include "G4tgbMaterialMgr.hh"
39 #include "G4tgbMaterialSimple.hh"
40 
41 #include "G4tgrMaterialFactory.hh"
42 #include "G4tgrMaterialSimple.hh"
43 #include "G4tgrMaterialMixture.hh"
44 #include "G4tgrUtils.hh"
45 #include "G4tgrMessenger.hh"
46 #include "G4NistManager.hh"
47 
48 
50 
51 
52 // -------------------------------------------------------------------------
54 {
55 }
56 
57 
58 // -------------------------------------------------------------------------
60 {
61  if( !theInstance )
62  {
67  }
68  return theInstance;
69 }
70 
71 
72 // -------------------------------------------------------------------------
74 {
75  G4mstgbisot::const_iterator isotcite;
76  for( isotcite = theG4tgbIsotopes.begin();
77  isotcite != theG4tgbIsotopes.end(); isotcite++)
78  {
79  delete (*isotcite).second;
80  }
81  theG4tgbIsotopes.clear();
82 
83  G4mstgbelem::const_iterator elemcite;
84  for( elemcite = theG4tgbElements.begin();
85  elemcite != theG4tgbElements.end(); elemcite++)
86  {
87  delete (*elemcite).second;
88  }
89  theG4tgbElements.clear();
90 
91  G4mstgbmate::const_iterator matcite;
92  for( matcite = theG4tgbMaterials.begin();
93  matcite != theG4tgbMaterials.end(); matcite++)
94  {
95  delete (*matcite).second;
96  }
97  theG4tgbMaterials.clear();
98 
99  delete theInstance;
100 }
101 
102 
103 // -------------------------------------------------------------------------
105 {
106  const G4mstgrisot tgrIsots
108  G4mstgrisot::const_iterator cite;
109  for( cite = tgrIsots.begin(); cite != tgrIsots.end(); cite++ )
110  {
111  G4tgrIsotope* tgr = (*cite).second;
112  G4tgbIsotope* tgb = new G4tgbIsotope( tgr );
113  theG4tgbIsotopes[tgb->GetName()] = tgb;
114  }
115 }
116 
117 
118 // -------------------------------------------------------------------------
120 {
121  const G4mstgrelem tgrElems
123  G4mstgrelem::const_iterator cite;
124  for( cite = tgrElems.begin(); cite != tgrElems.end(); cite++ )
125  {
126  G4tgrElement* tgr = (*cite).second;
127  G4tgbElement* tgb = new G4tgbElement( tgr );
128  theG4tgbElements[tgb->GetName()] = tgb;
129  }
130 }
131 
132 
133 // -------------------------------------------------------------------------
135 {
136  const G4mstgrmate tgrMates
138  G4mstgrmate::const_iterator cite;
139  for( cite = tgrMates.begin(); cite != tgrMates.end(); cite++ )
140  {
141  G4tgrMaterial* tgr = (*cite).second;
142  G4tgbMaterial* tgb = 0;
143  if( tgr->GetType() == "MaterialSimple" ) {
144  tgb = new G4tgbMaterialSimple( tgr );
145  } else if( tgr->GetType() == "MaterialMixtureByWeight" ) {
146  tgb = new G4tgbMaterialMixtureByWeight( tgr );
147  } else if( tgr->GetType() == "MaterialMixtureByNoAtoms" ) {
148  tgb = new G4tgbMaterialMixtureByNoAtoms( tgr );
149  } else if( tgr->GetType() == "MaterialMixtureByVolume" ) {
150  tgb = new G4tgbMaterialMixtureByVolume( tgr );
151  } else {
152  return;
153  }
154  theG4tgbMaterials[tgb->GetName()] = tgb;
155  }
156 }
157 
158 
159 // -------------------------------------------------------------------------
161 {
162  G4Isotope* g4isot = FindBuiltG4Isotope( name );
163  if( g4isot == 0 )
164  {
165  G4tgbIsotope* tgbisot = FindG4tgbIsotope( name );
166  // FindG4tgbIsotope never returns 0, otherwise if not found, crashes
167  g4isot = tgbisot->BuildG4Isotope();
168  // Register it
169  G4String isotname = g4isot->GetName();
170  theG4Isotopes[isotname] = g4isot;
171  }
172  else
173  {
174 #ifdef G4VERBOSE
176  {
177  G4cout << " G4tgbMaterialMgr::FindOrBuildG4Isotope() -"
178  << " G4Isotope already built: " << g4isot->GetName() << G4endl;
179  }
180 #endif
181  }
182 
183 #ifdef G4VERBOSE
185  {
186  G4cout << " G4tgbMaterialMgr::FindOrBuildG4Isotope() - Isotope: "
187  << name << G4endl;
188  }
189 #endif
190  return g4isot;
191 }
192 
193 
194 // -------------------------------------------------------------------------
196 {
197  G4Isotope* g4isot = 0;
198 
199  G4msg4isot::const_iterator cite = theG4Isotopes.find( name );
200  if( cite != theG4Isotopes.end() )
201  {
202  g4isot = (*cite).second;
203 #ifdef G4VERBOSE
205  {
206  G4cout << " G4tgbMaterialMgr::FindBuiltG4Isotope() - Isotope: "
207  << name << " = " << g4isot << G4endl;
208  }
209 #endif
210 
211  }
212 
213  return g4isot;
214 }
215 
216 
217 // -------------------------------------------------------------------------
219  G4bool bMustExist ) const
220 {
221  G4tgbIsotope* isot = 0;
222 
223  G4mstgbisot::const_iterator cite = theG4tgbIsotopes.find( name );
224  if( cite != theG4tgbIsotopes.end() )
225  {
226 #ifdef G4VERBOSE
228  {
229  G4cout << " G4tgbMaterialMgr::FindG4tgbIsotope() -"
230  << " G4tgbIsotope found: " << ( (*cite).second )->GetName()
231  << G4endl;
232  }
233 #endif
234  isot = (*cite).second;
235  }
236  if( (isot == 0) && bMustExist )
237  {
238  G4String ErrMessage = "Isotope " + name + " not found !";
239  G4Exception("G4tgbMaterialMgr::FindG4tgbIsotope()",
240  "InvalidSetup", FatalException, ErrMessage);
241  }
242 
243  return isot;
244 }
245 
246 
247 // -------------------------------------------------------------------------
249  G4bool bMustExist )
250 {
251  G4Element* g4elem = FindBuiltG4Element( name );
252  if( g4elem == 0 )
253  {
254  G4tgbElement* tgbelem = FindG4tgbElement( name, false );
255  if( tgbelem == 0)
256  {
257  // If FindG4tgbElement returns 0, look for a G4NISTElement
258  G4cout << " G4NistManager::Instance()->FindOrBuildElement( " << G4endl;
260  }
261  else
262  {
263  if( tgbelem->GetType() == "ElementSimple" )
264  {
265  g4elem = tgbelem->BuildG4ElementSimple();
266  }
267  else if( tgbelem->GetType() == "ElementFromIsotopes" )
268  {
269  g4elem = tgbelem->BuildG4ElementFromIsotopes();
270  }
271  else
272  {
273  G4String ErrMessage = "Element type " + tgbelem->GetType()
274  + " does not exist !";
275  G4Exception("G4tgbMaterialMgr::GetG4Element()",
276  "InvalidSetup", FatalException, ErrMessage);
277  }
278  }
279  // Register it
280  if( (g4elem != 0) )
281  {
282  theG4Elements[g4elem->GetName()] = g4elem;
283 #ifdef G4VERBOSE
285  {
286  G4cout << " G4tgbMaterialMgr::FindOrBuildG4Element() - Element: "
287  << name << G4endl;
288  }
289 #endif
290  }
291  else
292  {
293  if( bMustExist )
294  {
295  G4String ErrMessage = "Element " + name + " not found !";
296  G4Exception("G4tgbMaterialMgr::FindOrBuildG4Element()",
297  "InvalidSetup", FatalException, ErrMessage);
298  }
299 #ifdef G4VERBOSE
301  {
302  G4cout << " G4tgbMaterialMgr::FindOrBuildG4Element() - Element: "
303  << name << " not found " << G4endl;
304  }
305 #endif
306  }
307  }
308  else
309  {
310 #ifdef G4VERBOSE
312  {
313  G4cout << " G4tgbMaterialMgr::GetG4Element() -"
314  << " G4Element already built: " << g4elem->GetName() << G4endl;
315  }
316 #endif
317  }
318 
319  return g4elem;
320 }
321 
322 
323 // -------------------------------------------------------------------------
325 {
326  G4Element* g4elem = 0;
327 
328  G4msg4elem::const_iterator cite = theG4Elements.find( name );
329  if( cite != theG4Elements.end() )
330  {
331  g4elem = (*cite).second;
332 #ifdef G4VERBOSE
334  {
335  G4cout << " G4tgbMaterialMgr::FindBuiltG4Element() - Element: "
336  << name << " = " << g4elem << G4endl;
337  }
338 #endif
339  }
340 
341  return g4elem;
342 }
343 
344 
345 // -------------------------------------------------------------------------
347  G4bool bMustExist ) const
348 {
349  G4tgbElement* elem = 0;
350 
351  G4mstgbelem::const_iterator cite = theG4tgbElements.find( name );
352  if( cite != theG4tgbElements.end() )
353  {
354 #ifdef G4VERBOSE
356  {
357  G4cout << " G4tgbMaterialMgr::FindG4tgbElement() -"
358  << " G4tgbElement found: " << ( (*cite).second )->GetName()
359  << G4endl;
360  }
361 #endif
362  elem = (*cite).second;
363  }
364  if( (elem == 0) && bMustExist )
365  {
366  G4String ErrMessage = "Element " + name + " not found !";
367  G4Exception("G4tgbMaterialMgr::FindG4tgbElement()",
368  "InvalidSetup", FatalException, ErrMessage);
369  }
370 
371  return elem;
372 }
373 
374 
375 // -------------------------------------------------------------------------
377  G4bool bMustExist )
378 {
379  G4Material* g4mate = FindBuiltG4Material( name );
380  if( g4mate == 0)
381  {
382  G4tgbMaterial* tgbmate = FindG4tgbMaterial( name, false );
383 
384  if( tgbmate == 0)
385  {
386  // if FindG4tgbMaterial() returns 0, look for a G4NISTMaterial
388  }
389  else
390  {
391  g4mate = tgbmate->BuildG4Material();
392 
393  if( tgbmate->GetTgrMate()->GetIonisationMeanExcitationEnergy() != -1. )
394  {
395  g4mate->GetIonisation()->SetMeanExcitationEnergy(tgbmate->
396  GetTgrMate()->GetIonisationMeanExcitationEnergy());
397  }
398  }
399 
400  // Register it
401  if( g4mate != 0 )
402  {
403  theG4Materials[g4mate->GetName()] = g4mate;
404 #ifdef G4VERBOSE
406  {
407  G4cout << " G4tgbMaterialMgr::FindOrBuildG4Material() - Material: "
408  << name << G4endl;
409  }
410 #endif
411  }
412  else
413  {
414  if( bMustExist )
415  {
416  G4String ErrMessage = "Material " + name + " not found !";
417  G4Exception("G4tgbMaterialMgr::FindOrBuildG4Material()",
418  "InvalidSetup", FatalException, ErrMessage);
419  }
420 #ifdef G4VERBOSE
422  {
423  G4cout << " G4tgbMaterialMgr::FindOrBuildG4Material() - Element: "
424  << name << " not found " << G4endl;
425  }
426 #endif
427  }
428  }
429  else
430  {
431 #ifdef G4VERBOSE
433  {
434  G4cout << " G4tgbMaterialMgr::FindOrBuildG4Material() -"
435  << " G4Material already built: " << g4mate->GetName() << G4endl;
436  }
437 #endif
438  }
439 
440  return g4mate;
441 }
442 
443 
444 // -------------------------------------------------------------------------
446 {
447  G4Material* g4mate = 0;
448  //---------- look for an existing G4Material
449  G4msg4mate::const_iterator cite = theG4Materials.find( name );
450  if( cite != theG4Materials.end() )
451  {
452  g4mate = (*cite).second;
453 #ifdef G4VERBOSE
455  {
456  G4cout << " G4tgbMaterialMgr::FindBuiltG4Material() - Material: "
457  << name << " = " << g4mate << G4endl;
458  }
459 #endif
460  }
461 
462  return g4mate;
463 }
464 
465 
466 // -------------------------------------------------------------------------
468  G4bool bMustExist ) const
469 {
470  G4tgbMaterial* mate = 0;
471  G4mstgbmate::const_iterator cite = theG4tgbMaterials.find( name );
472  if( cite != theG4tgbMaterials.end() )
473  {
474  mate = (*cite).second;
475 #ifdef G4VERBOSE
477  {
478  G4cout << " G4tgbMaterialMgr::FindG4tgbMaterial() -"
479  << " G4tgbMaterial found: " << ( (*cite).second )->GetName()
480  << " type " << ( (*cite).second )->GetName() << G4endl;
481  }
482 #endif
483  }
484 
485  if( (mate == 0) && bMustExist )
486  {
487  G4String ErrMessage = "Material " + name + " not found !";
488  G4Exception("G4tgbMaterialMgr::FindG4tgbMaterial()",
489  "InvalidSetup", FatalException, ErrMessage);
490  }
491 
492  return mate;
493 }