CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/DetectorDescription/Core/src/Polycone.cc

Go to the documentation of this file.
00001 #include "DetectorDescription/Core/src/Polycone.h" 
00002 
00003 #include <string>
00004 #include <assert.h>
00005 #include "DetectorDescription/Base/interface/DDdebug.h"
00006 
00007 #include "DetectorDescription/Base/interface/DDException.h"
00008 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00009 #include "CLHEP/Units/GlobalPhysicalConstants.h"
00010 #include<cmath>
00011 
00012 using DDI::Polycone;
00013 
00014 
00015 
00016 Polycone::Polycone ( double startPhi, double deltaPhi,
00017               const std::vector<double> & z,
00018               const std::vector<double> & rmin,
00019               const std::vector<double> & rmax)
00020  : Solid(ddpolycone_rrz)              
00021 {
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("Polycone(..): 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 Polycone::Polycone ( double startPhi, double deltaPhi,
00042               const std::vector<double> & z,
00043               const std::vector<double> & r)
00044  : Solid(ddpolycone_rz)       
00045 {
00046   p_.push_back(startPhi);
00047   p_.push_back(deltaPhi);
00048   if(z.size()!=r.size())
00049   {
00050     std::string s=std::string("Polycone(..): std::vectors z,rmin,rmax not of same length");
00051     throw DDException(s);
00052   } 
00053   else
00054   {
00055     for(unsigned int i=0;i<z.size(); ++i)
00056     {
00057       p_.push_back(z[i]);
00058       p_.push_back(r[i]);
00059     }
00060   }
00061 }            
00062  
00063  
00064 double Polycone::volume() const 
00065 {
00066   double result = -1.;
00067   if (shape_==ddpolycone_rrz) {
00068    int loop = (p_.size()-2)/3 -1;
00069    assert(loop>0);
00070    double sec=0;
00071    DCOUT('V',"Polycone::volume(), loop=" << loop);
00072    int i=2;
00073    for (int j=2; j<(loop+2); ++j) {
00074      double dz= std::fabs(p_[i]-p_[i+3]);
00075       DCOUT('v', "   dz=" << dz/cm << "cm zi=" << p_[i] << " zii=" << p_[i+3] );
00076       double v_min = dz * pi/3. *(  p_[i+1]*p_[i+1] + p_[i+4]*p_[i+4]
00077                             + p_[i+1]*p_[i+4] );
00078       DCOUT('v', "   v_min" << v_min/cm3 << "cm3 rmi=" << p_[i+1]);                 
00079       double v_max = dz * pi/3. *(  p_[i+2]*p_[i+2] + p_[i+5]*p_[i+5]
00080                             + p_[i+2]*p_[i+5] );
00081       DCOUT('v', "   v_max" << v_max/cm3 << "cm3");                 
00082       double s = v_max - v_min;
00083       //assert(s>=0);
00084       sec += s;
00085       i += 3;                                                                                      
00086    }  
00087    result = sec * std::fabs(p_[1])/rad/(2.*pi);
00088   }
00089   
00090   if (shape_==ddpolycone_rz) {
00091     double volume=0;
00092     double phiFrom=p_[0]/rad;
00093     double phiTo=(p_[0]+p_[1])/rad;
00094     double slice=(std::fabs(phiFrom-phiTo))/(2*pi);
00095     double zBegin=0;
00096     double zEnd=0;
00097     double rBegin=0;
00098     double rEnd=0;
00099     double z=0;
00100     unsigned int i=2;
00101  
00102     while(i<(p_.size()-2))
00103     {
00104       zBegin=p_[i];
00105       zEnd=p_[i+2];
00106       rBegin=p_[i+1];
00107       rEnd=p_[i+3];
00108       z=zBegin-zEnd;
00109 
00110      /* 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 */
00111 
00112       double volume1=(rEnd*rEnd+rBegin*rBegin+rBegin*rEnd)*z/3;
00113 
00114       volume=volume+volume1;
00115 
00116       i=i+2;
00117     }
00118 
00119     /* last line (goes from last z/r value to first */
00120     i=p_.size()-2;
00121     zBegin=p_[i];
00122     zEnd=p_[2];
00123     rBegin=p_[i+1];
00124     rEnd=p_[3];
00125     z=zBegin-zEnd;
00126 
00127     double volume2=(rEnd*rEnd+rBegin*rBegin+rBegin*rEnd)*z/3;
00128 
00129 
00130     volume=volume+volume2;
00131   
00132     volume=std::fabs(slice*pi*volume);
00133 
00134     result = volume;
00135 
00136   }
00137   return result;
00138 }