Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-10 02:21:26

0001 #include <CLHEP/Units/SystemOfUnits.h>
0002 #include "DetectorDescription/Core/interface/DDSolid.h"
0003 #include "DetectorDescription/Core/interface/DDSolidShapes.h"
0004 #include "DetectorDescription/Core/interface/Sphere.h"
0005 #include "Utilities/Testing/interface/CppUnit_testdriver.icpp"
0006 #include "cppunit/extensions/HelperMacros.h"
0007 #include <G4Sphere.hh>
0008 #include <cmath>
0009 #include <limits>
0010 #include <string>
0011 
0012 using namespace std;
0013 using CLHEP::cm;
0014 using CLHEP::cm3;
0015 using CLHEP::deg;
0016 
0017 class testSphere : public CppUnit::TestFixture {
0018   CPPUNIT_TEST_SUITE(testSphere);
0019   CPPUNIT_TEST(matched_g4_and_dd);
0020 
0021   CPPUNIT_TEST_SUITE_END();
0022 
0023 public:
0024   void matched_g4_and_dd(void);
0025 };
0026 
0027 void testSphere::matched_g4_and_dd(void) {
0028   double innerRadius = 10. * cm;
0029   double outerRadius = 15. * cm;
0030   double startPhi = 0. * deg;
0031   double deltaPhi = 90. * deg;
0032   double startTheta = 0. * deg;
0033   double deltaTheta = 180. * deg;
0034   string name("fred1");
0035 
0036   G4Sphere g4(name, innerRadius, outerRadius, startPhi, deltaPhi, startTheta, deltaTheta);
0037   DDI::Sphere dd(innerRadius, outerRadius, startPhi, deltaPhi, startTheta, deltaTheta);
0038   DDSphere dds = DDSolidFactory::sphere(name, innerRadius, outerRadius, startPhi, deltaPhi, startTheta, deltaTheta);
0039   cout << endl;
0040   dd.stream(cout);
0041   cout << endl;
0042 
0043   double g4v = g4.GetCubicVolume() / cm3;
0044   double ddv = dd.volume() / cm3;
0045   double ddsv = dds.volume() / cm3;
0046 
0047   cout << "\tg4 volume = " << g4v << " cm3" << endl;
0048   cout << "\tdd volume = " << ddv << " cm3" << endl;
0049   cout << "\tDD Information: " << dds << " vol=" << ddsv << " cm3" << endl;
0050 
0051   CPPUNIT_ASSERT(abs(g4v - ddv) < numeric_limits<float>::epsilon());
0052   CPPUNIT_ASSERT(abs(g4v - ddsv) < numeric_limits<float>::epsilon());
0053 }
0054 
0055 CPPUNIT_TEST_SUITE_REGISTRATION(testSphere);