Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:10:04

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2021 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #include "Acts/Definitions/Algebra.hpp"
0010 #include "Acts/Plugins/Python/Utilities.hpp"
0011 #include "Acts/TrackFinding/TrackSelector.hpp"
0012 #include "ActsExamples/Fatras/FatrasSimulation.hpp"
0013 #include "ActsExamples/Io/Json/JsonGeometryList.hpp"
0014 #include "ActsExamples/Printers/HitsPrinter.hpp"
0015 #include "ActsExamples/Printers/ParticlesPrinter.hpp"
0016 #include "ActsExamples/Printers/TrackParametersPrinter.hpp"
0017 #include "ActsExamples/Utilities/Range.hpp"
0018 #include "ActsExamples/Utilities/TrackSelectorAlgorithm.hpp"
0019 
0020 #include <vector>
0021 
0022 #include <pybind11/pybind11.h>
0023 #include <pybind11/stl.h>
0024 
0025 namespace py = pybind11;
0026 
0027 using namespace ActsExamples;
0028 using namespace Acts;
0029 
0030 namespace Acts::Python {
0031 
0032 void addExampleAlgorithms(Context& ctx) {
0033   auto [m, mex] = ctx.get("main", "examples");
0034 
0035   mex.def("readJsonGeometryList", ActsExamples::readJsonGeometryList);
0036 
0037   ACTS_PYTHON_DECLARE_ALGORITHM(
0038       ActsExamples::FatrasSimulation, mex, "FatrasSimulation", inputParticles,
0039       outputParticlesInitial, outputParticlesFinal, outputSimHits,
0040       imputParametrisationNuclearInteraction, randomNumbers, trackingGeometry,
0041       magneticField, pMin, emScattering, emEnergyLossIonisation,
0042       emEnergyLossRadiation, emPhotonConversion, generateHitsOnSensitive,
0043       generateHitsOnMaterial, generateHitsOnPassive, averageHitsPerParticle);
0044 
0045   ACTS_PYTHON_DECLARE_ALGORITHM(ActsExamples::ParticlesPrinter, mex,
0046                                 "ParticlesPrinter", inputParticles);
0047 
0048   ACTS_PYTHON_DECLARE_ALGORITHM(
0049       ActsExamples::HitsPrinter, mex, "HitsPrinter", inputClusters,
0050       inputMeasurementParticlesMap, inputHitIds, selectIndexStart,
0051       selectIndexLength, selectVolume, selectLayer, selectModule);
0052 
0053   ACTS_PYTHON_DECLARE_ALGORITHM(ActsExamples::TrackParametersPrinter, mex,
0054                                 "TrackParametersPrinter", inputTrackParameters);
0055 
0056   {
0057     using Alg = ActsExamples::TrackSelectorAlgorithm;
0058     using Config = Alg::Config;
0059 
0060     auto alg = py::class_<Alg, IAlgorithm, std::shared_ptr<Alg>>(
0061                    mex, "TrackSelectorAlgorithm")
0062                    .def(py::init<const Alg::Config&, Acts::Logging::Level>(),
0063                         py::arg("config"), py::arg("level"))
0064                    .def_property_readonly("config", &Alg::config);
0065 
0066     auto c = py::class_<Config>(alg, "Config").def(py::init<>());
0067 
0068     ACTS_PYTHON_STRUCT_BEGIN(c, Config);
0069     ACTS_PYTHON_MEMBER(inputTracks);
0070     ACTS_PYTHON_MEMBER(outputTracks);
0071     ACTS_PYTHON_MEMBER(selectorConfig);
0072     ACTS_PYTHON_STRUCT_END();
0073   }
0074 
0075   {
0076     using EtaBinnedConfig = Acts::TrackSelector::EtaBinnedConfig;
0077     using Config = Acts::TrackSelector::Config;
0078 
0079     auto tool = py::class_<Acts::TrackSelector>(m, "TrackSelector")
0080                     .def(py::init<const Config&>(), py::arg("config"))
0081                     .def(py::init<const EtaBinnedConfig&>(), py::arg("config"));
0082 
0083     {
0084       auto mc = py::class_<Acts::TrackSelector::MeasurementCounter>(
0085                     tool, "MeasurementCounter")
0086                     .def(py::init<>())
0087                     .def("addCounter",
0088                          &Acts::TrackSelector::MeasurementCounter::addCounter);
0089     }
0090 
0091     {
0092       auto c = py::class_<Config>(tool, "Config").def(py::init<>());
0093 
0094       patchKwargsConstructor(c);
0095 
0096       ACTS_PYTHON_STRUCT_BEGIN(c, Config);
0097       ACTS_PYTHON_MEMBER(loc0Min);
0098       ACTS_PYTHON_MEMBER(loc0Max);
0099       ACTS_PYTHON_MEMBER(loc1Min);
0100       ACTS_PYTHON_MEMBER(loc1Max);
0101       ACTS_PYTHON_MEMBER(timeMin);
0102       ACTS_PYTHON_MEMBER(timeMax);
0103       ACTS_PYTHON_MEMBER(phiMin);
0104       ACTS_PYTHON_MEMBER(phiMax);
0105       ACTS_PYTHON_MEMBER(etaMin);
0106       ACTS_PYTHON_MEMBER(etaMax);
0107       ACTS_PYTHON_MEMBER(absEtaMin);
0108       ACTS_PYTHON_MEMBER(absEtaMax);
0109       ACTS_PYTHON_MEMBER(ptMin);
0110       ACTS_PYTHON_MEMBER(ptMax);
0111       ACTS_PYTHON_MEMBER(minMeasurements);
0112       ACTS_PYTHON_MEMBER(maxHoles);
0113       ACTS_PYTHON_MEMBER(maxOutliers);
0114       ACTS_PYTHON_MEMBER(maxSharedHits);
0115       ACTS_PYTHON_MEMBER(maxChi2);
0116       ACTS_PYTHON_MEMBER(measurementCounter);
0117       ACTS_PYTHON_STRUCT_END();
0118 
0119       pythonRangeProperty(c, "loc0", &Config::loc0Min, &Config::loc0Max);
0120       pythonRangeProperty(c, "loc1", &Config::loc1Min, &Config::loc1Max);
0121       pythonRangeProperty(c, "time", &Config::timeMin, &Config::timeMax);
0122       pythonRangeProperty(c, "phi", &Config::phiMin, &Config::phiMax);
0123       pythonRangeProperty(c, "eta", &Config::etaMin, &Config::etaMax);
0124       pythonRangeProperty(c, "absEta", &Config::absEtaMin, &Config::absEtaMax);
0125       pythonRangeProperty(c, "pt", &Config::ptMin, &Config::ptMax);
0126     }
0127 
0128     {
0129       auto c = py::class_<EtaBinnedConfig>(tool, "EtaBinnedConfig")
0130                    .def(py::init<>())
0131                    .def(py::init<const Config&>());
0132 
0133       patchKwargsConstructor(c);
0134 
0135       c.def_property_readonly("nEtaBins", &EtaBinnedConfig::nEtaBins);
0136 
0137       ACTS_PYTHON_STRUCT_BEGIN(c, EtaBinnedConfig);
0138       ACTS_PYTHON_MEMBER(cutSets);
0139       ACTS_PYTHON_MEMBER(absEtaEdges);
0140       ACTS_PYTHON_STRUCT_END();
0141     }
0142   }
0143 }
0144 }  // namespace Acts::Python