Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:51:46

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 <string>
0009 #include <memory>
0010 #include <vector>
0011 
0012 #include "cppunit/TestAssert.h"
0013 #include "cppunit/TestFixture.h"
0014 
0015 using namespace cms;
0016 
0017 class testDDFilteredViewGoTo : public CppUnit::TestFixture {
0018   CPPUNIT_TEST_SUITE(testDDFilteredViewGoTo);
0019   CPPUNIT_TEST(checkFilteredView);
0020   CPPUNIT_TEST_SUITE_END();
0021 
0022 public:
0023   void setUp() override;
0024   void tearDown() override {}
0025   void checkFilteredView();
0026 
0027 private:
0028   void printMe(const cms::DDFilteredView&);
0029   double refRadLength_ = 0.03142;
0030   double refXi_ = 6.24526e-05;
0031   std::string fileName_;
0032   std::vector<int> refPos_{0, 0, 6, 2, 2};
0033 };
0034 
0035 CPPUNIT_TEST_SUITE_REGISTRATION(testDDFilteredViewGoTo);
0036 
0037 void testDDFilteredViewGoTo::setUp() {
0038   fileName_ = edm::FileInPath("Geometry/CMSCommonData/data/dd4hep/cmsExtendedGeometry2021.xml").fullPath();
0039 }
0040 
0041 void testDDFilteredViewGoTo::checkFilteredView() {
0042   std::unique_ptr<DDDetector> det = std::make_unique<DDDetector>("DUMMY", fileName_);
0043   DDFilteredView fview(det.get(), det->description()->worldVolume());
0044 
0045   int count = 1;
0046   auto testPos = fview.navPos();
0047   while (fview.next(0)) {
0048     std::cout << "#" << count << ": ";
0049     printMe(fview);
0050 
0051     if (count == 45) {
0052       testPos = fview.navPos();
0053     }
0054     if (count == 50) {
0055       break;
0056     }
0057     count++;
0058   }
0059 
0060   // world_volume/OCMS_1/CMSE_1/Tracker_1/PixelBarrel_1/pixbarlayer0:PixelBarrelLayer0_1/PixelBarrelLadderFull0_6/PixelBarrelModuleBoxFull_1/PixelBarrelModuleFullPlus_4/PixelBarrelSensorFull_1/PixelBarrelActiveFull0_1
0061   //
0062   std::vector<int> activeVol{0, 0, 6, 2, 93, 12, 1, 7, 1, 0};
0063   fview.goTo(activeVol);
0064   printMe(fview);
0065 
0066   double radLength = fview.get<double>("TrackerRadLength");
0067   double xi = fview.getNextValue("TrackerXi");
0068   CPPUNIT_ASSERT(abs(radLength - refRadLength_) < 10e-6);
0069   CPPUNIT_ASSERT(abs(xi - refXi_) < 10e-6);
0070 
0071   std::cout << "TrackerRadLength = " << radLength << "\nTrackerXi = " << xi << "\n";
0072 
0073   std::cout << "\n==== Let's go to #45\n";
0074   fview.goTo(testPos);
0075   printMe(fview);
0076 
0077   int i = 0;
0078   for (auto it : fview.navPos()) {
0079     CPPUNIT_ASSERT(it == testPos[i++]);
0080   }
0081   i = 0;
0082   for (auto it : testPos) {
0083     CPPUNIT_ASSERT(it == refPos_[i++]);
0084   }
0085 
0086   // Start with Tracker
0087   std::cout << "\n==== Let's go to Tracker\n";
0088   fview.goTo({0, 0, 6});
0089   CPPUNIT_ASSERT(fview.fullName() == "tracker:Tracker");
0090   printMe(fview);
0091 
0092   // Go to the first daughter
0093   fview.next(0);
0094   printMe(fview);
0095 
0096   // Use it as an escape level
0097   int startLevel = fview.level();
0098 
0099   count = 1;
0100 
0101   do {
0102     std::cout << "#" << count++ << ": ";
0103     std::cout << "started at level " << startLevel << "\n";
0104     printMe(fview);
0105 
0106   } while (fview.next(0) && fview.level() < startLevel);
0107 
0108   std::cout << "\n==== Continue iteration\n";
0109 
0110   count = 1;
0111   fview.next(0);
0112   startLevel = fview.level();
0113   printMe(fview);
0114 
0115   do {
0116     std::cout << "#" << count++;
0117     std::cout << " started at level " << startLevel << ":\n";
0118     printMe(fview);
0119   } while (fview.next(0) && fview.level() < startLevel);
0120 
0121   fview.next(0);
0122   printMe(fview);
0123 
0124   std::cout << "\n==== Let's do it again, go to Tracker\n";
0125   fview.goTo({0, 0, 6});
0126   CPPUNIT_ASSERT(fview.name() == "Tracker");
0127   printMe(fview);
0128 
0129   // Go to the first daughter
0130   fview.next(0);
0131   printMe(fview);
0132 
0133   // Use it as an escape level
0134   startLevel = fview.level();
0135 
0136   count = 1;
0137 
0138   do {
0139     std::cout << "#" << count++ << ": ";
0140     std::cout << "started at level " << startLevel << "\n";
0141     printMe(fview);
0142 
0143   } while (fview.next(0) && fview.level() < startLevel);
0144 }
0145 
0146 void testDDFilteredViewGoTo::printMe(const cms::DDFilteredView& fview) {
0147   std::cout << ">>> " << fview.level() << " level: " << fview.name() << " is a "
0148             << cms::dd::name(cms::DDSolidShapeMap, fview.shape()) << "\n";
0149   std::cout << "Full path to it is " << fview.path() << "\n";
0150 
0151   auto copies = fview.copyNos();
0152   std::cout << "    copy Nos: ";
0153   std::for_each(copies.rbegin(), copies.rend(), [](const auto& it) { std::cout << it << ", "; });
0154   std::cout << "\n    levels  : ";
0155   for (auto it : fview.navPos()) {
0156     std::cout << it << ", ";
0157   }
0158   std::cout << "\n";
0159 }