Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Detector.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Detector.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2021 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 
20 
21 #include <array>
22 #include <cstddef>
23 #include <memory>
24 #include <optional>
25 #include <string>
26 #include <tuple>
27 #include <utility>
28 #include <vector>
29 
30 #include <pybind11/pybind11.h>
31 #include <pybind11/stl.h>
32 
33 namespace py = pybind11;
34 using namespace ActsExamples;
35 
36 namespace Acts::Python {
37 void addDetector(Context& ctx) {
38  auto [m, mex] = ctx.get("main", "examples");
39  {
40  py::class_<IContextDecorator, std::shared_ptr<IContextDecorator>>(
41  mex, "IContextDecorator")
42  .def("decorate", &IContextDecorator::decorate)
43  .def("name", &IContextDecorator::name);
44  }
45 
46  {
48 
49  auto gd = py::class_<GenericDetector, std::shared_ptr<GenericDetector>>(
50  mex, "GenericDetector")
51  .def(py::init<>())
52  .def("finalize",
53  py::overload_cast<
54  const Config&,
55  std::shared_ptr<const Acts::IMaterialDecorator>>(
57 
58  py::class_<Config>(gd, "Config")
59  .def(py::init<>())
60  .def_readwrite("buildLevel", &Config::buildLevel)
61  .def_readwrite("surfaceLogLevel", &Config::surfaceLogLevel)
62  .def_readwrite("layerLogLevel", &Config::layerLogLevel)
63  .def_readwrite("volumeLogLevel", &Config::volumeLogLevel)
64  .def_readwrite("buildProto", &Config::buildProto);
65  }
66 
67  {
68  using TelescopeDetector = Telescope::TelescopeDetector;
70 
71  auto td =
72  py::class_<TelescopeDetector, std::shared_ptr<TelescopeDetector>>(
73  mex, "TelescopeDetector")
74  .def(py::init<>())
75  .def("finalize",
76  py::overload_cast<
77  const Config&,
78  const std::shared_ptr<const Acts::IMaterialDecorator>&>(
80 
81  py::class_<Config>(td, "Config")
82  .def(py::init<>())
83  .def_readwrite("positions", &Config::positions)
84  .def_readwrite("stereos", &Config::stereos)
85  .def_readwrite("offsets", &Config::offsets)
86  .def_readwrite("bounds", &Config::bounds)
87  .def_readwrite("thickness", &Config::thickness)
88  .def_readwrite("surfaceType", &Config::surfaceType)
89  .def_readwrite("binValue", &Config::binValue);
90  }
91 
92  {
93  using AlignedDetector = Contextual::AlignedDetector;
95 
96  auto d = py::class_<AlignedDetector, std::shared_ptr<AlignedDetector>>(
97  mex, "AlignedDetector")
98  .def(py::init<>())
99  .def("finalize",
100  py::overload_cast<
101  const Config&,
102  std::shared_ptr<const Acts::IMaterialDecorator>>(
104 
105  auto c = py::class_<Config, GenericDetector::Config>(d, "Config")
106  .def(py::init<>());
109  ACTS_PYTHON_MEMBER(iovSize);
110  ACTS_PYTHON_MEMBER(flushSize);
111  ACTS_PYTHON_MEMBER(doGarbageCollection);
112  ACTS_PYTHON_MEMBER(sigmaInPlane);
113  ACTS_PYTHON_MEMBER(sigmaOutPlane);
114  ACTS_PYTHON_MEMBER(sigmaInRot);
115  ACTS_PYTHON_MEMBER(sigmaOutRot);
116  ACTS_PYTHON_MEMBER(firstIovNominal);
117  ACTS_PYTHON_MEMBER(decoratorLogLevel);
120 
121  py::enum_<Config::Mode>(c, "Mode")
122  .value("Internal", Config::Mode::Internal)
123  .value("External", Config::Mode::External);
124  }
125 
126  {
128 
129  auto d = py::class_<TGeoDetector, std::shared_ptr<TGeoDetector>>(
130  mex, "TGeoDetector")
131  .def(py::init<>())
132  .def("finalize",
133  py::overload_cast<
134  const Config&,
135  std::shared_ptr<const Acts::IMaterialDecorator>>(
137 
138  py::class_<Options::Interval>(mex, "Interval")
139  .def(py::init<>())
140  .def(py::init<std::optional<double>, std::optional<double>>())
141  .def_readwrite("lower", &Options::Interval::lower)
142  .def_readwrite("upper", &Options::Interval::upper);
143 
144  auto c = py::class_<Config>(d, "Config").def(py::init<>());
145 
146  c.def_property(
147  "jsonFile", nullptr,
148  [](Config& cfg, const std::string& file) { cfg.readJson(file); });
149 
150  py::enum_<Config::SubVolume>(c, "SubVolume")
151  .value("Negative", Config::SubVolume::Negative)
152  .value("Central", Config::SubVolume::Central)
153  .value("Positive", Config::SubVolume::Positive);
154 
155  py::enum_<Acts::BinningType>(c, "BinningType")
156  .value("equidistant", Acts::BinningType::equidistant)
157  .value("arbitrary", Acts::BinningType::arbitrary);
158 
159  auto volume = py::class_<Config::Volume>(c, "Volume").def(py::init<>());
160  ACTS_PYTHON_STRUCT_BEGIN(volume, Config::Volume);
162  ACTS_PYTHON_MEMBER(binToleranceR);
163  ACTS_PYTHON_MEMBER(binTolerancePhi);
164  ACTS_PYTHON_MEMBER(binToleranceZ);
165  ACTS_PYTHON_MEMBER(cylinderDiscSplit);
166  ACTS_PYTHON_MEMBER(cylinderNZSegments);
167  ACTS_PYTHON_MEMBER(cylinderNPhiSegments);
168  ACTS_PYTHON_MEMBER(discNRSegments);
169  ACTS_PYTHON_MEMBER(discNPhiSegments);
170  ACTS_PYTHON_MEMBER(itkModuleSplit);
171  ACTS_PYTHON_MEMBER(barrelMap);
172  ACTS_PYTHON_MEMBER(discMap);
173  ACTS_PYTHON_MEMBER(splitPatterns);
174 
175  ACTS_PYTHON_MEMBER(layers);
176  ACTS_PYTHON_MEMBER(subVolumeName);
177  ACTS_PYTHON_MEMBER(sensitiveNames);
178  ACTS_PYTHON_MEMBER(sensitiveAxes);
179  ACTS_PYTHON_MEMBER(rRange);
180  ACTS_PYTHON_MEMBER(zRange);
181  ACTS_PYTHON_MEMBER(splitTolR);
182  ACTS_PYTHON_MEMBER(splitTolZ);
183  ACTS_PYTHON_MEMBER(binning0);
184  ACTS_PYTHON_MEMBER(binning1);
186 
187  auto regTriplet = [&c](const std::string& name, auto v) {
188  using type = decltype(v);
189  py::class_<Config::LayerTriplet<type>>(c, name.c_str())
190  .def(py::init<>())
191  .def(py::init<type>())
192  .def(py::init<type, type, type>())
193  .def_readwrite("negative", &Config::LayerTriplet<type>::negative)
194  .def_readwrite("central", &Config::LayerTriplet<type>::central)
195  .def_readwrite("positive", &Config::LayerTriplet<type>::positive)
196  .def("at", py::overload_cast<Config::SubVolume>(
198  };
199 
200  regTriplet("LayerTripletBool", true);
201  regTriplet("LayerTripletString", std::string{""});
202  regTriplet("LayerTripletVectorString", std::vector<std::string>{});
203  regTriplet("LayerTripletInterval", Options::Interval{});
204  regTriplet("LayerTripletDouble", double{5.5});
205  regTriplet("LayerTripletVectorBinning",
206  std::vector<std::pair<int, Acts::BinningType>>{});
207 
209  ACTS_PYTHON_MEMBER(surfaceLogLevel);
210  ACTS_PYTHON_MEMBER(layerLogLevel);
211  ACTS_PYTHON_MEMBER(volumeLogLevel);
212  ACTS_PYTHON_MEMBER(fileName);
213  ACTS_PYTHON_MEMBER(buildBeamPipe);
214  ACTS_PYTHON_MEMBER(beamPipeRadius);
215  ACTS_PYTHON_MEMBER(beamPipeHalflengthZ);
216  ACTS_PYTHON_MEMBER(beamPipeLayerThickness);
217  ACTS_PYTHON_MEMBER(beamPipeEnvelopeR);
218  ACTS_PYTHON_MEMBER(layerEnvelopeR);
219  ACTS_PYTHON_MEMBER(unitScalor);
222 
224  }
225 }
226 
227 } // namespace Acts::Python