LDMX Software
DetectorIDBindings.cxx
1#if DETECTORID_BINDINGS_ENABLED
2#include <boost/python.hpp>
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("EID_TRACKER", SubdetectorIDType::EID_TRACKER)
67 .value("EID_TRIGGER_SCINT", SubdetectorIDType::EID_TRIGGER_SCINT)
68 .value("EID_HCAL", SubdetectorIDType::EID_HCAL)
69 .value("EID_HCAL", SubdetectorIDType::EID_HCAL)
70 .export_values();
71
72 class_<DetectorID>("DetectorID", init<>(args("self")));
73 class_<HcalAbstractID>("HcalAbstractID", init<>(args("self")));
74 class_<EcalAbstractID>("EcalAbstractID", init<>(args("self")));
75 class_<EcalID>("EcalID",
76 "Extension of DetectorID providing access to ECal layers and "
77 "cell numbers in a hex grid",
78 init<>(args("self"), "Empty ECAL id (but not null!)"))
79 .def(init<RawValue>(args("self", "rawid"), "Create from raw number"))
80 .def(init<unsigned int, unsigned int, unsigned int>(
81 args("self", "layer", "module", "cell"), "Create from pieces"))
82 .def(init<unsigned int, unsigned int, unsigned int, unsigned int>(
83 args("self", "layer", "module", "u", "v"),
84 "Create from pieces including u/v cell"))
85 .def(init<unsigned int, unsigned int,
86 std::pair<unsigned int, unsigned int>>(
87 args("self", "layer", "module", "uv"),
88 "Create from pieces including u/v cell"))
89 .def("module", &EcalID::module,
90 "Get the value of the module field from the ID.", args("self"))
91 .def("layer", &EcalID::layer,
92 "Get the value of the layer field from the ID.", args("self"))
93 .def("cell", &EcalID::cell,
94 "Get the value of the cell field from the ID.", args("self"))
95 // Requires defining a translator for pair
96 // .def("getCellUV", &EcalID::getCellUV, "Get the cell u,v index assuming
97 // a CMS-standard 432-cell sensor" )
98 .def("raw", &EcalID::raw, "The raw value", args("self"));
99 class_<EcalElectronicsID>(
100 "EcalElectronicsID",
101 "Identifies a location in the Ecal readout chain\n"
102 "-- fiber : optical fiber number (backend number), range "
103 "assumed O(0-96)\n"
104 "-- elink : electronic link number, range assumed O(0-47)\n"
105 "-- channel : channel-on-elink, range O(0-37)\n"
106 "For transient use only i.e. we use this ID to\n"
107 "help translate the digitized data coming off the detector\n"
108 "into spatially-important EcalIDs.",
109 init<>(args("self"), "Empty EcalElectronics id (but not null!)"))
110 .def(init<RawValue>(
111 "Create from raw number\n\n Importantly, this is NOT the PackedIndex "
112 "value, it is the entire raw value including the subsystem ID.",
113 args("self", "rawid")))
114 .def(init<unsigned int, unsigned int, unsigned int>(
115 args("self", "fiber", "elink", "channel"), "Create from pieces"))
116 .def("fiber", &EcalElectronicsID::fiber,
117 "Get the value of the fiber from the ID.", args("self"))
118 .def("elink", &EcalElectronicsID::elink,
119 "Get the value of the elink from the ID.", args("self"))
120 .def("channel", &EcalElectronicsID::channel,
121 "Get the value of the channel from the ID.", args("self"))
122 .def("index", &EcalElectronicsID::index, "Get the compact index value",
123 args("self"))
124 .def("idFromIndex", &EcalElectronicsID::idFromIndex, args("index"),
125 "Construct an electronics id from an index")
126 .def("raw", &EcalElectronicsID::raw, "The raw value", args("self"))
127 .staticmethod("idFromIndex");
128 class_<EcalTriggerID>(
129 "EcalTriggerID",
130 "Extension of DetectorID providing access to ECal "
131 "trigger cell information",
132 init<>(args("self"), "Empty EcALTrigger id (but not null!)"))
133 .def(init<RawValue>(args("self", "rawid"), "Create from raw number"))
134 .def(init<unsigned int, unsigned int, unsigned int>(
135 args("self", "layer", "module", "cell"), "Create from pieces"))
136 .def("module", &EcalTriggerID::module,
137 "Get the value of the module field from the ID.", args("self"))
138 .def("layer", &EcalTriggerID::layer,
139 "Get the value of the layer field from the ID.", args("self"))
140 .def("triggercell", &EcalTriggerID::triggercell,
141 "Get the value of the trigger cell field from the ID.", args("self"))
142 .def("raw", &EcalTriggerID::raw, "The raw value", args("self"));
143 // Currently not actually defined
144 // .def("getCellUV", &EcalTriggerID::getCellUV);
145 class_<HcalID>("HcalID", "Implements detector ids for Hcal subdetector",
146 init<>(args("self"), "Empty HcalID (but not null)"))
147 .def(init<RawValue>(args("self", "rawid"), "Create from raw number"))
148 .def(init<unsigned int, unsigned int, unsigned int>(
149 args("self", "section", "layer", "strip"), "Create from pieces"))
150 .def("section", &HcalID::section,
151 "Get the value of the 'section' field from the ID.", args("self"))
152 .def("layer", &HcalID::layer,
153 "Get the value of the layer field from the ID.", args("self"))
154 .def("strip", &HcalID::strip,
155 "Get the value of the 'strip' (bar) field from the ID.",
156 args("self"))
157 .def("raw", &HcalID::raw, "The raw value", args("self"));
158 class_<HcalElectronicsID>(
159 "HcalElectronicsID",
160
161 "Identifies a location in the Hcal readout chain\n"
162 "-- fiber : optical fiber number (backend number), range assumed "
163 "O(0-96)\n"
164 "-- elink : electronic link number, range assumed O(0-47)\n"
165 "-- channel : channel-on-elink, range O(0-37)\n\n"
166 "For transient use only i.e. we use this ID to help translate the "
167 "digitized data coming off the detector into spatially-important "
168 "HcalDigiIDs.",
169 init<>(args("self"), "Empty HCAL id (but not null!)"))
170 .def(init<RawValue>("Create from raw number", args("self", "rawid")))
171 .def(init<unsigned int, unsigned int, unsigned int>(
172 "Create from pieces", args("self", "fiber", "elink", "channel")))
173 .def("fiber", &HcalElectronicsID::fiber,
174 "Get the value of the fiber from the ID.", args("self"))
175 .def("elink", &HcalElectronicsID::elink,
176 "Get the value of the elink from the ID.", args("self"))
177 .def("channel", &HcalElectronicsID::channel,
178 "Get the value of the channel from the ID.", args("self"))
179 .def("index", &HcalElectronicsID::index, "Get the compact index value",
180 args("self"))
181 .def("idFromIndex", &HcalElectronicsID::idFromIndex, args("index"),
182 "Create an electronics ID from an index")
183 .def("raw", &HcalElectronicsID::raw, "The raw value", args("self"))
184 .staticmethod("idFromIndex");
185 class_<HcalDigiID>("HcalDigiID",
186 "Extension of HcalAbstractID providing access to HCal "
187 "digi information",
188 init<>(args("self"), "Empty HcalDigiID (but not null)"))
189 .def(init<RawValue>("Create from raw number", args("self", "rawid")))
190 .def(init<unsigned int, unsigned int, unsigned int, unsigned int>(
191 "Create from pieces",
192 args("self", "section", "layer", "strip", "end")))
193 .def("section", &HcalDigiID::section,
194 "Get the value of the 'section' field from the ID.", args("self"))
195 .def("layer", &HcalDigiID::layer,
196 "Get the value of the 'layer' field from the ID.", args("self"))
197 .def("strip", &HcalDigiID::strip,
198 "Get the value of the 'strip' (bar) field from the ID.",
199 args("self"))
200 .def("end", &HcalDigiID::end,
201 "Get the value of the 'end' (positive/negative) field from the ID.",
202 args("self"))
203 .def("isNegativeEnd", &HcalDigiID::isNegativeEnd,
204 "Get whether the 'end' field from the ID is negative.", args("self"))
205 .def("raw", &HcalElectronicsID::raw, "The raw value", args("self"));
206 class_<HcalTriggerID>(
207 "HcalTriggerID",
208 "Extension of DetectorID providing access to HCal trigger cell",
209 init<>(args("self"), "Empty HCAL trigger id (but not null!)"))
210 .def(init<RawValue>("Create from raw number", args("self", "rawid")))
211 .def(init<unsigned int, unsigned int, unsigned int, unsigned int>(
212 "Create from pieces",
213 args("self", "section", "layer", "superstrip", "end")))
214 .def("section", &HcalTriggerID::section,
215 "Get the value of the 'section' field from the ID.", args("self"))
216 .def("layer", &HcalTriggerID::layer,
217 "Get the value of the 'layer' field from the ID.", args("self"))
218 .def("superstrip", &HcalTriggerID::superstrip,
219 "Get the value of the 'superstrip' field from the ID.", args("self"))
220 .def("end", &HcalTriggerID::end,
221 "Get the value of the 'end' field from the ID.", args("self"))
222 .def("isNegativeEnd", &HcalTriggerID::isNegativeEnd,
223 "Get whether the 'end' field from the ID is negative.", args("self"))
224 .def("isComposite", &HcalTriggerID::isComposite,
225 "Get whether the ID is the composite of two bar ends.", args("self"))
226 .def("raw", &HcalTriggerID::raw, "The raw value", args("self"));
227 class_<SimSpecialID>("SimSpecialID",
228 "Implements detector ids for special simulation-derived "
229 "hits like scoring planes",
230 init<>(args("self"), "Empty id (but not null!)"))
231 .def(init<RawValue>("Create from raw number", args("self", "rawid")))
232 .def("ScoringPlaneID", &SimSpecialID::ScoringPlaneID,
233 "Create a scoring id from pieces", args("plane"))
234 .staticmethod("ScoringPlaneID")
235 .def("plane", &SimSpecialID::plane,
236 "Get the value of the plane field from the ID, if it is a scoring "
237 "plane. Otherwise, return -1",
238 args("self"))
239 .def("subtypePayload", &SimSpecialID::subtypePayload,
240 "Get the raw payload contents", args("self"))
241 .def("raw", &SimSpecialID::raw, "The raw value", args("self"));
242 class_<TrackerID>("TrackerID",
243 "Extension of DetectorID providing access to layer and "
244 "module number for tracker IDs")
245 .def(init<RawValue>("Create from a raw id, but check",
246 args("self", "rawid")))
247 .def(init<SubdetectorIDType, unsigned int, unsigned int>(
248 "Create from pieces", args("self", "system", "layer", "module")))
249 .def("module", &TrackerID::module,
250 "Get the value of the module field from the ID", args("self"))
251 .def("layer", &TrackerID::layer,
252 "Get the value of the layer field from the ID", args("self"))
253 .def("raw", &TrackerID::raw, "The raw value");
254 class_<TrigScintID>(
255 "TrigScintID",
256 "Class that defines the detector ID of the trigger scintillator.",
257 init<>(args("self"), "Default constructor"))
258 .def(init<RawValue>("Constructor with raw id", args("self", "rawid")))
259 .def(init<unsigned int, unsigned int>("Create from pieces",
260 args("self", "module", "bar")));
261}
262#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.