CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Polycone.cc
Go to the documentation of this file.
3 
4 #include <cassert>
5 #include <cmath>
6 
11 
12 using DDI::Polycone;
13 using namespace geant_units::operators;
14 
15 Polycone::Polycone(double startPhi,
16  double deltaPhi,
17  const std::vector<double>& z,
18  const std::vector<double>& rmin,
19  const std::vector<double>& rmax)
21  p_.emplace_back(startPhi);
22  p_.emplace_back(deltaPhi);
23  if ((z.size() != rmin.size()) || (z.size() != rmax.size())) {
24  throw cms::Exception("DDException") << "Polycone(..): std::vectors z,rmin,rmax not of same length";
25  } else {
26  for (unsigned int i = 0; i < z.size(); ++i) {
27  p_.emplace_back(z[i]);
28  p_.emplace_back(rmin[i]);
29  p_.emplace_back(rmax[i]);
30  }
31  }
32 }
33 
34 Polycone::Polycone(double startPhi, double deltaPhi, const std::vector<double>& z, const std::vector<double>& r)
36  p_.emplace_back(startPhi);
37  p_.emplace_back(deltaPhi);
38  if (z.size() != r.size()) {
39  throw cms::Exception("DDException") << "Polycone(..): std::vectors z,rmin,rmax not of same length";
40  } else {
41  for (unsigned int i = 0; i < z.size(); ++i) {
42  p_.emplace_back(z[i]);
43  p_.emplace_back(r[i]);
44  }
45  }
46 }
47 
48 double Polycone::volume() const {
49  double result = -1.;
51  unsigned int loop = (p_.size() - 2) / 3 - 1;
52  assert(loop > 0);
53  double sec = 0;
54  int i = 2;
55  for (unsigned int j = 2; j < (loop + 2); ++j) {
56  double dz = std::fabs(p_[i] - p_[i + 3]);
57  double v_min = dz * 1_pi / 3. * (p_[i + 1] * p_[i + 1] + p_[i + 4] * p_[i + 4] + p_[i + 1] * p_[i + 4]);
58  double v_max = dz * 1_pi / 3. * (p_[i + 2] * p_[i + 2] + p_[i + 5] * p_[i + 5] + p_[i + 2] * p_[i + 5]);
59  double s = v_max - v_min;
60  //assert(s>=0);
61  sec += s;
62  i += 3;
63  }
64  result = sec * std::fabs(p_[1]) / 2._pi;
65  }
66 
68  double volume = 0;
69  double phiFrom = p_[0];
70  double phiTo = p_[0] + p_[1];
71  double slice = (std::fabs(phiFrom - phiTo)) / 2_pi;
72  double zBegin = 0;
73  double zEnd = 0;
74  double rBegin = 0;
75  double rEnd = 0;
76  double z = 0;
77  unsigned int i = 2;
78 
79  while (i < (p_.size() - 2)) {
80  zBegin = p_[i];
81  zEnd = p_[i + 2];
82  rBegin = p_[i + 1];
83  rEnd = p_[i + 3];
84  z = zBegin - zEnd;
85 
86  /* for calculation of volume1 look at calculation of DDConsImpl of a volume1. Furthermore z can be smaller than zero. This makes sense since volumes we have to substract */
87  double volume1 = (rEnd * rEnd + rBegin * rBegin + rBegin * rEnd) * z / 3;
88  volume = volume + volume1;
89  i = i + 2;
90  }
91 
92  /* last line (goes from last z/r value to first */
93  i = p_.size() - 2;
94  zBegin = p_[i];
95  zEnd = p_[2];
96  rBegin = p_[i + 1];
97  rEnd = p_[3];
98  z = zBegin - zEnd;
99 
100  double volume2 = (rEnd * rEnd + rBegin * rBegin + rBegin * rEnd) * z / 3;
101  volume = volume + volume2;
102  volume = std::fabs(slice * 1_pi * volume);
103  result = volume;
104  }
105  return result;
106 }
107 
108 void DDI::Polycone::stream(std::ostream& os) const {
109  os << " startPhi[deg]=" << convertRadToDeg(p_[0]) << " dPhi[deg]=" << convertRadToDeg(p_[1]) << " Sizes[cm]=";
110  for (unsigned k = 2; k < p_.size(); ++k)
111  os << convertMmToCm(p_[k]) << " ";
112 }
DDSolidShape shape_
Definition: Solid.h:29
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
assert(be >=bs)
Polycone(double startPhi, double deltaPhi, const std::vector< double > &z, const std::vector< double > &rmin, const std::vector< double > &rmax)
Definition: Polycone.cc:15
tuple result
Definition: mps_fire.py:311
DDSolidShape
Definition: DDSolidShapes.h:6
void stream(std::ostream &) const override
Definition: Polycone.cc:108
double volume() const override
Definition: Polycone.cc:48
std::vector< double > p_
Definition: Solid.h:30
constexpr NumType convertMmToCm(NumType millimeters)
Definition: GeantUnits.h:63