CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Polycone.cc
Go to the documentation of this file.
2 
3 #include <assert.h>
5 #include "CLHEP/Units/GlobalSystemOfUnits.h"
6 #include "CLHEP/Units/GlobalPhysicalConstants.h"
7 #include <cmath>
8 
9 using DDI::Polycone;
10 
11 Polycone::Polycone (double startPhi, double deltaPhi,
12  const std::vector<double> & z,
13  const std::vector<double> & rmin,
14  const std::vector<double> & rmax) : Solid (ddpolycone_rrz)
15 {
16  p_.push_back(startPhi);
17  p_.push_back(deltaPhi);
18  if((z.size()!=rmin.size()) || (z.size()!=rmax.size()) )
19  {
20  throw cms::Exception("DDException") << "Polycone(..): std::vectors z,rmin,rmax not of same length";
21  }
22  else
23  {
24  for(unsigned int i=0;i<z.size(); ++i)
25  {
26  p_.push_back(z[i]);
27  p_.push_back(rmin[i]);
28  p_.push_back(rmax[i]);
29  }
30  }
31 }
32 
33 
34 Polycone::Polycone (double startPhi, double deltaPhi,
35  const std::vector<double> & z,
36  const std::vector<double> & r) : Solid (ddpolycone_rz)
37 {
38  p_.push_back(startPhi);
39  p_.push_back(deltaPhi);
40  if(z.size()!=r.size())
41  {
42  throw cms::Exception("DDException") << "Polycone(..): std::vectors z,rmin,rmax not of same length";
43  }
44  else
45  {
46  for( unsigned int i = 0; i < z.size(); ++i )
47  {
48  p_.push_back(z[i]);
49  p_.push_back(r[i]);
50  }
51  }
52 }
53 
54 double Polycone::volume() const
55 {
56  double result = -1.;
57  if (shape_==ddpolycone_rrz)
58  {
59  unsigned int loop = (p_.size()-2)/3 -1;
60  assert(loop>0);
61  double sec=0;
62  DCOUT('V',"Polycone::volume(), loop=" << loop);
63  int i=2;
64  for (unsigned int j=2; j<(loop+2); ++j) {
65  double dz= std::fabs(p_[i]-p_[i+3]);
66  DCOUT('v', " dz=" << dz/cm << "cm zi=" << p_[i] << " zii=" << p_[i+3] );
67  double v_min = dz * pi/3. *( p_[i+1]*p_[i+1] + p_[i+4]*p_[i+4]
68  + p_[i+1]*p_[i+4] );
69  DCOUT('v', " v_min" << v_min/cm3 << "cm3 rmi=" << p_[i+1]);
70  double v_max = dz * pi/3. *( p_[i+2]*p_[i+2] + p_[i+5]*p_[i+5]
71  + p_[i+2]*p_[i+5] );
72  DCOUT('v', " v_max" << v_max/cm3 << "cm3");
73  double s = v_max - v_min;
74  //assert(s>=0);
75  sec += s;
76  i += 3;
77  }
78  result = sec * std::fabs(p_[1])/rad/(2.*pi);
79  }
80 
81  if (shape_==ddpolycone_rz)
82  {
83  double volume=0;
84  double phiFrom=p_[0]/rad;
85  double phiTo=(p_[0]+p_[1])/rad;
86  double slice=(std::fabs(phiFrom-phiTo))/(2*pi);
87  double zBegin=0;
88  double zEnd=0;
89  double rBegin=0;
90  double rEnd=0;
91  double z=0;
92  unsigned int i=2;
93 
94  while(i<(p_.size()-2))
95  {
96  zBegin=p_[i];
97  zEnd=p_[i+2];
98  rBegin=p_[i+1];
99  rEnd=p_[i+3];
100  z=zBegin-zEnd;
101 
102  /* 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 */
103  double volume1=(rEnd*rEnd+rBegin*rBegin+rBegin*rEnd)*z/3;
104  volume=volume+volume1;
105  i=i+2;
106  }
107 
108  /* last line (goes from last z/r value to first */
109  i=p_.size()-2;
110  zBegin=p_[i];
111  zEnd=p_[2];
112  rBegin=p_[i+1];
113  rEnd=p_[3];
114  z=zBegin-zEnd;
115 
116  double volume2=(rEnd*rEnd+rBegin*rBegin+rBegin*rEnd)*z/3;
117  volume=volume+volume2;
118  volume=std::fabs(slice*pi*volume);
119  result = volume;
120  }
121  return result;
122 }
int i
Definition: DBlmapReader.cc:9
double volume() const
Definition: Polycone.cc:54
DDSolidShape shape_
Definition: Solid.h:31
assert(m_qm.get())
int loop
CMSSW
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:11
const Double_t pi
tuple result
Definition: query.py:137
int j
Definition: DBlmapReader.cc:9
std::vector< double > p_
Definition: Solid.h:32
#define DCOUT(M_v_Y, M_v_S)
Definition: DDdebug.h:53