Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:08

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Geometry/GeometryContext.hpp"
0012 #include "Acts/Plugins/DD4hep/DD4hepDetectorSurfaceFactory.hpp"
0013 #include "Acts/Plugins/DD4hep/DD4hepLayerStructure.hpp"
0014 #include "Acts/Surfaces/SurfaceBounds.hpp"
0015 #include "Acts/Tests/CommonHelpers/CylindricalTrackingGeometry.hpp"
0016 #include "Acts/Utilities/Logger.hpp"
0017 
0018 #include <fstream>
0019 #include <string>
0020 
0021 #include <DD4hep/DetElement.h>
0022 #include <DD4hep/DetFactoryHelper.h>
0023 #include <DD4hep/Detector.h>
0024 #include <XML/Utilities.h>
0025 #include <XMLFragments.hpp>
0026 
0027 #include "DD4hepTestsHelper.hpp"
0028 
0029 Acts::GeometryContext tContext;
0030 Acts::Test::CylindricalTrackingGeometry cGeometry =
0031     Acts::Test::CylindricalTrackingGeometry(tContext);
0032 
0033 const char* disc_layer_head_xml =
0034     R""""(
0035     <detectors>
0036         <detector id="1" name="Endcap" type="EndcapDetector" readout="PixelReadout">
0037             <type_flags type="DetType_TRACKER + DetType_BARREL"/>
0038             <layers>
0039 )"""";
0040 
0041 const char* tail_xml =
0042     R""""(
0043             </layers>
0044         </detector>
0045     </detectors>
0046 )"""";
0047 
0048 const char* indent_12_xml = "            ";
0049 
0050 BOOST_AUTO_TEST_SUITE(DD4hepPlugin)
0051 
0052 BOOST_AUTO_TEST_CASE(DD4hepDiscLayerStructure) {
0053   double rZ = 400.;
0054 
0055   // First create some test surfaces
0056   Acts::Test::CylindricalTrackingGeometry::DetectorStore dStore;
0057   auto rSurfacesR0 = cGeometry.surfacesRing(dStore, 6.4, 12.4, 18., 0.125, 0.,
0058                                             42., rZ, 2., 22u);
0059 
0060   auto rSurfacesR1 = cGeometry.surfacesRing(dStore, 12.4, 20.4, 30., 0.125, 0.,
0061                                             80., rZ, 2., 22u);
0062 
0063   std::vector<std::vector<const Acts::Surface*>> rSurfaces = {rSurfacesR0,
0064                                                               rSurfacesR1};
0065 
0066   // Running three tests with
0067   // - no binning / no support
0068   // - 22 x 2 bins and expansion / support
0069   // - 44 x 1 bins without expansion /  support with proto material
0070   std::vector<std::array<unsigned int, 4u>> rphiBinning = {
0071       {1u, 1u, 0u, 0u}, {2u, 22u, 1u, 1u}, {1u, 44u, 0u, 0u}};
0072 
0073   std::size_t itest = 0;
0074   for (auto [nr, nphi, er, ephi] : rphiBinning) {
0075     // Create an XML from it
0076     std::ofstream cxml;
0077 
0078     std::string fNameBase = "DiscLayer_nr";
0079     fNameBase += std::to_string(nr);
0080     fNameBase += "_nphi";
0081     fNameBase += std::to_string(nphi);
0082 
0083     cxml.open(fNameBase + ".xml");
0084     cxml << head_xml;
0085     cxml << segmentation_xml;
0086     cxml << disc_layer_head_xml;
0087     cxml << "<layer name=\"E0\" id=\"0\">" << '\n';
0088 
0089     if (nr * nphi > 1u) {
0090       cxml << indent_12_xml << "<acts_surface_binning";
0091       cxml << " rtype=\"equidistant\"";
0092       cxml << " phitype=\"equidistant\"";
0093       cxml << " nr=\"" << nr << "\" rmin=\"20*mm\" rmax=\"120*mm\"";
0094       cxml << " rexpansion= \"" << er << "\"";
0095       cxml << " nphi=\"" << nphi << "\"  phimin=\"-3.1415\" phimax=\"3.1415\"";
0096       cxml << " phiexpansion= \"" << ephi << "\"/>";
0097     }
0098     cxml << "<modules>" << '\n';
0099 
0100     for (const auto& ring : rSurfaces) {
0101       for (const auto& s : ring) {
0102         cxml << indent_12_xml
0103              << DD4hepTestsHelper::surfaceToXML(tContext, *s,
0104                                                 Acts::Transform3::Identity())
0105              << "\n";
0106       }
0107     }
0108 
0109     cxml << "</modules>" << '\n';
0110 
0111     // test the support structure definition
0112     unsigned int passiveAddon = 0u;
0113     if (itest == 1u) {
0114       cxml << indent_12_xml << "  <acts_passive_surface>" << '\n';
0115       cxml << indent_12_xml
0116            << "    <tubs rmin=\"20*mm\" rmax=\"120*mm\" dz=\"2*mm\" "
0117            << "cz=\"" << rZ + 10. << "\" material=\"Air\"/>" << '\n';
0118       cxml << indent_12_xml << "  </acts_passive_surface>" << '\n';
0119       passiveAddon = 1u;
0120     } else if (itest == 2u) {
0121       cxml << indent_12_xml << "  <acts_passive_surface>" << '\n';
0122       cxml << indent_12_xml
0123            << "    <tubs rmin=\"20*mm\" rmax=\"120*mm\" dz=\"2*mm\" "
0124            << "cz=\"" << rZ + 10. << "\" material=\"Air\"/>" << '\n';
0125       cxml << "    <acts_proto_material/>" << '\n';
0126       cxml << indent_12_xml << "  </acts_passive_surface>" << '\n';
0127       passiveAddon = 1u;
0128     }
0129 
0130     cxml << "</layer>" << '\n';
0131 
0132     cxml << tail_xml;
0133     cxml << end_xml;
0134     cxml.close();
0135 
0136     auto lcdd = &(dd4hep::Detector::getInstance());
0137     lcdd->fromCompact(fNameBase + ".xml");
0138     lcdd->volumeManager();
0139     lcdd->apply("DD4hepVolumeManager", 0, nullptr);
0140 
0141     auto world = lcdd->world();
0142 
0143     // Now the test starts ...
0144     auto sFactory = std::make_shared<Acts::DD4hepDetectorSurfaceFactory>(
0145         Acts::getDefaultLogger("DD4hepDetectorSurfaceFactory",
0146                                Acts::Logging::VERBOSE));
0147 
0148     Acts::Experimental::DD4hepLayerStructure discStructure(
0149         std::move(sFactory),
0150         Acts::getDefaultLogger("DD4hepLayerStructure", Acts::Logging::VERBOSE));
0151 
0152     Acts::DD4hepDetectorElement::Store dd4hepStore;
0153 
0154     Acts::Experimental::DD4hepLayerStructure::Options lsOptions;
0155     lsOptions.name = "DiscLayer";
0156     lsOptions.logLevel = Acts::Logging::VERBOSE;
0157 
0158     auto [discInternalsBuilder, discExt] =
0159         discStructure.builder(dd4hepStore, tContext, world, lsOptions);
0160 
0161     // Build the internal volume structure
0162     auto [surfaces, volumes, surfacesUpdater, volumeUpdater] =
0163         discInternalsBuilder->construct(tContext);
0164 
0165     // All surfaces are filled
0166     BOOST_CHECK_EQUAL(surfaces.size(), 44u + passiveAddon);
0167     // No volumes are added
0168     BOOST_CHECK(volumes.empty());
0169     // The surface updator is connected
0170     BOOST_CHECK(surfacesUpdater.connected());
0171     // The volume updator is connected
0172     BOOST_CHECK(volumeUpdater.connected());
0173 
0174     // Kill that instance before going into the next test
0175     lcdd->destroyInstance();
0176 
0177     // Increase test counter
0178     ++itest;
0179   }
0180 }
0181 
0182 BOOST_AUTO_TEST_SUITE_END()