VGM Version 5.3
Loading...
Searching...
No Matches
Material.cxx
Go to the documentation of this file.
1// $Id$
2
3// -----------------------------------------------------------------------
4// The RootGM 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// VGM implementations for Root material.
16//
17// Author: Ivana Hrivnacova; IPN Orsay
18
20#include "RootGM/common/Units.h"
23
24#include "TGeoMaterial.h"
25
26#include <cstdlib>
27
28const double RootGM::Material::fgkVacuumDensity = 1.e-25; // g/cm3
29const double RootGM::Material::fgkVacuumTemperature = 2.73; // kelvin
30const double RootGM::Material::fgkVacuumPressure = 2.96077e-23; // atmosphere
31
32//_____________________________________________________________________________
33RootGM::Material::Material(const std::string& name, double density,
34 VGM::IElement* element, double radlen, double intlen)
35 : VGM::IMaterial(), fMaterial(0), fElements()
36
37{
45
46 if (!element) {
47 std::cerr << " RootGM::Material::Material: " << std::endl;
48 std::cerr << " No element defined.";
49 std::cerr << "*** Error: Aborting execution ***" << std::endl;
50 exit(1);
51 }
52
53 // Create vacuum if density is lower than universe mean density
54 // or Z < 1.0
55 if (density < fgkVacuumDensity || element->Z() < 1.0) {
56 fMaterial = new TGeoMaterial(name.data(), element->A(), element->Z(),
57 fgkVacuumDensity / RootGM::Units::MassDensity(),
58 TGeoMaterial::kMatStateGas, fgkVacuumTemperature,
59 fgkVacuumPressure / RootGM::Units::Pressure());
60 }
61 else {
62 fMaterial = new TGeoMaterial(name.data(), element->A(), element->Z(),
63 density / RootGM::Units::MassDensity());
64 }
65
66 // Add element
67 fElements.push_back(element);
68
69 // Set parameters
70 fMaterial->SetRadLen(radlen, intlen);
71
72 // Register material in the map
74}
75
76//_____________________________________________________________________________
77RootGM::Material::Material(const std::string& name, double density,
78 VGM::IElement* element, double radlen, double intlen,
79 VGM::MaterialState state, double temperature, double pressure)
80 : VGM::IMaterial(), fMaterial(0), fElements()
81{
92
93 if (!element) {
94 std::cerr << " RootGM::Material::Material: " << std::endl;
95 std::cerr << " No element defined.";
96 std::cerr << "*** Error: Aborting execution ***" << std::endl;
97 exit(1);
98 }
99
100 // Create vacuum if density is lower than universe mean density
101 // or Z < 1.0
102 if (density < fgkVacuumDensity || element->Z() < 1.0) {
103 fMaterial = new TGeoMaterial(name.data(), element->A(), element->Z(),
104 fgkVacuumDensity / RootGM::Units::MassDensity(),
105 TGeoMaterial::kMatStateGas,
106 fgkVacuumTemperature / RootGM::Units::Temperature(),
107 fgkVacuumPressure / RootGM::Units::Pressure());
108 }
109 else {
110 fMaterial = new TGeoMaterial(name.data(), element->A(), element->Z(),
111 density / RootGM::Units::MassDensity(), GetGeoState(state),
112 temperature / RootGM::Units::Temperature(),
113 pressure / RootGM::Units::Pressure());
114 }
115
116 // Add element
117 fElements.push_back(element);
118
119 // Set parameters
120 fMaterial->SetRadLen(radlen, intlen);
121
122 // Register material in the map
123 RootGM::MaterialMap::Instance()->AddMaterial(this, fMaterial);
124}
125
126//_____________________________________________________________________________
127RootGM::Material::Material(const std::string& name, double density,
128 const VGM::ElementVector& elements, const VGM::MassFractionVector& fractions)
129 : VGM::IMaterial(), fMaterial(0), fElements()
130{
139
140 if (!elements.size()) {
141 std::cerr << " RootGM::Material::Material: " << std::endl;
142 std::cerr << " No elements defined.";
143 std::cerr << "*** Error: Aborting execution ***" << std::endl;
144 exit(1);
145 }
146
147 // Check coherence
148 if (elements.size() != fractions.size()) {
149 std::cerr << " RootGM::Material::Material: " << std::endl;
150 std::cerr << " Elements size and fractions size differ." << std::endl;
151 std::cerr << "*** Error: Aborting execution ***" << std::endl;
152 exit(1);
153 }
154
155 fMaterial = new TGeoMixture(
156 name.data(), elements.size(), density / RootGM::Units::MassDensity());
157
158 TGeoMixture* mixture = (TGeoMixture*)fMaterial;
159
160 // Add elements
161 for (UInt_t i = 0; i < elements.size(); i++) {
162 VGM::IElement* element = elements[i];
163 mixture->AddElement(element->A(), element->Z(), fractions[i]);
164 fElements.push_back(element);
165 }
166
167 // Register material in the map
168 RootGM::MaterialMap::Instance()->AddMaterial(this, fMaterial);
169}
170
171//_____________________________________________________________________________
172RootGM::Material::Material(const std::string& name, double density,
173 const VGM::ElementVector& elements, const VGM::MassFractionVector& fractions,
174 VGM::MaterialState state, double temperature, double pressure)
175 : VGM::IMaterial(), fMaterial(0), fElements()
176{
188
189 if (!elements.size()) {
190 std::cerr << " RootGM::Material::Material: " << std::endl;
191 std::cerr << " No elements defined.";
192 std::cerr << "*** Error: Aborting execution ***" << std::endl;
193 exit(1);
194 }
195
196 // Check coherence
197 if (elements.size() != fractions.size()) {
198 std::cerr << " RootGM::Material::Material: " << std::endl;
199 std::cerr << " Elements size and fractions size differ." << std::endl;
200 std::cerr << "*** Error: Aborting execution ***" << std::endl;
201 exit(1);
202 }
203
204 fMaterial = new TGeoMixture(
205 name.data(), elements.size(), density / RootGM::Units::MassDensity());
206
207 fMaterial->SetState(GetGeoState(state));
208 fMaterial->SetTemperature(temperature / RootGM::Units::Temperature());
209 fMaterial->SetPressure(pressure / RootGM::Units::Pressure());
210
211 TGeoMixture* mixture = (TGeoMixture*)fMaterial;
212
213 // Add elements
214 for (UInt_t i = 0; i < elements.size(); i++) {
215 VGM::IElement* element = elements[i];
216 mixture->AddElement(element->A(), element->Z(), fractions[i]);
217 fElements.push_back(element);
218 }
219
220 // Register material in the map
221 RootGM::MaterialMap::Instance()->AddMaterial(this, fMaterial);
222}
223
224//_____________________________________________________________________________
225RootGM::Material::Material(const std::string& name, double density,
226 const VGM::ElementVector& elements, const VGM::AtomCountVector& atomCounts)
227 : VGM::IMaterial(), fMaterial(0), fElements()
228{
237
238 if (!elements.size()) {
239 std::cerr << " RootGM::Material::Material: " << std::endl;
240 std::cerr << " No elements defined.";
241 std::cerr << "*** Error: Aborting execution ***" << std::endl;
242 exit(1);
243 }
244
245 // Check coherence
246 if (elements.size() != atomCounts.size()) {
247 std::cerr << " RootGM::Material::Material: " << std::endl;
248 std::cerr << " Elements size and atomCounts size differ." << std::endl;
249 std::cerr << "*** Error: Aborting execution ***" << std::endl;
250 exit(1);
251 }
252
253 fMaterial = new TGeoMixture(
254 name.data(), elements.size(), density / RootGM::Units::MassDensity());
255
256 TGeoMixture* mixture = (TGeoMixture*)fMaterial;
257
258 // Calculate molecule mass to get mass fractions of elements
259 // (As we cannot add element via a, z, atomCount to mixture
260 // directly)
261
262 double amol = 0;
263 for (unsigned i = 0; i < elements.size(); i++)
264 amol += elements[i]->A() * atomCounts[i];
265
266 // Add elements
267 for (unsigned i = 0; i < elements.size(); i++) {
268 VGM::IElement* element = elements[i];
269 double fraction = atomCounts[i] * element->A() / amol;
270 mixture->AddElement(element->A(), element->Z(), fraction);
271 fElements.push_back(element);
272 }
273
274 // Register material in the map
275 RootGM::MaterialMap::Instance()->AddMaterial(this, fMaterial);
276}
277
278//_____________________________________________________________________________
279RootGM::Material::Material(const std::string& name, double density,
280 const VGM::ElementVector& elements, const VGM::AtomCountVector& atomCounts,
281 VGM::MaterialState state, double temperature, double pressure)
282 : VGM::IMaterial(), fMaterial(0), fElements()
283{
292
293 if (!elements.size()) {
294 std::cerr << " RootGM::Material::Material: " << std::endl;
295 std::cerr << " No elements defined.";
296 std::cerr << "*** Error: Aborting execution ***" << std::endl;
297 exit(1);
298 }
299
300 // Check coherence
301 if (elements.size() != atomCounts.size()) {
302 std::cerr << " RootGM::Material::Material: " << std::endl;
303 std::cerr << " Elements size and atomCounts size differ." << std::endl;
304 std::cerr << "*** Error: Aborting execution ***" << std::endl;
305 exit(1);
306 }
307
308 fMaterial = new TGeoMixture(
309 name.data(), elements.size(), density / RootGM::Units::MassDensity());
310
311 fMaterial->SetState(GetGeoState(state));
312 fMaterial->SetTemperature(temperature / RootGM::Units::Temperature());
313 fMaterial->SetPressure(pressure / RootGM::Units::Pressure());
314
315 TGeoMixture* mixture = (TGeoMixture*)fMaterial;
316
317 // Calculate molecule mass to get mass fractions of elements
318 // (As we cannot add element via a, z, atomCount to mixture
319 // directly)
320
321 double amol = 0;
322 for (unsigned i = 0; i < elements.size(); i++)
323 amol += elements[i]->A() * atomCounts[i];
324
325 // Add elements
326 for (UInt_t i = 0; i < elements.size(); i++) {
327 VGM::IElement* element = elements[i];
328 double fraction = atomCounts[i] * element->A() / amol;
329 mixture->AddElement(element->A(), element->Z(), fraction);
330 fElements.push_back(element);
331 }
332
333 // Register material in the map
334 RootGM::MaterialMap::Instance()->AddMaterial(this, fMaterial);
335}
336
337//_____________________________________________________________________________
339 TGeoMaterial* material, const VGM::ElementVector& elements)
340 : VGM::IMaterial(), fMaterial(material), fElements(elements)
341{
343
344 // Register material in the map
345 RootGM::MaterialMap::Instance()->AddMaterial(this, fMaterial);
346}
347
348//_____________________________________________________________________________
349RootGM::Material::Material() : VGM::IMaterial(), fMaterial(0), fElements()
350{
352}
353
354//_____________________________________________________________________________
356 : VGM::IMaterial(rhs), fMaterial(rhs.fMaterial), fElements(rhs.fElements)
357{
359}
360
361//_____________________________________________________________________________
366
367//
368// private functions
369//
370
371//_____________________________________________________________________________
372void RootGM::Material::CheckIndex(int iel) const
373{
374 if (iel < 0 || iel >= NofElements()) {
375 std::cerr << " RootGM::Material::CheckIndex: " << std::endl;
376 std::cerr << " Index of element outside limits." << std::endl;
377 std::cerr << "*** Error: Aborting execution ***" << std::endl;
378 ;
379 exit(1);
380 }
381}
382
383//_____________________________________________________________________________
384TGeoMaterial::EGeoMaterialState RootGM::Material::GetGeoState(
385 VGM::MaterialState state) const
386{
387 switch (state) {
388 case VGM::kUndefined:
389 return TGeoMaterial::kMatStateUndefined;
390 case VGM::kSolid:
391 return TGeoMaterial::kMatStateSolid;
392 case VGM::kLiquid:
393 return TGeoMaterial::kMatStateLiquid;
394 case VGM::kGas:
395 return TGeoMaterial::kMatStateGas;
396 default:
397 return TGeoMaterial::kMatStateUndefined;
398 }
399
400 return TGeoMaterial::kMatStateUndefined;
401}
402
403//_____________________________________________________________________________
404VGM::MaterialState RootGM::Material::GetVGMState(
405 TGeoMaterial::EGeoMaterialState state) const
406{
407 switch (state) {
408 case TGeoMaterial::kMatStateUndefined:
409 return VGM::kUndefined;
410 case TGeoMaterial::kMatStateSolid:
411 return VGM::kSolid;
412 case TGeoMaterial::kMatStateLiquid:
413 return VGM::kLiquid;
414 case TGeoMaterial::kMatStateGas:
415 return VGM::kGas;
416 default:
417 return VGM::kUndefined;
418 }
419
420 return VGM::kUndefined;
421}
422
423//
424// public functions
425//
426
427//_____________________________________________________________________________
428std::string RootGM::Material::Name() const
429{
430 return std::string(fMaterial->GetName());
431}
432
433//_____________________________________________________________________________
435{
436 return fMaterial->GetDensity() * RootGM::Units::MassDensity();
437}
438
439//_____________________________________________________________________________
441{
442 return fMaterial->GetRadLen() * RootGM::Units::Length();
443}
444
445//_____________________________________________________________________________
447{
448 return fMaterial->GetIntLen() * RootGM::Units::Length();
449}
450
451//_____________________________________________________________________________
453{
454 return GetVGMState(fMaterial->GetState());
455}
456
457//_____________________________________________________________________________
459{
460 return fMaterial->GetTemperature() * RootGM::Units::Temperature();
461}
462
463//_____________________________________________________________________________
465{
466 return fMaterial->GetPressure() * RootGM::Units::Pressure();
467}
468
469//_____________________________________________________________________________
471{
472 if (!fMaterial->IsMixture())
473 return 1;
474 else
475 return ((TGeoMixture*)fMaterial)->GetNelements();
476}
477
478//_____________________________________________________________________________
480{
481 CheckIndex(iel);
482
483 return fElements[iel];
484}
485
486//_____________________________________________________________________________
488{
489 CheckIndex(iel);
490
491 if (!fMaterial->IsMixture())
492 return 1.0;
493 else
494 return ((TGeoMixture*)fMaterial)->GetWmixt()[iel];
495}
496
497//_____________________________________________________________________________
498double RootGM::Material::AtomCount(int iel) const
499{
500 CheckIndex(iel);
501
502 if (NofElements() == 1) return 1.0;
503
504 // return ((TGeoMixture*)fMaterial)->GetNmixt()[iel];
505 // Temporarily excluded as Root breaks
506 std::cerr << "RootGM::Material::AtomCount is not implemented" << std::endl;
507 return 0;
508}
void AddMaterial(VGM::IMaterial *, TGeoMaterial *)
static MaterialMap * Instance()
VGM implementation for Root material.
Definition Material.h:32
virtual double Density() const
Return the density in g/cm3.
Definition Material.cxx:434
virtual double NuclearInterLength() const
Return the nuclear interaction length in mm.
Definition Material.cxx:446
virtual double Temperature() const
Return the temperature in kelvins.
Definition Material.cxx:458
virtual std::string Name() const
Return the name of this element.
Definition Material.cxx:428
virtual double Pressure() const
Return the density in atmosphere.
Definition Material.cxx:464
virtual double RadiationLength() const
Return the radiation length in mm.
Definition Material.cxx:440
virtual ~Material()
Definition Material.cxx:362
virtual VGM::MaterialState State() const
Return the material state.
Definition Material.cxx:452
virtual VGM::IElement * Element(int iel) const
Return the i-th element constituing this material.
Definition Material.cxx:479
virtual double AtomCount(int iel) const
Return the atom count of the i-th element constituing this material.
Definition Material.cxx:498
virtual int NofElements() const
Return the number of elements constituing this material.
Definition Material.cxx:470
virtual double MassFraction(int iel) const
Return the mass fraction of the i-th element constituing this material.
Definition Material.cxx:487
static double Pressure()
Return Root pressure unit in VGM unit.
Definition Units.h:89
static double Length()
Return Root length unit in VGM units.
Definition Units.h:84
static double MassDensity()
Return Root mass density unit in VGM units.
Definition Units.h:86
static double Temperature()
Return Root temperature unit in VGM unit.
Definition Units.h:88
The VGM interface to elements.
Definition IElement.h:34
virtual double Z() const =0
Return the effective atomic number.
virtual double A() const =0
Return the effective effective mass of a mole in g/mole.
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