CMS 3D CMS Logo

Polycone.cc
Go to the documentation of this file.
2 
3 #include <cassert>
4 #include <cmath>
5 
6 #include "CLHEP/Units/GlobalPhysicalConstants.h"
7 #include "CLHEP/Units/GlobalSystemOfUnits.h"
8 #include "CLHEP/Units/SystemOfUnits.h"
13 
14 using DDI::Polycone;
15 
16 Polycone::Polycone (double startPhi, double deltaPhi,
17  const std::vector<double> & z,
18  const std::vector<double> & rmin,
19  const std::vector<double> & rmax) : Solid (ddpolycone_rrz)
20 {
21  p_.emplace_back(startPhi);
22  p_.emplace_back(deltaPhi);
23  if((z.size()!=rmin.size()) || (z.size()!=rmax.size()) )
24  {
25  throw cms::Exception("DDException") << "Polycone(..): std::vectors z,rmin,rmax not of same length";
26  }
27  else
28  {
29  for(unsigned int i=0;i<z.size(); ++i)
30  {
31  p_.emplace_back(z[i]);
32  p_.emplace_back(rmin[i]);
33  p_.emplace_back(rmax[i]);
34  }
35  }
36 }
37 
38 
39 Polycone::Polycone (double startPhi, double deltaPhi,
40  const std::vector<double> & z,
41  const std::vector<double> & r) : Solid (ddpolycone_rz)
42 {
43  p_.emplace_back(startPhi);
44  p_.emplace_back(deltaPhi);
45  if(z.size()!=r.size())
46  {
47  throw cms::Exception("DDException") << "Polycone(..): std::vectors z,rmin,rmax not of same length";
48  }
49  else
50  {
51  for( unsigned int i = 0; i < z.size(); ++i )
52  {
53  p_.emplace_back(z[i]);
54  p_.emplace_back(r[i]);
55  }
56  }
57 }
58 
59 double Polycone::volume() const
60 {
61  double result = -1.;
62  if (shape_==ddpolycone_rrz)
63  {
64  unsigned int loop = (p_.size()-2)/3 -1;
65  assert(loop>0);
66  double sec=0;
67  int i=2;
68  for (unsigned int j=2; j<(loop+2); ++j) {
69  double dz= std::fabs(p_[i]-p_[i+3]);
70  double v_min = dz * pi/3. *( p_[i+1]*p_[i+1] + p_[i+4]*p_[i+4]
71  + p_[i+1]*p_[i+4] );
72  double v_max = dz * pi/3. *( p_[i+2]*p_[i+2] + p_[i+5]*p_[i+5]
73  + p_[i+2]*p_[i+5] );
74  double s = v_max - v_min;
75  //assert(s>=0);
76  sec += s;
77  i += 3;
78  }
79  result = sec * std::fabs(p_[1])/rad/(2.*pi);
80  }
81 
82  if (shape_==ddpolycone_rz)
83  {
84  double volume=0;
85  double phiFrom=p_[0]/rad;
86  double phiTo=(p_[0]+p_[1])/rad;
87  double slice=(std::fabs(phiFrom-phiTo))/(2*pi);
88  double zBegin=0;
89  double zEnd=0;
90  double rBegin=0;
91  double rEnd=0;
92  double z=0;
93  unsigned int i=2;
94 
95  while(i<(p_.size()-2))
96  {
97  zBegin=p_[i];
98  zEnd=p_[i+2];
99  rBegin=p_[i+1];
100  rEnd=p_[i+3];
101  z=zBegin-zEnd;
102 
103  /* 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 */
104  double volume1=(rEnd*rEnd+rBegin*rBegin+rBegin*rEnd)*z/3;
105  volume=volume+volume1;
106  i=i+2;
107  }
108 
109  /* last line (goes from last z/r value to first */
110  i=p_.size()-2;
111  zBegin=p_[i];
112  zEnd=p_[2];
113  rBegin=p_[i+1];
114  rEnd=p_[3];
115  z=zBegin-zEnd;
116 
117  double volume2=(rEnd*rEnd+rBegin*rBegin+rBegin*rEnd)*z/3;
118  volume=volume+volume2;
119  volume=std::fabs(slice*pi*volume);
120  result = volume;
121  }
122  return result;
123 }
124 
125 void DDI::Polycone::stream(std::ostream & os) const
126 {
127  os << " startPhi[deg]=" << p_[0]/deg
128  << " dPhi[deg]=" << p_[1]/deg
129  << " Sizes[cm]=";
130  for (unsigned k=2; k<p_.size(); ++k)
131  os << p_[k]/cm << " ";
132 }
DDSolidShape shape_
Definition: Solid.h:31
void stream(std::ostream &) const override
Definition: Polycone.cc:125
float float float z
Polycone(double startPhi, double deltaPhi, const std::vector< double > &z, const std::vector< double > &rmin, const std::vector< double > &rmax)
Definition: Polycone.cc:16
const Double_t pi
double volume() const override
Definition: Polycone.cc:59
int k[5][pyjets_maxn]
std::vector< double > p_
Definition: Solid.h:32