LDMX Software
SiStripWaveform.cxx
1#include "Tracking/Event/SiStripWaveform.h"
2
3#include <algorithm>
4#include <iomanip>
5#include <string>
6
7namespace ldmx {
8
9SiStripWaveform::SiStripWaveform(std::vector<short> samples, int16_t pchannel,
10 uint8_t hybrid_id, uint8_t feb_id,
11 uint8_t n_triggers)
12 : samples_(std::move(samples)),
13 pchannel_(pchannel),
14 hybrid_id_(hybrid_id),
15 feb_id_(feb_id),
16 n_triggers_(n_triggers) {}
17
18void SiStripWaveform::clear() {
19 samples_.clear();
20 pchannel_ = 0;
21 hybrid_id_ = 0;
22 feb_id_ = 0;
23 n_triggers_ = 0;
24}
25
26std::ostream& operator<<(std::ostream& output, const SiStripWaveform& w) {
27 // Header.
28 output << "[ SiStripWaveform ] FEB=" << static_cast<int>(w.feb_id_)
29 << " Hybrid=" << static_cast<int>(w.hybrid_id_)
30 << " PCh=" << w.pchannel_
31 << " NTrig=" << static_cast<int>(w.n_triggers_)
32 << " PeakAmp=" << w.peakAmplitude() << "\n";
33
34 if (w.samples_.empty()) return output;
35
36 // Determine scale — always include zero so the baseline is visible.
37 short s_min = *std::min_element(w.samples_.begin(), w.samples_.end());
38 short s_max = *std::max_element(w.samples_.begin(), w.samples_.end());
39 s_min = std::min(s_min, static_cast<short>(0));
40 s_max = std::max(s_max, static_cast<short>(0));
41
42 const int bar_width = 50;
43 const float range = static_cast<float>(s_max - s_min);
44
45 output << " Idx ADC |\n";
46
47 for (int i = 0; i < static_cast<int>(w.samples_.size()); ++i) {
48 short val = w.samples_[i];
49 int t = i / 3, s = i % 3;
50
51 const std::string label = "T" + std::to_string(t) + "." + std::to_string(s);
52
53 // Column positions for zero and this sample.
54 int zero_pos =
55 (range > 0) ? static_cast<int>((0.f - s_min) / range * (bar_width - 1))
56 : bar_width / 2;
57 int val_pos = (range > 0)
58 ? static_cast<int>((static_cast<float>(val) - s_min) /
59 range * (bar_width - 1))
60 : zero_pos;
61 val_pos = std::max(0, std::min(bar_width - 1, val_pos));
62
63 std::string bar(bar_width, ' ');
64 // Fill between zero and sample.
65 int lo = std::min(zero_pos, val_pos);
66 int hi = std::max(zero_pos, val_pos);
67 for (int k = lo; k <= hi; ++k) bar[k] = (val >= 0) ? '+' : '-';
68 // Tip marker.
69 bar[val_pos] = (val > 0) ? '>' : (val < 0) ? '<' : '|';
70 // Zero marker (only when sample is non-zero).
71 if (val != 0 && bar[zero_pos] == ' ') bar[zero_pos] = '|';
72
73 output << " " << std::left << std::setw(4) << label << " " << std::right
74 << std::setw(5) << static_cast<int>(val) << " |" << bar << "|\n";
75 }
76 return output;
77}
78
79} // namespace ldmx
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,...