Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2018 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/Geometry/GeometryContext.hpp"
0014 #include "Acts/Geometry/ProtoLayer.hpp"
0015 #include "Acts/Geometry/ProtoLayerHelper.hpp"
0016 #include "Acts/Tests/CommonHelpers/CylindricalTrackingGeometry.hpp"
0017 #include "Acts/Utilities/BinningType.hpp"
0018 #include "Acts/Utilities/Logger.hpp"
0019 #include "Acts/Visualization/GeometryView3D.hpp"
0020 #include "Acts/Visualization/ObjVisualization3D.hpp"
0021 #include "Acts/Visualization/ViewConfig.hpp"
0022 
0023 #include <cstddef>
0024 #include <string>
0025 #include <utility>
0026 #include <vector>
0027 
0028 namespace Acts {
0029 class Surface;
0030 
0031 namespace Test {
0032 namespace Layers {
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({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, ProtoLayerHelper::SortingConfig(binR, 5.));
0077 
0078   BOOST_CHECK_EQUAL(radialLayers.size(), 4);
0079 
0080   std::vector<ColorRGB> sortedColors = {{102, 204, 255},
0081                                         {102, 255, 153},
0082                                         {255, 204, 102},
0083                                         {204, 102, 0},
0084                                         {278, 123, 55}};
0085 
0086   std::size_t il = 0;
0087   for (auto& layer : radialLayers) {
0088     for (auto& sf : layer.surfaces()) {
0089       ViewConfig sorted(sortedColors[il]);
0090       GeometryView3D::drawSurface(objVis, *sf, tgContext,
0091                                   Transform3::Identity(), sorted);
0092     }
0093     ++il;
0094   }
0095 
0096   // Draw the sorted surfaces
0097   objVis.write("ProtoLayerHelper_CylinderLayers_radially");
0098   objVis.clear();
0099 
0100   /// Disc section ---------------------------------------------------
0101   std::vector<const Surface*> discSurfaces;
0102 
0103   std::vector<double> discZ = {-350., -250., -150., -100.};
0104   std::vector<double> discRadii = {55., 55., 55., 55.};
0105   std::vector<int> discModules = {22, 22, 22, 22};
0106 
0107   std::vector<double> dModuleHalfXMinY = {6.4, 6.4, 6.4, 6.4};
0108   std::vector<double> dModuleHalfXMaxY = {12.4, 12.4, 12.4, 12.4};
0109   std::vector<double> dModuleHalfY = {36., 36., 36., 36.};
0110   std::vector<double> dModuleTilt = {0.075, 0.075, 0.075, 0.075};
0111   std::vector<double> dModuleThickness = {0.15, 0.15, 0.15, 0.15};
0112 
0113   for (std::size_t ilp = 0; ilp < discZ.size(); ++ilp) {
0114     std::vector<const Surface*> layerSurfaces = ctGeometry.surfacesRing(
0115         dStore, dModuleHalfXMinY[ilp], dModuleHalfXMaxY[ilp], dModuleHalfY[ilp],
0116         dModuleThickness[ilp], dModuleTilt[ilp], discRadii[ilp], discZ[ilp], 2.,
0117         discModules[ilp]);
0118     discSurfaces.insert(discSurfaces.begin(), layerSurfaces.begin(),
0119                         layerSurfaces.end());
0120   }
0121 
0122   for (auto& sf : discSurfaces) {
0123     GeometryView3D::drawSurface(objVis, *sf, tgContext);
0124   }
0125   // Draw the all surfaces
0126   objVis.write("ProtoLayerHelper_DiscLayers_unsorted");
0127   objVis.clear();
0128 
0129   // Sort into ProtoLayers
0130   auto discLayersZ = plHelper.protoLayers(tgContext, discSurfaces, {binZ, 5.});
0131 
0132   BOOST_CHECK_EQUAL(discLayersZ.size(), 4);
0133 
0134   il = 0;
0135   for (auto& layer : discLayersZ) {
0136     for (auto& sf : layer.surfaces()) {
0137       ViewConfig ViewConfig(sortedColors[il]);
0138       GeometryView3D::drawSurface(objVis, *sf, tgContext,
0139                                   Transform3::Identity(), ViewConfig);
0140     }
0141     ++il;
0142   }
0143 
0144   // Draw the sorted surfaces
0145   objVis.write("ProtoLayerHelper_DiscLayers_longitudinally");
0146   objVis.clear();
0147 
0148   /// Ring layout section ---------------------------------------------------
0149   std::vector<const Surface*> ringSurfaces;
0150 
0151   std::vector<double> ringZ = {-350., -250., -150., -100., -360., -255.,
0152                                -120., -330., -260., -150., -95.};
0153   std::vector<double> ringRadii = {32., 32., 32., 32., 58., 58.,
0154                                    58., 84., 84., 84., 84.};
0155   std::vector<int> ringModules = {22, 22, 22, 22, 32, 32, 32, 44, 44, 44, 44};
0156 
0157   std::vector<double> rModuleHalfXMinY(11, 6.4);
0158   std::vector<double> rModuleHalfXMaxY(11, 6.4);
0159   std::vector<double> rModuleHalfY(11, 10.);
0160   std::vector<double> rModuleTilt(11, 0.075);
0161   std::vector<double> rModuleThickness(11, 0.15);
0162 
0163   for (std::size_t ilp = 0; ilp < ringZ.size(); ++ilp) {
0164     std::vector<const Surface*> layerSurfaces = ctGeometry.surfacesRing(
0165         dStore, rModuleHalfXMinY[ilp], rModuleHalfXMaxY[ilp], rModuleHalfY[ilp],
0166         rModuleThickness[ilp], rModuleTilt[ilp], ringRadii[ilp], ringZ[ilp], 2.,
0167         ringModules[ilp]);
0168     ringSurfaces.insert(ringSurfaces.begin(), layerSurfaces.begin(),
0169                         layerSurfaces.end());
0170   }
0171 
0172   for (auto& sf : ringSurfaces) {
0173     GeometryView3D::drawSurface(objVis, *sf, tgContext);
0174   }
0175   // Draw the all surfaces
0176   objVis.write("ProtoLayerHelper_RingLayers_unsorted");
0177   objVis.clear();
0178 
0179   // First: Sort into ProtoLayers radially
0180   auto rSorted = plHelper.protoLayers(
0181       tgContext, ringSurfaces, ProtoLayerHelper::SortingConfig(binR, 1.));
0182   BOOST_CHECK_EQUAL(rSorted.size(), 3);
0183 
0184   ColorRGB dColor = {0, 0, 0};
0185 
0186   int ir = 0;
0187   for (auto& rBatch : rSorted) {
0188     auto lSorted =
0189         plHelper.protoLayers(tgContext, rBatch.surfaces(),
0190                              ProtoLayerHelper::SortingConfig(binZ, 5.));
0191     il = 0;
0192     dColor[ir] = 256;
0193     for (auto& layer : lSorted) {
0194       dColor[ir] -= il * 50;
0195       for (auto& sf : layer.surfaces()) {
0196         GeometryView3D::drawSurface(objVis, *sf, tgContext);
0197       }
0198       ++il;
0199     }
0200     ++ir;
0201   }
0202   // Draw the all surfaces
0203   objVis.write("ProtoLayerHelper_RingLayers_sorted");
0204 
0205   // Perform the split at once
0206   auto rzSorted =
0207       plHelper.protoLayers(tgContext, ringSurfaces, {{binR, 1.}, {binZ, 5}});
0208 
0209   std::size_t irz = 0;
0210   for (auto& layer : rzSorted) {
0211     for (auto& sf : layer.surfaces()) {
0212       GeometryView3D::drawSurface(objVis, *sf, tgContext);
0213     }
0214     objVis.write("ProtoLayerHelper_RingLayers_rz_sorted" +
0215                  std::to_string(irz++));
0216     objVis.clear();
0217   }
0218 }
0219 
0220 BOOST_AUTO_TEST_SUITE_END()
0221 }  // namespace Layers
0222 }  // namespace Test
0223 
0224 }  // namespace Acts