Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:41

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