Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-06-30 07:52:24

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