Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2023 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/unit_test.hpp>
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Detector/detail/IndexedGridFiller.hpp"
0013 #include "Acts/Detector/detail/IndexedSurfacesGenerator.hpp"
0014 #include "Acts/Geometry/GeometryContext.hpp"
0015 #include "Acts/Geometry/GeometryIdentifier.hpp"
0016 #include "Acts/Plugins/ActSVG/IndexedSurfacesSvgConverter.hpp"
0017 #include "Acts/Surfaces/DiscSurface.hpp"
0018 #include "Acts/Surfaces/RadialBounds.hpp"
0019 #include "Acts/Tests/CommonHelpers/CylindricalTrackingGeometry.hpp"
0020 #include "Acts/Utilities/Grid.hpp"
0021 #include "Acts/Utilities/GridAxisGenerators.hpp"
0022 
0023 #include <tuple>
0024 
0025 using namespace Acts;
0026 using namespace Acts::Svg;
0027 using namespace Acts::Test;
0028 using namespace Acts::Experimental;
0029 using namespace Acts::Experimental::detail;
0030 
0031 GeometryContext tContext;
0032 CylindricalTrackingGeometry cGeometry = CylindricalTrackingGeometry(tContext);
0033 
0034 IndexedSurfacesConverter::Options generateDrawOptions() {
0035   // The converter options
0036   IndexedSurfacesConverter::Options isOptions;
0037   // Sensitive surface style
0038   Style sensitiveStyle;
0039   sensitiveStyle.fillColor = {51, 153, 255};
0040   sensitiveStyle.fillOpacity = 0.9;
0041   sensitiveStyle.highlightColor = {255, 153, 51};
0042   sensitiveStyle.highlights = {"onmouseover", "onmouseout"};
0043   sensitiveStyle.strokeWidth = 0.5;
0044   sensitiveStyle.strokeColor = {0, 0, 0};
0045   sensitiveStyle.nSegments = 72u;
0046   std::pair<GeometryIdentifier, Style> allSensitives = {GeometryIdentifier(0u),
0047                                                         sensitiveStyle};
0048 
0049   // Hierarchy map of styles
0050   GeometryHierarchyMap<Style> surfaceStyles({allSensitives});
0051   isOptions.surfaceStyles = surfaceStyles;
0052 
0053   // The grid style
0054   GridConverter::Options gridOptions;
0055   Style gridStyle;
0056   gridStyle.fillOpacity = 0.;
0057   gridStyle.strokeColor = {0, 0, 255};
0058   gridStyle.strokeWidth = 1.;
0059   gridStyle.highlightStrokeWidth = 3;
0060   gridStyle.highlightStrokeColor = {255, 0, 0};
0061   gridOptions.style = gridStyle;
0062 
0063   isOptions.gridOptions = gridOptions;
0064   return isOptions;
0065 }
0066 
0067 auto drawOptions = generateDrawOptions();
0068 
0069 BOOST_AUTO_TEST_SUITE(ActSvg)
0070 
0071 BOOST_AUTO_TEST_CASE(RingDisc1D) {
0072   // A single ring
0073   CylindricalTrackingGeometry::DetectorStore dStore;
0074   auto rSurfaces = cGeometry.surfacesRing(dStore, 6.4, 12.4, 36., 0.125, 0.,
0075                                           55., 0., 2., 22u);
0076 
0077   IndexedSurfacesGenerator<decltype(rSurfaces), IndexedSurfacesImpl> irSurfaces{
0078       rSurfaces, {}, {binPhi}};
0079 
0080   GridAxisGenerators::EqClosed aGenerator{{-M_PI, M_PI}, 44u};
0081   PolyhedronReferenceGenerator<1u, true> rGenerator;
0082 
0083   auto indexedRing = irSurfaces(tContext, aGenerator, rGenerator);
0084   // The displaying
0085   auto pIndexedRing = IndexedSurfacesConverter::convert(
0086       tContext, rSurfaces, indexedRing, drawOptions);
0087   auto pIndexRingView = View::xy(pIndexedRing, "RingDisc1D");
0088   toFile({pIndexRingView}, pIndexRingView._id + ".svg");
0089 }
0090 
0091 BOOST_AUTO_TEST_CASE(RingDisc1DWithSupport) {
0092   // A single ring
0093   CylindricalTrackingGeometry::DetectorStore dStore;
0094   auto rSurfaces = cGeometry.surfacesRing(dStore, 6.4, 12.4, 36., 0.125, 0.,
0095                                           55., 0., 2., 22u);
0096 
0097   auto rBounds = std::make_shared<RadialBounds>(20., 20.);
0098   auto dSurface = Surface::makeShared<DiscSurface>(Transform3::Identity(),
0099                                                    std::move(rBounds));
0100   rSurfaces.push_back(dSurface.get());
0101 
0102   IndexedSurfacesGenerator<decltype(rSurfaces), IndexedSurfacesImpl> irSurfaces{
0103       rSurfaces, {rSurfaces.size() - 1u}, {binPhi}};
0104 
0105   GridAxisGenerators::EqClosed aGenerator{{-M_PI, M_PI}, 44u};
0106   PolyhedronReferenceGenerator<1u, true> rGenerator;
0107 
0108   auto indexedRing = irSurfaces(tContext, aGenerator, rGenerator);
0109   // The displaying
0110   auto pIndexedRing = IndexedSurfacesConverter::convert(
0111       tContext, rSurfaces, indexedRing, drawOptions);
0112   auto pIndexRingView = View::xy(pIndexedRing, "RingDisc1DWithSupport");
0113   toFile({pIndexRingView}, pIndexRingView._id + ".svg");
0114 }
0115 
0116 BOOST_AUTO_TEST_CASE(RingDisc2D) {
0117   // Two rings to make a disc
0118   CylindricalTrackingGeometry::DetectorStore dStore;
0119   auto rSurfacesR0 = cGeometry.surfacesRing(dStore, 6.4, 12.4, 18., 0.125, 0.,
0120                                             42., 0., 2., 22u);
0121 
0122   auto rSurfacesR1 = cGeometry.surfacesRing(dStore, 12.4, 20.4, 30., 0.125, 0.,
0123                                             80., 0., 2., 22u);
0124 
0125   decltype(rSurfacesR0) rSurfaces = rSurfacesR0;
0126   rSurfaces.insert(rSurfaces.end(), rSurfacesR1.begin(), rSurfacesR1.end());
0127 
0128   IndexedSurfacesGenerator<decltype(rSurfaces), IndexedSurfacesImpl> irSurfaces{
0129       rSurfaces, {}, {binR, binPhi}};
0130 
0131   GridAxisGenerators::VarBoundEqClosed aGenerator{
0132       {24., 74., 110.}, {-M_PI, M_PI}, 44u};
0133   PolyhedronReferenceGenerator<1u, true> rGenerator;
0134 
0135   auto indexedRing = irSurfaces(tContext, aGenerator, rGenerator);
0136   // The displaying
0137   auto pIndexedRing = IndexedSurfacesConverter::convert(
0138       tContext, rSurfaces, indexedRing, drawOptions);
0139   auto pIndexRingView = View::xy(pIndexedRing, "RingDisc2D");
0140 
0141   toFile({pIndexRingView}, pIndexRingView._id + ".svg");
0142 }
0143 
0144 BOOST_AUTO_TEST_CASE(RingDisc2DFine) {
0145   // Three rings to make a disc
0146   CylindricalTrackingGeometry::DetectorStore dStore;
0147   auto rSurfacesR0 = cGeometry.surfacesRing(dStore, 6.4, 12.4, 18., 0.125, 0.,
0148                                             42., 0., 2., 22u);
0149 
0150   auto rSurfacesR1 = cGeometry.surfacesRing(dStore, 12.4, 20.4, 30., 0.125, 0.,
0151                                             80., 0., 2., 22u);
0152 
0153   auto rSurfacesR2 = cGeometry.surfacesRing(dStore, 18.4, 28.4, 30., 0.125, 0.,
0154                                             122., 0., 2., 36u);
0155 
0156   decltype(rSurfacesR0) rSurfaces = rSurfacesR0;
0157   rSurfaces.insert(rSurfaces.end(), rSurfacesR1.begin(), rSurfacesR1.end());
0158   rSurfaces.insert(rSurfaces.end(), rSurfacesR2.begin(), rSurfacesR2.end());
0159 
0160   IndexedSurfacesGenerator<decltype(rSurfaces), IndexedSurfacesImpl> irSurfaces{
0161       rSurfaces, {}, {binR, binPhi}};
0162 
0163   GridAxisGenerators::EqBoundEqClosed aGenerator{
0164       {24., 152}, 8u, {-M_PI, M_PI}, 88u};
0165 
0166   PolyhedronReferenceGenerator<1u, true> rGenerator;
0167   auto indexedRing = irSurfaces(tContext, aGenerator, rGenerator);
0168   // The displaying
0169   auto pIndexedRing = IndexedSurfacesConverter::convert(
0170       tContext, rSurfaces, indexedRing, drawOptions);
0171   auto pIndexRingView = View::xy(pIndexedRing, "RingDisc2DFine");
0172 
0173   toFile({pIndexRingView}, pIndexRingView._id + ".svg");
0174 }
0175 
0176 BOOST_AUTO_TEST_CASE(RingDisc2DFineExpanded) {
0177   // Three rings to make a disc
0178   CylindricalTrackingGeometry::DetectorStore dStore;
0179   auto rSurfacesR0 = cGeometry.surfacesRing(dStore, 6.4, 12.4, 18., 0.125, 0.,
0180                                             42., 0., 2., 22u);
0181 
0182   auto rSurfacesR1 = cGeometry.surfacesRing(dStore, 12.4, 20.4, 30., 0.125, 0.,
0183                                             80., 0., 2., 22u);
0184 
0185   auto rSurfacesR2 = cGeometry.surfacesRing(dStore, 18.4, 28.4, 30., 0.125, 0.,
0186                                             122., 0., 2., 36u);
0187 
0188   decltype(rSurfacesR0) rSurfaces = rSurfacesR0;
0189   rSurfaces.insert(rSurfaces.end(), rSurfacesR1.begin(), rSurfacesR1.end());
0190   rSurfaces.insert(rSurfaces.end(), rSurfacesR2.begin(), rSurfacesR2.end());
0191 
0192   IndexedSurfacesGenerator<decltype(rSurfaces), IndexedSurfacesImpl> irSurfaces{
0193       rSurfaces, {}, {binR, binPhi}, {2u, 4u}};
0194 
0195   GridAxisGenerators::EqBoundEqClosed aGenerator{
0196       {24., 152}, 8u, {-M_PI, M_PI}, 88u};
0197   PolyhedronReferenceGenerator<1u, true> rGenerator;
0198 
0199   auto indexedRing = irSurfaces(tContext, aGenerator, rGenerator);
0200   // The displaying
0201   auto pIndexedRing = IndexedSurfacesConverter::convert(
0202       tContext, rSurfaces, indexedRing, drawOptions);
0203   auto pIndexRingView = View::xy(pIndexedRing, "RingDisc2DFineExpanded");
0204 
0205   toFile({pIndexRingView}, pIndexRingView._id + ".svg");
0206 }
0207 
0208 BOOST_AUTO_TEST_CASE(Cylinder2D) {
0209   CylindricalTrackingGeometry::DetectorStore dStore;
0210   auto surfaces = cGeometry.surfacesCylinder(dStore, 8.4, 36., 0.15, 0.145,
0211                                              116., 3., 2., {52, 14});
0212 
0213   IndexedSurfacesGenerator<decltype(surfaces), IndexedSurfacesImpl> icSurfaces{
0214       surfaces, {}, {binZ, binPhi}, {1u, 1u}};
0215 
0216   GridAxisGenerators::EqBoundEqClosed aGenerator{
0217       {-500., 500}, 28, {-M_PI, M_PI}, 52u};
0218   PolyhedronReferenceGenerator<1u, true> rGenerator;
0219 
0220   auto indexedCylinder = icSurfaces(tContext, aGenerator, rGenerator);
0221   // The displaying
0222   auto pIndexeCylinder = IndexedSurfacesConverter::convert(
0223       tContext, surfaces, indexedCylinder, drawOptions);
0224   auto pIndexCylinderView = View::zphi(pIndexeCylinder, "Cylinder");
0225 
0226   toFile({pIndexCylinderView}, pIndexCylinderView._id + ".svg");
0227 }
0228 
0229 BOOST_AUTO_TEST_SUITE_END()