Back to home page

EIC code displayed by LXR

 
 

    


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

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