LDMX Software
RawTrackerDecoder.cxx
1#include "Tracking/Reco/RawTrackerDecoder.h"
2
3#include <cstring>
4#include <vector>
5
6#include "Tracking/Event/RawSiStripHit.h"
7
8namespace tracking::reco {
9
12 ps.get<std::string>("input_collection", input_collection_);
13 input_pass_name_ = ps.get<std::string>("input_pass_name", input_pass_name_);
15 ps.get<std::string>("output_collection", output_collection_);
16 n_samples_ = ps.get<int>("n_samples", n_samples_);
17}
18
20 const auto& raw =
21 event.getCollection<uint8_t>(input_collection_, input_pass_name_);
22
23 std::vector<ldmx::RawSiStripHit> hits;
24
25 // Need at least the 10-byte header (4B event_count + 6B padding).
26 if (raw.size() < 10) {
27 event.add(output_collection_, hits);
28 return;
29 }
30
31 uint32_t event_count{0};
32 std::memcpy(&event_count, raw.data(), sizeof(event_count));
33
34 const std::size_t payload_start = 10;
35 const std::size_t n_multisamples = (raw.size() - payload_start) / 10;
36
37 if (n_multisamples == 0) {
38 event.add(output_collection_, hits);
39 return;
40 }
41
42 const auto& hdr = event.getEventHeader();
43 uint64_t ror_ts = 0;
44 if (hdr.hasIntParameter("RoR Timestamp LSB") &&
45 hdr.hasIntParameter("RoR Timestamp MSB")) {
46 ror_ts = (static_cast<uint64_t>(static_cast<uint32_t>(
47 hdr.getIntParameter("RoR Timestamp MSB")))
48 << 32) |
49 static_cast<uint32_t>(hdr.getIntParameter("RoR Timestamp LSB"));
50 }
51 auto timestamp = static_cast<long>(ror_ts);
52
53 hits.reserve(n_multisamples - 1);
54
55 // Skip the last multisample (replicates FrameParser behaviour).
56 for (std::size_t i = 0; i < n_multisamples - 1; ++i) {
57 const uint8_t* ms = raw.data() + payload_start + i * 10;
58
59 uint16_t s0{0}, s1{0}, s2{0};
60 std::memcpy(&s0, ms + 0, 2);
61 std::memcpy(&s1, ms + 2, 2);
62 std::memcpy(&s2, ms + 4, 2);
63
64 uint8_t channel = ms[6];
65 uint8_t apv_id = ms[7] & 0x07;
66 uint8_t hybrid_id = (ms[7] >> 4) & 0x07;
67 uint8_t feb_id = ms[8] & 0x0F;
68
69 // Bytes 8–9 as little-endian uint16_t; shift right 4, mask 6 bits.
70 uint16_t trig_word{0};
71 std::memcpy(&trig_word, ms + 8, 2);
72 uint16_t apv_trigger = (trig_word >> 4) & 0x3F;
73
74 uint8_t flags = ms[9];
75 uint8_t read_error = (flags >> 2) & 1;
76 uint8_t tail = (flags >> 3) & 1;
77 uint8_t head = (flags >> 4) & 1;
78 uint8_t filter = (flags >> 5) & 1;
79
81 channel,
82 std::vector<short>{static_cast<short>(s0), static_cast<short>(s1),
83 static_cast<short>(s2)},
84 timestamp);
85 hit.setApvId(apv_id);
86 hit.setHybridId(hybrid_id);
87 hit.setFebId(feb_id);
88 hit.setApvTrigger(apv_trigger);
89 hit.setReadError(read_error);
90 hit.setHead(head);
91 hit.setTail(tail);
92 hit.setFilter(filter);
93 hits.push_back(std::move(hit));
94 }
95
96 event.add(output_collection_, hits);
97}
98
99} // namespace tracking::reco
100
#define DECLARE_PRODUCER(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Implements an event buffer system for storing event data.
Definition Event.h:42
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
Implementation of a raw digitized hit from a silicon strip detector.
Decodes raw Rogue frame data from SingleSubsystemUnpacker into a collection of RawSiStripHit objects ...
void configure(framework::config::Parameters &ps) override
Callback for the EventProcessor to configure itself from the given set of parameters.
int n_samples_
ADC samples per hit (always 3 for APV25).
std::string input_collection_
Raw byte buffer collection name from SingleSubsystemUnpacker.
void produce(framework::Event &event) override
Process the event and put new data products into it.
std::string output_collection_
Name for the output RawSiStripHit collection.
std::string input_pass_name_
Pass name of the upstream producer.