Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:11:18

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2020 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/data/test_case.hpp>
0010 #include <boost/test/unit_test.hpp>
0011 
0012 #include "Acts/Definitions/Algebra.hpp"
0013 #include "Acts/Detector/ProtoDetector.hpp"
0014 #include "Acts/Geometry/Extent.hpp"
0015 #include "Acts/Surfaces/Surface.hpp"
0016 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0017 #include "Acts/Utilities/BinningData.hpp"
0018 #include "Acts/Utilities/BinningType.hpp"
0019 
0020 #include <iostream>
0021 #include <limits>
0022 #include <memory>
0023 #include <optional>
0024 #include <string>
0025 #include <vector>
0026 
0027 namespace {
0028 
0029 /// @brief This method creates a world volume with
0030 /// some sub structure, this detector is not yet
0031 /// synchronized, it can then be typed into the
0032 /// Detector or the TrackGeometry description
0033 ///
0034 /// @return a proto world volume
0035 Acts::ProtoDetector createProtoDetector() {
0036   // Container
0037   Acts::ProtoVolume detectorVolume;
0038   detectorVolume.name = "detector-container";
0039   detectorVolume.extent.set(Acts::binZ, -2000., 2000);
0040 
0041   // Beam Pipe volume
0042   Acts::ProtoVolume beamPipe;
0043   beamPipe.name = "beam-pipe";
0044   beamPipe.extent.set(Acts::binR, 0., 30.);
0045 
0046   // Pixel section
0047   Acts::ProtoVolume pixelContainer;
0048   pixelContainer.name = "pixel-container";
0049   pixelContainer.extent.set(Acts::binR, 40., 200);
0050 
0051   // Pixel volume sub structure
0052   Acts::ProtoVolume pixelNec;
0053   pixelNec.name = "pixel-nec";
0054   pixelNec.extent.set(Acts::binZ, -1900., -600);
0055 
0056   Acts::ProtoVolume pixelBarrel;
0057   pixelBarrel.name = "pixel-barrel";
0058   pixelBarrel.extent.set(Acts::binR, 41., 199.);
0059   pixelBarrel.extent.set(Acts::binZ, -550., 550.);
0060 
0061   Acts::ProtoVolume pixelBarrelL0;
0062   pixelBarrelL0.name = "pixel-barrel-l0";
0063   pixelBarrelL0.extent.set(Acts::binR, 45., 50.);
0064   pixelBarrelL0.internal = Acts::ProtoVolume::InternalStructure{
0065       Acts::Surface::SurfaceType::Cylinder};
0066 
0067   Acts::ProtoVolume pixelBarrelL1;
0068   pixelBarrelL1.name = "pixel-barrel-l1";
0069   pixelBarrelL1.extent.set(Acts::binR, 70., 80.);
0070   pixelBarrelL1.internal = Acts::ProtoVolume::InternalStructure{
0071       Acts::Surface::SurfaceType::Cylinder};
0072 
0073   pixelBarrel.container = Acts::ProtoVolume::ContainerStructure{
0074       {pixelBarrelL0, pixelBarrelL1},
0075       {Acts::BinningData(Acts::open, Acts::binR, {0., 1.})},
0076       true};
0077 
0078   Acts::ProtoVolume pixelPec;
0079   pixelPec.name = "pixel-pec";
0080   pixelPec.extent.set(Acts::binZ, 600., 1900.);
0081 
0082   pixelContainer.container = Acts::ProtoVolume::ContainerStructure{
0083       {pixelNec, pixelBarrel, pixelPec},
0084       {Acts::BinningData(Acts::open, Acts::binZ, {0., 1})}};
0085 
0086   detectorVolume.container = Acts::ProtoVolume::ContainerStructure{
0087       {beamPipe, pixelContainer},
0088       {Acts::BinningData(Acts::open, Acts::binR, {0., 1})}};
0089 
0090   Acts::ProtoDetector detector;
0091   detector.name = "detector";
0092   detector.worldVolume = detectorVolume;
0093 
0094   return detector;
0095 }
0096 
0097 }  // namespace
0098 
0099 namespace Acts {
0100 
0101 namespace Test {
0102 
0103 BOOST_AUTO_TEST_SUITE(Detector)
0104 
0105 BOOST_AUTO_TEST_CASE(ProtoTrackingGeometryTests) {
0106   // Get the raw proto detector description
0107   auto detector = createProtoDetector();
0108   detector.harmonize(true);
0109 
0110   // Get the top detector volume
0111   auto& detectorVolume = detector.worldVolume;
0112 
0113   // The detector volume should have received maximum dimensions
0114   CHECK_CLOSE_ABS(detectorVolume.extent.min(Acts::binR), 0,
0115                   std::numeric_limits<ActsScalar>::epsilon());
0116 
0117   CHECK_CLOSE_ABS(detectorVolume.extent.max(Acts::binR), 200.,
0118                   std::numeric_limits<ActsScalar>::epsilon());
0119 
0120   // The detector container should have binning in R
0121   BOOST_CHECK(detectorVolume.container.has_value());
0122   BOOST_CHECK(!detectorVolume.internal.has_value());
0123 
0124   auto& cts = detectorVolume.container.value();
0125 
0126   BOOST_CHECK_EQUAL(cts.constituentBinning.size(), 1u);
0127   BOOST_CHECK_EQUAL(cts.constituentBinning[0].type, Acts::arbitrary);
0128   BOOST_CHECK_EQUAL(cts.constituentBinning[0].binvalue, Acts::binR);
0129 
0130   const auto& binBoundaries = cts.constituentBinning[0].boundaries();
0131   BOOST_CHECK_EQUAL(binBoundaries.size(), 3u);
0132   CHECK_CLOSE_ABS(binBoundaries[0u], 0.,
0133                   std::numeric_limits<ActsScalar>::epsilon());
0134   CHECK_CLOSE_ABS(binBoundaries[1u], 35.,
0135                   std::numeric_limits<ActsScalar>::epsilon());
0136   CHECK_CLOSE_ABS(binBoundaries[2u], 200.,
0137                   std::numeric_limits<ActsScalar>::epsilon());
0138 
0139   // The first volume is the beam pipe, it should have gotten the
0140   // z dimension
0141   auto& beamPipe = cts.constituentVolumes[0u];
0142 
0143   BOOST_CHECK_EQUAL(beamPipe.name, "beam-pipe");
0144   CHECK_CLOSE_ABS(beamPipe.extent.min(Acts::binZ), -2000.,
0145                   std::numeric_limits<ActsScalar>::epsilon());
0146 
0147   CHECK_CLOSE_ABS(beamPipe.extent.max(Acts::binZ), 2000.,
0148                   std::numeric_limits<ActsScalar>::epsilon());
0149 
0150   // The new beam pipe radius should have been applied
0151   CHECK_CLOSE_ABS(beamPipe.extent.max(Acts::binR), 35.,
0152                   std::numeric_limits<ActsScalar>::epsilon());
0153 
0154   // The second volume is the pixel detector
0155   auto& pixelContainer = cts.constituentVolumes[1u];
0156   BOOST_CHECK_EQUAL(pixelContainer.name, "pixel-container");
0157 
0158   // Pixel container should have fitting boundaries
0159   CHECK_CLOSE_ABS(pixelContainer.extent.min(Acts::binR), 35.,
0160                   std::numeric_limits<ActsScalar>::epsilon());
0161   CHECK_CLOSE_ABS(pixelContainer.extent.max(Acts::binR), 200.,
0162                   std::numeric_limits<ActsScalar>::epsilon());
0163   CHECK_CLOSE_ABS(pixelContainer.extent.min(Acts::binZ), -2000.,
0164                   std::numeric_limits<ActsScalar>::epsilon());
0165   CHECK_CLOSE_ABS(pixelContainer.extent.max(Acts::binZ), 2000.,
0166                   std::numeric_limits<ActsScalar>::epsilon());
0167 
0168   // The Pixel container has constituents
0169   BOOST_CHECK(pixelContainer.container.has_value());
0170   auto& cts1 = pixelContainer.container.value();
0171 
0172   // All of the internal containers should now have synchronized
0173   // inner & outer boundaries
0174   for (auto& pv : cts1.constituentVolumes) {
0175     CHECK_CLOSE_ABS(pv.extent.min(Acts::binR), 35.,
0176                     std::numeric_limits<ActsScalar>::epsilon());
0177 
0178     CHECK_CLOSE_ABS(pv.extent.max(Acts::binR), 200.,
0179                     std::numeric_limits<ActsScalar>::epsilon());
0180   }
0181 
0182   // The binning should have been estimated
0183   BOOST_CHECK_EQUAL(cts1.constituentBinning.size(), 1u);
0184   BOOST_CHECK_EQUAL(cts1.constituentBinning[0].type, Acts::arbitrary);
0185   BOOST_CHECK_EQUAL(cts1.constituentBinning[0].binvalue, Acts::binZ);
0186 
0187   const auto& binBoundariesZ = cts1.constituentBinning[0].boundaries();
0188   BOOST_CHECK_EQUAL(binBoundariesZ.size(), 4u);
0189   CHECK_CLOSE_ABS(binBoundariesZ[0u], -2000.,
0190                   std::numeric_limits<ActsScalar>::epsilon());
0191   CHECK_CLOSE_ABS(binBoundariesZ[1u], -575,
0192                   std::numeric_limits<ActsScalar>::epsilon());
0193   CHECK_CLOSE_ABS(binBoundariesZ[2u], 575.,
0194                   std::numeric_limits<ActsScalar>::epsilon());
0195   CHECK_CLOSE_ABS(binBoundariesZ[3u], 2000.,
0196                   std::numeric_limits<ActsScalar>::epsilon());
0197 
0198   // The second volume is the pixel barrel
0199   auto& pixelBarrel = cts1.constituentVolumes[1u];
0200   BOOST_CHECK_EQUAL(pixelBarrel.name, "pixel-barrel");
0201 
0202   // It is a container volume value
0203   BOOST_CHECK(pixelBarrel.container.has_value());
0204   auto& cts2 = pixelBarrel.container.value();
0205   // It is, however, a layer container
0206   BOOST_CHECK(cts2.layerContainer);
0207   for (auto& lVolume : cts2.constituentVolumes) {
0208     BOOST_CHECK(lVolume.internal.has_value());
0209   }
0210 }
0211 
0212 BOOST_AUTO_TEST_CASE(ProtoDetectorTests) {
0213   // Get the raw proto detector description
0214   auto detector = createProtoDetector();
0215   detector.harmonize(false);
0216   std::cout << detector.toString() << std::endl;
0217 }
0218 
0219 BOOST_AUTO_TEST_SUITE_END()
0220 
0221 }  // namespace Test
0222 
0223 }  // namespace Acts