LDMX Software
DetectorIDBindings.cxx
1#if DETECTORID_BINDINGS_ENABLED
2#include <boost/python.hpp> // IWYU pragma: keep (needed by BOOST_PYTHON_MODULE)
3
4#include "DetDescr/DetectorID.h"
7#include "DetDescr/EcalID.h"
10#include "DetDescr/HcalDigiID.h"
11#include "DetDescr/HcalElectronicsID.h"
12#include "DetDescr/HcalID.h"
14#include "DetDescr/SimSpecialID.h"
15#include "DetDescr/TrackerID.h"
16#include "DetDescr/TrigScintID.h"
17
18BOOST_PYTHON_MODULE(libDetDescr) {
19 // init<Ts...>(...) defines constructors.
20 //
21 // To add names to parameters, add an args() call as a parameter to
22 // the init function call.
23 //
24 // To add a docstring to a constructor, pass it as the last parameter to the
25 // init function call (as a string literal)
26 //
27 // One constructor can be called within the class_<>() function call. To have
28 // multiple constructors, you use init<> together with .def() to append
29 // others.
30 //
31 // If you want to add a docstring to the class as a whole, pass it as the
32 // second parameter (*note:* not last if you want a constructor) to the
33 // class_<>() function call
34 //
35 // def(...) defines functions and .def() defines member functions.
36 //
37 // To add names names to parameters, add an args() call as a parameter
38 //
39 // To add a docstring, pass a string literal as the last parameter to the
40 // def/.def function call
41 //
42 // args(...) give names to parameters. This both adds the names to the
43 // generated documentation and allows using python's named parameters
44 //
45 // .staticmethod("name") is required for any static member functions. Note
46 // that things will compile without it but the function won't be callable from
47 // python
48 //
49 // Enums need each value to be specified with the .value() function. Any enum
50 // values specified before export_values() will be accessible directly from
51 // the module while others will need fully qualified names (module.enum.value)
52
53 using namespace boost::python;
54 using namespace ldmx;
55 using RawValue = DetectorID::RawValue;
56
57 enum_<SubdetectorIDType>("SubdetectorID")
58 .value("SD_NULL", SubdetectorIDType::SD_NULL)
59 .value("SD_TRACKER_TAGGER", SubdetectorIDType::SD_TRACKER_TAGGER)
60 .value("SD_TRIGGER_SCINT", SubdetectorIDType::SD_TRIGGER_SCINT)
61 .value("SD_ACTVE_TARGET", SubdetectorIDType::SD_ACTVE_TARGET)
62 .value("SD_TRACKER_RECOIL", SubdetectorIDType::SD_TRACKER_RECOIL)
63 .value("SD_ECAL", SubdetectorIDType::SD_ECAL)
64 .value("SD_HCAL", SubdetectorIDType::SD_HCAL)
65 .value("SD_SIM_SPECIAL", SubdetectorIDType::SD_SIM_SPECIAL)
66 .value("SD_TRACKER_TESTSTAND", SubdetectorIDType::SD_TRACKER_TESTSTAND)
67 .value("EID_TRACKER", SubdetectorIDType::EID_TRACKER)
68 .value("EID_TRIGGER_SCINT", SubdetectorIDType::EID_TRIGGER_SCINT)
69 .value("EID_HCAL", SubdetectorIDType::EID_HCAL)
70 .value("EID_HCAL", SubdetectorIDType::EID_HCAL)
71 .export_values();
72
73 class_<DetectorID>("DetectorID", init<>(args("self")));
74 class_<HcalAbstractID>("HcalAbstractID", init<>(args("self")));
75 class_<EcalAbstractID>("EcalAbstractID", init<>(args("self")));
76 class_<EcalID>("EcalID",
77 "Extension of DetectorID providing access to ECal layers and "
78 "cell numbers in a hex grid",
79 init<>(args("self"), "Empty ECAL id (but not null!)"))
80 .def(init<RawValue>(args("self", "rawid"), "Create from raw number"))
81 .def(init<unsigned int, unsigned int, unsigned int>(
82 args("self", "layer", "module", "cell"), "Create from pieces"))
83 .def(init<unsigned int, unsigned int, unsigned int, unsigned int>(
84 args("self", "layer", "module", "u", "v"),
85 "Create from pieces including u/v cell"))
86 .def(init<unsigned int, unsigned int,
87 std::pair<unsigned int, unsigned int>>(
88 args("self", "layer", "module", "uv"),
89 "Create from pieces including u/v cell"))
90 .def("module", &EcalID::module,
91 "Get the value of the module field from the ID.", args("self"))
92 .def("layer", &EcalID::layer,
93 "Get the value of the layer field from the ID.", args("self"))
94 .def("cell", &EcalID::cell,
95 "Get the value of the cell field from the ID.", args("self"))
96 // Requires defining a translator for pair
97 // .def("getCellUV", &EcalID::getCellUV, "Get the cell u,v index assuming
98 // a CMS-standard 432-cell sensor" )
99 .def("raw", &EcalID::raw, "The raw value", args("self"));
100 class_<EcalElectronicsID>(
101 "EcalElectronicsID",
102 "Identifies a location in the Ecal readout chain\n"
103 "-- fiber : optical fiber number (backend number), range "
104 "assumed O(0-96)\n"
105 "-- elink : electronic link number, range assumed O(0-47)\n"
106 "-- channel : channel-on-elink, range O(0-37)\n"
107 "For transient use only i.e. we use this ID to\n"
108 "help translate the digitized data coming off the detector\n"
109 "into spatially-important EcalIDs.",
110 init<>(args("self"), "Empty EcalElectronics id (but not null!)"))
111 .def(init<RawValue>(
112 "Create from raw number\n\n Importantly, this is NOT the PackedIndex "
113 "value, it is the entire raw value including the subsystem ID.",
114 args("self", "rawid")))
115 .def(init<unsigned int, unsigned int, unsigned int>(
116 args("self", "fiber", "elink", "channel"), "Create from pieces"))
117 .def("fiber", &EcalElectronicsID::fiber,
118 "Get the value of the fiber from the ID.", args("self"))
119 .def("elink", &EcalElectronicsID::elink,
120 "Get the value of the elink from the ID.", args("self"))
121 .def("channel", &EcalElectronicsID::channel,
122 "Get the value of the channel from the ID.", args("self"))
123 .def("index", &EcalElectronicsID::index, "Get the compact index value",
124 args("self"))
125 .def("idFromIndex", &EcalElectronicsID::idFromIndex, args("index"),
126 "Construct an electronics id from an index")
127 .def("raw", &EcalElectronicsID::raw, "The raw value", args("self"))
128 .staticmethod("idFromIndex");
129 class_<EcalTriggerID>(
130 "EcalTriggerID",
131 "Extension of DetectorID providing access to ECal "
132 "trigger cell information",
133 init<>(args("self"), "Empty EcALTrigger id (but not null!)"))
134 .def(init<RawValue>(args("self", "rawid"), "Create from raw number"))
135 .def(init<unsigned int, unsigned int, unsigned int>(
136 args("self", "layer", "module", "cell"), "Create from pieces"))
137 .def("module", &EcalTriggerID::module,
138 "Get the value of the module field from the ID.", args("self"))
139 .def("layer", &EcalTriggerID::layer,
140 "Get the value of the layer field from the ID.", args("self"))
141 .def("triggercell", &EcalTriggerID::triggercell,
142 "Get the value of the trigger cell field from the ID.", args("self"))
143 .def("raw", &EcalTriggerID::raw, "The raw value", args("self"));
144 // Currently not actually defined
145 // .def("getCellUV", &EcalTriggerID::getCellUV);
146 class_<HcalID>("HcalID", "Implements detector ids for Hcal subdetector",
147 init<>(args("self"), "Empty HcalID (but not null)"))
148 .def(init<RawValue>(args("self", "rawid"), "Create from raw number"))
149 .def(init<unsigned int, unsigned int, unsigned int>(
150 args("self", "section", "layer", "strip"), "Create from pieces"))
151 .def("section", &HcalID::section,
152 "Get the value of the 'section' field from the ID.", args("self"))
153 .def("layer", &HcalID::layer,
154 "Get the value of the layer field from the ID.", args("self"))
155 .def("strip", &HcalID::strip,
156 "Get the value of the 'strip' (bar) field from the ID.",
157 args("self"))
158 .def("raw", &HcalID::raw, "The raw value", args("self"));
159 class_<HcalElectronicsID>(
160 "HcalElectronicsID",
161
162 "Identifies a location in the Hcal readout chain\n"
163 "-- fiber : optical fiber number (backend number), range assumed "
164 "O(0-96)\n"
165 "-- elink : electronic link number, range assumed O(0-47)\n"
166 "-- channel : channel-on-elink, range O(0-37)\n\n"
167 "For transient use only i.e. we use this ID to help translate the "
168 "digitized data coming off the detector into spatially-important "
169 "HcalDigiIDs.",
170 init<>(args("self"), "Empty HCAL id (but not null!)"))
171 .def(init<RawValue>("Create from raw number", args("self", "rawid")))
172 .def(init<unsigned int, unsigned int, unsigned int>(
173 "Create from pieces", args("self", "fiber", "elink", "channel")))
174 .def("fiber", &HcalElectronicsID::fiber,
175 "Get the value of the fiber from the ID.", args("self"))
176 .def("elink", &HcalElectronicsID::elink,
177 "Get the value of the elink from the ID.", args("self"))
178 .def("channel", &HcalElectronicsID::channel,
179 "Get the value of the channel from the ID.", args("self"))
180 .def("index", &HcalElectronicsID::index, "Get the compact index value",
181 args("self"))
182 .def("idFromIndex", &HcalElectronicsID::idFromIndex, args("index"),
183 "Create an electronics ID from an index")
184 .def("raw", &HcalElectronicsID::raw, "The raw value", args("self"))
185 .staticmethod("idFromIndex");
186 class_<HcalDigiID>("HcalDigiID",
187 "Extension of HcalAbstractID providing access to HCal "
188 "digi information",
189 init<>(args("self"), "Empty HcalDigiID (but not null)"))
190 .def(init<RawValue>("Create from raw number", args("self", "rawid")))
191 .def(init<unsigned int, unsigned int, unsigned int, unsigned int>(
192 "Create from pieces",
193 args("self", "section", "layer", "strip", "end")))
194 .def("section", &HcalDigiID::section,
195 "Get the value of the 'section' field from the ID.", args("self"))
196 .def("layer", &HcalDigiID::layer,
197 "Get the value of the 'layer' field from the ID.", args("self"))
198 .def("strip", &HcalDigiID::strip,
199 "Get the value of the 'strip' (bar) field from the ID.",
200 args("self"))
201 .def("end", &HcalDigiID::end,
202 "Get the value of the 'end' (positive/negative) field from the ID.",
203 args("self"))
204 .def("isNegativeEnd", &HcalDigiID::isNegativeEnd,
205 "Get whether the 'end' field from the ID is negative.", args("self"))
206 .def("raw", &HcalElectronicsID::raw, "The raw value", args("self"));
207 class_<HcalTriggerID>(
208 "HcalTriggerID",
209 "Extension of DetectorID providing access to HCal trigger cell",
210 init<>(args("self"), "Empty HCAL trigger id (but not null!)"))
211 .def(init<RawValue>("Create from raw number", args("self", "rawid")))
212 .def(init<unsigned int, unsigned int, unsigned int, unsigned int>(
213 "Create from pieces",
214 args("self", "section", "layer", "superstrip", "end")))
215 .def("section", &HcalTriggerID::section,
216 "Get the value of the 'section' field from the ID.", args("self"))
217 .def("layer", &HcalTriggerID::layer,
218 "Get the value of the 'layer' field from the ID.", args("self"))
219 .def("superstrip", &HcalTriggerID::superstrip,
220 "Get the value of the 'superstrip' field from the ID.", args("self"))
221 .def("end", &HcalTriggerID::end,
222 "Get the value of the 'end' field from the ID.", args("self"))
223 .def("isNegativeEnd", &HcalTriggerID::isNegativeEnd,
224 "Get whether the 'end' field from the ID is negative.", args("self"))
225 .def("isComposite", &HcalTriggerID::isComposite,
226 "Get whether the ID is the composite of two bar ends.", args("self"))
227 .def("raw", &HcalTriggerID::raw, "The raw value", args("self"));
228 class_<SimSpecialID>("SimSpecialID",
229 "Implements detector ids for special simulation-derived "
230 "hits like scoring planes",
231 init<>(args("self"), "Empty id (but not null!)"))
232 .def(init<RawValue>("Create from raw number", args("self", "rawid")))
233 .def("ScoringPlaneID", &SimSpecialID::scoringPlaneId,
234 "Create a scoring id from pieces", args("plane"))
235 .staticmethod("ScoringPlaneID")
236 .def("plane", &SimSpecialID::plane,
237 "Get the value of the plane field from the ID, if it is a scoring "
238 "plane. Otherwise, return -1",
239 args("self"))
240 .def("subtypePayload", &SimSpecialID::subtypePayload,
241 "Get the raw payload contents", args("self"))
242 .def("raw", &SimSpecialID::raw, "The raw value", args("self"));
243 class_<TrackerID>("TrackerID",
244 "Extension of DetectorID providing access to layer and "
245 "module number for tracker IDs")
246 .def(init<RawValue>("Create from a raw id, but check",
247 args("self", "rawid")))
248 .def(init<SubdetectorIDType, unsigned int, unsigned int>(
249 "Create from pieces", args("self", "system", "layer", "module")))
250 .def("module", &TrackerID::module,
251 "Get the value of the module field from the ID", args("self"))
252 .def("layer", &TrackerID::layer,
253 "Get the value of the layer field from the ID", args("self"))
254 .def("raw", &TrackerID::raw, "The raw value");
255 class_<TrigScintID>(
256 "TrigScintID",
257 "Class that defines the detector ID of the trigger scintillator.",
258 init<>(args("self"), "Default constructor"))
259 .def(init<RawValue>("Constructor with raw id", args("self", "rawid")))
260 .def(init<unsigned int, unsigned int>("Create from pieces",
261 args("self", "module", "bar")));
262}
263#endif
Class that serves as a parent for ECal detector IDs of various types.
Class that identifies a location in the Ecal readout chain.
Class that defines an ECal detector ID with a cell number.
Class that defines an ECal trigger cell detector ID.
Class that serves as a parent for HCal detector IDs of various types.
Class that defines an HCal sensitive detector.
Class that defines an HCal trigger cell detector ID.
Class that defines a Tracker detector ID with a module number.