Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-04 02:02:27

0001 #include "DetectorDescription/Core/interface/Sphere.h"
0002 #include "DataFormats/Math/interface/GeantUnits.h"
0003 
0004 #include <cmath>
0005 #include <ostream>
0006 #include <vector>
0007 
0008 #include "DetectorDescription/Core/interface/DDSolidShapes.h"
0009 #include "DetectorDescription/Core/interface/Solid.h"
0010 
0011 using namespace geant_units;
0012 using namespace geant_units::operators;
0013 
0014 DDI::Sphere::Sphere(
0015     double innerRadius, double outerRadius, double startPhi, double deltaPhi, double startTheta, double deltaTheta)
0016     : Solid(DDSolidShape::ddsphere) {
0017   p_.emplace_back(innerRadius);
0018   p_.emplace_back(outerRadius);
0019   p_.emplace_back(startPhi);
0020   p_.emplace_back(deltaPhi);
0021   p_.emplace_back(startTheta);
0022   p_.emplace_back(deltaTheta);
0023 }
0024 
0025 void DDI::Sphere::stream(std::ostream& os) const {
0026   os << " innerRadius=" << convertMmToCm(p_[0]) << " outerRadius=" << convertMmToCm(p_[1])
0027      << " startPhi=" << convertRadToDeg(p_[2]) << " deltaPhi=" << convertRadToDeg(p_[3])
0028      << " startTheta=" << convertRadToDeg(p_[4]) << " deltaTheta=" << convertRadToDeg(p_[5]);
0029 }
0030 
0031 double DDI::Sphere::volume() const {
0032   double volume(0.);
0033   if (std::fabs(p_[3]) <= 2._pi && std::fabs(p_[5]) <= piRadians) {
0034     volume = std::fabs((p_[1] * p_[1] * p_[1] - p_[0] * p_[0] * p_[0]) / 3. *
0035                        (std::cos(p_[4] + p_[5]) - std::cos(p_[4])) * p_[3]);
0036   } else if (std::fabs(p_[3]) <= 2._pi && std::fabs(p_[5]) > piRadians) {
0037     volume = std::fabs((p_[1] * p_[1] * p_[1] - p_[0] * p_[0] * p_[0]) / 3. *
0038                        (std::cos(p_[4] + p_[5] - 180._deg) - std::cos(p_[4])) * p_[3]);
0039   } else if (std::fabs(p_[3]) > 2._pi && std::fabs(p_[5]) <= piRadians) {
0040     volume = std::fabs((p_[1] * p_[1] * p_[1] - p_[0] * p_[0] * p_[0]) / 3. *
0041                        (std::cos(p_[4] + p_[5]) - std::cos(p_[4])) * (p_[3] - p_[2]));
0042   }
0043   return volume;
0044 }