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/PseudoTrap.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 testPseudoTrap : public CppUnit::TestFixture {
0016   CPPUNIT_TEST_SUITE(testPseudoTrap);
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 testPseudoTrap::matched_g4_and_dd(void) {
0026   using CLHEP::m;
0027   double pDx1 = 0.293734 * m;  /**< Half-length along x at the surface positioned at -dz */
0028   double pDx2 = 1.86356 * m;   /**<  Half-length along x at the surface positioned at +dz */
0029   double pDy1 = 0.3000 * m;    /**<  Half-length along y at the surface positioned at -dz */
0030   double pDy2 = 0.3000 * m;    /**<  Half-length along y at the surface positioned at +dz */
0031   double pDz = 2.92934 * m;    /**< Half of the height of the pseudo trapezoid along z */
0032   double radius = -1.1350 * m; /**< radius of the cut-out (negative sign) or rounding (pos. sign) */
0033   bool atMinusZ = true;        /**< if true, the cut-out or rounding is applied at -dz,
0034                            else at +dz */
0035   string name("fred1");
0036 
0037   DDI::PseudoTrap dd(pDx1, pDx2, pDy1, pDy2, pDz, radius, atMinusZ);
0038   DDPseudoTrap dds = DDSolidFactory::pseudoTrap(name, pDx1, pDx2, pDy1, pDy2, pDz, radius, atMinusZ);
0039   G4VSolid *g4 = DDG4SolidConverter::pseudotrap(dds);
0040   cout << endl;
0041   dd.stream(cout);
0042   cout << endl;
0043 
0044   double g4v = g4->GetCubicVolume() / CLHEP::cm3;
0045   double ddv = dd.volume() / CLHEP::cm3;
0046   double ddsv = dds.volume() / CLHEP::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.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(testPseudoTrap);