Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-18 08:22:58

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/TrackParamsLookupEstimation.hpp"
0010 
0011 #include "Acts/Surfaces/RectangleBounds.hpp"
0012 #include "ActsExamples/Framework/ProcessCode.hpp"
0013 
0014 namespace ActsExamples {
0015 
0016 TrackParamsLookupEstimation::TrackParamsLookupEstimation(
0017     const Config& config, std::unique_ptr<const Acts::Logger> logger)
0018     : IAlgorithm("TrackParamsLookupEstimation", std::move(logger)),
0019       m_cfg(config) {
0020   // Iterate over the reference layers and create
0021   // track parameter accumulators
0022   for (const auto& [geoId, refSurface] : m_cfg.refLayers) {
0023     // Get bounds to construct the accumulator grid
0024     auto bounds =
0025         dynamic_cast<const Acts::RectangleBounds*>(&refSurface->bounds());
0026 
0027     if (bounds == nullptr) {
0028       throw std::invalid_argument("Only rectangle bounds supported");
0029     }
0030     if (refSurface->type() != Acts::Surface::SurfaceType::Plane) {
0031       throw std::invalid_argument("Only plane surfaces supported");
0032     }
0033 
0034     // Initialize the accumulator grid
0035     auto halfX = bounds->halfLengthX();
0036     auto halfY = bounds->halfLengthY();
0037 
0038     TrackParamsLookupAxisGen axisGen{
0039         {-halfX, halfX}, m_cfg.bins.first, {-halfY, halfY}, m_cfg.bins.second};
0040 
0041     // Each reference layer has its own accumulator
0042     m_accumulators[geoId] = std::make_unique<TrackParamsLookupAccumulator>(
0043         TrackParamsLookupGrid(axisGen()));
0044   }
0045 
0046   m_inputParticles.initialize(m_cfg.inputParticles);
0047   m_inputSimHits.initialize(m_cfg.inputHits);
0048 }
0049 
0050 ProcessCode TrackParamsLookupEstimation::finalize() {
0051   // Finiliaze the lookup tables and write them
0052   TrackParamsLookup lookup;
0053   for (auto& [id, acc] : m_accumulators) {
0054     lookup.insert({id, acc->finalizeLookup()});
0055   }
0056   for (const auto& writer : m_cfg.trackLookupGridWriters) {
0057     writer->writeLookup(lookup);
0058   }
0059 
0060   return ProcessCode::SUCCESS;
0061 };
0062 
0063 ProcessCode TrackParamsLookupEstimation::execute(
0064     const AlgorithmContext& ctx) const {
0065   // Get the particles and hits
0066   const auto& particles = m_inputParticles(ctx);
0067   const auto& hits = m_inputSimHits(ctx);
0068 
0069   // Iterate over the reference layer hits and
0070   // accumulate the track parameters
0071   for (const auto& [geoId, refSurface] : m_cfg.refLayers) {
0072     // Get reference layer hits
0073     auto refLayerHits = hits.equal_range(geoId);
0074 
0075     for (auto hit = refLayerHits.first; hit != refLayerHits.second; ++hit) {
0076       // Get the corresponding particle
0077       const auto& id = hit->particleId();
0078       const auto& particle = particles.find(id);
0079 
0080       if (particle == particles.end()) {
0081         throw std::invalid_argument("Particle not found");
0082       }
0083 
0084       // Hit stores the reference layer parameters
0085       auto refLayerPars = Acts::BoundTrackParameters::createCurvilinear(
0086           hit->fourPosition(), hit->direction(), particle->qOverP(),
0087           std::nullopt, particle->hypothesis());
0088 
0089       // Particle stores the IP parameters
0090       auto ipPars = Acts::BoundTrackParameters::createCurvilinear(
0091           particle->fourPosition(), particle->direction(), particle->qOverP(),
0092           std::nullopt, particle->hypothesis());
0093 
0094       // Get the local position of the hit
0095       auto localPos = refSurface
0096                           ->globalToLocal(ctx.recoGeoContext, hit->position(),
0097                                           Acts::Vector3{0, 1, 0})
0098                           .value();
0099 
0100       // Add the track parameters to the accumulator grid
0101       m_accumulators.at(geoId)->addTrack(ipPars, refLayerPars, localPos);
0102     }
0103   }
0104 
0105   return ProcessCode::SUCCESS;
0106 }
0107 
0108 }  // namespace ActsExamples