Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-22 07:53:24

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/GeometryIdentifier.hpp"
0013 #include "Acts/Seeding/HoughTransformUtils.hpp"
0014 #include "Acts/Utilities/Logger.hpp"
0015 
0016 #include <array>
0017 #include <memory>
0018 #include <vector>
0019 
0020 using namespace Acts;
0021 
0022 namespace ActsTests {
0023 
0024 auto logger = getDefaultLogger("UnitTests", Logging::VERBOSE);
0025 
0026 struct DriftCircle {
0027   double y{0.};
0028   double z{0.};
0029   double rDrift{0.};
0030   double rDriftError{0.};
0031 
0032   DriftCircle(const double _y, const double _z, const double _r,
0033               const double _rUncert)
0034       : y{_y}, z{_z}, rDrift{_r}, rDriftError{_rUncert} {}
0035 };
0036 
0037 BOOST_AUTO_TEST_SUITE(SeedingSuite)
0038 
0039 BOOST_AUTO_TEST_CASE(hough_transform_seeder) {
0040   Logging::ScopedFailureThreshold ft{Logging::FATAL};
0041 
0042   // we are using the slope on yz plane with the y coordinate (hardcoded from
0043   // the csv MuonSimHit data)
0044   std::vector<std::pair<double, double>> simHits = {
0045       {-0.0401472 / 0.994974, -422.612}};
0046 
0047   // Define the drift Circles
0048   constexpr double uncert{0.3};
0049   std::array<DriftCircle, 6> driftCircles{
0050       DriftCircle{-427.981, -225.541, 14.5202, uncert},
0051       DriftCircle{-412.964, -199.53, 1.66237, uncert},
0052       DriftCircle{-427.981, -173.519, 12.3176, uncert},
0053       DriftCircle{-427.981, 173.519, 1.5412, uncert},
0054       DriftCircle{-442.999, 199.53, 12.3937, uncert},
0055       DriftCircle{-427.981, 225.541, 3.77967, uncert}
0056 
0057   };
0058 
0059   // configure the binning of the hough plane
0060   HoughTransformUtils::HoughPlaneConfig planeCfg;
0061   planeCfg.nBinsX = 1000;
0062   planeCfg.nBinsY = 1000;
0063 
0064   // instantiate the peak finder
0065   HoughTransformUtils::PeakFinders::IslandsAroundMaxConfig peakFinderCfg;
0066   peakFinderCfg.fractionCutoff = 0.7;
0067   peakFinderCfg.threshold = 3.;
0068   peakFinderCfg.minSpacingBetweenPeaks = {0., 30.};
0069 
0070   // and map the hough plane to parameter ranges.
0071   // The first coordinate is tan(theta), the second is z0 in mm
0072   HoughTransformUtils::HoughAxisRanges axisRanges{-3., 3., -2000., 2000.};
0073 
0074   // create the functions parametrising the hough space lines for drift circles.
0075   // Note that there are two solutions for each drift circle and angle
0076 
0077   // left solution
0078   auto houghParamFromDCleft = [](double tanTheta, const DriftCircle& DC) {
0079     return DC.y - tanTheta * DC.z - DC.rDrift / std::cos(std::atan(tanTheta));
0080   };
0081   // right solution
0082   auto houghParamFromDCright = [](double tanTheta, const DriftCircle& DC) {
0083     return DC.y - tanTheta * DC.z + DC.rDrift / std::cos(std::atan(tanTheta));
0084   };
0085 
0086   // create the function parametrising the drift radius uncertainty
0087   auto houghWidthFromDC = [](double, const DriftCircle& DC) {
0088     return std::min(DC.rDriftError * 3.,
0089                     1.0);  // scale reported errors up to at least 1mm or 3
0090                            // times the reported error as drift circle calib not
0091                            // fully reliable at this stage
0092   };
0093 
0094   // instantiate the hough plane
0095   HoughTransformUtils::HoughPlane<GeometryIdentifier::Value> houghPlane(
0096       planeCfg);
0097 
0098   // also instantiate the peak finder
0099   HoughTransformUtils::PeakFinders::IslandsAroundMax<GeometryIdentifier::Value>
0100       peakFinder(peakFinderCfg);
0101 
0102   // loop over the true hits
0103   for (auto& sh : simHits) {
0104     houghPlane.reset();
0105 
0106     for (std::size_t k = 0; k < driftCircles.size(); ++k) {
0107       auto dc = driftCircles[k];
0108 
0109       houghPlane.fill<DriftCircle>(dc, axisRanges, houghParamFromDCleft,
0110                                    houghWidthFromDC, k);
0111       houghPlane.fill<DriftCircle>(dc, axisRanges, houghParamFromDCright,
0112                                    houghWidthFromDC, k);
0113     }
0114 
0115     // now get the peaks
0116     auto maxima = peakFinder.findPeaks(houghPlane, axisRanges);
0117     for (auto& max : maxima) {
0118       // check the Hough Transforms results
0119       BOOST_CHECK_CLOSE(max.x, sh.first, 4.);
0120       BOOST_CHECK_CLOSE(max.y, sh.second, 0.2);
0121     }
0122   }
0123 }
0124 
0125 BOOST_AUTO_TEST_SUITE_END()
0126 
0127 }  // namespace ActsTests