Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:09:48

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2022 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 "ActsExamples/TrackFinding/SeedingOrthogonalAlgorithm.hpp"
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Seeding/SeedFilter.hpp"
0013 #include "ActsExamples/EventData/SimSeed.hpp"
0014 
0015 #include <cmath>
0016 #include <functional>
0017 #include <ostream>
0018 #include <stdexcept>
0019 #include <type_traits>
0020 #include <utility>
0021 
0022 namespace ActsExamples {
0023 struct AlgorithmContext;
0024 }  // namespace ActsExamples
0025 
0026 ActsExamples::SeedingOrthogonalAlgorithm::SeedingOrthogonalAlgorithm(
0027     ActsExamples::SeedingOrthogonalAlgorithm::Config cfg,
0028     Acts::Logging::Level lvl)
0029     : ActsExamples::IAlgorithm("SeedingAlgorithm", lvl), m_cfg(std::move(cfg)) {
0030   m_cfg.seedFilterConfig = m_cfg.seedFilterConfig.toInternalUnits();
0031   m_cfg.seedFinderConfig =
0032       m_cfg.seedFinderConfig.toInternalUnits().calculateDerivedQuantities();
0033   m_cfg.seedFinderOptions =
0034       m_cfg.seedFinderOptions.toInternalUnits().calculateDerivedQuantities(
0035           m_cfg.seedFinderConfig);
0036 
0037   printOptions();
0038   printConfig<SimSpacePoint>();
0039 
0040   if (m_cfg.inputSpacePoints.empty()) {
0041     throw std::invalid_argument("Missing space point input collections");
0042   }
0043 
0044   for (const auto &spName : m_cfg.inputSpacePoints) {
0045     if (spName.empty()) {
0046       throw std::invalid_argument("Invalid space point input collection");
0047     }
0048 
0049     auto &handle = m_inputSpacePoints.emplace_back(
0050         std::make_unique<ReadDataHandle<SimSpacePointContainer>>(
0051             this,
0052             "InputSpacePoints#" + std::to_string(m_inputSpacePoints.size())));
0053     handle->initialize(spName);
0054   }
0055 
0056   if (m_cfg.outputSeeds.empty()) {
0057     throw std::invalid_argument("Missing seeds output collection");
0058   }
0059 
0060   m_outputSeeds.initialize(m_cfg.outputSeeds);
0061 
0062   if (m_cfg.seedFilterConfig.maxSeedsPerSpM !=
0063       m_cfg.seedFinderConfig.maxSeedsPerSpM) {
0064     throw std::invalid_argument("Inconsistent config maxSeedsPerSpM");
0065   }
0066 
0067   // construct seed filter
0068   m_cfg.seedFinderConfig.seedFilter =
0069       std::make_unique<Acts::SeedFilter<SimSpacePoint>>(
0070           Acts::SeedFilter<SimSpacePoint>(m_cfg.seedFilterConfig));
0071 
0072   m_finder = Acts::SeedFinderOrthogonal<SimSpacePoint>(m_cfg.seedFinderConfig);
0073 }
0074 
0075 ActsExamples::ProcessCode ActsExamples::SeedingOrthogonalAlgorithm::execute(
0076     const AlgorithmContext &ctx) const {
0077   std::vector<const SimSpacePoint *> spacePoints;
0078 
0079   for (const auto &isp : m_inputSpacePoints) {
0080     for (const auto &spacePoint : (*isp)(ctx)) {
0081       spacePoints.push_back(&spacePoint);
0082     }
0083   }
0084 
0085   Acts::SeedFinderOrthogonal<SimSpacePoint> finder(m_cfg.seedFinderConfig);
0086 
0087   std::function<
0088       std::tuple<Acts::Vector3, Acts::Vector2, std::optional<Acts::ActsScalar>>(
0089           const SimSpacePoint *sp)>
0090       create_coordinates = [](const SimSpacePoint *sp) {
0091         Acts::Vector3 position(sp->x(), sp->y(), sp->z());
0092         Acts::Vector2 variance(sp->varianceR(), sp->varianceZ());
0093         return std::make_tuple(position, variance, sp->t());
0094       };
0095 
0096   SimSeedContainer seeds = finder.createSeeds(m_cfg.seedFinderOptions,
0097                                               spacePoints, create_coordinates);
0098 
0099   ACTS_DEBUG("Created " << seeds.size() << " track seeds from "
0100                         << spacePoints.size() << " space points");
0101 
0102   m_outputSeeds(ctx, std::move(seeds));
0103 
0104   return ActsExamples::ProcessCode::SUCCESS;
0105 }
0106 
0107 void ActsExamples::SeedingOrthogonalAlgorithm::printOptions() const {
0108   ACTS_DEBUG("SeedFinderOptions")
0109   ACTS_DEBUG("beamPos           " << m_cfg.seedFinderOptions.beamPos);
0110   // field induction
0111   ACTS_DEBUG("bFieldInZ         " << m_cfg.seedFinderOptions.bFieldInZ);
0112   // derived quantities
0113   ACTS_DEBUG("pTPerHelixRadius  " << m_cfg.seedFinderOptions.pTPerHelixRadius);
0114   ACTS_DEBUG("minHelixDiameter2 " << m_cfg.seedFinderOptions.minHelixDiameter2);
0115   ACTS_DEBUG("pT2perRadius      " << m_cfg.seedFinderOptions.pT2perRadius);
0116   ACTS_DEBUG("sigmapT2perRadius " << m_cfg.seedFinderOptions.sigmapT2perRadius);
0117   ACTS_DEBUG("...\n")
0118 }
0119 
0120 template <typename sp>
0121 void ActsExamples::SeedingOrthogonalAlgorithm::printConfig() const {
0122   ACTS_DEBUG("SeedFinderOrthogonalConfig")
0123   ACTS_DEBUG("minPt                 " << m_cfg.seedFinderConfig.minPt);
0124   ACTS_DEBUG("deltaRMinTopSP        " << m_cfg.seedFinderConfig.deltaRMinTopSP);
0125   ACTS_DEBUG("deltaRMaxTopSP        " << m_cfg.seedFinderConfig.deltaRMaxTopSP);
0126   ACTS_DEBUG("deltaRMinBottomSP     "
0127              << m_cfg.seedFinderConfig.deltaRMinBottomSP);
0128   ACTS_DEBUG("deltaRMaxBottomSP     "
0129              << m_cfg.seedFinderConfig.deltaRMaxBottomSP);
0130   ACTS_DEBUG("impactMax             " << m_cfg.seedFinderConfig.impactMax);
0131   ACTS_DEBUG("maxPtScattering       "
0132              << m_cfg.seedFinderConfig.maxPtScattering);
0133   ACTS_DEBUG("collisionRegionMin    "
0134              << m_cfg.seedFinderConfig.collisionRegionMin);
0135   ACTS_DEBUG("collisionRegionMax    "
0136              << m_cfg.seedFinderConfig.collisionRegionMax);
0137   ACTS_DEBUG("zMin                  " << m_cfg.seedFinderConfig.zMin);
0138   ACTS_DEBUG("zMax                  " << m_cfg.seedFinderConfig.zMax);
0139   ACTS_DEBUG("rMax                  " << m_cfg.seedFinderConfig.rMax);
0140   ACTS_DEBUG("rMin                  " << m_cfg.seedFinderConfig.rMin);
0141   ACTS_DEBUG("highland              " << m_cfg.seedFinderConfig.highland);
0142   ACTS_DEBUG("maxScatteringAngle2   "
0143              << m_cfg.seedFinderConfig.maxScatteringAngle2);
0144   ACTS_DEBUG("...\n")
0145 }