File indexing completed on 2025-01-18 09:13:08
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Geometry/GeometryContext.hpp"
0013 #include "Acts/Plugins/DD4hep/DD4hepDetectorElement.hpp"
0014 #include "Acts/Surfaces/Surface.hpp"
0015 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0016
0017 #include <fstream>
0018 #include <iostream>
0019
0020 #include <DD4hep/DetElement.h>
0021 #include <DD4hep/Detector.h>
0022
0023 #include "DD4hep/DetFactoryHelper.h"
0024 #include "XML/Utilities.h"
0025 #include "XMLFragments.hpp"
0026
0027 Acts::GeometryContext tContext;
0028
0029 const char* cylinder_xml =
0030 R""""(
0031 <detectors>
0032 <detector id="1" name="Cylinder" type="Cylinder">
0033 <type_flags type="DetType_TRACKER"/>
0034 <tubs name="Cylinder" rmin="10*cm" rmax="11*cm" dz="100*cm" material="Vacuum" sensitive="true"/>
0035 </detector>
0036 </detectors>
0037 )"""";
0038
0039 const char* sectoral_cylinder_xml =
0040 R""""(
0041 <detectors>
0042 <detector id="1" name="SectoralCylinder" type="Cylinder">
0043 <type_flags type="DetType_TRACKER"/>
0044 <tubs name="Cylinder" rmin="10*cm" rmax="11*cm" dz="100*cm" phimin="0.1*rad" phimax="0.8*rad" material="Vacuum" sensitive="true"/>
0045 </detector>
0046 </detectors>
0047 )"""";
0048
0049 const char* disc_xml =
0050 R""""(
0051 <detectors>
0052 <detector id="1" name="Disc" type="Disc">
0053 <type_flags type="DetType_TRACKER"/>
0054 <tubs name="Disc" rmin="10*cm" rmax="90*cm" dz="1*cm" material="Vacuum" sensitive="true"/>
0055 </detector>
0056 </detectors>
0057 )"""";
0058
0059 const char* sectoral_disc_xml =
0060 R""""(
0061 <detectors>
0062 <detector id="1" name="SectoralDisc" type="Disc">
0063 <type_flags type="DetType_TRACKER"/>
0064 <tubs name="Disc" rmin="10*cm" rmax="90*cm" dz="1*cm" phimin="0.*rad" phimax="1.5*rad" material="Vacuum" sensitive="true"/>
0065 </detector>
0066 </detectors>
0067 )"""";
0068
0069 const char* rectangle_xml =
0070 R""""(
0071 <detectors>
0072 <detector id="1" name="Rectangle" type="Rectangle">
0073 <type_flags type="DetType_TRACKER"/>
0074 <box name="Rectangle" dx="10*cm" dy="90*cm" dz="0.1*cm" cx="1.*cm" cy="2.*cm" cz="3.*cm" material="Vacuum" sensitive="true"/>
0075 </detector>
0076 </detectors>
0077 )"""";
0078
0079 const char* trapezoid_xml =
0080 R""""(
0081 <detectors>
0082 <detector id="1" name="Trapezoid" type="Trapezoid">
0083 <type_flags type="DetType_TRACKER"/>
0084 <trap name="Trapezoid" x1="10*cm" x2="20*cm" dy="30*cm" dz="0.1*cm" cx="2.*cm" cy="3.*cm" cz="4.*cm" material="Vacuum" sensitive="true"/>
0085 </detector>
0086 </detectors>
0087 )"""";
0088
0089 BOOST_AUTO_TEST_SUITE(DD4hepPlugin)
0090
0091 BOOST_AUTO_TEST_CASE(DD4hepPluginDetectorElementCylinder) {
0092 std::ofstream cxml;
0093 cxml.open("Cylinder.xml");
0094 cxml << head_xml;
0095 cxml << cylinder_xml;
0096 cxml << end_xml;
0097 cxml.close();
0098
0099 auto lcdd = &(dd4hep::Detector::getInstance());
0100 lcdd->fromCompact("Cylinder.xml");
0101 lcdd->volumeManager();
0102 lcdd->apply("DD4hepVolumeManager", 0, nullptr);
0103
0104 auto world = lcdd->world();
0105
0106 std::shared_ptr<Acts::DD4hepDetectorElement> cylindricalElement = nullptr;
0107 for (const auto& [chn, child] : world.children()) {
0108 cylindricalElement =
0109 std::make_shared<Acts::DD4hepDetectorElement>(child, "XYZ", 10.);
0110 }
0111
0112 BOOST_REQUIRE_NE(cylindricalElement, nullptr);
0113
0114 const auto& surface = cylindricalElement->surface();
0115 BOOST_CHECK_EQUAL(surface.type(), Acts::Surface::SurfaceType::Cylinder);
0116 BOOST_CHECK(
0117 surface.transform(tContext).isApprox(Acts::Transform3::Identity()));
0118 auto boundValues = surface.bounds().values();
0119 CHECK_CLOSE_ABS(boundValues[0u], 105., 1e-10);
0120 CHECK_CLOSE_ABS(boundValues[1u], 1000., 1e-10);
0121 lcdd->destroyInstance();
0122 }
0123
0124 BOOST_AUTO_TEST_CASE(DD4hepPluginDetectorElementSectoralCylinder) {
0125 std::ofstream cxml;
0126 cxml.open("SectoralCylinder.xml");
0127 cxml << head_xml;
0128 cxml << sectoral_cylinder_xml;
0129 cxml << end_xml;
0130 cxml.close();
0131
0132 auto lcdd = &(dd4hep::Detector::getInstance());
0133 lcdd->fromCompact("SectoralCylinder.xml");
0134 lcdd->volumeManager();
0135 lcdd->apply("DD4hepVolumeManager", 0, nullptr);
0136
0137 auto world = lcdd->world();
0138
0139 std::shared_ptr<Acts::DD4hepDetectorElement> cylindricalElement = nullptr;
0140 for (const auto& [chn, child] : world.children()) {
0141 cylindricalElement =
0142 std::make_shared<Acts::DD4hepDetectorElement>(child, "XYZ", 10.);
0143 }
0144
0145 BOOST_REQUIRE_NE(cylindricalElement, nullptr);
0146
0147 const auto& surface = cylindricalElement->surface();
0148 BOOST_CHECK_EQUAL(surface.type(), Acts::Surface::SurfaceType::Cylinder);
0149 BOOST_CHECK(
0150 surface.transform(tContext).isApprox(Acts::Transform3::Identity()));
0151 auto boundValues = surface.bounds().values();
0152 CHECK_CLOSE_ABS(boundValues[0u], 105., 1e-10);
0153 CHECK_CLOSE_ABS(boundValues[1u], 1000., 1e-10);
0154 CHECK_CLOSE_ABS(boundValues[2u], 0.35, 1e-10);
0155 CHECK_CLOSE_ABS(boundValues[3u], 0.45, 1e-10);
0156 lcdd->destroyInstance();
0157 }
0158
0159 BOOST_AUTO_TEST_CASE(DD4hepPluginDetectorElementDisc) {
0160 std::ofstream cxml;
0161 cxml.open("Disc.xml");
0162 cxml << head_xml;
0163 cxml << disc_xml;
0164 cxml << end_xml;
0165 cxml.close();
0166
0167 auto lcdd = &(dd4hep::Detector::getInstance());
0168 lcdd->fromCompact("Disc.xml");
0169 lcdd->volumeManager();
0170 lcdd->apply("DD4hepVolumeManager", 0, nullptr);
0171
0172 auto world = lcdd->world();
0173
0174 std::shared_ptr<Acts::DD4hepDetectorElement> discElement = nullptr;
0175 for (const auto& [chn, child] : world.children()) {
0176 discElement =
0177 std::make_shared<Acts::DD4hepDetectorElement>(child, "XYZ", 10., true);
0178 }
0179
0180 BOOST_REQUIRE_NE(discElement, nullptr);
0181
0182 const auto& surface = discElement->surface();
0183 BOOST_CHECK_EQUAL(surface.type(), Acts::Surface::SurfaceType::Disc);
0184 BOOST_CHECK(
0185 surface.transform(tContext).isApprox(Acts::Transform3::Identity()));
0186 auto boundValues = surface.bounds().values();
0187 CHECK_CLOSE_ABS(boundValues[0u], 100., 1e-10);
0188 CHECK_CLOSE_ABS(boundValues[1u], 900., 1e-10);
0189 lcdd->destroyInstance();
0190 }
0191
0192 BOOST_AUTO_TEST_CASE(DD4hepPluginDetectorElementSectoralDisc) {
0193 std::ofstream cxml;
0194 cxml.open("SectoralDisc.xml");
0195 cxml << head_xml;
0196 cxml << sectoral_disc_xml;
0197 cxml << end_xml;
0198 cxml.close();
0199
0200 auto lcdd = &(dd4hep::Detector::getInstance());
0201 lcdd->fromCompact("SectoralDisc.xml");
0202 lcdd->volumeManager();
0203 lcdd->apply("DD4hepVolumeManager", 0, nullptr);
0204
0205 auto world = lcdd->world();
0206
0207 std::shared_ptr<Acts::DD4hepDetectorElement> discElement = nullptr;
0208 for (const auto& [chn, child] : world.children()) {
0209 discElement =
0210 std::make_shared<Acts::DD4hepDetectorElement>(child, "XYZ", 10., true);
0211 }
0212
0213 BOOST_REQUIRE_NE(discElement, nullptr);
0214
0215 const auto& surface = discElement->surface();
0216 BOOST_CHECK_EQUAL(surface.type(), Acts::Surface::SurfaceType::Disc);
0217 BOOST_CHECK(
0218 surface.transform(tContext).isApprox(Acts::Transform3::Identity()));
0219 auto boundValues = surface.bounds().values();
0220
0221 CHECK_CLOSE_ABS(boundValues[0u], 100., 1e-10);
0222 CHECK_CLOSE_ABS(boundValues[1u], 900., 1e-10);
0223 CHECK_CLOSE_ABS(boundValues[2u], 0.75, 1e-10);
0224 CHECK_CLOSE_ABS(boundValues[3u], 0.75, 1e-10);
0225 lcdd->destroyInstance();
0226 }
0227
0228 BOOST_AUTO_TEST_CASE(DD4hepPluginDetectorElementRectangle) {
0229 std::ofstream cxml;
0230 cxml.open("Rectangle.xml");
0231 cxml << head_xml;
0232 cxml << rectangle_xml;
0233 cxml << end_xml;
0234 cxml.close();
0235
0236 auto lcdd = &(dd4hep::Detector::getInstance());
0237 lcdd->fromCompact("Rectangle.xml");
0238 lcdd->volumeManager();
0239 lcdd->apply("DD4hepVolumeManager", 0, nullptr);
0240
0241 auto world = lcdd->world();
0242
0243 std::shared_ptr<Acts::DD4hepDetectorElement> rectangleElement = nullptr;
0244 for (const auto& [chn, child] : world.children()) {
0245 rectangleElement =
0246 std::make_shared<Acts::DD4hepDetectorElement>(child, "XYZ", 10., true);
0247 }
0248
0249 BOOST_REQUIRE_NE(rectangleElement, nullptr);
0250
0251 const auto& surface = rectangleElement->surface();
0252 BOOST_CHECK_EQUAL(surface.type(), Acts::Surface::SurfaceType::Plane);
0253
0254 auto sTransform = surface.transform(tContext);
0255 BOOST_CHECK(sTransform.translation().isApprox(Acts::Vector3(10., 20., 30.)));
0256
0257 const auto& sBounds = surface.bounds();
0258 BOOST_CHECK_EQUAL(sBounds.type(),
0259 Acts::SurfaceBounds::BoundsType::eRectangle);
0260
0261 auto boundValues = sBounds.values();
0262
0263 CHECK_CLOSE_ABS(boundValues[0u], -50., 1e-10);
0264 CHECK_CLOSE_ABS(boundValues[1u], -450., 1e-10);
0265 CHECK_CLOSE_ABS(boundValues[2u], 50, 1e-10);
0266 CHECK_CLOSE_ABS(boundValues[3u], 450, 1e-10);
0267
0268 lcdd->destroyInstance();
0269 }
0270
0271 BOOST_AUTO_TEST_CASE(DD4hepPluginDetectorElementTrapezoid) {
0272 std::ofstream cxml;
0273 cxml.open("Trapezoid.xml");
0274 cxml << head_xml;
0275 cxml << trapezoid_xml;
0276 cxml << end_xml;
0277 cxml.close();
0278
0279 auto lcdd = &(dd4hep::Detector::getInstance());
0280 lcdd->fromCompact("Trapezoid.xml");
0281 lcdd->volumeManager();
0282 lcdd->apply("DD4hepVolumeManager", 0, nullptr);
0283
0284 auto world = lcdd->world();
0285
0286 std::shared_ptr<Acts::DD4hepDetectorElement> trapezoidElement = nullptr;
0287 for (const auto& [chn, child] : world.children()) {
0288 trapezoidElement =
0289 std::make_shared<Acts::DD4hepDetectorElement>(child, "xZ", 10., true);
0290 }
0291
0292 BOOST_REQUIRE_NE(trapezoidElement, nullptr);
0293
0294 const auto& surface = trapezoidElement->surface();
0295 BOOST_CHECK_EQUAL(surface.type(), Acts::Surface::SurfaceType::Plane);
0296
0297 auto sTransform = surface.transform(tContext);
0298 BOOST_CHECK(sTransform.translation().isApprox(Acts::Vector3(20., 30., 40.)));
0299
0300 const auto& sBounds = surface.bounds();
0301 BOOST_CHECK_EQUAL(sBounds.type(),
0302 Acts::SurfaceBounds::BoundsType::eTrapezoid);
0303
0304 auto boundValues = sBounds.values();
0305 CHECK_CLOSE_ABS(boundValues[0u], 100., 1e-10);
0306 CHECK_CLOSE_ABS(boundValues[1u], 200., 1e-10);
0307 CHECK_CLOSE_ABS(boundValues[2u], 150, 1e-10);
0308
0309 lcdd->destroyInstance();
0310 }
0311
0312 BOOST_AUTO_TEST_SUITE_END()