Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-11 09:33:35

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