VGM Version 5.3
Loading...
Searching...
No Matches
Material.cxx
Go to the documentation of this file.
1// $Id$
2
3// -----------------------------------------------------------------------
4// The Geant4GM package of the Virtual Geometry Model
5// Copyright (C) 2007, Ivana Hrivnacova
6// All rights reserved.
7//
8// For the licensing terms see vgm/LICENSE.
9// Contact: ivana@ipno.in2p3.fr
10// -----------------------------------------------------------------------
11
12//
13// Class Material
14// ---------------
15// The interface to materials.
16//
17// Author: Ivana Hrivnacova; IPN Orsay
18
19#include "ClhepVGM/Units.h"
20
22
26
27#include "G4PhysicalConstants.hh"
28#include "G4SystemOfUnits.hh"
29
30//_____________________________________________________________________________
31Geant4GM::Material::Material(const std::string& name, double density,
32 VGM::IElement* element, bool isVacuum)
33 : VGM::IMaterial(), fMaterial(0)
34
35{
42
43 if (!element) {
44 std::cerr << " Geant4GM::Material::Material: " << std::endl;
45 std::cerr << " No element defined.";
46 std::cerr << "*** Error: Aborting execution ***" << std::endl;
47 exit(1);
48 }
49
50 // Convert units
52
53 // Create vacuum if not allowed low density or
54 // if material was associated with an element with Z < 1.0
55 //
56 if (density < universe_mean_density || isVacuum) {
57 // lower density not allowed in Geant4
58 density = universe_mean_density;
59
60 // Create vacuum
61 fMaterial = new G4Material(
62 name, density, 1, kStateGas, 2.73 * kelvin, 3.e-18 * pascal);
63 }
64 else {
65 // Create normal material
66 fMaterial = new G4Material(name, density, 1);
67 }
68
69 // Add element
70 G4Element* g4Element = ElementMap::Instance()->GetElement(element);
71 fMaterial->AddElement(g4Element, 1.);
72}
73
74//_____________________________________________________________________________
75Geant4GM::Material::Material(const std::string& name, double density,
76 VGM::IElement* element, VGM::MaterialState state, double temperature,
77 double pressure, bool isVacuum)
78 : VGM::IMaterial(), fMaterial(0)
79
80{
90
91 if (!element) {
92 std::cerr << " Geant4GM::Material::Material: " << std::endl;
93 std::cerr << " No element defined.";
94 std::cerr << "*** Error: Aborting execution ***" << std::endl;
95 exit(1);
96 }
97
98 // Convert units
100 temperature /= ClhepVGM::Units::Temperature();
101 pressure /= ClhepVGM::Units::Pressure();
102 G4State g4State = GetG4State(state);
103
104 // Create vacuum if not allowed low density or
105 // if material was associated with an element with Z < 1.0
106 //
107 if (density < universe_mean_density || isVacuum) {
108 // lower density not allowed in Geant4
109 density = universe_mean_density;
110
111 // Create vacuum
112 fMaterial = new G4Material(
113 name, density, 1, kStateGas, 2.73 * kelvin, 3.e-18 * pascal);
114 }
115 else {
116 // Create normal material
117 fMaterial =
118 new G4Material(name, density, 1, g4State, temperature, pressure);
119 }
120
121 // Add element
122 G4Element* g4Element = ElementMap::Instance()->GetElement(element);
123 fMaterial->AddElement(g4Element, 1.);
124}
125
126//_____________________________________________________________________________
127Geant4GM::Material::Material(const std::string& name, double density,
128 const VGM::ElementVector& elements, const VGM::MassFractionVector& fractions)
129 : VGM::IMaterial(), fMaterial(0)
130{
139
140 //
141
142 if (!elements.size()) {
143 std::cerr << " Geant4GM::Material::Material: " << std::endl;
144 std::cerr << " No elements defined.";
145 std::cerr << "*** Error: Aborting execution ***" << std::endl;
146 exit(1);
147 }
148
149 // Check coherence
150 if (elements.size() != fractions.size()) {
151 std::cerr << " Geant4GM::Material::Material: " << std::endl;
152 std::cerr << " Elements size and fractions size differ.";
153 std::cerr << "*** Error: Aborting execution ***" << std::endl;
154 exit(1);
155 }
156
157 // Convert units
158 density /= ClhepVGM::Units::MassDensity();
159
160 // Update density if lower than universe_mean_density
161 if (density < universe_mean_density) {
162 // lower density not allowed in Geant4
163 density = universe_mean_density;
164 }
165
166 // Create material
167 fMaterial = new G4Material(name, density, elements.size());
168
169 // Add elements
170 for (unsigned int i = 0; i < elements.size(); i++) {
171 G4Element* g4Element = ElementMap::Instance()->GetElement(elements[i]);
172 fMaterial->AddElement(g4Element, fractions[i]);
173 }
174}
175
176//_____________________________________________________________________________
177Geant4GM::Material::Material(const std::string& name, double density,
178 const VGM::ElementVector& elements, const VGM::MassFractionVector& fractions,
179 VGM::MaterialState state, double temperature, double pressure)
180 : VGM::IMaterial(), fMaterial(0)
181{
193
194 //
195
196 if (!elements.size()) {
197 std::cerr << " Geant4GM::Material::Material: " << std::endl;
198 std::cerr << " No elements defined.";
199 std::cerr << "*** Error: Aborting execution ***" << std::endl;
200 exit(1);
201 }
202
203 // Check coherence
204 if (elements.size() != fractions.size()) {
205 std::cerr << " Geant4GM::Material::Material: " << std::endl;
206 std::cerr << " Elements size and fractions size differ.";
207 std::cerr << "*** Error: Aborting execution ***" << std::endl;
208 exit(1);
209 }
210
211 // Convert units
212 density /= ClhepVGM::Units::MassDensity();
213 temperature /= ClhepVGM::Units::Temperature();
214 pressure /= ClhepVGM::Units::Pressure();
215 G4State g4State = GetG4State(state);
216
217 // Update density if lower than universe_mean_density
218 if (density < universe_mean_density) {
219 // lower density not allowed in Geant4
220 density = universe_mean_density;
221 }
222
223 // Create material
224 fMaterial = new G4Material(
225 name, density, elements.size(), g4State, temperature, pressure);
226
227 // Add elements
228 for (unsigned int i = 0; i < elements.size(); i++) {
229 G4Element* g4Element = ElementMap::Instance()->GetElement(elements[i]);
230 fMaterial->AddElement(g4Element, fractions[i]);
231 }
232}
233
234//_____________________________________________________________________________
235Geant4GM::Material::Material(const std::string& name, double density,
236 const VGM::ElementVector& elements, const VGM::AtomCountVector& atomCounts)
237 : VGM::IMaterial(), fMaterial(0)
238{
247
248 //
249
250 if (!elements.size()) {
251 std::cerr << " Geant4GM::Material::Material: " << std::endl;
252 std::cerr << " No elements defined.";
253 std::cerr << "*** Error: Aborting execution ***" << std::endl;
254 exit(1);
255 }
256
257 // Check coherence
258 if (elements.size() != atomCounts.size()) {
259 std::cerr << " Geant4GM::Material::Material: " << std::endl;
260 std::cerr << " Elements size and atomCounts size differ.";
261 std::cerr << "*** Error: Aborting execution ***" << std::endl;
262 exit(1);
263 }
264
265 // Convert units
266 density /= ClhepVGM::Units::MassDensity();
267
268 // Update density if lower than universe_mean_density
269 if (density < universe_mean_density) {
270 // lower density not allowed in Geant4
271 density = universe_mean_density;
272 }
273
274 // Create material
275 fMaterial = new G4Material(name, density, elements.size());
276
277 // Add elements
278 for (unsigned int i = 0; i < elements.size(); i++) {
279 G4Element* g4Element = ElementMap::Instance()->GetElement(elements[i]);
280 fMaterial->AddElement(g4Element, atomCounts[i]);
281 }
282}
283
284//_____________________________________________________________________________
285Geant4GM::Material::Material(const std::string& name, double density,
286 const VGM::ElementVector& elements, const VGM::AtomCountVector& atomCounts,
287 VGM::MaterialState state, double temperature, double pressure)
288 : VGM::IMaterial(), fMaterial(0)
289{
301
302 //
303
304 if (!elements.size()) {
305 std::cerr << " Geant4GM::Material::Material: " << std::endl;
306 std::cerr << " No elements defined.";
307 std::cerr << "*** Error: Aborting execution ***" << std::endl;
308 exit(1);
309 }
310
311 // Check coherence
312 if (elements.size() != atomCounts.size()) {
313 std::cerr << " Geant4GM::Material::Material: " << std::endl;
314 std::cerr << " Elements size and atomCounts size differ.";
315 std::cerr << "*** Error: Aborting execution ***" << std::endl;
316 exit(1);
317 }
318
319 // Convert units
320 density /= ClhepVGM::Units::MassDensity();
321 temperature /= ClhepVGM::Units::Temperature();
322 pressure /= ClhepVGM::Units::Pressure();
323 G4State g4State = GetG4State(state);
324
325 // Update density if lower than universe_mean_density
326 if (density < universe_mean_density) {
327 // lower density not allowed in Geant4
328 density = universe_mean_density;
329 }
330
331 // Create material
332 fMaterial = new G4Material(
333 name, density, elements.size(), g4State, temperature, pressure);
334
335 // Add elements
336 for (unsigned int i = 0; i < elements.size(); i++) {
337 G4Element* g4Element = ElementMap::Instance()->GetElement(elements[i]);
338 fMaterial->AddElement(g4Element, atomCounts[i]);
339 }
340}
341
342//_____________________________________________________________________________
343Geant4GM::Material::Material(G4Material* material)
344 : VGM::IMaterial(), fMaterial(material)
345{
347}
348
349//_____________________________________________________________________________
351{
353}
354
355//_____________________________________________________________________________
356Geant4GM::Material::Material(const Material& rhs) : VGM::IMaterial(rhs)
357{
359}
360
361//_____________________________________________________________________________
366
367//
368// private functions
369//
370
371//_____________________________________________________________________________
372void Geant4GM::Material::CheckIndex(int iel) const
373{
374 if (iel < 0 || iel >= NofElements()) {
375 std::cerr << " Geant4GM::Material::CheckIndex: " << std::endl;
376 std::cerr << " In material: " << Name() << std::endl;
377 std::cerr << " Index of element " << iel << " outside limits."
378 << std::endl;
379 std::cerr << "*** Error: Aborting execution ***" << std::endl;
380 exit(1);
381 }
382}
383
384//_____________________________________________________________________________
385G4State Geant4GM::Material::GetG4State(VGM::MaterialState state) const
386{
387 switch (state) {
388 case VGM::kUndefined:
389 return kStateUndefined;
390 case VGM::kSolid:
391 return kStateSolid;
392 case VGM::kLiquid:
393 return kStateLiquid;
394 case VGM::kGas:
395 return kStateGas;
396 default:
397 return kStateUndefined;
398 }
399
400 return kStateUndefined;
401}
402
403//_____________________________________________________________________________
404VGM::MaterialState Geant4GM::Material::GetVGMState(G4State state) const
405{
406 switch (state) {
407 case kStateUndefined:
408 return VGM::kUndefined;
409 case kStateSolid:
410 return VGM::kSolid;
411 case kStateLiquid:
412 return VGM::kLiquid;
413 case kStateGas:
414 return VGM::kGas;
415 default:
416 return VGM::kUndefined;
417 }
418
419 return VGM::kUndefined;
420}
421
422//
423// public functions
424//
425
426//_____________________________________________________________________________
427std::string Geant4GM::Material::Name() const { return fMaterial->GetName(); }
428
429//_____________________________________________________________________________
431{
432 return fMaterial->GetDensity() * ClhepVGM::Units::MassDensity();
433}
434
435//_____________________________________________________________________________
437{
438 return fMaterial->GetRadlen() * ClhepVGM::Units::Length();
439}
440
441//_____________________________________________________________________________
443{
444 return fMaterial->GetNuclearInterLength() * ClhepVGM::Units::Length();
445}
446
447//_____________________________________________________________________________
449{
450 return GetVGMState(fMaterial->GetState());
451}
452
453//_____________________________________________________________________________
455{
456 return fMaterial->GetTemperature() * ClhepVGM::Units::Temperature();
457}
458
459//_____________________________________________________________________________
461{
462 return fMaterial->GetPressure() * ClhepVGM::Units::Pressure();
463}
464
465//_____________________________________________________________________________
467{
468 return fMaterial->GetNumberOfElements();
469}
470
471//_____________________________________________________________________________
473{
474 CheckIndex(iel);
475
476 G4Element* g4Element = const_cast<G4Element*>((*fMaterial->GetElementVector())[iel]);
477 return ElementMap::Instance()->GetElement(g4Element);
478}
479
480//_____________________________________________________________________________
482{
483 CheckIndex(iel);
484
485 return fMaterial->GetFractionVector()[iel];
486}
487
488//_____________________________________________________________________________
489double Geant4GM::Material::AtomCount(int iel) const
490{
491 CheckIndex(iel);
492
493 if (NofElements() == 1) return 1.0;
494
495 return fMaterial->GetVecNbOfAtomsPerVolume()[iel] /
496 fMaterial->GetTotNbOfAtomsPerVolume();
497}
static double Temperature()
Return CLHEP default temperature unit in VGM unit.
Definition Units.cxx:116
static double MassDensity()
Return CLHEP default mass density unit in VGM units.
Definition Units.cxx:98
static double Pressure()
Return CLHEP default pressure unit in VGM unit.
Definition Units.cxx:125
static double Length()
Return CLHEP default length unit in VGM units.
Definition Units.cxx:83
static ElementMap * Instance()
G4Element * GetElement(VGM::IElement *iElement) const
VGM implementation for Geant4 material.
Definition Material.h:32
virtual double MassFraction(int iel) const
Return the mass fraction of the i-th element constituing this material.
Definition Material.cxx:481
virtual VGM::IElement * Element(int iel) const
Return the i-th element constituing this material.
Definition Material.cxx:472
virtual double Pressure() const
Return the density in atmosphere.
Definition Material.cxx:460
virtual double Temperature() const
Return the temperature in kelvins.
Definition Material.cxx:454
virtual double Density() const
Return the density in g/cm3.
Definition Material.cxx:430
virtual std::string Name() const
Return the name of this element.
Definition Material.cxx:427
virtual double AtomCount(int iel) const
Return the atom count of the i-th element constituing this material.
Definition Material.cxx:489
virtual ~Material()
Definition Material.cxx:362
virtual VGM::MaterialState State() const
Return the material state.
Definition Material.cxx:448
virtual double RadiationLength() const
Return the radiation length in mm.
Definition Material.cxx:436
virtual double NuclearInterLength() const
Return the nuclear interaction length in mm.
Definition Material.cxx:442
virtual int NofElements() const
Return the number of elements constituing this material.
Definition Material.cxx:466
The VGM interface to elements.
Definition IElement.h:34
VGM interfaces.
Definition VMedium.h:28
std::vector< int > AtomCountVector
Definition IMaterial.h:33
std::vector< double > MassFractionVector
Definition IMaterial.h:32
std::vector< IElement * > ElementVector
Definition IMaterial.h:31
MaterialState
Definition IMaterial.h:36
@ kGas
Gas materila.
Definition IMaterial.h:40
@ kLiquid
Liquid material.
Definition IMaterial.h:39
@ kSolid
Solid material.
Definition IMaterial.h:38
@ kUndefined
Undefined material state.
Definition IMaterial.h:37