CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/DetectorDescription/Core/src/Ellipsoid.cc

Go to the documentation of this file.
00001 #include "DetectorDescription/Core/src/Ellipsoid.h"
00002 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00003 #include <iostream>
00004 #include <cmath>
00005 
00006 void DDI::Ellipsoid::stream(std::ostream & os) const
00007 {
00008    os << " xSemiAxis[cm]=" << p_[0]/cm
00009       << " ySemiAxis[cm]=" << p_[1]/cm
00010       << " zSemiAxis" << p_[2]/cm
00011       << " zBottomCut" << p_[3]/cm
00012       << " zTopCut" << p_[4]/cm;
00013 }
00014 
00015 double DDI::Ellipsoid::halfVol(double dz, double maxz)  const {
00016   double volume(0.);
00017   double z(0.);
00018   double x;
00019   double y;
00020   double c2 = p_[2] * p_[2];
00021   for (;z <= maxz; z=z+dz) {
00022     // what is x here? what is y?  This assumes a TRIANGLE approximation 
00023     // This assumes that I can estimate the decrease in x and y at current z
00024     // at current z, x is the projection down to the x axis.
00025     // x = a * sqrt(1-z^2 / c^2 )
00026     // unneccesary paranoia?
00027     if ( z*z / c2 >  1.0 ) {
00028       std::cout << "error!" << std::endl;
00029       exit(0);
00030     }
00031     x = p_[0] * sqrt( 1 - z*z/c2);
00032     y = p_[1] * sqrt( 1 - z*z/c2);
00033 //     if (dispcount < 100)
00034 //     std::cout << "x = " << x << " y = " << y << " z = " << z << std::endl;
00035 //     ++dispcount;
00036     volume = volume + Geom::pi() * dz * x  * y;
00037   }
00038 //   std::cout << " x = " << x;
00039 //   std::cout << " y = " << y;
00040 //   std::cout << " z = " << z;
00041 //   std::cout << " vol = " << volume << std::endl;
00042   return volume;
00043 }
00044 
00045 double DDI::Ellipsoid::volume() const { 
00046   double volume(0.);
00047   // default if both p_[3] and p_[4] are 0
00048   volume = 4./3. * Geom::pi() * p_[0] * p_[1] * p_[2];
00049   if ( p_[3] > 0.0 ) {
00050     //fail
00051     std::cout << "FAIL: p_[3] > 0.0" <<std::endl;
00052   } else if ( p_[4] < 0.0 ) {
00053     //fail
00054     std::cout << "FAIL: p_[4] <  0.0" <<std::endl;
00055   } else if ( p_[3] < 0. && p_[4] > 0. ) {
00056     volume = halfVol (p_[4]/100000., p_[4]) + halfVol (std::fabs(p_[3]/100000.), std::fabs(p_[3]));
00057   } else if ( p_[3] < 0. ) {
00058     volume = volume / 2 + halfVol(std::fabs(p_[3]/100000.), std::fabs(p_[3]));
00059   } else if ( p_[4] > 0. ) {
00060     volume = volume / 2 + halfVol (p_[4]/100000., p_[4]);
00061   }
00062   return volume; 
00063 
00064 }