Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:40

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 "ActsExamples/TrackFinding/SeedingOrthogonalAlgorithm.hpp"
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/EventData/Seed.hpp"
0013 #include "Acts/Seeding/SeedFilter.hpp"
0014 #include "ActsExamples/EventData/SimSeed.hpp"
0015 
0016 #include <cmath>
0017 #include <functional>
0018 #include <ostream>
0019 #include <stdexcept>
0020 #include <type_traits>
0021 #include <utility>
0022 
0023 namespace ActsExamples {
0024 struct AlgorithmContext;
0025 }  // namespace ActsExamples
0026 
0027 ActsExamples::SeedingOrthogonalAlgorithm::SeedingOrthogonalAlgorithm(
0028     ActsExamples::SeedingOrthogonalAlgorithm::Config cfg,
0029     Acts::Logging::Level lvl)
0030     : ActsExamples::IAlgorithm("SeedingAlgorithm", lvl), m_cfg(std::move(cfg)) {
0031   m_cfg.seedFilterConfig = m_cfg.seedFilterConfig.toInternalUnits();
0032   m_cfg.seedFinderConfig =
0033       m_cfg.seedFinderConfig.toInternalUnits().calculateDerivedQuantities();
0034   m_cfg.seedFinderOptions =
0035       m_cfg.seedFinderOptions.toInternalUnits().calculateDerivedQuantities(
0036           m_cfg.seedFinderConfig);
0037 
0038   printOptions();
0039   printConfig<SimSpacePoint>();
0040 
0041   if (m_cfg.inputSpacePoints.empty()) {
0042     throw std::invalid_argument("Missing space point input collections");
0043   }
0044 
0045   for (const auto &spName : m_cfg.inputSpacePoints) {
0046     if (spName.empty()) {
0047       throw std::invalid_argument("Invalid space point input collection");
0048     }
0049 
0050     auto &handle = m_inputSpacePoints.emplace_back(
0051         std::make_unique<ReadDataHandle<SimSpacePointContainer>>(
0052             this,
0053             "InputSpacePoints#" + std::to_string(m_inputSpacePoints.size())));
0054     handle->initialize(spName);
0055   }
0056 
0057   if (m_cfg.outputSeeds.empty()) {
0058     throw std::invalid_argument("Missing seeds output collection");
0059   }
0060 
0061   m_outputSeeds.initialize(m_cfg.outputSeeds);
0062 
0063   if (m_cfg.seedFilterConfig.maxSeedsPerSpM !=
0064       m_cfg.seedFinderConfig.maxSeedsPerSpM) {
0065     throw std::invalid_argument("Inconsistent config maxSeedsPerSpM");
0066   }
0067 
0068   // construct seed filter
0069   m_cfg.seedFinderConfig.seedFilter =
0070       std::make_unique<Acts::SeedFilter<proxy_type>>(
0071           m_cfg.seedFilterConfig, logger().cloneWithSuffix("Filter"));
0072 
0073   m_finder = std::make_unique<Acts::SeedFinderOrthogonal<proxy_type>>(
0074       m_cfg.seedFinderConfig, logger().cloneWithSuffix("Finder"));
0075 }
0076 
0077 ActsExamples::ProcessCode ActsExamples::SeedingOrthogonalAlgorithm::execute(
0078     const AlgorithmContext &ctx) const {
0079   std::vector<const SimSpacePoint *> spacePoints;
0080 
0081   for (const auto &isp : m_inputSpacePoints) {
0082     for (const auto &spacePoint : (*isp)(ctx)) {
0083       spacePoints.push_back(&spacePoint);
0084     }
0085   }
0086 
0087   // Config
0088   Acts::SpacePointContainerConfig spConfig;
0089 
0090   // Options
0091   Acts::SpacePointContainerOptions spOptions;
0092   spOptions.beamPos = {0., 0.};
0093 
0094   ActsExamples::SpacePointContainer container(spacePoints);
0095   Acts::SpacePointContainer<decltype(container), Acts::detail::RefHolder>
0096       spContainer(spConfig, spOptions, container);
0097 
0098   ACTS_INFO("About to process " << spContainer.size() << " space points ...");
0099 
0100   std::vector<Acts::Seed<proxy_type>> seeds =
0101       m_finder->createSeeds(m_cfg.seedFinderOptions, spContainer);
0102 
0103   ACTS_INFO("Created " << seeds.size() << " track seeds from "
0104                        << spacePoints.size() << " space points");
0105 
0106   // need to convert here from seed of proxies to seed of sps
0107   SimSeedContainer seedsToAdd;
0108   seedsToAdd.reserve(seeds.size());
0109 
0110   for (const auto &seed : seeds) {
0111     const auto &sps = seed.sp();
0112     seedsToAdd.emplace_back(*sps[0]->externalSpacePoint(),
0113                             *sps[1]->externalSpacePoint(),
0114                             *sps[2]->externalSpacePoint());
0115     seedsToAdd.back().setVertexZ(seed.z());
0116     seedsToAdd.back().setQuality(seed.seedQuality());
0117   }
0118 
0119   m_outputSeeds(ctx, std::move(seedsToAdd));
0120 
0121   return ActsExamples::ProcessCode::SUCCESS;
0122 }
0123 
0124 void ActsExamples::SeedingOrthogonalAlgorithm::printOptions() const {
0125   ACTS_DEBUG("SeedFinderOptions");
0126   ACTS_DEBUG("beamPos           " << m_cfg.seedFinderOptions.beamPos);
0127   // field induction
0128   ACTS_DEBUG("bFieldInZ         " << m_cfg.seedFinderOptions.bFieldInZ);
0129   // derived quantities
0130   ACTS_DEBUG("pTPerHelixRadius  " << m_cfg.seedFinderOptions.pTPerHelixRadius);
0131   ACTS_DEBUG("minHelixDiameter2 " << m_cfg.seedFinderOptions.minHelixDiameter2);
0132   ACTS_DEBUG("pT2perRadius      " << m_cfg.seedFinderOptions.pT2perRadius);
0133   ACTS_DEBUG("sigmapT2perRadius " << m_cfg.seedFinderOptions.sigmapT2perRadius);
0134   ACTS_DEBUG("...\n");
0135 }
0136 
0137 template <typename sp>
0138 void ActsExamples::SeedingOrthogonalAlgorithm::printConfig() const {
0139   ACTS_DEBUG("SeedFinderOrthogonalConfig");
0140   ACTS_DEBUG("minPt                 " << m_cfg.seedFinderConfig.minPt);
0141   ACTS_DEBUG("deltaRMinTopSP        " << m_cfg.seedFinderConfig.deltaRMinTopSP);
0142   ACTS_DEBUG("deltaRMaxTopSP        " << m_cfg.seedFinderConfig.deltaRMaxTopSP);
0143   ACTS_DEBUG("deltaRMinBottomSP     "
0144              << m_cfg.seedFinderConfig.deltaRMinBottomSP);
0145   ACTS_DEBUG("deltaRMaxBottomSP     "
0146              << m_cfg.seedFinderConfig.deltaRMaxBottomSP);
0147   ACTS_DEBUG("impactMax             " << m_cfg.seedFinderConfig.impactMax);
0148   ACTS_DEBUG("maxPtScattering       "
0149              << m_cfg.seedFinderConfig.maxPtScattering);
0150   ACTS_DEBUG("collisionRegionMin    "
0151              << m_cfg.seedFinderConfig.collisionRegionMin);
0152   ACTS_DEBUG("collisionRegionMax    "
0153              << m_cfg.seedFinderConfig.collisionRegionMax);
0154   ACTS_DEBUG("zMin                  " << m_cfg.seedFinderConfig.zMin);
0155   ACTS_DEBUG("zMax                  " << m_cfg.seedFinderConfig.zMax);
0156   ACTS_DEBUG("rMax                  " << m_cfg.seedFinderConfig.rMax);
0157   ACTS_DEBUG("rMin                  " << m_cfg.seedFinderConfig.rMin);
0158   ACTS_DEBUG("highland              " << m_cfg.seedFinderConfig.highland);
0159   ACTS_DEBUG("maxScatteringAngle2   "
0160              << m_cfg.seedFinderConfig.maxScatteringAngle2);
0161   ACTS_DEBUG("...\n");
0162 }