CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/DetectorDescription/Core/src/Polycone.cc

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