File indexing completed on 2025-01-18 09:12:04
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Plugins/Python/Utilities.hpp"
0010 #include "Acts/Utilities/Logger.hpp"
0011 #include "Acts/Visualization/IVisualization3D.hpp"
0012 #include "Acts/Visualization/ViewConfig.hpp"
0013 #include "ActsExamples/Io/Csv/CsvBFieldWriter.hpp"
0014 #include "ActsExamples/Io/Csv/CsvExaTrkXGraphWriter.hpp"
0015 #include "ActsExamples/Io/Csv/CsvMeasurementWriter.hpp"
0016 #include "ActsExamples/Io/Csv/CsvParticleWriter.hpp"
0017 #include "ActsExamples/Io/Csv/CsvProtoTrackWriter.hpp"
0018 #include "ActsExamples/Io/Csv/CsvSeedWriter.hpp"
0019 #include "ActsExamples/Io/Csv/CsvSimHitWriter.hpp"
0020 #include "ActsExamples/Io/Csv/CsvSpacePointWriter.hpp"
0021 #include "ActsExamples/Io/Csv/CsvSpacePointsBucketWriter.hpp"
0022 #include "ActsExamples/Io/Csv/CsvTrackParameterWriter.hpp"
0023 #include "ActsExamples/Io/Csv/CsvTrackWriter.hpp"
0024 #include "ActsExamples/Io/Csv/CsvTrackingGeometryWriter.hpp"
0025 #include "ActsExamples/Io/Obj/ObjPropagationStepsWriter.hpp"
0026 #include "ActsExamples/Io/Obj/ObjSimHitWriter.hpp"
0027 #include "ActsExamples/Io/Obj/ObjTrackingGeometryWriter.hpp"
0028 #include "ActsExamples/Io/Root/RootBFieldWriter.hpp"
0029 #include "ActsExamples/Io/Root/RootMaterialTrackWriter.hpp"
0030 #include "ActsExamples/Io/Root/RootMaterialWriter.hpp"
0031 #include "ActsExamples/Io/Root/RootMeasurementWriter.hpp"
0032 #include "ActsExamples/Io/Root/RootNuclearInteractionParametersWriter.hpp"
0033 #include "ActsExamples/Io/Root/RootParticleWriter.hpp"
0034 #include "ActsExamples/Io/Root/RootPropagationStepsWriter.hpp"
0035 #include "ActsExamples/Io/Root/RootPropagationSummaryWriter.hpp"
0036 #include "ActsExamples/Io/Root/RootSeedWriter.hpp"
0037 #include "ActsExamples/Io/Root/RootSimHitWriter.hpp"
0038 #include "ActsExamples/Io/Root/RootSpacepointWriter.hpp"
0039 #include "ActsExamples/Io/Root/RootTrackParameterWriter.hpp"
0040 #include "ActsExamples/Io/Root/RootTrackStatesWriter.hpp"
0041 #include "ActsExamples/Io/Root/RootTrackSummaryWriter.hpp"
0042 #include "ActsExamples/Io/Root/RootVertexWriter.hpp"
0043 #include "ActsExamples/Io/Root/SeedingPerformanceWriter.hpp"
0044 #include "ActsExamples/Io/Root/TrackFinderNTupleWriter.hpp"
0045 #include "ActsExamples/Io/Root/TrackFinderPerformanceWriter.hpp"
0046 #include "ActsExamples/Io/Root/TrackFitterPerformanceWriter.hpp"
0047 #include "ActsExamples/Io/Root/VertexNTupleWriter.hpp"
0048 #include "ActsExamples/MaterialMapping/IMaterialWriter.hpp"
0049 #include "ActsExamples/TrackFinding/ITrackParamsLookupReader.hpp"
0050 #include "ActsExamples/TrackFinding/ITrackParamsLookupWriter.hpp"
0051
0052 #include <memory>
0053 #include <string>
0054 #include <vector>
0055
0056 #include <pybind11/pybind11.h>
0057 #include <pybind11/stl.h>
0058 #include <pybind11/stl/filesystem.h>
0059
0060 namespace Acts {
0061 class TrackingGeometry;
0062 namespace detail {
0063 struct Step;
0064 }
0065 }
0066 namespace ActsExamples {
0067 class IWriter;
0068 struct AlgorithmContext;
0069 }
0070
0071 namespace py = pybind11;
0072 using namespace pybind11::literals;
0073
0074 using namespace ActsExamples;
0075
0076 namespace {
0077 template <ActsExamples::CsvBFieldWriter::CoordinateType CType, bool Grid>
0078 void register_csv_bfield_writer_binding(
0079 pybind11::class_<ActsExamples::CsvBFieldWriter>& w) {
0080 std::string name =
0081 std::string(CType == ActsExamples::CsvBFieldWriter::CoordinateType::XYZ
0082 ? "Xyz"
0083 : "Rz") +
0084 std::string(Grid ? "Grid" : "Gridless");
0085
0086 using Config = ActsExamples::CsvBFieldWriter::Config<CType, Grid>;
0087 w.def_static((std::string("run") + name).c_str(),
0088 [](const Config& config, Acts::Logging::Level level) {
0089 ActsExamples::CsvBFieldWriter::run(config, level);
0090 },
0091 py::arg("config"), py::arg("level"));
0092 auto c = py::class_<Config>(w, (std::string("Config") + name).c_str())
0093 .def(py::init<>());
0094 ACTS_PYTHON_STRUCT_BEGIN(c, Config);
0095 ACTS_PYTHON_MEMBER(fileName);
0096 ACTS_PYTHON_MEMBER(bField);
0097 ACTS_PYTHON_MEMBER(range);
0098 ACTS_PYTHON_MEMBER(bins);
0099 ACTS_PYTHON_STRUCT_END();
0100 }
0101 }
0102
0103 namespace Acts::Python {
0104
0105 void addOutput(Context& ctx) {
0106 auto [m, mex] = ctx.get("main", "examples");
0107
0108 ACTS_PYTHON_DECLARE_WRITER(ActsExamples::ObjPropagationStepsWriter, mex,
0109 "ObjPropagationStepsWriter", collection, outputDir,
0110 outputScalor, outputPrecision);
0111
0112 ACTS_PYTHON_DECLARE_WRITER(ActsExamples::ObjSimHitWriter, mex,
0113 "ObjSimHitWriter", inputSimHits, outputDir,
0114 outputStem, outputPrecision, drawConnections,
0115 momentumThreshold, momentumThresholdTraj,
0116 nInterpolatedPoints, keepOriginalHits);
0117
0118 {
0119 auto c = py::class_<ViewConfig>(m, "ViewConfig").def(py::init<>());
0120
0121 ACTS_PYTHON_STRUCT_BEGIN(c, ViewConfig);
0122 ACTS_PYTHON_MEMBER(visible);
0123 ACTS_PYTHON_MEMBER(color);
0124 ACTS_PYTHON_MEMBER(offset);
0125 ACTS_PYTHON_MEMBER(lineThickness);
0126 ACTS_PYTHON_MEMBER(surfaceThickness);
0127 ACTS_PYTHON_MEMBER(quarterSegments);
0128 ACTS_PYTHON_MEMBER(triangulate);
0129 ACTS_PYTHON_MEMBER(outputName);
0130 ACTS_PYTHON_STRUCT_END();
0131
0132 patchKwargsConstructor(c);
0133
0134 py::class_<Color>(m, "Color")
0135 .def(py::init<>())
0136 .def(py::init<int, int, int>())
0137 .def(py::init<double, double, double>())
0138 .def(py::init<std::string_view>())
0139 .def_readonly("rgb", &Color::rgb);
0140 }
0141
0142 py::class_<IVisualization3D>(m, "IVisualization3D")
0143 .def("write", py::overload_cast<const std::filesystem::path&>(
0144 &IVisualization3D::write, py::const_));
0145
0146 {
0147 using Writer = ActsExamples::ObjTrackingGeometryWriter;
0148 auto w = py::class_<Writer, std::shared_ptr<Writer>>(
0149 mex, "ObjTrackingGeometryWriter")
0150 .def(py::init<const Writer::Config&, Acts::Logging::Level>(),
0151 py::arg("config"), py::arg("level"))
0152 .def("write", py::overload_cast<const AlgorithmContext&,
0153 const Acts::TrackingGeometry&>(
0154 &Writer::write));
0155
0156 auto c = py::class_<Writer::Config>(w, "Config").def(py::init<>());
0157 ACTS_PYTHON_STRUCT_BEGIN(c, Writer::Config);
0158 ACTS_PYTHON_MEMBER(outputScalor);
0159 ACTS_PYTHON_MEMBER(outputPrecision);
0160 ACTS_PYTHON_MEMBER(outputDir);
0161 ACTS_PYTHON_MEMBER(containerView);
0162 ACTS_PYTHON_MEMBER(volumeView);
0163 ACTS_PYTHON_MEMBER(sensitiveView);
0164 ACTS_PYTHON_MEMBER(passiveView);
0165 ACTS_PYTHON_MEMBER(gridView);
0166 ACTS_PYTHON_STRUCT_END();
0167 }
0168
0169
0170 {
0171 py::class_<PlotHelpers::Binning>(mex, "Binning")
0172 .def(py::init<std::string, int, double, double>(), "title"_a, "bins"_a,
0173 "bMin"_a, "bMax"_a)
0174 .def(py::init<std::string, std::vector<double>>(), "title"_a, "bins"_a);
0175
0176 py::class_<EffPlotTool::Config>(mex, "EffPlotToolConfig")
0177 .def(py::init<std::map<std::string, PlotHelpers::Binning>>(),
0178 "varBinning"_a);
0179
0180 py::class_<FakeRatePlotTool::Config>(mex, "FakeRatePlotToolConfig")
0181 .def(py::init<std::map<std::string, PlotHelpers::Binning>>(),
0182 "varBinning"_a);
0183
0184 py::class_<DuplicationPlotTool::Config>(mex, "DuplicationPlotToolConfig")
0185 .def(py::init<std::map<std::string, PlotHelpers::Binning>>(),
0186 "varBinning"_a);
0187 }
0188
0189
0190 ACTS_PYTHON_DECLARE_WRITER(ActsExamples::RootPropagationStepsWriter, mex,
0191 "RootPropagationStepsWriter", collection, filePath,
0192 fileMode);
0193
0194 ACTS_PYTHON_DECLARE_WRITER(ActsExamples::RootPropagationSummaryWriter, mex,
0195 "RootPropagationSummaryWriter",
0196 inputSummaryCollection, filePath, fileMode);
0197
0198 ACTS_PYTHON_DECLARE_WRITER(ActsExamples::RootParticleWriter, mex,
0199 "RootParticleWriter", inputParticles, filePath,
0200 fileMode, treeName);
0201
0202 ACTS_PYTHON_DECLARE_WRITER(ActsExamples::RootVertexWriter, mex,
0203 "RootVertexWriter", inputVertices, filePath,
0204 fileMode, treeName);
0205
0206 ACTS_PYTHON_DECLARE_WRITER(ActsExamples::TrackFinderNTupleWriter, mex,
0207 "TrackFinderNTupleWriter", inputTracks,
0208 inputParticles, inputParticleMeasurementsMap,
0209 inputTrackParticleMatching, filePath, fileMode,
0210 treeNameTracks, treeNameParticles);
0211
0212 ACTS_PYTHON_DECLARE_WRITER(ActsExamples::TrackFitterPerformanceWriter, mex,
0213 "TrackFitterPerformanceWriter", inputTracks,
0214 inputParticles, inputTrackParticleMatching,
0215 filePath, resPlotToolConfig, effPlotToolConfig,
0216 trackSummaryPlotToolConfig);
0217
0218 ACTS_PYTHON_DECLARE_WRITER(
0219 ActsExamples::SeedingPerformanceWriter, mex, "SeedingPerformanceWriter",
0220 inputSeeds, inputMeasurementParticlesMap, inputParticles, filePath,
0221 fileMode, effPlotToolConfig, duplicationPlotToolConfig);
0222
0223 ACTS_PYTHON_DECLARE_WRITER(
0224 ActsExamples::RootTrackParameterWriter, mex, "RootTrackParameterWriter",
0225 inputTrackParameters, inputProtoTracks, inputParticles, inputSimHits,
0226 inputMeasurementParticlesMap, inputMeasurementSimHitsMap, filePath,
0227 treeName, fileMode);
0228
0229 ACTS_PYTHON_DECLARE_WRITER(
0230 ActsExamples::RootMaterialTrackWriter, mex, "RootMaterialTrackWriter",
0231 inputMaterialTracks, filePath, fileMode, treeName, recalculateTotals,
0232 prePostStep, storeSurface, storeVolume, collapseInteractions);
0233
0234 {
0235 using Writer = ActsExamples::RootBFieldWriter;
0236 auto w =
0237 py::class_<Writer>(mex, "RootBFieldWriter")
0238 .def_static(
0239 "run",
0240 [](const Writer::Config& config, Acts::Logging::Level level) {
0241 Writer::run(config, Acts::getDefaultLogger("RootBFieldWriter",
0242 level));
0243 },
0244 py::arg("config"), py::arg("level"));
0245
0246 py::enum_<Writer::GridType>(w, "GridType")
0247 .value("rz", Writer::GridType::rz)
0248 .value("xyz", Writer::GridType::xyz);
0249
0250 auto c = py::class_<Writer::Config>(w, "Config").def(py::init<>());
0251 ACTS_PYTHON_STRUCT_BEGIN(c, Writer::Config);
0252 ACTS_PYTHON_MEMBER(treeName);
0253 ACTS_PYTHON_MEMBER(fileName);
0254 ACTS_PYTHON_MEMBER(fileMode);
0255 ACTS_PYTHON_MEMBER(bField);
0256 ACTS_PYTHON_MEMBER(gridType);
0257 ACTS_PYTHON_MEMBER(rBounds);
0258 ACTS_PYTHON_MEMBER(zBounds);
0259 ACTS_PYTHON_MEMBER(rBins);
0260 ACTS_PYTHON_MEMBER(zBins);
0261 ACTS_PYTHON_MEMBER(phiBins);
0262 ACTS_PYTHON_STRUCT_END();
0263 }
0264
0265 {
0266 using Writer = ActsExamples::RootMeasurementWriter;
0267 auto w = py::class_<Writer, IWriter, std::shared_ptr<Writer>>(
0268 mex, "RootMeasurementWriter")
0269 .def(py::init<const Writer::Config&, Acts::Logging::Level>(),
0270 py::arg("config"), py::arg("level"));
0271
0272 auto c = py::class_<Writer::Config>(w, "Config").def(py::init<>());
0273
0274 ACTS_PYTHON_STRUCT_BEGIN(c, Writer::Config);
0275 ACTS_PYTHON_MEMBER(inputMeasurements);
0276 ACTS_PYTHON_MEMBER(inputClusters);
0277 ACTS_PYTHON_MEMBER(inputSimHits);
0278 ACTS_PYTHON_MEMBER(inputMeasurementSimHitsMap);
0279 ACTS_PYTHON_MEMBER(filePath);
0280 ACTS_PYTHON_MEMBER(fileMode);
0281 ACTS_PYTHON_MEMBER(surfaceByIdentifier);
0282 ACTS_PYTHON_STRUCT_END();
0283 }
0284
0285 py::class_<IMaterialWriter, std::shared_ptr<IMaterialWriter>>(
0286 mex, "IMaterialWriter");
0287
0288 py::class_<ActsExamples::ITrackParamsLookupWriter,
0289 std::shared_ptr<ActsExamples::ITrackParamsLookupWriter>>(
0290 mex, "ITrackParamsLookupWriter");
0291
0292 py::class_<ActsExamples::ITrackParamsLookupReader,
0293 std::shared_ptr<ActsExamples::ITrackParamsLookupReader>>(
0294 mex, "ITrackParamsLookupReader");
0295
0296 {
0297 using Writer = ActsExamples::RootMaterialWriter;
0298 auto w = py::class_<Writer, IMaterialWriter, std::shared_ptr<Writer>>(
0299 mex, "RootMaterialWriter")
0300 .def(py::init<const Writer::Config&, Acts::Logging::Level>(),
0301 py::arg("config"), py::arg("level"))
0302 .def("write", py::overload_cast<const Acts::TrackingGeometry&>(
0303 &Writer::write));
0304
0305 auto c = py::class_<Writer::Config>(w, "Config").def(py::init<>());
0306
0307 ACTS_PYTHON_STRUCT_BEGIN(c, Writer::Config);
0308 ACTS_PYTHON_MEMBER(processSensitives);
0309 ACTS_PYTHON_MEMBER(processApproaches);
0310 ACTS_PYTHON_MEMBER(processRepresenting);
0311 ACTS_PYTHON_MEMBER(processBoundaries);
0312 ACTS_PYTHON_MEMBER(processVolumes);
0313 ACTS_PYTHON_MEMBER(folderSurfaceNameBase);
0314 ACTS_PYTHON_MEMBER(folderVolumeNameBase);
0315 ACTS_PYTHON_MEMBER(voltag);
0316 ACTS_PYTHON_MEMBER(boutag);
0317 ACTS_PYTHON_MEMBER(laytag);
0318 ACTS_PYTHON_MEMBER(apptag);
0319 ACTS_PYTHON_MEMBER(sentag);
0320 ACTS_PYTHON_MEMBER(ntag);
0321 ACTS_PYTHON_MEMBER(vtag);
0322 ACTS_PYTHON_MEMBER(otag);
0323 ACTS_PYTHON_MEMBER(mintag);
0324 ACTS_PYTHON_MEMBER(maxtag);
0325 ACTS_PYTHON_MEMBER(ttag);
0326 ACTS_PYTHON_MEMBER(x0tag);
0327 ACTS_PYTHON_MEMBER(l0tag);
0328 ACTS_PYTHON_MEMBER(atag);
0329 ACTS_PYTHON_MEMBER(ztag);
0330 ACTS_PYTHON_MEMBER(rhotag);
0331 ACTS_PYTHON_MEMBER(filePath);
0332 ACTS_PYTHON_MEMBER(fileMode);
0333 ACTS_PYTHON_STRUCT_END();
0334 }
0335
0336 ACTS_PYTHON_DECLARE_WRITER(ActsExamples::RootSeedWriter, mex,
0337 "RootSeedWriter", inputSeeds, writingMode,
0338 filePath, fileMode, treeName);
0339
0340 ACTS_PYTHON_DECLARE_WRITER(ActsExamples::RootSimHitWriter, mex,
0341 "RootSimHitWriter", inputSimHits, filePath,
0342 fileMode, treeName);
0343
0344 ACTS_PYTHON_DECLARE_WRITER(ActsExamples::RootSpacepointWriter, mex,
0345 "RootSpacepointWriter", inputSpacepoints, filePath,
0346 fileMode, treeName);
0347
0348 ACTS_PYTHON_DECLARE_WRITER(
0349 ActsExamples::RootTrackStatesWriter, mex, "RootTrackStatesWriter",
0350 inputTracks, inputParticles, inputTrackParticleMatching, inputSimHits,
0351 inputMeasurementSimHitsMap, filePath, treeName, fileMode);
0352
0353 ACTS_PYTHON_DECLARE_WRITER(
0354 ActsExamples::RootTrackSummaryWriter, mex, "RootTrackSummaryWriter",
0355 inputTracks, inputParticles, inputTrackParticleMatching, filePath,
0356 treeName, fileMode, writeCovMat, writeGsfSpecific, writeGx2fSpecific);
0357
0358 ACTS_PYTHON_DECLARE_WRITER(
0359 ActsExamples::VertexNTupleWriter, mex, "VertexNTupleWriter",
0360 inputVertices, inputTracks, inputTruthVertices, inputParticles,
0361 inputSelectedParticles, inputTrackParticleMatching, bField, filePath,
0362 treeName, fileMode, vertexMatchThreshold, trackMatchThreshold, useTracks);
0363
0364
0365 ACTS_PYTHON_DECLARE_WRITER(ActsExamples::CsvParticleWriter, mex,
0366 "CsvParticleWriter", inputParticles, outputDir,
0367 outputStem, outputPrecision);
0368
0369 ACTS_PYTHON_DECLARE_WRITER(ActsExamples::CsvMeasurementWriter, mex,
0370 "CsvMeasurementWriter", inputMeasurements,
0371 inputClusters, inputMeasurementSimHitsMap,
0372 outputDir, outputPrecision);
0373
0374 ACTS_PYTHON_DECLARE_WRITER(ActsExamples::CsvSimHitWriter, mex,
0375 "CsvSimHitWriter", inputSimHits, outputDir,
0376 outputStem, outputPrecision);
0377
0378 ACTS_PYTHON_DECLARE_WRITER(ActsExamples::CsvSpacePointWriter, mex,
0379 "CsvSpacePointWriter", inputSpacepoints, outputDir,
0380 outputPrecision);
0381
0382 ACTS_PYTHON_DECLARE_WRITER(ActsExamples::CsvSpacePointsBucketWriter, mex,
0383 "CsvSpacePointsBucketWriter", inputBuckets,
0384 outputDir, outputPrecision);
0385
0386 ACTS_PYTHON_DECLARE_WRITER(ActsExamples::CsvTrackWriter, mex,
0387 "CsvTrackWriter", inputTracks, outputDir, fileName,
0388 inputMeasurementParticlesMap, outputPrecision,
0389 nMeasurementsMin, truthMatchProbMin, ptMin);
0390
0391 ACTS_PYTHON_DECLARE_WRITER(ActsExamples::CsvSeedWriter, mex, "CsvSeedWriter",
0392 inputTrackParameters, inputSimSeeds, inputSimHits,
0393 inputMeasurementParticlesMap,
0394 inputMeasurementSimHitsMap, fileName, outputDir);
0395
0396 ACTS_PYTHON_DECLARE_WRITER(
0397 ActsExamples::CsvTrackingGeometryWriter, mex, "CsvTrackingGeometryWriter",
0398 trackingGeometry, outputDir, outputPrecision, writeSensitive,
0399 writeBoundary, writeSurfaceGrid, writeLayerVolume, writePerEvent);
0400
0401 ACTS_PYTHON_DECLARE_WRITER(ActsExamples::TrackFinderPerformanceWriter, mex,
0402 "TrackFinderPerformanceWriter", inputTracks,
0403 inputParticles, inputTrackParticleMatching,
0404 inputParticleTrackMatching, filePath, fileMode,
0405 effPlotToolConfig, fakeRatePlotToolConfig,
0406 duplicationPlotToolConfig,
0407 trackSummaryPlotToolConfig, writeMatchingDetails);
0408
0409 ACTS_PYTHON_DECLARE_WRITER(
0410 ActsExamples::RootNuclearInteractionParametersWriter, mex,
0411 "RootNuclearInteractionParametersWriter", inputSimulationProcesses,
0412 filePath, fileMode, interactionProbabilityBins, momentumBins,
0413 invariantMassBins, multiplicityMax, writeOptionalHistograms,
0414 nSimulatedEvents);
0415
0416 ACTS_PYTHON_DECLARE_WRITER(ActsExamples::CsvTrackParameterWriter, mex,
0417 "CsvTrackParameterWriter", inputTrackParameters,
0418 inputTracks, outputDir, outputStem,
0419 outputPrecision);
0420
0421 ACTS_PYTHON_DECLARE_WRITER(ActsExamples::CsvProtoTrackWriter, mex,
0422 "CsvProtoTrackWriter", inputSpacepoints,
0423 inputPrototracks, outputDir);
0424
0425 {
0426 using Writer = ActsExamples::CsvBFieldWriter;
0427
0428 auto w = py::class_<Writer>(mex, "CsvBFieldWriter");
0429
0430 py::enum_<Writer::CoordinateType>(w, "CoordinateType")
0431 .value("rz", Writer::CoordinateType::RZ)
0432 .value("xyz", Writer::CoordinateType::XYZ);
0433
0434 register_csv_bfield_writer_binding<Writer::CoordinateType::XYZ, true>(w);
0435 register_csv_bfield_writer_binding<Writer::CoordinateType::XYZ, false>(w);
0436 register_csv_bfield_writer_binding<Writer::CoordinateType::RZ, true>(w);
0437 register_csv_bfield_writer_binding<Writer::CoordinateType::RZ, false>(w);
0438 }
0439
0440 ACTS_PYTHON_DECLARE_WRITER(ActsExamples::CsvExaTrkXGraphWriter, mex,
0441 "CsvExaTrkXGraphWriter", inputGraph, outputDir,
0442 outputStem);
0443 }
0444
0445 }