test
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.
3 #include "CLHEP/Units/GlobalSystemOfUnits.h"
4 #include <cmath>
5 
6 using DDI::Polyhedra;
7 
8 using std::fabs;
9 using std::cos;
10 using std::sin;
11 
12 Polyhedra::Polyhedra( int sides, double startPhi, double deltaPhi,
13  const std::vector<double> & z,
14  const std::vector<double> & rmin,
15  const std::vector<double> & rmax) : Solid(ddpolyhedra_rrz)
16 {
17  p_.push_back(sides);
18  p_.push_back(startPhi);
19  p_.push_back(deltaPhi);
20  if((z.size()!=rmin.size()) || (z.size()!=rmax.size()) )
21  {
22  throw cms::Exception("DDException") << "Polyhedra(..): std::vectors z,rmin,rmax not of same length";
23  }
24  else
25  {
26  for(unsigned int i=0;i<z.size(); ++i)
27  {
28  p_.push_back(z[i]);
29  p_.push_back(rmin[i]);
30  p_.push_back(rmax[i]);
31  }
32  }
33 }
34 
35 
36 Polyhedra::Polyhedra( int sides, double startPhi, double deltaPhi,
37  const std::vector<double> & z,
38  const std::vector<double> & r) : Solid(ddpolyhedra_rz)
39 {
40  p_.push_back(sides);
41  p_.push_back(startPhi);
42  p_.push_back(deltaPhi);
43  if(z.size()!=r.size())
44  {
45  throw cms::Exception("DDException") << "Polyhedra(..): std::vectors z,rmin,rmax not of same length";
46  }
47  else
48  {
49  for(unsigned int i=0;i<z.size(); ++i)
50  {
51  p_.push_back(z[i]);
52  p_.push_back(r[i]);
53  }
54  }
55 }
56 
57 double Polyhedra::volume() const
58 {
59  double volume=0;
60  /* 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 */
61 
62  /* 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 */
63 
64  //FIXME: rz, rrz !!
65  if (shape()==ddpolyhedra_rrz)
66  {
67  int loop = (p_.size()-3)/3 -1;
68  double sec=0;
69  double a = 0.5*fabs(p_[2]/rad / p_[0]);
70  DCOUT('V',"Polyhedra::volume(), loop=" << loop << " alph[deg]=" << a/deg);
71  int i=3;
72  for (int j=3; j<(loop+3); ++j)
73  {
74  double dz= fabs(p_[i]-p_[i+3]);
75  DCOUT('v', " dz[m] =" << dz/m);
76  /*
77  double ai, aii;
78  ai = (p_[i+2]*p_[i+2] - p_[i+1]*p_[i+1]);
79  aii = (p_[i+5]*p_[i+5] - p_[i+4]*p_[i+4]);
80  DCOUT('v', " rx_i[m] =" << p_[i+2]/m << " rm_i[m] =" << p_[i+1]/m);
81  DCOUT('v', " rx_ii[m]=" << p_[i+5]/m << " rm_ii[m]=" << p_[i+4]/m);
82  //double s = dz/3.*(ai*bi + 0.5*(ai*bii + bi*aii) + aii*bii);
83  double s = dz/3.*sin(a)*cos(a)*(ai + aii + 0.5*(ai+aii));
84  */
85  double z=dz/2.;
86 
87  double H1=(p_[i+2]-p_[i+1])*cos(a);
88  double Bl1=p_[i+1]*sin(a);
89  double Tl1=p_[i+2]*sin(a);
90 
91  double H2=(p_[i+5]-p_[i+4])*cos(a);
92  double Bl2=p_[i+4]*sin(a);
93  double Tl2=p_[i+5]*sin(a);
94 
95  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;
96  s = s*p_[0];
97  sec += s;
98  i+=3;
99  }
100  volume=sec;
101  return volume;
102  }
103  int sides=int(p_[0]);
104  //double phiFrom=p_[1]/rad;
105  double phiDelta=p_[2]/rad;
106 
107  double zBegin=0;
108  double zEnd=0;
109  double rBegin=0;
110  double rEnd=0;
111  double z=0;
112  double alpha=0;
113  double beta=0;
114  unsigned int i=3;
115 
116  alpha=fabs(phiDelta);
117  beta=0.5*(alpha/sides);
118 
119  while(i<(p_.size()-2))
120  {
121  zBegin=p_[i];
122  zEnd=p_[i+2];
123  rBegin=p_[i+1];
124  rEnd=p_[i+3];
125  z=zBegin-zEnd;
126 
127  /* volume for 1 side (we multiplie by cos(beta)sin(beta)sides later*/
128  double volume1=(rEnd*rEnd+rBegin*rBegin+rBegin*rEnd)*z/3;
129 
130  volume=volume+volume1;
131 
132  i=i+2;
133  }
134 
135  /* last line (goes from last z/r value to first */
136 
137  i=p_.size()-2;
138  zBegin=p_[i];
139  zEnd=p_[3];
140  rBegin=p_[i+1];
141  rEnd=p_[4];
142  z=zBegin-zEnd;
143 
144  double volume2=(rEnd*rEnd+rBegin*rBegin+rBegin*rEnd)*z/3;
145 
146  volume=volume+volume2;
147 
148  volume=fabs(sides*cos(beta)*sin(beta)*volume);
149 
150  return volume;
151 }
const double beta
int i
Definition: DBlmapReader.cc:9
float alpha
Definition: AMPTWrapper.h:95
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
int loop
CMSSW
float float float z
double volume() const
Definition: Polyhedra.cc:57
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:12
double a
Definition: hdecay.h:121
std::vector< double > p_
Definition: Solid.h:32
DDSolidShape shape() const
Definition: Solid.h:24
#define DCOUT(M_v_Y, M_v_S)
Definition: DDdebug.h:53