Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Output.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Output.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 
47 
48 #include <array>
49 #include <memory>
50 #include <string>
51 #include <tuple>
52 #include <vector>
53 
54 #include <pybind11/pybind11.h>
55 #include <pybind11/stl.h>
56 
57 namespace Acts {
58 class TrackingGeometry;
59 namespace detail {
60 struct Step;
61 } // namespace detail
62 } // namespace Acts
63 namespace ActsExamples {
64 class IWriter;
65 struct AlgorithmContext;
66 } // namespace ActsExamples
67 
68 namespace py = pybind11;
69 using namespace pybind11::literals;
70 
71 using namespace ActsExamples;
72 
73 namespace {
74 template <ActsExamples::CsvBFieldWriter::CoordinateType CType, bool Grid>
75 void register_csv_bfield_writer_binding(
76  pybind11::class_<ActsExamples::CsvBFieldWriter>& w) {
78  std::string(CType == ActsExamples::CsvBFieldWriter::CoordinateType::XYZ
79  ? "Xyz"
80  : "Rz") +
81  std::string(Grid ? "Grid" : "Gridless");
82 
84  w.def_static((std::string("run") + name).c_str(),
87  },
88  py::arg("config"), py::arg("level"));
89  auto c = py::class_<Config>(w, (std::string("Config") + name).c_str())
90  .def(py::init<>());
92  ACTS_PYTHON_MEMBER(fileName);
94  ACTS_PYTHON_MEMBER(range);
97 }
98 } // namespace
99 
100 namespace Acts::Python {
101 void addOutput(Context& ctx) {
102  auto [m, mex] = ctx.get("main", "examples");
103 
106  "ObjPropagationStepsWriter", collection, outputDir, outputScalor,
107  outputPrecision);
108 
109  {
110  auto c = py::class_<ViewConfig>(m, "ViewConfig").def(py::init<>());
111 
116  ACTS_PYTHON_MEMBER(lineThickness);
117  ACTS_PYTHON_MEMBER(surfaceThickness);
118  ACTS_PYTHON_MEMBER(nSegments);
119  ACTS_PYTHON_MEMBER(triangulate);
122 
124  }
125 
126  {
128  auto w = py::class_<Writer, std::shared_ptr<Writer>>(
129  mex, "ObjTrackingGeometryWriter")
130  .def(py::init<const Writer::Config&, Acts::Logging::Level>(),
131  py::arg("config"), py::arg("level"))
132  .def("write", py::overload_cast<const AlgorithmContext&,
133  const Acts::TrackingGeometry&>(
134  &Writer::write));
135 
136  auto c = py::class_<Writer::Config>(w, "Config").def(py::init<>());
138  ACTS_PYTHON_MEMBER(outputScalor);
139  ACTS_PYTHON_MEMBER(outputPrecision);
141  ACTS_PYTHON_MEMBER(containerView);
142  ACTS_PYTHON_MEMBER(volumeView);
143  ACTS_PYTHON_MEMBER(sensitiveView);
144  ACTS_PYTHON_MEMBER(passiveView);
145  ACTS_PYTHON_MEMBER(gridView);
147  }
148 
149  // Bindings for the binning in e.g., CKFPerformanceWriter
150  {
151  py::class_<PlotHelpers::Binning>(mex, "Binning")
152  .def(py::init<std::string, int, double, double>(), "title"_a, "bins"_a,
153  "bMin"_a, "bMax"_a)
154  .def(py::init<std::string, std::vector<double>>(), "title"_a, "bins"_a);
155 
156  py::class_<EffPlotTool::Config>(mex, "EffPlotToolConfig")
157  .def(py::init<std::map<std::string, PlotHelpers::Binning>>(),
158  "varBinning"_a);
159 
160  py::class_<FakeRatePlotTool::Config>(mex, "FakeRatePlotToolConfig")
161  .def(py::init<std::map<std::string, PlotHelpers::Binning>>(),
162  "varBinning"_a);
163 
164  py::class_<DuplicationPlotTool::Config>(mex, "DuplicationPlotToolConfig")
165  .def(py::init<std::map<std::string, PlotHelpers::Binning>>(),
166  "varBinning"_a);
167  }
168 
169  // ROOT WRITERS
171  "RootPropagationStepsWriter", collection, filePath,
172  fileMode);
173 
175  "RootParticleWriter", inputParticles, filePath,
176  fileMode, treeName);
177 
179  "TrackFinderPerformanceWriter", inputProtoTracks,
181  filePath, fileMode, treeNameTracks,
182  treeNameParticles);
183 
185  "TrackFitterPerformanceWriter", inputTrajectories,
187  filePath, resPlotToolConfig, effPlotToolConfig,
188  trackSummaryPlotToolConfig);
189 
191  ActsExamples::SeedingPerformanceWriter, mex, "SeedingPerformanceWriter",
193  fileMode, effPlotToolConfig, duplicationPlotToolConfig);
194 
196  ActsExamples::RootTrackParameterWriter, mex, "RootTrackParameterWriter",
197  inputTrackParameters, inputProtoTracks, inputParticles, inputSimHits,
198  inputMeasurementParticlesMap, inputMeasurementSimHitsMap, filePath,
199  treeName, fileMode);
200 
202  "RootMaterialTrackWriter", collection, filePath,
203  fileMode, treeName, recalculateTotals, prePostStep,
204  storeSurface, storeVolume, collapseInteractions);
205 
206  {
207  using Writer = ActsExamples::RootBFieldWriter;
208  auto w =
209  py::class_<Writer>(mex, "RootBFieldWriter")
210  .def_static(
211  "run",
212  [](const Writer::Config& config, Acts::Logging::Level level) {
213  Writer::run(config, Acts::getDefaultLogger("RootBFieldWriter",
214  level));
215  },
216  py::arg("config"), py::arg("level"));
217 
218  py::enum_<Writer::GridType>(w, "GridType")
219  .value("rz", Writer::GridType::rz)
220  .value("xyz", Writer::GridType::xyz);
221 
222  auto c = py::class_<Writer::Config>(w, "Config").def(py::init<>());
224  ACTS_PYTHON_MEMBER(treeName);
225  ACTS_PYTHON_MEMBER(fileName);
226  ACTS_PYTHON_MEMBER(fileMode);
228  ACTS_PYTHON_MEMBER(gridType);
230  ACTS_PYTHON_MEMBER(zBounds);
231  ACTS_PYTHON_MEMBER(rBins);
232  ACTS_PYTHON_MEMBER(zBins);
233  ACTS_PYTHON_MEMBER(phiBins);
235  }
236 
237  {
239  auto w = py::class_<Writer, IWriter, std::shared_ptr<Writer>>(
240  mex, "RootMeasurementWriter")
241  .def(py::init<const Writer::Config&, Acts::Logging::Level>(),
242  py::arg("config"), py::arg("level"));
243 
244  auto c = py::class_<Writer::Config>(w, "Config").def(py::init<>());
245 
246  c.def("addBoundIndicesFromDigiConfig",
247  [](Writer::Config& self, const DigitizationConfig& digiCfg) {
248  self.boundIndices =
250  digiCfg.getBoundIndices());
251  });
252 
254  ACTS_PYTHON_MEMBER(inputMeasurements);
255  ACTS_PYTHON_MEMBER(inputClusters);
256  ACTS_PYTHON_MEMBER(inputSimHits);
257  ACTS_PYTHON_MEMBER(inputMeasurementSimHitsMap);
259  ACTS_PYTHON_MEMBER(fileMode);
260  ACTS_PYTHON_MEMBER(boundIndices);
263  }
264 
265  py::class_<IMaterialWriter, std::shared_ptr<IMaterialWriter>>(
266  mex, "IMaterialWriter");
267 
268  {
269  using Writer = ActsExamples::RootMaterialWriter;
270  auto w = py::class_<Writer, IMaterialWriter, std::shared_ptr<Writer>>(
271  mex, "RootMaterialWriter")
272  .def(py::init<const Writer::Config&, Acts::Logging::Level>(),
273  py::arg("config"), py::arg("level"))
274  .def("write", py::overload_cast<const Acts::TrackingGeometry&>(
275  &Writer::write));
276 
277  auto c = py::class_<Writer::Config>(w, "Config").def(py::init<>());
278 
280  ACTS_PYTHON_MEMBER(processSensitives);
281  ACTS_PYTHON_MEMBER(processApproaches);
282  ACTS_PYTHON_MEMBER(processRepresenting);
283  ACTS_PYTHON_MEMBER(processBoundaries);
284  ACTS_PYTHON_MEMBER(processVolumes);
285  ACTS_PYTHON_MEMBER(folderSurfaceNameBase);
286  ACTS_PYTHON_MEMBER(folderVolumeNameBase);
287  ACTS_PYTHON_MEMBER(voltag);
288  ACTS_PYTHON_MEMBER(boutag);
289  ACTS_PYTHON_MEMBER(laytag);
290  ACTS_PYTHON_MEMBER(apptag);
291  ACTS_PYTHON_MEMBER(sentag);
292  ACTS_PYTHON_MEMBER(ntag);
293  ACTS_PYTHON_MEMBER(vtag);
294  ACTS_PYTHON_MEMBER(otag);
295  ACTS_PYTHON_MEMBER(mintag);
296  ACTS_PYTHON_MEMBER(maxtag);
297  ACTS_PYTHON_MEMBER(ttag);
298  ACTS_PYTHON_MEMBER(x0tag);
299  ACTS_PYTHON_MEMBER(l0tag);
300  ACTS_PYTHON_MEMBER(atag);
301  ACTS_PYTHON_MEMBER(ztag);
302  ACTS_PYTHON_MEMBER(rhotag);
304  ACTS_PYTHON_MEMBER(fileMode);
306  }
307 
309  "RootPlanarClusterWriter", inputClusters,
310  inputSimHits, filePath, fileMode, treeName,
312 
314  "RootSimHitWriter", inputSimHits, filePath,
315  fileMode, treeName);
316 
318  "RootSpacepointWriter", inputSpacepoints, filePath,
319  fileMode, treeName);
320 
323  "RootTrajectoryStatesWriter", inputTrajectories, inputParticles,
324  inputSimHits, inputMeasurementParticlesMap, inputMeasurementSimHitsMap,
325  filePath, treeName, fileMode);
326 
328  "RootTrajectorySummaryWriter", inputTrajectories,
330  filePath, treeName, fileMode, writeCovMat);
331 
333  ActsExamples::VertexPerformanceWriter, mex, "VertexPerformanceWriter",
334  inputAllTruthParticles, inputSelectedTruthParticles, inputTrackParameters,
335  inputAssociatedTruthParticles, inputTrackParameters, inputTrajectories,
336  inputMeasurementParticlesMap, inputVertices, bField, filePath, treeName,
337  fileMode, minTrackVtxMatchFraction, truthMatchProbMin, useTracks);
338 
339  // CSV WRITERS
341  "CsvParticleWriter", inputParticles, outputDir,
342  outputStem, outputPrecision);
343 
345  "CsvMeasurementWriter", inputMeasurements,
346  inputClusters, inputMeasurementSimHitsMap,
347  outputDir, outputPrecision);
348 
350  "CsvPlanarClusterWriter", inputClusters,
351  inputSimHits, outputDir, outputPrecision,
353 
355  "CsvSimHitWriter", inputSimHits, outputDir,
356  outputStem, outputPrecision);
357 
359  "CsvSpacepointWriter", inputSpacepoints, outputDir,
360  outputPrecision);
361 
363  ActsExamples::CsvMultiTrajectoryWriter, mex, "CsvMultiTrajectoryWriter",
365  outputPrecision, nMeasurementsMin, truthMatchProbMin, ptMin);
366 
368  ActsExamples::CsvTrackingGeometryWriter, mex, "CsvTrackingGeometryWriter",
369  trackingGeometry, outputDir, outputPrecision, writeSensitive,
370  writeBoundary, writeSurfaceGrid, writeLayerVolume, writePerEvent);
371 
373  "CKFPerformanceWriter", inputTrajectories,
375  filePath, fileMode, effPlotToolConfig,
376  fakeRatePlotToolConfig, duplicationPlotToolConfig,
377  trackSummaryPlotToolConfig, duplicatedPredictor);
378 
381  "RootNuclearInteractionParametersWriter", inputSimulationProcesses,
382  filePath, fileMode, interactionProbabilityBins, momentumBins,
383  invariantMassBins, multiplicityMax, writeOptionalHistograms,
384  nSimulatedEvents);
385 
387  "CsvTrackParameterWriter", inputTrackParameters,
388  inputTrajectories, outputDir, outputStem,
389  outputPrecision);
390 
392  "CsvProtoTrackWriter", inputSpacepoints,
393  inputPrototracks, outputDir);
394 
395  {
396  using Writer = ActsExamples::CsvBFieldWriter;
397 
398  auto w = py::class_<Writer>(mex, "CsvBFieldWriter");
399 
400  py::enum_<Writer::CoordinateType>(w, "CoordinateType")
401  .value("rz", Writer::CoordinateType::RZ)
402  .value("xyz", Writer::CoordinateType::XYZ);
403 
404  register_csv_bfield_writer_binding<Writer::CoordinateType::XYZ, true>(w);
405  register_csv_bfield_writer_binding<Writer::CoordinateType::XYZ, false>(w);
406  register_csv_bfield_writer_binding<Writer::CoordinateType::RZ, true>(w);
407  register_csv_bfield_writer_binding<Writer::CoordinateType::RZ, false>(w);
408  }
409 }
410 } // namespace Acts::Python