LDMX Software
SiStripChannelMap.h
1#ifndef TRACKING_RECO_SISTRIPCHANNELMAP_H_
2#define TRACKING_RECO_SISTRIPCHANNELMAP_H_
3
4#include <cstdint>
5#include <cstdio>
6#include <string>
7
8namespace tracking::reco {
9
18namespace channelmap {
19
21inline constexpr int K_CHANNELS_PER_APV = 128;
23inline constexpr int K_APVS_PER_HYBRID = 5;
25inline constexpr int K_CHANNELS_PER_HYBRID =
28inline constexpr int K_SAMPLES_PER_APV_TRIGGER = 3;
29
38inline constexpr int16_t pchannel(uint8_t apv_id, uint8_t channel) {
39 return static_cast<int16_t>(
41 (apv_id * K_CHANNELS_PER_APV + (K_CHANNELS_PER_APV - 1) - channel));
42}
43
52inline constexpr void apvChannelFromPchannel(int16_t pchannel, uint8_t& apv_id,
53 uint8_t& channel) {
54 const int x = (K_CHANNELS_PER_HYBRID - 1) - pchannel;
55 apv_id = static_cast<uint8_t>(x / K_CHANNELS_PER_APV);
56 channel =
57 static_cast<uint8_t>((K_CHANNELS_PER_APV - 1) - (x % K_CHANNELS_PER_APV));
58}
59
70inline constexpr int stripId(int16_t pchannel, int n_strips, int first_strip,
71 bool reversed) {
72 return reversed ? first_strip + n_strips - 1 - pchannel
73 : first_strip + pchannel;
74}
75
77inline std::string channelKey(uint8_t feb, uint8_t hybrid, uint8_t apv,
78 uint8_t channel) {
79 return std::to_string(feb) + ":" + std::to_string(hybrid) + ":" +
80 std::to_string(apv) + ":" + std::to_string(channel);
81}
82
85inline constexpr uint32_t channelId(uint8_t feb, uint8_t hybrid, uint8_t apv,
86 uint8_t channel) {
87 return (static_cast<uint32_t>(feb) << 24) |
88 (static_cast<uint32_t>(hybrid) << 16) |
89 (static_cast<uint32_t>(apv) << 8) | static_cast<uint32_t>(channel);
90}
91
94inline bool parseChannelKey(const std::string& key, uint8_t& feb,
95 uint8_t& hybrid, uint8_t& apv, uint8_t& channel) {
96 unsigned f, h, a, c;
97 if (std::sscanf(key.c_str(), "%u:%u:%u:%u", &f, &h, &a, &c) != 4)
98 return false;
99 feb = static_cast<uint8_t>(f);
100 hybrid = static_cast<uint8_t>(h);
101 apv = static_cast<uint8_t>(a);
102 channel = static_cast<uint8_t>(c);
103 return true;
104}
105
107inline constexpr uint32_t groupKey(uint8_t feb, uint8_t hybrid,
108 int16_t pchannel) {
109 return (static_cast<uint32_t>(feb) << 24) |
110 (static_cast<uint32_t>(hybrid) << 16) |
111 static_cast<uint32_t>(static_cast<uint16_t>(pchannel));
112}
113
115inline constexpr int16_t pchannelFromGroupKey(uint32_t key) {
116 return static_cast<int16_t>(key & 0xFFFF);
117}
118
119} // namespace channelmap
120} // namespace tracking::reco
121
122#endif // TRACKING_RECO_SISTRIPCHANNELMAP_H_
bool parseChannelKey(const std::string &key, uint8_t &feb, uint8_t &hybrid, uint8_t &apv, uint8_t &channel)
Parse a "feb:hybrid:apv:channel" key (as produced by channelKey()) back into its electronics fields.
constexpr int stripId(int16_t pchannel, int n_strips, int first_strip, bool reversed)
Map a physical strip number (pchannel) onto a sensor strip index using a DAQ-map transform: an option...
std::string channelKey(uint8_t feb, uint8_t hybrid, uint8_t apv, uint8_t channel)
Build the per-channel pedestal-map key "feb:hybrid:apv:channel".
constexpr uint32_t channelId(uint8_t feb, uint8_t hybrid, uint8_t apv, uint8_t channel)
Pack the full electronics address (feb, hybrid, apv, channel) into a single 32-bit id,...
constexpr void apvChannelFromPchannel(int16_t pchannel, uint8_t &apv_id, uint8_t &channel)
Inverse of pchannel(): recover the (APV id, APV channel) pair from a physical strip number.
constexpr int K_CHANNELS_PER_HYBRID
Number of physical strips per hybrid (kApvsPerHybrid * kChannelsPerApv).
constexpr int K_SAMPLES_PER_APV_TRIGGER
Number of ADC samples the APV25 reads out per channel per trigger.
constexpr int16_t pchannelFromGroupKey(uint32_t key)
Extract the pchannel back out of a key produced by groupKey().
constexpr int K_CHANNELS_PER_APV
Number of readout channels per APV25 chip.
constexpr uint32_t groupKey(uint8_t feb, uint8_t hybrid, int16_t pchannel)
Pack (feb, hybrid, pchannel) into a single 32-bit waveform-grouping key.
constexpr int16_t pchannel(uint8_t apv_id, uint8_t channel)
Convert an (APV id, APV channel) pair into the physical strip number (pchannel) within a hybrid,...
constexpr int K_APVS_PER_HYBRID
Number of APV25 chips per hybrid.