Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-04 02:03:01

0001 #include "CLHEP/Units/GlobalSystemOfUnits.h"
0002 #include "DetectorDescription/Core/interface/DDSolid.h"
0003 #include "DetectorDescription/Core/interface/DDSolidShapes.h"
0004 #include "DetectorDescription/Core/interface/Box.h"
0005 #include "Utilities/Testing/interface/CppUnit_testdriver.icpp"
0006 #include "cppunit/extensions/HelperMacros.h"
0007 #include <G4Box.hh>
0008 #include <cmath>
0009 #include <limits>
0010 #include <string>
0011 
0012 using namespace std;
0013 
0014 class testBox : public CppUnit::TestFixture {
0015   CPPUNIT_TEST_SUITE(testBox);
0016   CPPUNIT_TEST(matched_g4_and_dd);
0017 
0018   CPPUNIT_TEST_SUITE_END();
0019 
0020 public:
0021   void matched_g4_and_dd(void);
0022 };
0023 
0024 void testBox::matched_g4_and_dd(void) {
0025   double xHalfLength(2. * cm);
0026   double yHalfLength(2. * cm);
0027   double zHalfLength(2. * cm);
0028   string name("fred1");
0029 
0030   G4Box g4(name, xHalfLength, yHalfLength, zHalfLength);
0031   DDI::Box dd(xHalfLength, yHalfLength, zHalfLength);
0032   DDBox dds = DDSolidFactory::box(name, xHalfLength, yHalfLength, zHalfLength);
0033   cout << endl;
0034   dd.stream(cout);
0035   cout << endl;
0036 
0037   double g4v = g4.GetCubicVolume() / cm3;
0038   double ddv = dd.volume() / cm3;
0039   double ddsv = dds.volume() / cm3;
0040 
0041   cout << "\tg4 volume = " << g4.GetCubicVolume() / cm3 << " cm3" << endl;
0042   cout << "\tdd volume = " << dd.volume() / cm3 << " cm3" << endl;
0043   cout << "\tDD Information: " << dds << " vol= " << dds.volume() << endl;
0044 
0045   CPPUNIT_ASSERT(abs(g4v - ddv) < numeric_limits<float>::epsilon());
0046   CPPUNIT_ASSERT(abs(g4v - ddsv) < numeric_limits<float>::epsilon());
0047 }
0048 
0049 CPPUNIT_TEST_SUITE_REGISTRATION(testBox);