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: G4tgbMaterialMgr.cc,v 1.5 2008/12/18 12:59:28 gunter Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-03 $ |
---|
29 | // |
---|
30 | // |
---|
31 | // class G4tgbMaterialMgr |
---|
32 | |
---|
33 | // History: |
---|
34 | // - Created. P.Arce, CIEMAT (November 2007) |
---|
35 | // ------------------------------------------------------------------------- |
---|
36 | |
---|
37 | #include "G4tgbMaterialMgr.hh" |
---|
38 | #include "G4tgbMaterialMixtureByWeight.hh" |
---|
39 | #include "G4tgbMaterialMixtureByVolume.hh" |
---|
40 | #include "G4tgbMaterialMixtureByNoAtoms.hh" |
---|
41 | #include "G4tgbMaterialSimple.hh" |
---|
42 | |
---|
43 | #include "G4tgrMaterialFactory.hh" |
---|
44 | #include "G4tgrMaterialSimple.hh" |
---|
45 | #include "G4tgrMaterialMixture.hh" |
---|
46 | #include "G4tgrUtils.hh" |
---|
47 | #include "G4tgrMessenger.hh" |
---|
48 | #include "G4NistManager.hh" |
---|
49 | |
---|
50 | |
---|
51 | G4tgbMaterialMgr* G4tgbMaterialMgr::theInstance = 0; |
---|
52 | |
---|
53 | |
---|
54 | // ------------------------------------------------------------------------- |
---|
55 | G4tgbMaterialMgr::G4tgbMaterialMgr() |
---|
56 | { |
---|
57 | } |
---|
58 | |
---|
59 | |
---|
60 | // ------------------------------------------------------------------------- |
---|
61 | G4tgbMaterialMgr* G4tgbMaterialMgr::GetInstance() |
---|
62 | { |
---|
63 | if( !theInstance ) |
---|
64 | { |
---|
65 | theInstance = new G4tgbMaterialMgr; |
---|
66 | theInstance->CopyIsotopes(); |
---|
67 | theInstance->CopyElements(); |
---|
68 | theInstance->CopyMaterials(); |
---|
69 | } |
---|
70 | return theInstance; |
---|
71 | } |
---|
72 | |
---|
73 | |
---|
74 | // ------------------------------------------------------------------------- |
---|
75 | G4tgbMaterialMgr::~G4tgbMaterialMgr() |
---|
76 | { |
---|
77 | G4mstgbisot::const_iterator isotcite; |
---|
78 | for( isotcite = theG4tgbIsotopes.begin(); |
---|
79 | isotcite != theG4tgbIsotopes.end(); isotcite++) |
---|
80 | { |
---|
81 | delete (*isotcite).second; |
---|
82 | } |
---|
83 | theG4tgbIsotopes.clear(); |
---|
84 | |
---|
85 | G4mstgbelem::const_iterator elemcite; |
---|
86 | for( elemcite = theG4tgbElements.begin(); |
---|
87 | elemcite != theG4tgbElements.end(); elemcite++) |
---|
88 | { |
---|
89 | delete (*elemcite).second; |
---|
90 | } |
---|
91 | theG4tgbElements.clear(); |
---|
92 | |
---|
93 | G4mstgbmate::const_iterator matcite; |
---|
94 | for( matcite = theG4tgbMaterials.begin(); |
---|
95 | matcite != theG4tgbMaterials.end(); matcite++) |
---|
96 | { |
---|
97 | delete (*matcite).second; |
---|
98 | } |
---|
99 | theG4tgbMaterials.clear(); |
---|
100 | |
---|
101 | delete theInstance; |
---|
102 | } |
---|
103 | |
---|
104 | |
---|
105 | // ------------------------------------------------------------------------- |
---|
106 | void G4tgbMaterialMgr::CopyIsotopes() |
---|
107 | { |
---|
108 | const G4mstgrisot tgrIsots |
---|
109 | = G4tgrMaterialFactory::GetInstance()->GetIsotopeList(); |
---|
110 | G4mstgrisot::const_iterator cite; |
---|
111 | for( cite = tgrIsots.begin(); cite != tgrIsots.end(); cite++ ) |
---|
112 | { |
---|
113 | G4tgrIsotope* tgr = (*cite).second; |
---|
114 | G4tgbIsotope* tgb = new G4tgbIsotope( tgr ); |
---|
115 | theG4tgbIsotopes[tgb->GetName()] = tgb; |
---|
116 | } |
---|
117 | } |
---|
118 | |
---|
119 | |
---|
120 | // ------------------------------------------------------------------------- |
---|
121 | void G4tgbMaterialMgr::CopyElements() |
---|
122 | { |
---|
123 | const G4mstgrelem tgrElems |
---|
124 | = G4tgrMaterialFactory::GetInstance()->GetElementList(); |
---|
125 | G4mstgrelem::const_iterator cite; |
---|
126 | for( cite = tgrElems.begin(); cite != tgrElems.end(); cite++ ) |
---|
127 | { |
---|
128 | G4tgrElement* tgr = (*cite).second; |
---|
129 | G4tgbElement* tgb = new G4tgbElement( tgr ); |
---|
130 | theG4tgbElements[tgb->GetName()] = tgb; |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | |
---|
135 | // ------------------------------------------------------------------------- |
---|
136 | void G4tgbMaterialMgr::CopyMaterials() |
---|
137 | { |
---|
138 | const G4mstgrmate tgrMates |
---|
139 | = G4tgrMaterialFactory::GetInstance()->GetMaterialList(); |
---|
140 | G4mstgrmate::const_iterator cite; |
---|
141 | for( cite = tgrMates.begin(); cite != tgrMates.end(); cite++ ) |
---|
142 | { |
---|
143 | G4tgrMaterial* tgr = (*cite).second; |
---|
144 | G4tgbMaterial* tgb = 0; |
---|
145 | if( tgr->GetType() == "MaterialSimple" ) { |
---|
146 | tgb = new G4tgbMaterialSimple( tgr ); |
---|
147 | } else if( tgr->GetType() == "MaterialMixtureByWeight" ) { |
---|
148 | tgb = new G4tgbMaterialMixtureByWeight( tgr ); |
---|
149 | } else if( tgr->GetType() == "MaterialMixtureByNoAtoms" ) { |
---|
150 | tgb = new G4tgbMaterialMixtureByNoAtoms( tgr ); |
---|
151 | } else if( tgr->GetType() == "MaterialMixtureByVolume" ) { |
---|
152 | tgb = new G4tgbMaterialMixtureByVolume( tgr ); |
---|
153 | } |
---|
154 | theG4tgbMaterials[tgb->GetName()] = tgb; |
---|
155 | } |
---|
156 | } |
---|
157 | |
---|
158 | |
---|
159 | // ------------------------------------------------------------------------- |
---|
160 | G4Isotope* G4tgbMaterialMgr::FindOrBuildG4Isotope(const G4String & name) |
---|
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 |
---|
175 | if( G4tgrMessenger::GetVerboseLevel() >= 1 ) |
---|
176 | { |
---|
177 | G4cout << " G4tgbMaterialMgr::FindOrBuildG4Isotope() -" |
---|
178 | << " G4Isotope already built: " << g4isot->GetName() << G4endl; |
---|
179 | } |
---|
180 | #endif |
---|
181 | } |
---|
182 | |
---|
183 | #ifdef G4VERBOSE |
---|
184 | if( G4tgrMessenger::GetVerboseLevel() >= 2 ) |
---|
185 | { |
---|
186 | G4cout << " G4tgbMaterialMgr::FindOrBuildG4Isotope() - Isotope: " |
---|
187 | << name << G4endl; |
---|
188 | } |
---|
189 | #endif |
---|
190 | return g4isot; |
---|
191 | } |
---|
192 | |
---|
193 | |
---|
194 | // ------------------------------------------------------------------------- |
---|
195 | G4Isotope* G4tgbMaterialMgr::FindBuiltG4Isotope(const G4String & name) const |
---|
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 |
---|
204 | if( G4tgrMessenger::GetVerboseLevel() >= 2 ) |
---|
205 | { |
---|
206 | G4cout << " G4tgbMaterialMgr::FindBuiltG4Isotope() - Isotope: " |
---|
207 | << name << " = " << g4isot << G4endl; |
---|
208 | } |
---|
209 | #endif |
---|
210 | |
---|
211 | } |
---|
212 | |
---|
213 | return g4isot; |
---|
214 | } |
---|
215 | |
---|
216 | |
---|
217 | // ------------------------------------------------------------------------- |
---|
218 | G4tgbIsotope* G4tgbMaterialMgr::FindG4tgbIsotope(const G4String & name, |
---|
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 |
---|
227 | if( G4tgrMessenger::GetVerboseLevel() >= 2 ) |
---|
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 | // ------------------------------------------------------------------------- |
---|
248 | G4Element* G4tgbMaterialMgr::FindOrBuildG4Element(const G4String & name, |
---|
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; |
---|
259 | g4elem = G4NistManager::Instance()->FindOrBuildElement(name); |
---|
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 |
---|
284 | if( G4tgrMessenger::GetVerboseLevel() >= 2 ) |
---|
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 |
---|
300 | if( G4tgrMessenger::GetVerboseLevel() >= 2 ) |
---|
301 | { |
---|
302 | G4cout << " G4tgbMaterialMgr::FindOrBuildG4Element() - Element: " |
---|
303 | << name << " not found " << G4endl; |
---|
304 | } |
---|
305 | #endif |
---|
306 | } |
---|
307 | } |
---|
308 | else |
---|
309 | { |
---|
310 | #ifdef G4VERBOSE |
---|
311 | if( G4tgrMessenger::GetVerboseLevel() >= 1 ) |
---|
312 | { |
---|
313 | G4cout << " G4tgbMaterialMgr::GetG4Element() -" |
---|
314 | << " G4Element already built: " << g4elem->GetName() << G4endl; |
---|
315 | } |
---|
316 | #endif |
---|
317 | } |
---|
318 | |
---|
319 | return g4elem; |
---|
320 | } |
---|
321 | |
---|
322 | |
---|
323 | // ------------------------------------------------------------------------- |
---|
324 | G4Element* G4tgbMaterialMgr::FindBuiltG4Element(const G4String & name) const |
---|
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 |
---|
333 | if( G4tgrMessenger::GetVerboseLevel() >= 2 ) |
---|
334 | { |
---|
335 | G4cout << " G4tgbMaterialMgr::FindBuiltG4Element() - Element: " |
---|
336 | << name << " = " << g4elem << G4endl; |
---|
337 | } |
---|
338 | #endif |
---|
339 | } |
---|
340 | |
---|
341 | return g4elem; |
---|
342 | } |
---|
343 | |
---|
344 | |
---|
345 | // ------------------------------------------------------------------------- |
---|
346 | G4tgbElement* G4tgbMaterialMgr::FindG4tgbElement(const G4String & name, |
---|
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 |
---|
355 | if( G4tgrMessenger::GetVerboseLevel() >= 2 ) |
---|
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 | // ------------------------------------------------------------------------- |
---|
376 | G4Material* G4tgbMaterialMgr::FindOrBuildG4Material(const G4String & name, |
---|
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 |
---|
387 | g4mate = G4NistManager::Instance()->FindOrBuildMaterial(name); |
---|
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 |
---|
405 | if( G4tgrMessenger::GetVerboseLevel() >= 2 ) |
---|
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 |
---|
421 | if( G4tgrMessenger::GetVerboseLevel() >= 2 ) |
---|
422 | { |
---|
423 | G4cout << " G4tgbMaterialMgr::FindOrBuildG4Material() - Element: " |
---|
424 | << name << " not found " << G4endl; |
---|
425 | } |
---|
426 | #endif |
---|
427 | } |
---|
428 | } |
---|
429 | else |
---|
430 | { |
---|
431 | #ifdef G4VERBOSE |
---|
432 | if( G4tgrMessenger::GetVerboseLevel() >= 1 ) |
---|
433 | { |
---|
434 | G4cout << " G4tgbMaterialMgr::FindOrBuildG4Material() -" |
---|
435 | << " G4Material already built: " << g4mate->GetName() << G4endl; |
---|
436 | } |
---|
437 | #endif |
---|
438 | } |
---|
439 | |
---|
440 | return g4mate; |
---|
441 | } |
---|
442 | |
---|
443 | |
---|
444 | // ------------------------------------------------------------------------- |
---|
445 | G4Material* G4tgbMaterialMgr::FindBuiltG4Material(const G4String & name) const |
---|
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 |
---|
454 | if( G4tgrMessenger::GetVerboseLevel() >= 2 ) |
---|
455 | { |
---|
456 | G4cout << " G4tgbMaterialMgr::FindBuiltG4Material() - Material: " |
---|
457 | << name << " = " << g4mate << G4endl; |
---|
458 | } |
---|
459 | #endif |
---|
460 | } |
---|
461 | |
---|
462 | return g4mate; |
---|
463 | } |
---|
464 | |
---|
465 | |
---|
466 | // ------------------------------------------------------------------------- |
---|
467 | G4tgbMaterial* G4tgbMaterialMgr::FindG4tgbMaterial(const G4String & name, |
---|
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 |
---|
476 | if( G4tgrMessenger::GetVerboseLevel() >= 2 ) |
---|
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 | } |
---|