CMS 3D CMS Logo

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