CMS 3D CMS Logo

DDMaterial.cc
Go to the documentation of this file.
1 #include <ostream>
2 #include <string>
3 #include <vector>
4 
11 
12 using DDI::Material;
13 using namespace geant_units::operators;
14 
15 DDMaterial::DDMaterial() : DDBase< DDName, std::unique_ptr<Material>>() { }
16 
26  : DDBase< DDName, std::unique_ptr<Material>>()
27 {
28  create( name );
29 }
30 
44 DDMaterial::DDMaterial( const DDName & name, double z, double a, double d )
45  : DDBase< DDName, std::unique_ptr<Material>>()
46 {
47  create( name, std::make_unique<Material>( z, a, d ));
48 }
49 
63  : DDBase< DDName, std::unique_ptr<Material>>()
64 {
65  create( name, std::make_unique<Material>( 0, 0, density ));
66 }
67 
71 int
72 DDMaterial::addMaterial( const DDMaterial & m, double fm )
73 {
74  if( m.ddname() == ddname()) {
75  throw cms::Exception("DDException") << "DDMaterial::addMaterial(..): name-clash\n trying to add material " << m << " to itself! ";
76  }
77  rep().addMaterial( m, fm );
78  return rep().noOfConstituents();
79 }
80 
81 int
83 {
84  return rep().noOfConstituents();
85 }
86 
88 {
89  return rep().constituent( i );
90 }
91 
92 double
94 {
95  return rep().a();
96 }
97 
98 double
100 {
101  return rep().z();
102 }
103 
104 double DDMaterial::density() const
105 {
106  return rep().density();
107 }
108 
109 namespace {
110  std::ostream &doStream(std::ostream & os, const DDMaterial & mat, int level)
111  {
112  ++level;
113  if (mat) {
114  os << '[' << mat.name() <<']' << " z=" << mat.z()
115  << " a=" << convertUnitsTo(1._g_per_mole, mat.a()) << "*g/mole"
116  << " d=" << convertUnitsTo(1._g_per_cm3 , mat.density()) << "*g/cm3";
117  std::string s(2*level,' ');
118  for (int i=0; i<mat.noOfConstituents(); ++i) {
120  os << std::endl << s << i+1 << " : fm=" << f.second
121  << " : ";
122  doStream(os, f.first, level);
123  }
124  }
125  else
126  os << "* material not declared * ";
127  --level;
128  return os;
129  }
130 }
131 
132 std::ostream & operator<<(std::ostream & os, const DDMaterial & mat)
133 {
134  return doStream( os, mat, 0 );
135 }
Definition: DDBase.h:10
double a() const
returns the atomic mass
Definition: DDMaterial.cc:93
constexpr NumType convertUnitsTo(long double desiredUnits, NumType val)
Definition: GeantUnits.h:128
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:43
DDMaterial()
Creates a uninitialized reference-object (see DDLogicalPart documentation for details on reference ob...
Definition: DDMaterial.cc:15
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
const DDI::rep_traits< DDName, std::unique_ptr< DDI::Material > >::reference rep() const
Definition: DDBase.h:80
int addMaterial(const DDMaterial &m, double fm)
adds a material to the mixture proportional to its fraction-mass fm.
Definition: DDMaterial.cc:72
double z() const
retruns the atomic number
Definition: DDMaterial.cc:99
FractionV::value_type constituent(int i) const
returns the i-th compound material and its fraction-mass
Definition: DDMaterial.cc:87
double f[11][100]
double density() const
returns the density
Definition: DDMaterial.cc:104
int noOfConstituents() const
returns the number of compound materials or 0 for elementary materials
Definition: DDMaterial.cc:82
friend std::ostream & operator<<(std::ostream &, const DDMaterial &)
Definition: DDMaterial.cc:132
const N & ddname() const
Definition: DDBase.h:76
void create(const DDName &name, std::unique_ptr< DDI::Material > vals)
Definition: DDBase.h:121