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 testDDFilteredViewFind : public CppUnit::TestFixture {
0018   CPPUNIT_TEST_SUITE(testDDFilteredViewFind);
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   int refCopyNoTag_ = 1000;
0032   int refCopyNoOffset_ = 100;
0033   int refCopyNo_ = 1;
0034   std::string fileName_;
0035   std::vector<int> refPos_{0, 0, 6, 2, 2};
0036 };
0037 
0038 CPPUNIT_TEST_SUITE_REGISTRATION(testDDFilteredViewFind);
0039 
0040 void testDDFilteredViewFind::setUp() {
0041   fileName_ = edm::FileInPath("Geometry/CMSCommonData/data/dd4hep/cmsExtendedGeometry2021.xml").fullPath();
0042 }
0043 
0044 void testDDFilteredViewFind::checkFilteredView() {
0045   std::unique_ptr<DDDetector> det = std::make_unique<DDDetector>("DUMMY", fileName_);
0046   DDFilteredView fview(det.get(), det->description()->worldVolume());
0047 
0048   int count = 1;
0049   auto testPos = fview.navPos();
0050   while (fview.next(0)) {
0051     std::cout << "#" << count << ": ";
0052     printMe(fview);
0053 
0054     if (count == 45) {
0055       testPos = fview.navPos();
0056     }
0057     if (count == 50) {
0058       break;
0059     }
0060     count++;
0061   }
0062 
0063   // world_volume/OCMS_1/CMSE_1/Tracker_1/PixelBarrel_1/pixbarlayer0:PixelBarrelLayer0_1/PixelBarrelLadderFull0_6/PixelBarrelModuleBoxFull_1/PixelBarrelModuleFullPlus_4/PixelBarrelSensorFull_1/PixelBarrelActiveFull0_1
0064   //
0065   std::vector<int> activeVol{0, 0, 6, 2, 93, 12, 1, 7, 1, 0};
0066   fview.goTo(activeVol);
0067   printMe(fview);
0068   fview.findSpecPar("TrackerRadLength", "TrackerXi");
0069 
0070   double radLength = fview.getNextValue("TrackerRadLength");
0071   std::cout << radLength << "\n";
0072   double xi = fview.getNextValue("TrackerXi");
0073   CPPUNIT_ASSERT(abs(radLength - refRadLength_) < 10e-6);
0074   CPPUNIT_ASSERT(abs(xi - refXi_) < 10e-6);
0075 
0076   std::cout << "TrackerRadLength = " << radLength << "\nTrackerXi = " << xi << "\n";
0077 
0078   std::cout << "\n==== Let's go to #45\n";
0079   fview.goTo(testPos);
0080   printMe(fview);
0081 
0082   int i = 0;
0083   for (auto it : fview.navPos()) {
0084     CPPUNIT_ASSERT(it == testPos[i++]);
0085   }
0086   i = 0;
0087   for (auto it : testPos) {
0088     CPPUNIT_ASSERT(it == refPos_[i++]);
0089   }
0090 
0091   // Start with Muon
0092   std::cout << "\n==== Let's go to Muon\n";
0093   fview.goTo({0, 0, 8});
0094   printMe(fview);
0095 
0096   CPPUNIT_ASSERT(fview.fullName() == "muonBase:MUON");
0097 
0098   // Go to the first daughter
0099   fview.next(0);
0100   printMe(fview);
0101 
0102   // Use it as an escape level
0103   int startLevel = fview.level();
0104 
0105   count = 1;
0106 
0107   do {
0108     std::cout << "#" << count++ << ": ";
0109     std::cout << "started at level " << startLevel << "\n";
0110     printMe(fview);
0111 
0112   } while (fview.next(0) && fview.level() < startLevel);
0113 
0114   std::cout << "\n==== Continue iteration\n";
0115 
0116   count = 1;
0117   fview.next(0);
0118   startLevel = fview.level();
0119   printMe(fview);
0120 
0121   do {
0122     std::cout << "#" << count++;
0123     std::cout << " started at level " << startLevel << ":\n";
0124     printMe(fview);
0125   } while (fview.next(0) && fview.level() < startLevel);
0126 
0127   fview.next(0);
0128   printMe(fview);
0129 
0130   std::cout << "\n==== Let's do it again, go to Muon\n";
0131   fview.goTo({0, 0, 8});
0132   printMe(fview);
0133   CPPUNIT_ASSERT(fview.name() == "MUON");
0134 
0135   // Go to the first daughter
0136   fview.next(0);
0137   printMe(fview);
0138 
0139   // Use it as an escape level
0140   startLevel = fview.level();
0141 
0142   count = 1;
0143 
0144   do {
0145     std::cout << "#" << count++ << ": ";
0146     std::cout << "started at level " << startLevel << "\n";
0147     printMe(fview);
0148 
0149   } while (fview.next(0) && fview.level() < startLevel);
0150 
0151   fview.goTo({0, 0, 8, 0});
0152   printMe(fview);
0153   fview.findSpecPar("CopyNoTag", "CopyNoOffset");
0154 
0155   auto tag = fview.getNextValue("CopyNoTag");
0156   auto offset = fview.getNextValue("CopyNoOffset");
0157   std::cout << "CopyNoTag = " << tag << "\n";
0158   std::cout << "CopyNoOffset = " << fview.getNextValue("CopyNoOffset") << "\n";
0159   CPPUNIT_ASSERT(refCopyNoTag_ == tag);
0160   CPPUNIT_ASSERT(refCopyNoOffset_ == offset);
0161 
0162   const auto& nodes = fview.history();
0163   int ctr(0);
0164   for (const auto& t : nodes.tags) {
0165     std::cout << t << ": " << nodes.offsets[ctr] << ", " << nodes.copyNos[ctr] << "\n";
0166     CPPUNIT_ASSERT(refCopyNoTag_ == t);
0167     CPPUNIT_ASSERT(refCopyNoOffset_ == nodes.offsets[ctr]);
0168     CPPUNIT_ASSERT(refCopyNo_ == nodes.copyNos[ctr]);
0169     ctr++;
0170   }
0171 }
0172 
0173 void testDDFilteredViewFind::printMe(const cms::DDFilteredView& fview) {
0174   std::cout << ">>> " << fview.level() << " level: " << fview.name() << " is a "
0175             << cms::dd::name(cms::DDSolidShapeMap, fview.shape()) << "\n";
0176   std::cout << "Full path to it is " << fview.path() << "\n";
0177 
0178   auto copies = fview.copyNos();
0179   std::cout << "    copy Nos: ";
0180   std::for_each(copies.rbegin(), copies.rend(), [](const auto& it) { std::cout << it << ", "; });
0181   std::cout << "\n    levels  : ";
0182   for (auto it : fview.navPos()) {
0183     std::cout << it << ", ";
0184   }
0185   std::cout << "\n";
0186 }