3 #include <common/data.h>
10 #include <Math/Rotation3D.h>
11 #include <Math/SMatrix.h>
12 #include <Math/SVector.h>
13 #include <Math/Transform3D.h>
14 #include <Math/Vector3D.h>
15 #include <Math/Vector4D.h>
17 #include <ufw/utils.hpp>
24 using pos_3d = ROOT::Math::PositionVector3D<ROOT::Math::Cartesian3D<double>>;
25 using dir_3d = ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<double>>;
26 using vec_4d = ROOT::Math::XYZTVector;
28 using mom_3d = dir_3d;
29 using mom_4d = ROOT::Math::PxPyPzEVector;
31 using rot_3d = ROOT::Math::Rotation3D;
39 using xform_3d = ROOT::Math::Transform3D;
44 struct fmt::formatter<sand::pos_3d> : formatter<string_view> {
45 auto format(
const sand::pos_3d& c, format_context& ctx)
const -> format_context::iterator {
46 return fmt::format_to(ctx.out(),
"({:.3f}, {:.3f}, {:.3f})", c.x(), c.y(), c.z());
51 struct fmt::formatter<sand::dir_3d> : formatter<string_view> {
52 auto format(
const sand::dir_3d& c, format_context& ctx)
const -> format_context::iterator {
53 return fmt::format_to(ctx.out(),
"({:.3f}, {:.3f}, {:.3f})", c.x(), c.y(), c.z());
58 struct fmt::formatter<sand::vec_4d> : formatter<string_view> {
59 auto format(
const sand::vec_4d& c, format_context& ctx)
const -> format_context::iterator {
60 return fmt::format_to(ctx.out(),
"({:.3f}, {:.3f}, {:.3f}, {:.3f})", c.x(), c.y(), c.z(), c.t());
65 struct fmt::formatter<sand::rot_3d> : formatter<string_view> {
66 auto format(
const sand::rot_3d& c, format_context& ctx)
const -> format_context::iterator {
67 sand::rot_3d::Scalar r[9];
69 return fmt::format_to(ctx.out(),
"R(({:.3f}, {:.3f}, {:.3f}), ({:.3f}, {:.3f}, {:.3f}), ({:.3f}, {:.3f}, {:.3f}))",
70 r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8]);
75 struct fmt::formatter<sand::xform_3d> : formatter<string_view> {
76 auto format(
const sand::xform_3d& c, format_context& ctx)
const -> format_context::iterator {
77 sand::xform_3d::Scalar r[12];
79 return fmt::format_to(
81 "R(({:.3f}, {:.3f}, {:.3f}), ({:.3f}, {:.3f}, {:.3f}), ({:.3f}, {:.3f}, {:.3f})), T({:.3f}, {:.3f}, {:.3f}))",
82 r[0], r[1], r[2], r[4], r[5], r[6], r[8], r[9], r[10], r[3], r[7], r[11]);
92 using std::string::string;
93 using std::string::operator=;
97 geo_path operator/ (
const std::string_view& rhs)
const {
109 inline std::string_view
token(std::size_t)
const;
124 if (sv.front() ==
'/') {
125 append(sv.substr(1));
130 if (sv.front() ==
'/') {
133 reserve(size() + 1 + sv.size());
147 if (std::string_view(sub.data(), sub.size()) == sub) {
148 erase(0, sub.size());
157 std::size_t start = 0;
158 std::size_t stop = 0;
160 return std::string_view();
166 start = find(
'/', start) + 1;
168 stop = find(
'/', start);
169 if (stop == std::string::npos) {
172 return std::string_view(data() + start, stop - start);
178 enum subdetector_t : uint8_t {
201 static constexpr
size_t kNumComponents =
static_cast<size_t>(subdetector_t::kLoopableEnd);
206 inline std::map<subdetector_t, std::string> component_to_string = {
207 {subdetector_t::GRAIN,
"LArHit"},
208 {subdetector_t::STT,
"Straw"},
209 {subdetector_t::DRIFT,
"DriftVolume"},
210 {subdetector_t::ECAL,
"EMCalSci"},
211 {subdetector_t::MAGNET,
"Magnet"},
212 {subdetector_t::WORLD,
"World"},
218 inline std::map<std::string, subdetector_t> string_to_component = {
219 {
"LArHit", subdetector_t::GRAIN},
220 {
"Straw", subdetector_t::STT},
221 {
"DriftVolume", subdetector_t::DRIFT},
222 {
"EMCalSci", subdetector_t::ECAL},
223 {
"Magnet", subdetector_t::MAGNET},
224 {
"World", subdetector_t::WORLD},
230 inline std::initializer_list<std::string> grain_names = {
"GRAIN",
"GRIAN"};
235 inline std::initializer_list<std::string> stt_names = {
"horizontalST",
"STT",
"TrkMod",
"CMod",
236 "C3H6Mod",
"Trk",
"SuperMod",
"Drift"};
242 inline bool is_generic_drift_name(std::string_view name) {
243 if (name.size() <= 2 || name.substr(0, 2) !=
"s_")
return false;
244 auto digits_end = name.find_first_not_of(
"0123456789", 2);
245 if (digits_end == 2)
return false;
246 if (digits_end == std::string_view::npos)
return true;
247 return name[digits_end] ==
'_' && digits_end + 1 < name.size();
253 inline std::initializer_list<std::string> drift_names = {
"SANDtracker",
"Trk",
"CMod",
"C3H6Mod",
"SuperMod",
"Drift",
254 "C3H6Target",
"CTarget",
"C3H6Mylar",
"CMylar",
"Frame"};
259 inline std::initializer_list<std::string> ecal_names = {
"ECAL",
"kloe_calo_volume"};
264 inline std::initializer_list<std::string> magnet_names = {
"KLOE",
"Yoke",
"Mag"};
269 inline std::initializer_list<std::string> world_names = {
"World",
"rock",
"volSAND",
270 "sand_inner",
"Enclosure",
"volDetEnclosure"};
277 using supermodule_t = uint8_t;
278 using plane_t = uint8_t;
279 using tube_t = uint16_t;
281 enum region_t : uint8_t { BARREL = 0, ENDCAP_A = 1, ENDCAP_B = 2, UNKNOWN = 255 };
282 enum element_t : uint8_t {
284 ENDCAP_CURVE_TOP = 2,
285 ENDCAP_CURVE_BOT = 3,
295 uint8_t reserved___0;
296 subdetector_t subdetector;
297 uint8_t padding___1[6];
300 uint8_t reserved___0;
301 subdetector_t subdetector;
302 supermodule_t supermodule;
304 uint8_t padding___1[4];
307 uint8_t reserved___0;
308 subdetector_t subdetector;
310 supermodule_t supermodule;
313 uint8_t padding___1[2];
316 uint8_t reserved___0;
317 subdetector_t subdetector;
318 uint8_t padding___1[6];
321 uint8_t reserved___0;
322 subdetector_t subdetector;
323 supermodule_t supermodule;
326 uint8_t padding___1[2];
335 static_assert(
sizeof(
geo_id) ==
sizeof(uint64_t),
"geo_id size is not 8 bytes");
338 inline bool operator== (
geo_id lhs,
geo_id rhs) {
return lhs.raw == rhs.raw; }
341 inline bool operator< (geo_id lhs, geo_id rhs) {
return lhs.raw < rhs.raw; }
348 using link_t = uint8_t;
349 using channel_t = uint32_t;
355 uint8_t reserved___0;
356 subdetector_t subdetector;
372 inline bool operator!= (channel_id lhs, channel_id rhs) {
return lhs.raw != rhs.raw; }
375 inline bool operator< (channel_id lhs, channel_id rhs) {
return lhs.raw < rhs.raw; }
382 struct fmt::formatter<sand::subdetector_t> : formatter<string_view> {
383 auto format(sand::subdetector_t s, format_context& ctx)
const -> format_context::iterator {
386 return fmt::format_to(ctx.out(),
"DRIFT");
388 return fmt::format_to(ctx.out(),
"ECAL");
390 return fmt::format_to(ctx.out(),
"GRAIN");
392 return fmt::format_to(ctx.out(),
"STT");
394 return fmt::format_to(ctx.out(),
"MUON");
396 return fmt::format_to(ctx.out(),
"NONE");
402 struct fmt::formatter<sand::geo_id> : formatter<string_view> {
403 auto format(
const sand::geo_id& gid, format_context& ctx)
const -> format_context::iterator {
404 switch (gid.subdetector) {
406 return fmt::format_to(ctx.out(),
"[{}: module {}, plane {}]", gid.subdetector, gid.drift.supermodule,
409 return fmt::format_to(ctx.out(),
"[{}: region {}, module {}, element {}, plane {}]", gid.subdetector,
410 gid.ecal.region, gid.ecal.supermodule, gid.ecal.element, gid.ecal.plane);
412 return fmt::format_to(ctx.out(),
"[{}: inner vessel]", gid.subdetector);
414 return fmt::format_to(ctx.out(),
"[{}: module {}, plane {}, tube {}]", gid.subdetector, gid.stt.supermodule,
415 gid.stt.plane, gid.stt.tube);
417 return fmt::format_to(ctx.out(),
"[{}: not a valid subdetector]", gid.subdetector);
423 struct fmt::formatter<sand::channel_id> : formatter<string_view> {
424 auto format(
const sand::channel_id& chid, format_context& ctx)
const -> format_context::iterator {
425 return fmt::format_to(ctx.out(),
"[{}: link {}, channel {}]", chid.subdetector, chid.link, chid.channel);
geo_path & operator/=(const std::string_view &)
Definition: sand.h:115
std::string_view token(std::size_t) const
Definition: sand.h:156
geo_path & operator-=(const geo_path &)
Definition: sand.h:146