Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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/TruncTubs.h"
0005 #include "SimG4Core/Geometry/interface/DDG4SolidConverter.h"
0006 #include "Utilities/Testing/interface/CppUnit_testdriver.icpp"
0007 #include "cppunit/extensions/HelperMacros.h"
0008 #include <G4VSolid.hh>
0009 #include <cmath>
0010 #include <limits>
0011 #include <string>
0012 
0013 using namespace std;
0014 
0015 class testTruncTubs : public CppUnit::TestFixture {
0016   CPPUNIT_TEST_SUITE(testTruncTubs);
0017   CPPUNIT_TEST(matched_g4_and_dd);
0018 
0019   CPPUNIT_TEST_SUITE_END();
0020 
0021 public:
0022   void matched_g4_and_dd(void);
0023 };
0024 
0025 void testTruncTubs::matched_g4_and_dd(void) {
0026   double zHalf = 50.0 * cm;
0027   double rIn = 20.0 * cm;
0028   double rOut = 40.0 * cm;
0029   double startPhi = 0.0 * deg;
0030   double deltaPhi = 90.0 * deg;
0031   double cutAtStart = 25.0 * cm;
0032   double cutAtDelta = 35.0 * cm;
0033   bool cutInside = true;
0034   string name("fred1");
0035 
0036   DDI::TruncTubs dd(zHalf, rIn, rOut, startPhi, deltaPhi, cutAtStart, cutAtDelta, cutInside);
0037   DDTruncTubs dds =
0038       DDSolidFactory::truncTubs(name, zHalf, rIn, rOut, startPhi, deltaPhi, cutAtStart, cutAtDelta, cutInside);
0039   G4VSolid *g4 = DDG4SolidConverter::trunctubs(dds);
0040   cout << endl;
0041   dd.stream(cout);
0042   cout << endl;
0043 
0044   double g4v = g4->GetCubicVolume() / cm3;
0045   double ddv = dd.volume() / cm3;
0046   double ddsv = dds.volume() / cm3;
0047 
0048   cout << "\tg4 volume = " << g4v << " cm3" << endl;
0049   cout << "\tdd volume = " << ddv << " cm3" << endl;
0050   cout << "\tDD Information: " << dds << " vol=" << ddsv << " cm3" << endl;
0051 
0052   if (ddv > 0) {
0053     CPPUNIT_ASSERT(abs(g4v - ddv) < numeric_limits<float>::epsilon());
0054     CPPUNIT_ASSERT(abs(g4v - ddsv) < numeric_limits<float>::epsilon());
0055   }
0056 }
0057 
0058 CPPUNIT_TEST_SUITE_REGISTRATION(testTruncTubs);