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