Go to the documentation of this file.00001 #include "DetectorDescription/Core/src/Polyhedra.h"
00002 #include <string>
00003
00004 #include "DetectorDescription/Base/interface/DDdebug.h"
00005 #include "DetectorDescription/Base/interface/DDException.h"
00006 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00007 #include<cmath>
00008
00009 using DDI::Polyhedra;
00010
00011 using std::fabs;
00012 using std::cos;
00013 using std::sin;
00014
00015 Polyhedra::Polyhedra ( int sides, double startPhi, double deltaPhi,
00016 const std::vector<double> & z,
00017 const std::vector<double> & rmin,
00018 const std::vector<double> & rmax)
00019 : Solid(ddpolyhedra_rrz)
00020 {
00021 p_.push_back(sides);
00022 p_.push_back(startPhi);
00023 p_.push_back(deltaPhi);
00024 if((z.size()!=rmin.size()) || (z.size()!=rmax.size()) )
00025 {
00026 std::string s=std::string("Polyhedra(..): std::vectors z,rmin,rmax not of same length");
00027 throw DDException(s);
00028 }
00029 else
00030 {
00031 for(unsigned int i=0;i<z.size(); ++i)
00032 {
00033 p_.push_back(z[i]);
00034 p_.push_back(rmin[i]);
00035 p_.push_back(rmax[i]);
00036 }
00037 }
00038 }
00039
00040
00041 Polyhedra::Polyhedra ( int sides, double startPhi, double deltaPhi,
00042 const std::vector<double> & z,
00043 const std::vector<double> & r)
00044 : Solid(ddpolyhedra_rz)
00045 {
00046 p_.push_back(sides);
00047 p_.push_back(startPhi);
00048 p_.push_back(deltaPhi);
00049 if(z.size()!=r.size())
00050 {
00051 std::string s=std::string("Polyhedra(..): std::vectors z,rmin,rmax not of same length");
00052 throw DDException(s);
00053 }
00054 else
00055 {
00056 for(unsigned int i=0;i<z.size(); ++i)
00057 {
00058 p_.push_back(z[i]);
00059 p_.push_back(r[i]);
00060 }
00061 }
00062 }
00063
00064 double Polyhedra::volume() const
00065 {
00066 double volume=0;
00067
00068
00069
00070
00071
00072 if (shape()==ddpolyhedra_rrz) {
00073 int loop = (p_.size()-3)/3 -1;
00074 double sec=0;
00075 double a = 0.5*fabs(p_[2]/rad / p_[0]);
00076 DCOUT('V',"Polyhedra::volume(), loop=" << loop << " alph[deg]=" << a/deg);
00077 int i=3;
00078 for (int j=3; j<(loop+3); ++j) {
00079 double dz= fabs(p_[i]-p_[i+3]);
00080 DCOUT('v', " dz[m] =" << dz/m);
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 double z=dz/2.;
00091
00092 double H1=(p_[i+2]-p_[i+1])*cos(a);
00093 double Bl1=p_[i+1]*sin(a);
00094 double Tl1=p_[i+2]*sin(a);
00095
00096 double H2=(p_[i+5]-p_[i+4])*cos(a);
00097 double Bl2=p_[i+4]*sin(a);
00098 double Tl2=p_[i+5]*sin(a);
00099
00100 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;
00101 s = s*p_[0];
00102 sec += s;
00103 i+=3;
00104 }
00105 volume=sec;
00106 return volume;
00107 }
00108 int sides=int(p_[0]);
00109
00110 double phiDelta=p_[2]/rad;
00111
00112 double zBegin=0;
00113 double zEnd=0;
00114 double rBegin=0;
00115 double rEnd=0;
00116 double z=0;
00117 double alpha=0;
00118 double beta=0;
00119 unsigned int i=3;
00120
00121 alpha=fabs(phiDelta);
00122 beta=0.5*(alpha/sides);
00123
00124 while(i<(p_.size()-2))
00125 {
00126 zBegin=p_[i];
00127 zEnd=p_[i+2];
00128 rBegin=p_[i+1];
00129 rEnd=p_[i+3];
00130 z=zBegin-zEnd;
00131
00132
00133 double volume1=(rEnd*rEnd+rBegin*rBegin+rBegin*rEnd)*z/3;
00134
00135 volume=volume+volume1;
00136
00137 i=i+2;
00138 }
00139
00140
00141
00142 i=p_.size()-2;
00143 zBegin=p_[i];
00144 zEnd=p_[3];
00145 rBegin=p_[i+1];
00146 rEnd=p_[4];
00147 z=zBegin-zEnd;
00148
00149 double volume2=(rEnd*rEnd+rBegin*rBegin+rBegin*rEnd)*z/3;
00150
00151 volume=volume+volume2;
00152
00153 volume=fabs(sides*cos(beta)*sin(beta)*volume);
00154
00155 return volume;
00156
00157
00158
00159 }