Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2019 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/Definitions/Units.hpp"
0014 #include "Acts/Digitization/CartesianSegmentation.hpp"
0015 #include "Acts/Digitization/DigitizationCell.hpp"
0016 #include "Acts/Digitization/DigitizationModule.hpp"
0017 #include "Acts/Digitization/PlanarModuleStepper.hpp"
0018 #include "Acts/Geometry/GeometryContext.hpp"
0019 #include "Acts/Surfaces/RectangleBounds.hpp"
0020 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0021 
0022 #include <cmath>
0023 #include <cstdlib>
0024 #include <memory>
0025 #include <random>
0026 #include <utility>
0027 #include <vector>
0028 
0029 namespace bdata = boost::unit_test::data;
0030 using namespace Acts::UnitLiterals;
0031 
0032 namespace Acts::Test {
0033 
0034 double halfX = 5_mm;
0035 double halfY = 10_mm;
0036 std::size_t ntests = 100;
0037 std::size_t nbinsx = 100;
0038 std::size_t nbinsy = 200;
0039 double hThickness = 75_um;
0040 double lAngle = 0.1;
0041 double tanAlpha = tan(lAngle);
0042 double sguardX = 2 * hThickness * abs(tanAlpha);
0043 
0044 // Module bounds
0045 auto moduleBounds = std::make_shared<const RectangleBounds>(halfX, halfY);
0046 auto cSegmentation =
0047     std::make_shared<const CartesianSegmentation>(moduleBounds, nbinsx, nbinsy);
0048 
0049 // Create digitisation modules
0050 // (1) positive readout
0051 DigitizationModule pdModule(cSegmentation, hThickness, 1, lAngle, 0., true);
0052 // (2) negative readout
0053 DigitizationModule ndModule(cSegmentation, hThickness, -1, lAngle, 0., true);
0054 std::vector<DigitizationModule> testModules = {pdModule, ndModule};
0055 
0056 /// The Planar module stepper
0057 PlanarModuleStepper pmStepper;
0058 
0059 // Create a test context
0060 GeometryContext tgContext = GeometryContext();
0061 
0062 /// The following test checks test cases where the entry and exit is
0063 /// guaranteed to be in on the readout/counter plane
0064 BOOST_DATA_TEST_CASE(
0065     readout_counter_test,
0066     bdata::random((bdata::engine = std::mt19937(), bdata::seed = 0,
0067                    bdata::distribution = std::uniform_real_distribution<double>(
0068                        -halfX + sguardX, halfX - sguardX))) ^
0069         bdata::random(
0070             (bdata::engine = std::mt19937(), bdata::seed = 1,
0071              bdata::distribution = std::uniform_real_distribution<double>(
0072                  -halfX + sguardX, halfX - sguardX))) ^
0073         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 2,
0074                        bdata::distribution =
0075                            std::uniform_real_distribution<double>(-halfY,
0076                                                                   halfY))) ^
0077         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 3,
0078                        bdata::distribution =
0079                            std::uniform_real_distribution<double>(-halfY,
0080                                                                   halfY))) ^
0081         bdata::xrange(ntests),
0082     entryX, entryY, exitX, exitY, index) {
0083   // avoid warning with void
0084   (void)index;
0085 
0086   // Entry and exit point
0087   Vector3 entry(entryX, entryY, -hThickness);
0088   Vector3 exit(exitX, exitY, hThickness);
0089 
0090   // test the module flavours
0091   for (auto& dm : testModules) {
0092     // retrieve the digitiztion steps
0093     auto cSteps = pmStepper.cellSteps(tgContext, dm, entry, exit);
0094     BOOST_CHECK_NE(cSteps.size(), 0);
0095 
0096     // Test if the longitudinal distance between first and last step
0097     // is equal/close to the thickness of the module
0098     auto fPosition = cSteps.begin()->stepEntry;
0099     auto lPosition = cSteps.rbegin()->stepExit;
0100     double zDiff = (lPosition - fPosition).z();
0101 
0102     CHECK_CLOSE_REL(zDiff, 2 * hThickness, 10e-6);
0103   }
0104 }
0105 
0106 }  // namespace Acts::Test