Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-15 07:38: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 #pragma once
0010 
0011 #include "Acts/Geometry/GeometryHierarchyMap.hpp"
0012 #include "Acts/Utilities/Logger.hpp"
0013 #include "ActsExamples/EventData/Index.hpp"
0014 #include "ActsExamples/EventData/Measurement.hpp"
0015 #include "ActsExamples/EventData/SimParticle.hpp"
0016 #include "ActsExamples/EventData/TruthMatching.hpp"
0017 #include "ActsExamples/Framework/DataHandle.hpp"
0018 #include "ActsExamples/Framework/IAlgorithm.hpp"
0019 #include "ActsExamples/Framework/ProcessCode.hpp"
0020 
0021 #include <limits>
0022 #include <string>
0023 
0024 namespace ActsExamples {
0025 
0026 /// Select particles by applying some selection cuts.
0027 class ParticleSelector final : public IAlgorithm {
0028  public:
0029   struct MeasurementCounter {
0030     static constexpr std::uint32_t perLayerCapMax =
0031         std::numeric_limits<std::uint32_t>::max();
0032 
0033     /// Combination of a geometry hierarchy map and a minimum hit count
0034     struct CounterElement {
0035       Acts::GeometryHierarchyMap<std::uint32_t> geometryMap;
0036       std::uint32_t threshold{};
0037       std::uint32_t perLayerCap{perLayerCapMax};
0038 
0039       CounterElement(
0040           std::vector<Acts::GeometryHierarchyMap<std::uint32_t>::InputElement>&&
0041               geometryMap_,
0042           std::uint32_t threshold_, std::uint32_t perLayerCap_ = perLayerCapMax)
0043           : geometryMap(std::move(geometryMap_)),
0044             threshold(threshold_),
0045             perLayerCap(perLayerCap_) {}
0046     };
0047 
0048     boost::container::small_vector<CounterElement, 4> counters;
0049 
0050     bool isValidParticle(
0051         const SimParticle& particle,
0052         const InverseMultimap<SimBarcode>& particleMeasurementsMap,
0053         const MeasurementContainer& measurements) const;
0054 
0055     void addCounter(const std::vector<Acts::GeometryIdentifier>& identifiers,
0056                     std::uint32_t threshold,
0057                     std::uint32_t perLayerCap = perLayerCapMax) {
0058       std::vector<Acts::GeometryHierarchyMap<unsigned int>::InputElement>
0059           elements;
0060       for (const auto& id : identifiers) {
0061         elements.emplace_back(id, 0);
0062       }
0063       counters.emplace_back(std::move(elements), threshold, perLayerCap);
0064     }
0065   };
0066 
0067   struct Config {
0068     /// The input particles collection.
0069     std::string inputParticles;
0070     /// (Optionally) The input particle measurements map. Only required for
0071     /// measurement-based cuts.
0072     std::string inputParticleMeasurementsMap;
0073     /// (Optionally) The input measurements collection. Only required for
0074     /// measurement-based cuts.
0075     std::string inputMeasurements;
0076     /// The output particles collection.
0077     std::string outputParticles;
0078 
0079     // Minimum/maximum distance from the origin in the transverse plane.
0080     double rhoMin = 0;
0081     double rhoMax = std::numeric_limits<double>::infinity();
0082     // Minimum/maximum absolute distance from the origin along z.
0083     double absZMin = 0;
0084     double absZMax = std::numeric_limits<double>::infinity();
0085     // Minimum/maximum particle time.
0086     double timeMin = -std::numeric_limits<double>::infinity();
0087     double timeMax = std::numeric_limits<double>::infinity();
0088     // Direction cuts.
0089     double phiMin = -std::numeric_limits<double>::infinity();
0090     double phiMax = std::numeric_limits<double>::infinity();
0091     double etaMin = -std::numeric_limits<double>::infinity();
0092     double etaMax = std::numeric_limits<double>::infinity();
0093     double absEtaMin = 0;
0094     double absEtaMax = std::numeric_limits<double>::infinity();
0095     // Momentum cuts.
0096     double ptMin = 0;
0097     double ptMax = std::numeric_limits<double>::infinity();
0098     // Rest mass cuts
0099     double mMin = 0;
0100     double mMax = std::numeric_limits<double>::infinity();
0101     // Hit count cuts
0102     std::size_t hitsMin = 0;
0103     std::size_t hitsMax = std::numeric_limits<std::size_t>::max();
0104     // Measurement number cuts
0105     std::size_t measurementsMin = 0;
0106     std::size_t measurementsMax = std::numeric_limits<std::size_t>::max();
0107     /// Remove charged particles.
0108     bool removeCharged = false;
0109     /// Remove neutral particles.
0110     bool removeNeutral = false;
0111     /// Remove secondaries.
0112     bool removeSecondaries = false;
0113     /// Exclude particles depending on absolute pdg value
0114     std::vector<int> excludeAbsPdgs;
0115 
0116     /// Min primary vertex ID cut
0117     std::uint64_t minPrimaryVertexId = 0;
0118     /// Max primary vertex ID cut
0119     std::uint64_t maxPrimaryVertexId =
0120         std::numeric_limits<std::uint64_t>::max();
0121 
0122     /// The measurement counter to be used for the measurement cuts.
0123     MeasurementCounter measurementCounter;
0124   };
0125 
0126   explicit ParticleSelector(
0127       const Config& config,
0128       std::unique_ptr<const Acts::Logger> logger = nullptr);
0129 
0130   ProcessCode execute(const AlgorithmContext& ctx) const final;
0131 
0132   /// Get readonly access to the config parameters
0133   const Config& config() const { return m_cfg; }
0134 
0135  private:
0136   void logSelectionConfig() const;
0137 
0138   Config m_cfg;
0139 
0140   ReadDataHandle<SimParticleContainer> m_inputParticles{this, "InputParticles"};
0141   ReadDataHandle<ParticleMeasurementsMap> m_inputParticleMeasurementsMap{
0142       this, "InputParticleMeasurementsMap"};
0143   ReadDataHandle<MeasurementContainer> m_inputMeasurements{this,
0144                                                            "InputMeasurements"};
0145 
0146   WriteDataHandle<SimParticleContainer> m_outputParticles{this,
0147                                                           "OutputParticles"};
0148 };
0149 
0150 }  // namespace ActsExamples