Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:23:37

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