File indexing completed on 2024-04-06 12:05:30
0001 #include <cppunit/extensions/HelperMacros.h>
0002
0003 #include "DetectorDescription/DDCMS/interface/DDFilteredView.h"
0004 #include "DetectorDescription/DDCMS/interface/DDDetector.h"
0005 #include "FWCore/ParameterSet/interface/FileInPath.h"
0006 #include "DD4hep/Detector.h"
0007
0008 #include <iostream>
0009
0010 #include "cppunit/TestAssert.h"
0011 #include "cppunit/TestFixture.h"
0012
0013 using namespace cms;
0014 using namespace std;
0015
0016 class testDDSolid : public CppUnit::TestFixture {
0017 CPPUNIT_TEST_SUITE(testDDSolid);
0018 CPPUNIT_TEST(checkDDSolid);
0019 CPPUNIT_TEST_SUITE_END();
0020
0021 public:
0022 void setUp() override;
0023 void tearDown() override {}
0024 void checkDDSolid();
0025
0026 private:
0027 string fileName_;
0028 };
0029
0030 CPPUNIT_TEST_SUITE_REGISTRATION(testDDSolid);
0031
0032 void testDDSolid::setUp() {
0033 fileName_ = edm::FileInPath("DetectorDescription/DDCMS/data/cms-test-shapes.xml").fullPath();
0034 }
0035
0036 void testDDSolid::checkDDSolid() {
0037 unique_ptr<DDDetector> det = make_unique<DDDetector>("DUMMY", fileName_);
0038 DDFilteredView fview(det.get(), det->description()->worldVolume());
0039 int counter = 0;
0040 while (fview.next(0)) {
0041 std::cout << fview.path() << "\n";
0042 std::string title(fview.solid()->GetTitle());
0043 std::string name(cms::dd::name(cms::DDSolidShapeMap, fview.shape()));
0044 std::cout << "#" << counter++ << ": " << fview.name() << "[" << fview.copyNum() << "]"
0045 << " is a " << title << " == " << name << "\n";
0046 CPPUNIT_ASSERT(title.compare(name) == 0);
0047
0048 if ((dd4hep::isA<dd4hep::SubtractionSolid>(fview.solid()) and
0049 not dd4hep::isA<dd4hep::TruncatedTube>(fview.solid()) and
0050 not dd4hep::isA<dd4hep::PseudoTrap>(fview.solid()))) {
0051 DDSolid solid(fview.solid());
0052 auto solidA = solid.solidA();
0053 std::cout << "Solid A is a " << solidA->GetTitle() << "\n";
0054 if (dd4hep::isA<dd4hep::ConeSegment>(dd4hep::Solid(solidA))) {
0055 cout << " is a ConeSegment:\n";
0056 for (auto const& i : solidA.dimensions())
0057 cout << i / dd4hep::cm << " cm, ";
0058 }
0059 cout << "\n";
0060 DDSolid a(solidA);
0061 for (auto const& i : a.parameters())
0062 cout << i / dd4hep::cm << " cm, ";
0063 cout << "\n";
0064
0065 auto solidB = solid.solidB();
0066 std::cout << "Solid B is a " << solidB->GetTitle() << "\n";
0067 if (dd4hep::isA<dd4hep::ConeSegment>(dd4hep::Solid(solidB))) {
0068 cout << " is a ConeSegment:\n";
0069 for (auto const& i : solidB.dimensions())
0070 cout << i / dd4hep::cm << " cm, ";
0071 }
0072 cout << "\n";
0073 DDSolid b(solidB);
0074 for (auto const& i : b.parameters())
0075 cout << i / dd4hep::cm << " cm, ";
0076 cout << "\n";
0077 }
0078 }
0079 }