File indexing completed on 2024-12-22 23:29:37
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 testDDFilteredViewGet : public CppUnit::TestFixture {
0018 CPPUNIT_TEST_SUITE(testDDFilteredViewGet);
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(testDDFilteredViewGet);
0039
0040 void testDDFilteredViewGet::setUp() {
0041 fileName_ = edm::FileInPath("Geometry/CMSCommonData/data/dd4hep/cmsExtendedGeometry2021.xml").fullPath();
0042 }
0043
0044 void testDDFilteredViewGet::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
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 double xi = fview.getNextValue("TrackerXi");
0072 CPPUNIT_ASSERT(std::abs(radLength - refRadLength_) < 10e-6);
0073 CPPUNIT_ASSERT(std::abs(xi - refXi_) < 10e-6);
0074
0075 std::cout << "TrackerRadLength = " << radLength << "\nTrackerXi = " << xi << "\n";
0076 auto vals = fview.getValuesNS<std::string>("TrackerRadLength");
0077 for (auto i : vals)
0078 std::cout << "TrackerRadLength = " << i << "\n";
0079
0080 std::cout << "\n==== Let's go to #45\n";
0081 fview.goTo(testPos);
0082 printMe(fview);
0083
0084 int i = 0;
0085 for (auto it : fview.navPos()) {
0086 CPPUNIT_ASSERT(it == testPos[i++]);
0087 }
0088 i = 0;
0089 for (auto it : testPos) {
0090 CPPUNIT_ASSERT(it == refPos_[i++]);
0091 }
0092
0093
0094 std::cout << "\n==== Let's go to Muon\n";
0095 fview.goTo({0, 0, 8});
0096 printMe(fview);
0097
0098 CPPUNIT_ASSERT(fview.fullName() == "muonBase:MUON");
0099
0100
0101 fview.next(0);
0102 printMe(fview);
0103
0104
0105 int startLevel = fview.level();
0106
0107 count = 1;
0108
0109 do {
0110 std::cout << "#" << count++ << ": ";
0111 std::cout << "started at level " << startLevel << "\n";
0112 printMe(fview);
0113
0114 } while (fview.next(0) && fview.level() < startLevel);
0115
0116 std::cout << "\n==== Continue iteration\n";
0117
0118 count = 1;
0119 fview.next(0);
0120 startLevel = fview.level();
0121 printMe(fview);
0122
0123 do {
0124 std::cout << "#" << count++;
0125 std::cout << " started at level " << startLevel << ":\n";
0126 printMe(fview);
0127 } while (fview.next(0) && fview.level() < startLevel);
0128
0129 fview.next(0);
0130 printMe(fview);
0131
0132 std::cout << "\n==== Let's do it again, go to Muon\n";
0133 fview.goTo({0, 0, 8});
0134 printMe(fview);
0135 CPPUNIT_ASSERT(fview.name() == "MUON");
0136
0137
0138 fview.next(0);
0139 printMe(fview);
0140
0141
0142 startLevel = fview.level();
0143
0144 count = 1;
0145
0146 do {
0147 std::cout << "#" << count++ << ": ";
0148 std::cout << "started at level " << startLevel << "\n";
0149 printMe(fview);
0150
0151 } while (fview.next(0) && fview.level() < startLevel);
0152
0153 fview.goTo({0, 0, 8, 0});
0154 printMe(fview);
0155 fview.findSpecPar("CopyNoTag", "CopyNoOffset");
0156
0157 auto tag = fview.getNextValue("CopyNoTag");
0158 auto offset = fview.getNextValue("CopyNoOffset");
0159 std::cout << "CopyNoTag = " << tag << "\n";
0160 std::cout << "CopyNoOffset = " << fview.getNextValue("CopyNoOffset") << "\n";
0161 CPPUNIT_ASSERT(refCopyNoTag_ == tag);
0162 CPPUNIT_ASSERT(refCopyNoOffset_ == offset);
0163
0164 const auto& nodes = fview.history();
0165 int ctr(0);
0166 for (const auto& t : nodes.tags) {
0167 std::cout << t << ": " << nodes.offsets[ctr] << ", " << nodes.copyNos[ctr] << "\n";
0168 CPPUNIT_ASSERT(refCopyNoTag_ == t);
0169 CPPUNIT_ASSERT(refCopyNoOffset_ == nodes.offsets[ctr]);
0170 CPPUNIT_ASSERT(refCopyNo_ == nodes.copyNos[ctr]);
0171 ctr++;
0172 }
0173 }
0174
0175 void testDDFilteredViewGet::printMe(const cms::DDFilteredView& fview) {
0176 std::cout << ">>> " << fview.level() << " level: " << fview.name() << " is a "
0177 << cms::dd::name(cms::DDSolidShapeMap, fview.shape()) << "\n";
0178 std::cout << "Full path to it is " << fview.path() << "\n";
0179
0180 auto copies = fview.copyNos();
0181 std::cout << " copy Nos: ";
0182 std::for_each(copies.rbegin(), copies.rend(), [](const auto& it) { std::cout << it << ", "; });
0183 std::cout << "\n levels : ";
0184 for (auto it : fview.navPos()) {
0185 std::cout << it << ", ";
0186 }
0187 std::cout << "\n";
0188 }