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 
16 
26 
40 DDMaterial::DDMaterial(const DDName &name, double z, double a, double d) : DDBase<DDName, std::unique_ptr<Material>>() {
41  create(name, std::make_unique<Material>(z, a, d));
42 }
43 
57  create(name, std::make_unique<Material>(0, 0, density));
58 }
59 
63 int DDMaterial::addMaterial(const DDMaterial &m, double fm) {
64  if (m.ddname() == ddname()) {
65  throw cms::Exception("DDException") << "DDMaterial::addMaterial(..): name-clash\n trying to add material "
66  << m << " to itself! ";
67  }
68  rep().addMaterial(m, fm);
69  return rep().noOfConstituents();
70 }
71 
72 int DDMaterial::noOfConstituents() const { return rep().noOfConstituents(); }
73 
74 DDMaterial::FractionV::value_type DDMaterial::constituent(int i) const { return rep().constituent(i); }
75 
76 double DDMaterial::a() const { return rep().a(); }
77 
78 double DDMaterial::z() const { return rep().z(); }
79 
80 double DDMaterial::density() const { return rep().density(); }
81 
82 namespace {
83  std::ostream &doStream(std::ostream &os, const DDMaterial &mat, int level) {
84  ++level;
85  if (mat) {
86  os << '[' << mat.name() << ']' << " z=" << mat.z() << " a=" << convertUnitsTo(1._g_per_mole, mat.a()) << "*g/mole"
87  << " d=" << convertUnitsTo(1._g_per_cm3, mat.density()) << "*g/cm3";
88  std::string s(2 * level, ' ');
89  for (int i = 0; i < mat.noOfConstituents(); ++i) {
91  os << std::endl << s << i + 1 << " : fm=" << f.second << " : ";
92  doStream(os, f.first, level);
93  }
94  } else
95  os << "* material not declared * ";
96  --level;
97  return os;
98  }
99 } // namespace
100 
101 std::ostream &operator<<(std::ostream &os, const DDMaterial &mat) { return doStream(os, mat, 0); }
Definition: DDBase.h:10
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:45
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:17
const DDI::rep_traits< DDName, std::unique_ptr< DDI::Material > >::reference rep() const
Definition: DDBase.h:64
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
constexpr NumType convertUnitsTo(double desiredUnits, NumType val)
Definition: GeantUnits.h:73
int addMaterial(const DDMaterial &m, double fm)
adds a material to the mixture proportional to its fraction-mass fm.
Definition: DDMaterial.cc:63
std::ostream & operator<<(std::ostream &os, const DDMaterial &mat)
Definition: DDMaterial.cc:101
double f[11][100]
d
Definition: ztail.py:151
double density() const
returns the density
Definition: DDMaterial.cc:80
double z() const
retruns the atomic number
Definition: DDMaterial.cc:78
FractionV::value_type constituent(int i) const
returns the i-th compound material and its fraction-mass
Definition: DDMaterial.cc:74
int noOfConstituents() const
returns the number of compound materials or 0 for elementary materials
Definition: DDMaterial.cc:72
double a
Definition: hdecay.h:121
double a() const
returns the atomic mass
Definition: DDMaterial.cc:76
void create(const DDName &name, std::unique_ptr< DDI::Material > vals)
Definition: DDBase.h:95