Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-06 09:23:55

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/Definitions/Algebra.hpp"
0012 #include "Acts/Geometry/GeometryContext.hpp"
0013 #include "Acts/Geometry/ProtoLayer.hpp"
0014 #include "Acts/Geometry/ProtoLayerHelper.hpp"
0015 #include "Acts/Utilities/BinningType.hpp"
0016 #include "Acts/Utilities/Logger.hpp"
0017 #include "Acts/Visualization/GeometryView3D.hpp"
0018 #include "Acts/Visualization/ObjVisualization3D.hpp"
0019 #include "Acts/Visualization/ViewConfig.hpp"
0020 #include "ActsTests/CommonHelpers/CylindricalTrackingGeometry.hpp"
0021 
0022 #include <cstddef>
0023 #include <string>
0024 #include <utility>
0025 #include <vector>
0026 
0027 namespace Acts {
0028 class Surface;
0029 }  // namespace Acts
0030 
0031 using namespace Acts;
0032 
0033 namespace ActsTests {
0034 
0035 BOOST_AUTO_TEST_SUITE(GeometrySuite)
0036 
0037 BOOST_AUTO_TEST_CASE(ProtoLayerHelperTests) {
0038   ProtoLayerHelper::Config plhConfig;
0039   ProtoLayerHelper plHelper(
0040       plhConfig, getDefaultLogger("ProtoLayerHelper", Logging::VERBOSE));
0041 
0042   GeometryContext tgContext = GeometryContext();
0043 
0044   ObjVisualization3D objVis;
0045 
0046   CylindricalTrackingGeometry ctGeometry(tgContext);
0047   CylindricalTrackingGeometry::DetectorStore dStore;
0048 
0049   /// Cylindrical section ---------------------------------------------------
0050   std::vector<double> layerRadii = {32., 72., 116., 172.};
0051   std::vector<std::pair<int, int>> layerBinning = {
0052       {16, 14}, {32, 14}, {52, 14}, {78, 14}};
0053   std::vector<double> moduleTiltPhi = {0.145, 0.145, 0.145, 0.145};
0054   std::vector<double> moduleHalfX = {8.4, 8.4, 8.4, 8.4};
0055   std::vector<double> moduleHalfY = {36., 36., 36., 36.};
0056   std::vector<double> moduleThickness = {0.15, 0.15, 0.15, 0.15};
0057 
0058   std::vector<const Surface*> cylinderSurfaces;
0059   for (std::size_t ilp = 0; ilp < layerRadii.size(); ++ilp) {
0060     std::vector<Surface*> layerSurfaces = ctGeometry.surfacesCylinder(
0061         dStore, moduleHalfX[ilp], moduleHalfY[ilp], moduleThickness[ilp],
0062         moduleTiltPhi[ilp], layerRadii[ilp], 2., 5., layerBinning[ilp]);
0063     cylinderSurfaces.insert(cylinderSurfaces.begin(), layerSurfaces.begin(),
0064                             layerSurfaces.end());
0065   }
0066 
0067   ViewConfig unsorted{.color = {252, 160, 0}};
0068   for (auto& sf : cylinderSurfaces) {
0069     GeometryView3D::drawSurface(objVis, *sf, tgContext, Transform3::Identity(),
0070                                 unsorted);
0071   }
0072   // Draw the all surfaces
0073   objVis.write("ProtoLayerHelper_CylinderLayers_unsorted");
0074   objVis.clear();
0075 
0076   // Sort into ProtoLayers
0077   auto radialLayers = plHelper.protoLayers(
0078       tgContext, cylinderSurfaces,
0079       ProtoLayerHelper::SortingConfig(AxisDirection::AxisR, 5.));
0080 
0081   BOOST_CHECK_EQUAL(radialLayers.size(), 4);
0082 
0083   std::vector<Color> sortedColors = {{102, 204, 255},
0084                                      {102, 255, 153},
0085                                      {255, 204, 102},
0086                                      {204, 102, 0},
0087                                      {278, 123, 55}};
0088 
0089   std::size_t il = 0;
0090   for (auto& layer : radialLayers) {
0091     for (auto& sf : layer.surfaces()) {
0092       ViewConfig sorted{.color = sortedColors[il]};
0093       GeometryView3D::drawSurface(objVis, *sf, tgContext,
0094                                   Transform3::Identity(), sorted);
0095     }
0096     ++il;
0097   }
0098 
0099   // Draw the sorted surfaces
0100   objVis.write("ProtoLayerHelper_CylinderLayers_radially");
0101   objVis.clear();
0102 
0103   /// Disc section ---------------------------------------------------
0104   std::vector<const Surface*> discSurfaces;
0105 
0106   std::vector<double> discZ = {-350., -250., -150., -100.};
0107   std::vector<double> discRadii = {55., 55., 55., 55.};
0108   std::vector<int> discModules = {22, 22, 22, 22};
0109 
0110   std::vector<double> dModuleHalfXMinY = {6.4, 6.4, 6.4, 6.4};
0111   std::vector<double> dModuleHalfXMaxY = {12.4, 12.4, 12.4, 12.4};
0112   std::vector<double> dModuleHalfY = {36., 36., 36., 36.};
0113   std::vector<double> dModuleTilt = {0.075, 0.075, 0.075, 0.075};
0114   std::vector<double> dModuleThickness = {0.15, 0.15, 0.15, 0.15};
0115 
0116   for (std::size_t ilp = 0; ilp < discZ.size(); ++ilp) {
0117     std::vector<Surface*> layerSurfaces = ctGeometry.surfacesRing(
0118         dStore, dModuleHalfXMinY[ilp], dModuleHalfXMaxY[ilp], dModuleHalfY[ilp],
0119         dModuleThickness[ilp], dModuleTilt[ilp], discRadii[ilp], discZ[ilp], 2.,
0120         discModules[ilp]);
0121     discSurfaces.insert(discSurfaces.begin(), layerSurfaces.begin(),
0122                         layerSurfaces.end());
0123   }
0124 
0125   for (auto& sf : discSurfaces) {
0126     GeometryView3D::drawSurface(objVis, *sf, tgContext);
0127   }
0128   // Draw the all surfaces
0129   objVis.write("ProtoLayerHelper_DiscLayers_unsorted");
0130   objVis.clear();
0131 
0132   // Sort into ProtoLayers
0133   auto discLayersZ =
0134       plHelper.protoLayers(tgContext, discSurfaces, {AxisDirection::AxisZ, 5.});
0135 
0136   BOOST_CHECK_EQUAL(discLayersZ.size(), 4);
0137 
0138   il = 0;
0139   for (auto& layer : discLayersZ) {
0140     for (auto& sf : layer.surfaces()) {
0141       ViewConfig ViewConfig{.color = sortedColors[il]};
0142       GeometryView3D::drawSurface(objVis, *sf, tgContext,
0143                                   Transform3::Identity(), ViewConfig);
0144     }
0145     ++il;
0146   }
0147 
0148   // Draw the sorted surfaces
0149   objVis.write("ProtoLayerHelper_DiscLayers_longitudinally");
0150   objVis.clear();
0151 
0152   /// Ring layout section ---------------------------------------------------
0153   std::vector<const Surface*> ringSurfaces;
0154 
0155   std::vector<double> ringZ = {-350., -250., -150., -100., -360., -255.,
0156                                -120., -330., -260., -150., -95.};
0157   std::vector<double> ringRadii = {32., 32., 32., 32., 58., 58.,
0158                                    58., 84., 84., 84., 84.};
0159   std::vector<int> ringModules = {22, 22, 22, 22, 32, 32, 32, 44, 44, 44, 44};
0160 
0161   std::vector<double> rModuleHalfXMinY(11, 6.4);
0162   std::vector<double> rModuleHalfXMaxY(11, 6.4);
0163   std::vector<double> rModuleHalfY(11, 10.);
0164   std::vector<double> rModuleTilt(11, 0.075);
0165   std::vector<double> rModuleThickness(11, 0.15);
0166 
0167   for (std::size_t ilp = 0; ilp < ringZ.size(); ++ilp) {
0168     std::vector<Surface*> layerSurfaces = ctGeometry.surfacesRing(
0169         dStore, rModuleHalfXMinY[ilp], rModuleHalfXMaxY[ilp], rModuleHalfY[ilp],
0170         rModuleThickness[ilp], rModuleTilt[ilp], ringRadii[ilp], ringZ[ilp], 2.,
0171         ringModules[ilp]);
0172     ringSurfaces.insert(ringSurfaces.begin(), layerSurfaces.begin(),
0173                         layerSurfaces.end());
0174   }
0175 
0176   for (auto& sf : ringSurfaces) {
0177     GeometryView3D::drawSurface(objVis, *sf, tgContext);
0178   }
0179   // Draw the all surfaces
0180   objVis.write("ProtoLayerHelper_RingLayers_unsorted");
0181   objVis.clear();
0182 
0183   // First: Sort into ProtoLayers radially
0184   auto rSorted = plHelper.protoLayers(
0185       tgContext, ringSurfaces,
0186       ProtoLayerHelper::SortingConfig(AxisDirection::AxisR, 1.));
0187   BOOST_CHECK_EQUAL(rSorted.size(), 3);
0188 
0189   Color dColor = {0, 0, 0};
0190 
0191   int ir = 0;
0192   for (auto& rBatch : rSorted) {
0193     auto lSorted = plHelper.protoLayers(
0194         tgContext, rBatch.surfaces(),
0195         ProtoLayerHelper::SortingConfig(AxisDirection::AxisZ, 5.));
0196     il = 0;
0197     dColor[ir] = 256;
0198     for (auto& layer : lSorted) {
0199       dColor[ir] -= il * 50;
0200       for (auto& sf : layer.surfaces()) {
0201         GeometryView3D::drawSurface(objVis, *sf, tgContext);
0202       }
0203       ++il;
0204     }
0205     ++ir;
0206   }
0207   // Draw the all surfaces
0208   objVis.write("ProtoLayerHelper_RingLayers_sorted");
0209 
0210   // Perform the split at once
0211   auto rzSorted = plHelper.protoLayers(
0212       tgContext, ringSurfaces,
0213       {{AxisDirection::AxisR, 1.}, {AxisDirection::AxisZ, 5}});
0214 
0215   std::size_t irz = 0;
0216   for (auto& layer : rzSorted) {
0217     for (auto& sf : layer.surfaces()) {
0218       GeometryView3D::drawSurface(objVis, *sf, tgContext);
0219     }
0220     objVis.write("ProtoLayerHelper_RingLayers_rz_sorted" +
0221                  std::to_string(irz++));
0222     objVis.clear();
0223   }
0224 }
0225 
0226 BOOST_AUTO_TEST_SUITE_END()
0227 
0228 }  // namespace ActsTests