Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackFinding.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrackFinding.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2021-2023 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
34 
35 #include <array>
36 #include <cstddef>
37 #include <memory>
38 #include <tuple>
39 #include <utility>
40 #include <vector>
41 
42 #include <pybind11/pybind11.h>
43 #include <pybind11/stl.h>
44 
45 namespace Acts {
47 class TrackingGeometry;
48 } // namespace Acts
49 namespace ActsExamples {
50 class IAlgorithm;
51 class SimSpacePoint;
52 } // namespace ActsExamples
53 
54 namespace py = pybind11;
55 
56 using namespace ActsExamples;
57 using namespace Acts;
58 
59 namespace Acts::Python {
60 
62  auto [m, mex] = ctx.get("main", "examples");
63 
65  "SpacePointMaker", inputSourceLinks,
66  inputMeasurements, outputSpacePoints,
68 
69  {
71  auto c = py::class_<Config>(m, "SeedFilterConfig").def(py::init<>());
73  ACTS_PYTHON_MEMBER(deltaInvHelixDiameter);
74  ACTS_PYTHON_MEMBER(impactWeightFactor);
75  ACTS_PYTHON_MEMBER(zOriginWeightFactor);
76  ACTS_PYTHON_MEMBER(compatSeedWeight);
77  ACTS_PYTHON_MEMBER(deltaRMin);
79  ACTS_PYTHON_MEMBER(compatSeedLimit);
80  ACTS_PYTHON_MEMBER(seedConfirmation);
81  ACTS_PYTHON_MEMBER(centralSeedConfirmationRange);
82  ACTS_PYTHON_MEMBER(forwardSeedConfirmationRange);
83  ACTS_PYTHON_MEMBER(useDeltaRorTopRadius);
84  ACTS_PYTHON_MEMBER(seedWeightIncrement);
85  ACTS_PYTHON_MEMBER(numSeedIncrement);
86  ACTS_PYTHON_MEMBER(maxSeedsPerSpMConf);
87  ACTS_PYTHON_MEMBER(maxQualitySeedsPerSpMConf);
90  }
91 
92  {
94  auto c = py::class_<Config>(m, "SeedFinderConfig").def(py::init<>());
97  ACTS_PYTHON_MEMBER(cotThetaMax);
98  ACTS_PYTHON_MEMBER(deltaRMin);
99  ACTS_PYTHON_MEMBER(deltaRMax);
100  ACTS_PYTHON_MEMBER(deltaRMinBottomSP);
101  ACTS_PYTHON_MEMBER(deltaRMaxBottomSP);
102  ACTS_PYTHON_MEMBER(deltaRMinTopSP);
103  ACTS_PYTHON_MEMBER(deltaRMaxTopSP);
106  ACTS_PYTHON_MEMBER(maxPtScattering);
108  ACTS_PYTHON_MEMBER(collisionRegionMin);
109  ACTS_PYTHON_MEMBER(collisionRegionMax);
111  ACTS_PYTHON_MEMBER(phiMax);
112  ACTS_PYTHON_MEMBER(zMin);
113  ACTS_PYTHON_MEMBER(zMax);
114  ACTS_PYTHON_MEMBER(zOutermostLayers);
115  ACTS_PYTHON_MEMBER(rMax);
116  ACTS_PYTHON_MEMBER(rMin);
118  ACTS_PYTHON_MEMBER(zAlign);
119  ACTS_PYTHON_MEMBER(rAlign);
120  ACTS_PYTHON_MEMBER(sigmaError);
121  ACTS_PYTHON_MEMBER(maxBlockSize);
122  ACTS_PYTHON_MEMBER(nTrplPerSpBLimit);
123  ACTS_PYTHON_MEMBER(nAvgTrplPerSpBLimit);
125  ACTS_PYTHON_MEMBER(deltaZMax);
126  ACTS_PYTHON_MEMBER(zBinEdges);
127  ACTS_PYTHON_MEMBER(interactionPointCut);
128  ACTS_PYTHON_MEMBER(zBinsCustomLooping);
129  ACTS_PYTHON_MEMBER(skipZMiddleBinSearch);
130  ACTS_PYTHON_MEMBER(useVariableMiddleSPRange);
131  ACTS_PYTHON_MEMBER(deltaRMiddleMinSPRange);
132  ACTS_PYTHON_MEMBER(deltaRMiddleMaxSPRange);
133  ACTS_PYTHON_MEMBER(rRangeMiddleSP);
134  ACTS_PYTHON_MEMBER(rMinMiddle);
135  ACTS_PYTHON_MEMBER(rMaxMiddle);
136  ACTS_PYTHON_MEMBER(binSizeR);
137  ACTS_PYTHON_MEMBER(seedConfirmation);
138  ACTS_PYTHON_MEMBER(centralSeedConfirmationRange);
139  ACTS_PYTHON_MEMBER(forwardSeedConfirmationRange);
140  ACTS_PYTHON_MEMBER(useDetailedDoubleMeasurementInfo);
143  }
144  {
145  using seedOptions = Acts::SeedFinderOptions;
146  auto c = py::class_<seedOptions>(m, "SeedFinderOptions").def(py::init<>());
147  ACTS_PYTHON_STRUCT_BEGIN(c, seedOptions);
148  ACTS_PYTHON_MEMBER(beamPos);
149  ACTS_PYTHON_MEMBER(bFieldInZ);
152  }
153  {
155  auto c =
156  py::class_<Config>(m, "SeedFinderOrthogonalConfig").def(py::init<>());
159  ACTS_PYTHON_MEMBER(cotThetaMax);
160  ACTS_PYTHON_MEMBER(deltaRMinBottomSP);
161  ACTS_PYTHON_MEMBER(deltaRMaxBottomSP);
162  ACTS_PYTHON_MEMBER(deltaRMinTopSP);
163  ACTS_PYTHON_MEMBER(deltaRMaxTopSP);
165  ACTS_PYTHON_MEMBER(deltaPhiMax);
166  ACTS_PYTHON_MEMBER(deltaZMax);
168  ACTS_PYTHON_MEMBER(maxPtScattering);
170  ACTS_PYTHON_MEMBER(collisionRegionMin);
171  ACTS_PYTHON_MEMBER(collisionRegionMax);
173  ACTS_PYTHON_MEMBER(phiMax);
174  ACTS_PYTHON_MEMBER(zMin);
175  ACTS_PYTHON_MEMBER(zMax);
176  ACTS_PYTHON_MEMBER(zOutermostLayers);
177  ACTS_PYTHON_MEMBER(rMax);
178  ACTS_PYTHON_MEMBER(rMin);
180  ACTS_PYTHON_MEMBER(deltaZMax);
181  ACTS_PYTHON_MEMBER(interactionPointCut);
182  ACTS_PYTHON_MEMBER(deltaPhiMax);
183  ACTS_PYTHON_MEMBER(highland);
184  ACTS_PYTHON_MEMBER(maxScatteringAngle2);
185  ACTS_PYTHON_MEMBER(useVariableMiddleSPRange);
186  ACTS_PYTHON_MEMBER(deltaRMiddleMinSPRange);
187  ACTS_PYTHON_MEMBER(deltaRMiddleMaxSPRange);
188  ACTS_PYTHON_MEMBER(rRangeMiddleSP);
189  ACTS_PYTHON_MEMBER(rMinMiddle);
190  ACTS_PYTHON_MEMBER(rMaxMiddle);
191  ACTS_PYTHON_MEMBER(seedConfirmation);
192  ACTS_PYTHON_MEMBER(centralSeedConfirmationRange);
193  ACTS_PYTHON_MEMBER(forwardSeedConfirmationRange);
196  }
197 
198  {
200  auto c = py::class_<Config>(m, "SeedFinderFTFConfig").def(py::init<>());
204  ACTS_PYTHON_MEMBER(highland);
205  ACTS_PYTHON_MEMBER(maxScatteringAngle2);
206  ACTS_PYTHON_MEMBER(fastrack_input_file);
207  ACTS_PYTHON_MEMBER(m_phiSliceWidth);
208  ACTS_PYTHON_MEMBER(m_nMaxPhiSlice);
209  ACTS_PYTHON_MEMBER(m_useClusterWidth);
210  ACTS_PYTHON_MEMBER(m_layerGeometry);
214  }
215 
216  {
217  using seedConf = Acts::SeedConfirmationRangeConfig;
218  auto c = py::class_<seedConf>(m, "SeedConfirmationRangeConfig")
219  .def(py::init<>());
220  ACTS_PYTHON_STRUCT_BEGIN(c, seedConf);
221  ACTS_PYTHON_MEMBER(zMinSeedConf);
222  ACTS_PYTHON_MEMBER(zMaxSeedConf);
223  ACTS_PYTHON_MEMBER(rMaxSeedConf);
224  ACTS_PYTHON_MEMBER(nTopForLargeR);
225  ACTS_PYTHON_MEMBER(nTopForSmallR);
226  ACTS_PYTHON_MEMBER(seedConfMinBottomRadius);
227  ACTS_PYTHON_MEMBER(seedConfMaxZOrigin);
228  ACTS_PYTHON_MEMBER(minImpactSeedConf);
231  }
232 
233  {
235  auto c = py::class_<Config>(m, "SpacePointGridConfig").def(py::init<>());
236 
239  ACTS_PYTHON_MEMBER(rMax);
240  ACTS_PYTHON_MEMBER(zMax);
241  ACTS_PYTHON_MEMBER(zMin);
243  ACTS_PYTHON_MEMBER(phiMax);
244  ACTS_PYTHON_MEMBER(deltaRMax);
245  ACTS_PYTHON_MEMBER(cotThetaMax);
246  ACTS_PYTHON_MEMBER(phiBinDeflectionCoverage);
247  ACTS_PYTHON_MEMBER(maxPhiBins);
249  ACTS_PYTHON_MEMBER(zBinEdges);
252  }
253  {
255  auto c = py::class_<Options>(m, "SpacePointGridOptions").def(py::init<>());
256 
258  ACTS_PYTHON_MEMBER(bFieldInZ);
261  }
262 
264  ActsExamples::SeedingAlgorithm, mex, "SeedingAlgorithm", inputSpacePoints,
265  outputSeeds, seedFilterConfig, seedFinderConfig, seedFinderOptions,
266  gridConfig, gridOptions, allowSeparateRMax, zBinNeighborsTop,
267  zBinNeighborsBottom, numPhiNeighbors);
268 
270  "SeedingOrthogonalAlgorithm", inputSpacePoints,
271  outputSeeds, seedFilterConfig, seedFinderConfig,
272  seedFinderOptions);
273 
275  ActsExamples::SeedingFTFAlgorithm, mex, "SeedingFTFAlgorithm",
276  inputSpacePoints, outputSeeds, seedFilterConfig, seedFinderConfig,
277  seedFinderOptions, layerMappingFile, geometrySelection, inputSourceLinks,
278  trackingGeometry, ACTS_FTF_Map, fill_module_csv);
279 
281  ActsExamples::HoughTransformSeeder, mex, "HoughTransformSeeder",
282  inputSpacePoints, outputProtoTracks, inputSourceLinks, trackingGeometry,
283  geometrySelection, inputMeasurements, subRegions, nLayers, xMin, xMax,
284  yMin, yMax, houghHistSize_x, houghHistSize_y, hitExtend_x, threshold,
285  localMaxWindowSize, kA);
286 
289  "TrackParamsEstimationAlgorithm", inputSeeds, inputProtoTracks,
290  outputTrackParameters, outputSeeds, outputProtoTracks, trackingGeometry,
291  magneticField, bFieldMin, initialSigmas, initialVarInflation,
293 
294  {
296  using Config = Alg::Config;
297 
298  auto alg =
299  py::class_<Alg, ActsExamples::IAlgorithm, std::shared_ptr<Alg>>(
300  mex, "TrackFindingAlgorithm")
301  .def(py::init<const Config&, Acts::Logging::Level>(),
302  py::arg("config"), py::arg("level"))
303  .def_property_readonly("config", &Alg::config)
304  .def_static("makeTrackFinderFunction",
305  [](std::shared_ptr<const Acts::TrackingGeometry>
307  std::shared_ptr<const Acts::MagneticFieldProvider>
310  return Alg::makeTrackFinderFunction(
311  trackingGeometry, magneticField,
312  *Acts::getDefaultLogger("TrackFinding", level));
313  });
314 
315  py::class_<Alg::TrackFinderFunction,
316  std::shared_ptr<Alg::TrackFinderFunction>>(
317  alg, "TrackFinderFunction");
318 
319  auto c = py::class_<Config>(alg, "Config").def(py::init<>());
321  ACTS_PYTHON_MEMBER(inputMeasurements);
322  ACTS_PYTHON_MEMBER(inputSourceLinks);
323  ACTS_PYTHON_MEMBER(inputInitialTrackParameters);
325  ACTS_PYTHON_MEMBER(findTracks);
326  ACTS_PYTHON_MEMBER(measurementSelectorCfg);
327  ACTS_PYTHON_MEMBER(trackSelectorCfg);
328  ACTS_PYTHON_MEMBER(backward);
329  ACTS_PYTHON_MEMBER(maxSteps);
331  }
332 
334  "TrajectoriesToPrototracks", inputTrajectories,
335  outputProtoTracks);
336 
338  "TracksToTrajectories", inputTracks,
340 
341  {
342  auto constructor = [](const std::vector<
343  std::pair<GeometryIdentifier,
344  std::tuple<std::vector<double>,
345  std::vector<double>,
346  std::vector<size_t>>>>& input) {
347  std::vector<std::pair<GeometryIdentifier, MeasurementSelectorCuts>>
348  converted;
349  converted.reserve(input.size());
350  for (const auto& [id, cuts] : input) {
351  const auto& [bins, chi2, num] = cuts;
352  converted.emplace_back(id, MeasurementSelectorCuts{bins, chi2, num});
353  }
354  return std::make_unique<MeasurementSelector::Config>(converted);
355  };
356 
357  py::class_<MeasurementSelectorCuts>(m, "MeasurementSelectorCuts")
358  .def(py::init<>())
359  .def(py::init<std::vector<double>, std::vector<double>,
360  std::vector<size_t>>())
361  .def_readwrite("etaBins", &MeasurementSelectorCuts::etaBins)
362  .def_readwrite("chi2CutOff", &MeasurementSelectorCuts::chi2CutOff)
363  .def_readwrite("numMeasurementsCutOff",
364  &MeasurementSelectorCuts::numMeasurementsCutOff);
365 
366  auto ms = py::class_<MeasurementSelector>(m, "MeasurementSelector");
367  auto c =
368  py::class_<MeasurementSelector::Config>(ms, "Config")
369  .def(py::init<std::vector<
370  std::pair<GeometryIdentifier, MeasurementSelectorCuts>>>())
371  .def(py::init(constructor));
372  }
373 
375  "SeedsToPrototracks", inputSeeds,
376  outputProtoTracks);
377 
379  ActsExamples::PrototracksToSeeds, mex, "PrototracksToSeeds",
380  inputProtoTracks, inputSpacePoints, outputSeeds, outputProtoTracks);
381 
383  ActsExamples::MeasurementMapSelector, mex, "MeasurementMapSelector",
384  inputMeasurementParticleMap, inputSourceLinks,
385  outputMeasurementParticleMap, geometrySelection);
386 }
387 
388 } // namespace Acts::Python