CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Polyhedra.cc
Go to the documentation of this file.
2 #include <string>
3 
6 #include "CLHEP/Units/GlobalSystemOfUnits.h"
7 #include<cmath>
8 
9 using DDI::Polyhedra;
10 
11 using std::fabs;
12 using std::cos;
13 using std::sin;
14 
15 Polyhedra::Polyhedra ( int sides, 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_.push_back(sides);
22  p_.push_back(startPhi);
23  p_.push_back(deltaPhi);
24  if((z.size()!=rmin.size()) || (z.size()!=rmax.size()) )
25  {
26  std::string s=std::string("Polyhedra(..): std::vectors z,rmin,rmax not of same length");
27  throw DDException(s);
28  }
29  else
30  {
31  for(unsigned int i=0;i<z.size(); ++i)
32  {
33  p_.push_back(z[i]);
34  p_.push_back(rmin[i]);
35  p_.push_back(rmax[i]);
36  }
37  }
38 }
39 
40 
41 Polyhedra::Polyhedra ( int sides, double startPhi, double deltaPhi,
42  const std::vector<double> & z,
43  const std::vector<double> & r)
45 {
46  p_.push_back(sides);
47  p_.push_back(startPhi);
48  p_.push_back(deltaPhi);
49  if(z.size()!=r.size())
50  {
51  std::string s=std::string("Polyhedra(..): std::vectors z,rmin,rmax not of same length");
52  throw DDException(s);
53  }
54  else
55  {
56  for(unsigned int i=0;i<z.size(); ++i)
57  {
58  p_.push_back(z[i]);
59  p_.push_back(r[i]);
60  }
61  }
62 }
63 
64 double Polyhedra::volume() const
65 {
66  double volume=0;
67  /* the following assumption is made: there are at least 3 eaqual sides if there is a complete circle (this has to be done, otherwise you can not define a polygon in a circle */
68 
69  /* the calculation for the volume is similar as in the case of the polycone. However, the rotation is not defined as part of a circle, but as sides in a regular polygon (specified by parameter "sides"). The sides are defined betwee startPhi and endPhi and form triangles within the circle they are defined in. First we need to determine the aread of side. let alpha |startPhi-endPhi|. the half the angle of 1 side is beta=0.5*(alph/sides). If r is the raddius of the circle in which the regular polygon is defined, the are of such a side will be 0.5*(height side)*(base side)=0.5*(cos(beta)*r)*(2*sin(beta)*r)= cos(beta)sin(beta)*r*r. r is the radius that varies if we "walk" over the boundaries of the polygon that is described by the z and r values (this yields the same integral primitive as used with the Polycone. Read Polycone documentation in code first if you do not understand this */
70 
71  //FIXME: rz, rrz !!
72  if (shape()==ddpolyhedra_rrz) {
73  int loop = (p_.size()-3)/3 -1;
74  double sec=0;
75  double a = 0.5*fabs(p_[2]/rad / p_[0]);
76  DCOUT('V',"Polyhedra::volume(), loop=" << loop << " alph[deg]=" << a/deg);
77  int i=3;
78  for (int j=3; j<(loop+3); ++j) {
79  double dz= fabs(p_[i]-p_[i+3]);
80  DCOUT('v', " dz[m] =" << dz/m);
81  /*
82  double ai, aii;
83  ai = (p_[i+2]*p_[i+2] - p_[i+1]*p_[i+1]);
84  aii = (p_[i+5]*p_[i+5] - p_[i+4]*p_[i+4]);
85  DCOUT('v', " rx_i[m] =" << p_[i+2]/m << " rm_i[m] =" << p_[i+1]/m);
86  DCOUT('v', " rx_ii[m]=" << p_[i+5]/m << " rm_ii[m]=" << p_[i+4]/m);
87  //double s = dz/3.*(ai*bi + 0.5*(ai*bii + bi*aii) + aii*bii);
88  double s = dz/3.*sin(a)*cos(a)*(ai + aii + 0.5*(ai+aii));
89  */
90  double z=dz/2.;
91 
92  double H1=(p_[i+2]-p_[i+1])*cos(a);
93  double Bl1=p_[i+1]*sin(a);
94  double Tl1=p_[i+2]*sin(a);
95 
96  double H2=(p_[i+5]-p_[i+4])*cos(a);
97  double Bl2=p_[i+4]*sin(a);
98  double Tl2=p_[i+5]*sin(a);
99 
100  double s = (2*H1*Bl1+2*H1*Tl1)*z+(H1*Bl2-2*H1*Bl1+H1*Tl2-2*H1*Tl1+H2*Bl1+H2*Tl1+H2*Tl2-H2*Tl1)*z+(2/3)*(H2*Bl2-H2*Bl1-H1*Bl2+H1*Bl1-H1*Tl2+H1*Tl1)*z;
101  s = s*p_[0];
102  sec += s;
103  i+=3;
104  }
105  volume=sec;
106  return volume;
107  }
108  int sides=int(p_[0]);
109  //double phiFrom=p_[1]/rad;
110  double phiDelta=p_[2]/rad;
111 
112  double zBegin=0;
113  double zEnd=0;
114  double rBegin=0;
115  double rEnd=0;
116  double z=0;
117  double alpha=0;
118  double beta=0;
119  unsigned int i=3;
120 
121  alpha=fabs(phiDelta);
122  beta=0.5*(alpha/sides);
123 
124  while(i<(p_.size()-2))
125  {
126  zBegin=p_[i];
127  zEnd=p_[i+2];
128  rBegin=p_[i+1];
129  rEnd=p_[i+3];
130  z=zBegin-zEnd;
131 
132  /* volume for 1 side (we multiplie by cos(beta)sin(beta)sides later*/
133  double volume1=(rEnd*rEnd+rBegin*rBegin+rBegin*rEnd)*z/3;
134 
135  volume=volume+volume1;
136 
137  i=i+2;
138  }
139 
140  /* last line (goes from last z/r value to first */
141 
142  i=p_.size()-2;
143  zBegin=p_[i];
144  zEnd=p_[3];
145  rBegin=p_[i+1];
146  rEnd=p_[4];
147  z=zBegin-zEnd;
148 
149  double volume2=(rEnd*rEnd+rBegin*rBegin+rBegin*rEnd)*z/3;
150 
151  volume=volume+volume2;
152 
153  volume=fabs(sides*cos(beta)*sin(beta)*volume);
154 
155  return volume;
156 
157 
158 
159 }
const double beta
int i
Definition: DBlmapReader.cc:9
float alpha
Definition: AMPTWrapper.h:95
double deltaPhi(float phi1, float phi2)
Definition: VectorUtil.h:30
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
An exception for DDD errors.
Definition: DDException.h:23
double double double z
double volume() const
Definition: Polyhedra.cc:64
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
int j
Definition: DBlmapReader.cc:9
Polyhedra(int sides, double startPhi, double deltaPhi, const std::vector< double > &z, const std::vector< double > &rmin, const std::vector< double > &rmax)
Definition: Polyhedra.cc:15
double a
Definition: hdecay.h:121
std::vector< double > p_
Definition: Solid.h:41
DDSolidShape shape() const
Definition: Solid.h:30
string s
Definition: asciidump.py:422
#define DCOUT(M_v_Y, M_v_S)
Definition: DDdebug.h:53