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 <string>
0009 #include <memory>
0010
0011 #include "cppunit/TestAssert.h"
0012 #include "cppunit/TestFixture.h"
0013
0014 using namespace cms;
0015 using namespace std;
0016
0017 class testDDFilteredView : public CppUnit::TestFixture {
0018 CPPUNIT_TEST_SUITE(testDDFilteredView);
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 string fileName_;
0029 vector<double> refdattl_;
0030 vector<string> refsattl_;
0031 vector<double> refdLongFL_;
0032 vector<string> refsLongFL_;
0033 };
0034
0035 CPPUNIT_TEST_SUITE_REGISTRATION(testDDFilteredView);
0036
0037 void testDDFilteredView::setUp() {
0038 fileName_ = edm::FileInPath("Geometry/CMSCommonData/data/dd4hep/cmsExtendedGeometry2021.xml").fullPath();
0039 refdattl_ = {0.000809653, 0.000713002, 0.000654918, 0.000602767, 0.000566295, 0.000541647, 0.000516174, 0.000502512,
0040 0.000504225, 0.000506212, 0.000506275, 0.000487621, 0.000473034, 0.000454002, 0.000442383, 0.000441043,
0041 0.000443609, 0.000433124, 0.000440188, 0.000435257, 0.000439224, 0.000431385, 0.00041707, 0.000415677,
0042 0.000408389, 0.000400293, 0.000400989, 0.000395417, 0.00038936, 0.000383942};
0043 refsattl_ = {"0.8096535E-03/cm", "0.7130018E-03/cm", "0.6549183E-03/cm", "0.6027666E-03/cm", "0.5662951E-03/cm",
0044 "0.5416475E-03/cm", "0.5161745E-03/cm", "0.5025120E-03/cm", "0.5042249E-03/cm", "0.5062117E-03/cm",
0045 "0.5062750E-03/cm", "0.4876212E-03/cm", "0.4730343E-03/cm", "0.4540021E-03/cm", "0.4423832E-03/cm",
0046 "0.4410428E-03/cm", "0.4436095E-03/cm", "0.4331241E-03/cm", "0.4401879E-03/cm", "0.4352570E-03/cm",
0047 "0.4392237E-03/cm", "0.4313847E-03/cm", "0.4170704E-03/cm", "0.4156771E-03/cm", "0.4083890E-03/cm",
0048 "0.4002930E-03/cm", "0.4009888E-03/cm", "0.3954170E-03/cm", "0.3893599E-03/cm", "0.3839422E-03/cm"};
0049 refdLongFL_ = {
0050 227.993, 237.122, 241.701, 256.48, 266.754, 275.988, 276.982, 284.989, 286.307, 290.478, 290.5, 292, 295.5};
0051 refsLongFL_ = {"227.9925651",
0052 "237.1215213",
0053 "241.7005445",
0054 "256.47981",
0055 "266.7540042",
0056 "275.987715",
0057 "276.9823529",
0058 "284.9889299",
0059 "286.3065327",
0060 "290.4779412",
0061 "290.5",
0062 "292.0",
0063 "295.5"};
0064 }
0065
0066 void testDDFilteredView::checkFilteredView() {
0067 unique_ptr<DDDetector> det = make_unique<DDDetector>("DUMMY", fileName_);
0068 DDFilteredView fview(det.get(), det->description()->worldVolume());
0069 fview.next(0);
0070 std::cout << fview.name() << " is a " << cms::dd::name(cms::DDSolidShapeMap, fview.shape()) << "\n";
0071 std::cout << "Full path to it is " << fview.path() << "\n";
0072 auto copyNos = fview.copyNos();
0073 if (dd4hep::isA<dd4hep::Box>(fview.solid()))
0074 cout << "It's a Box\n";
0075 fview.parent();
0076 std::cout << fview.name() << " is a " << cms::dd::name(cms::DDSolidShapeMap, fview.shape()) << "\n";
0077
0078 std::cout << "All SpecPar names:\n";
0079 for (auto const n : det->specpars().names())
0080 std::cout << n << "\n";
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094 cout << "Get attl from hf as double values:\n";
0095 vector<double> attl = fview.get<vector<double>>("hf", "attl");
0096 int count(0);
0097 for (double i : attl) {
0098 i *= dd4hep::cm;
0099 std::cout << "attl " << i << " == " << refdattl_[count] << "\n";
0100 CPPUNIT_ASSERT(abs(i - refdattl_[count]) < 10e-6);
0101 count++;
0102 }
0103
0104 std::cout << "Get LongFL from hf as double values:\n";
0105 count = 0;
0106 std::vector<double> LongFL = fview.get<std::vector<double>>("hf", "LongFL");
0107 for (double i : LongFL) {
0108 i /= dd4hep::cm;
0109 std::cout << "LongFL " << i << " == " << refdLongFL_[count] << "\n";
0110 CPPUNIT_ASSERT(abs(i - refdLongFL_[count]) < 10e-2);
0111 count++;
0112 }
0113
0114 std::cout << "Get LongFL from hf as numerically evaluated string values:\n";
0115 count = 0;
0116 std::vector<std::string> sLongFL = fview.get<std::vector<std::string>>("hf", "LongFL");
0117 for (auto const& i : sLongFL) {
0118 double dblVal = std::stod(i) / dd4hep::cm;
0119 std::cout << "LongFL " << dblVal << " == " << refsLongFL_[count] << "\n";
0120 CPPUNIT_ASSERT(abs(dblVal - std::stod(refsLongFL_[count])) < 10e-6);
0121 count++;
0122 }
0123
0124 cout << "Get CSC upar parameters for ChamberSpecs_ME11 as a vector of strings:\n";
0125 std::vector<std::string> cscsPars = fview.get<std::vector<std::string>>("ChamberSpecs_ME11", "upar");
0126 for (auto const& i : cscsPars) {
0127 std::cout << i << ", ";
0128 count++;
0129 }
0130 std::cout << "\n";
0131
0132 cout << "Get CSC upar parameters for ChamberSpecs_ME11 as a vector of doubles:\n";
0133 std::vector<double> upars = fview.get("ChamberSpecs_ME11", "upar");
0134 for (auto const& i : upars) {
0135 std::cout << i << ", ";
0136 count++;
0137 }
0138 std::cout << "\n";
0139 }