1#ifndef TOFEVENTS_H_INCLUDED
2#define TOFEVENTS_H_INCLUDED
23#include "result/result.h"
25#include "tof_typedefs.h"
26#include "packets/monitoring.h"
27#include "packets/tof_packet.h"
28#include "events/tof_event_header.hpp"
29#include "calibration.h"
44#define N_CHN_PER_LTB 16
50static const f32 C_LIGHT_PADDLE = 15.4;
54static const u8 EVENTSTATUS_UNKNOWN = 0;
55static const u8 EVENTSTATUS_CRC32WRONG = 10;
56static const u8 EVENTSTATUS_TAILWRONG = 11;
57static const u8 EVENTSTATUS_CHIDWRONG = 12;
58static const u8 EVENTSTATUS_CELLSYNCERR = 13;
59static const u8 EVENTSTATUS_CHNSYNCERR = 14;
60static const u8 EVENTSTATUS_CELLANDCHNSYNCERR = 15;
61static const u8 EVENTSTATUS_ANYDATAMANGLING = 16;
62static const u8 EVENTSTATUS_INCOMPLETEREADOUT = 21;
63static const u8 EVENTSTATUS_INCOMPATIBLEDATA = 22;
64static const u8 EVENTSTATUS_EVENTTIMEOUT = 23;
65static const u8 EVENTSTATUS_GOODNOCRCORERRBITCHECK = 39;
66static const u8 EVENTSTATUS_GOODNOCRCCHECK = 40;
67static const u8 EVENTSTATUS_GOODNOERRBITCHECK = 41;
68static const u8 EVENTSTATUS_PERFECT = 42;
76enum class EventStatus : u8 {
77 Unknown = EVENTSTATUS_UNKNOWN,
78 Crc32Wrong = EVENTSTATUS_CRC32WRONG,
79 TailWrong = EVENTSTATUS_TAILWRONG,
80 ChannelIDWrong = EVENTSTATUS_CHIDWRONG,
81 CellSyncErrors = EVENTSTATUS_CELLSYNCERR,
82 ChnSyncErrors = EVENTSTATUS_CHNSYNCERR,
83 CellAndChnSyncErrors = EVENTSTATUS_CELLANDCHNSYNCERR,
84 AnyDataMangling = EVENTSTATUS_ANYDATAMANGLING,
85 IncompatibleData = EVENTSTATUS_INCOMPATIBLEDATA,
86 EventTimeOut = EVENTSTATUS_EVENTTIMEOUT,
87 GoodNoCRCOrErrBitCheck = EVENTSTATUS_GOODNOCRCORERRBITCHECK,
90 GoodNoCRCCheck = EVENTSTATUS_GOODNOCRCCHECK,
93 GoodNoErrBitCheck = EVENTSTATUS_GOODNOERRBITCHECK,
94 IncompleteReadout = EVENTSTATUS_INCOMPLETEREADOUT,
95 Perfect = EVENTSTATUS_PERFECT,
99std::ostream& operator<<(std::ostream& os,
const EventStatus& status);
102struct std::formatter<EventStatus> : std::formatter<std::string> {
104 constexpr auto parse(std::format_parse_context& ctx) {
108 auto format(
const EventStatus& status,
auto& ctx) {
109 std::ostringstream oss;
111 return std::format_to(ctx.out(),
"{}", oss.str());
117static const u8 TRIGGERTYPE_UNKNOWN = 0;
118static const u8 TRIGGERTYPE_ANY = 1;
119static const u8 TRIGGERTYPE_TRACK = 2;
120static const u8 TRIGGERTYPE_TRACKCENTRAL = 3;
121static const u8 TRIGGERTYPE_GAPS = 4;
122static const u8 TRIGGERTYPE_POISSON = 100;
123static const u8 TRIGGERTYPE_FORCED = 101;
133enum class TriggerType : u8 {
134 Unknown = TRIGGERTYPE_UNKNOWN,
136 Gaps = TRIGGERTYPE_GAPS,
137 Any = TRIGGERTYPE_ANY,
138 Track = TRIGGERTYPE_TRACK,
139 TrackCentral = TRIGGERTYPE_TRACKCENTRAL,
141 Poisson = TRIGGERTYPE_POISSON,
142 Forced = TRIGGERTYPE_FORCED,
145std::ostream& operator<<(std::ostream& os,
const TriggerType& t_type);
149static const u8 LTBTHRESHOLD_NOHIT = 0;
150static const u8 LTBTHRESHOLD_HIT = 1;
151static const u8 LTBTHRESHOLD_BETA = 2;
152static const u8 LTBTHRESHOLD_VETO = 3;
153static const u8 LTBTHRESHOLD_UNKNOWN = 255;
155enum class LTBThreshold : u8 {
156 NoHit = LTBTHRESHOLD_NOHIT,
158 Hit = LTBTHRESHOLD_HIT,
160 Beta = LTBTHRESHOLD_BETA,
162 Veto = LTBTHRESHOLD_VETO,
165 Unknown = LTBTHRESHOLD_UNKNOWN,
168std::ostream& operator<<(std::ostream& os,
const LTBThreshold& thresh);
180 static constexpr u16 HEAD = 0xAAAA;
181 static constexpr u16 TAIL = 0x5555;
182 static constexpr u16 SIZE = 30;
187 u16 channel_mask = 0;
198 static auto from_bytestream(
const Vec<u8> &bytestream, u64 &pos)
199 -> r::Result<RBEventHeader, g::IOError>;
201 auto get_channels()
const -> Vec<u8>;
202 auto get_nchan()
const -> u8;
203 auto get_active_data_channels()
const -> Vec<u8>;
204 auto has_ch9()
const -> bool;
205 auto get_n_datachan()
const -> u8;
206 auto get_fpga_temp()
const -> f32;
207 auto is_event_fragment()
const -> bool;
208 auto drs_lost_trigger()
const -> bool;
209 auto lost_lock()
const -> bool;
210 auto lost_lock_last_sec()
const -> bool;
211 auto is_locked()
const -> bool;
212 auto is_locked_last_sec()
const -> bool;
213 auto get_sine_fit()
const -> std::array<f32,3>;
229 static constexpr u16 HEAD = 0xF0F0;
230 static constexpr u16 TAIL = 0xF0F;
237 Gaps::ProtocolVersion version;
251 f32 coax_cbl_time = 0;
252 f32 hart_cbl_time = 0;
257 auto get_time_a()
const -> f32;
258 auto get_time_b()
const -> f32;
259 auto get_peak_a()
const -> f32;
260 auto get_peak_b()
const -> f32;
261 auto get_charge_a()
const -> f32;
262 auto get_charge_b()
const -> f32;
263 auto get_charge_min_i()
const -> f32;
264 auto get_x_pos()
const -> f32;
265 auto get_t_avg()
const -> f32;
273 void set_paddle_len(f32 paddle_len);
277 auto get_phase_delay() const -> f32;
278 auto get_cable_delay() const -> f32;
279 auto get_t0() const -> f32;
280 auto get_edep() const -> f32;
283 static auto from_bytestream(
const Vec<u8> &bytestream, u64 &pos)
309 f32 charge_a_f32 = 0;
310 f32 charge_b_f32 = 0;
322 static constexpr u16 HEAD = 0xAAAA;
323 static constexpr u16 TAIL = 0x5555;
327 EventStatus status = EventStatus::Unknown;
329 Vec<Vec<u16>> adc = Vec<Vec<u16>>();
330 Vec<TofHit> hits = Vec<TofHit>();
334 auto get_channel_by_label(u8 channel)
const ->
const Vec<u16>&;
335 auto get_channel_by_id(u8 channel)
const ->
const Vec<u16>&;
337 auto get_channel_adc(u8 channel)
const ->
const Vec<u16>&;
340 static auto calc_baseline(
const Vec<f32> &volts, usize min_bin, usize max_bin) -> f32;
342 static auto from_bytestream(
const Vec<u8> &bytestream, u64 &pos)
353 auto channel_check(u8 channel) const ->
bool;
354 Vec<u16> _empty_channel = Vec<u16>();
364 [[deprecated(
"Unused/not useful deemed feature")]]
366 static constexpr u16 HEAD = 0xAAAA;
367 static constexpr u16 TAIL = 0x5555;
368 static constexpr usize SIZE = 15;
379 static RBMissingHit from_bytestream(
const Vec<u8> &bytestream,
385static const u8 EVENT_QUALITY_UNKNOWN = 0;
386static const u8 EVENT_QUALITY_SILVER = 10;
387static const u8 EVENT_QUALITY_GOLD = 20;
388static const u8 EVENT_QUALITY_DIAMOND = 30;
389static const u8 EVENT_QUALITY_FOURLEAFCLOVER = 40;
398enum class EventQuality : u8 {
399 Unknown = EVENT_QUALITY_UNKNOWN,
400 Silver = EVENT_QUALITY_SILVER,
401 Gold = EVENT_QUALITY_GOLD,
402 Diamond = EVENT_QUALITY_DIAMOND,
407 FourLeafClover = EVENT_QUALITY_FOURLEAFCLOVER
410std::ostream& operator<<(std::ostream& os,
const EventQuality& qual);
414static const u8 COMPRESSION_LEVEL_UNKNOWN = 0;
415static const u8 COMPRESSION_LEVEL_NONE = 10;
417enum class CompressionLevel : u8 {
418 Unknown = COMPRESSION_LEVEL_UNKNOWN,
419 None = COMPRESSION_LEVEL_NONE,
422std::ostream& operator<<(std::ostream& os,
const CompressionLevel& level);
445 static constexpr u16 HEAD = 0xAAAA;
447 static constexpr u16 TAIL = 0x5555;
449 static constexpr usize SIZE = 0;
451 EventStatus event_status = EventStatus::Unknown;
457 u32 tiu_timestamp = 0;
464 u16 trigger_source = 0;
466 Vec<u16> channel_mask = Vec<u16>();
467 u64 mtb_link_mask = 0;
473 [[deprecated(
"The format of the gps timestamp changed and it is only 32 bits as of now")]]
476 auto get_timestamp_gps() const -> u32;
479 auto get_timestamp_abs48() const -> u64;
480 auto get_rb_link_ids() const -> Vec<u8>;
493 auto get_trigger_hits() const
494 -> Vec<std::tuple<u8, u8, u8, LTBThreshold>>;
497 auto get_trigger_sources() const -> Vec<TriggerType>;
509 static auto from_bytestream(const Vec<u8> &bytestream, u64 &pos)
512 auto to_string() const -> std::
string;
529 static constexpr u16 HEAD = 0xAAAA;
530 static constexpr u16 TAIL = 0x5555;
558 -> r::Result<TofEvent, g::IOError>;
579 [[deprecated(
"RBMissingHit is deprecated")]]
580 static auto get_n_rbmissinghits(u32 mask) -> u32;
581 static auto get_n_rbevents(u32 mask) -> u32;
586 auto normalize_hit_times() ->
void;
589 auto to_string() const -> std::
string;
594 auto get_rbevent(u8 board_id) const -> const
RBEvent&;
599 auto get_rbids() const -> Vec<u8>;
606 auto passed_consistency_check() ->
bool;
627 static constexpr u16 HEAD = 0xAAAA;
628 static constexpr u16 TAIL = 0x5555;
636 static auto from_bytestream(
const Vec<u8> &bytestream, u64 &pos) ->
RBWaveform;
637 auto to_string()
const -> std::string;
648 static constexpr u16 HEAD = 0xAAAA;
649 static constexpr u16 TAIL = 0x5555;
651 Gaps::ProtocolVersion version ;
654 u16 trigger_sources ;
666 u16 drs_dead_lost_hits;
668 Vec<u16> channel_mask ;
680 static auto from_tofpacket(
const TofPacket &packet)
681 -> r::Result<TofEventSummary, g::IOError>;
682 static auto from_bytestream(
const Vec<u8> &stream, u64 &pos) -> r::Result<TofEventSummary, g::IOError> ;
690 auto normalize_hit_times() -> void;
694 auto get_timestamp48() const -> u64;
696 auto get_rb_link_ids() const -> Vec<u8>;
710 auto get_trigger_hits() const -> Vec<std::tuple<u8, u8, u8, LTBThreshold>>;
712 auto get_trigger_sources() const -> Vec<TriggerType>;
714 auto to_string() const -> std::
string;
717std::ostream& operator<<(std::ostream& os, const
TofHit& pad);
721std::ostream& operator<<(std::ostream& os, const
TofEvent& et);
723std::ostream& operator<<(std::ostream& os, const
RBEvent& re);
725std::ostream& operator<<(std::ostream& os, const
RBEventHeader& rh);
727std::ostream& operator<<(std::ostream& os, const
RBWaveform& rh);
Definition calibration.h:105
std::map< u8, TofPaddle > TofPaddleMap
A map of paddle id -> TofPaddle.
Definition database.h:62
auto get_timestamp_gps48() const -> u64
Definition calibration.h:34
static auto calc_baseline(const Vec< f32 > &volts, usize min_bin, usize max_bin) -> f32
Get the baseline for a single channel.
u8 n_trigger_paddles
Definition events.h:658
static auto from_bytestream(const Vec< u8 > &bytestream, u64 &pos) -> r::Result< TofEvent, g::IOError >
auto get_hits() const -> Vec< TofHit >
Get all hits from all rb_events.
Vec< RBEvent > rb_events
Definition events.h:538
Vec< RBMissingHit > missing_hits
Definition events.h:542
static auto from_tofpacket(const TofPacket &packet) -> TofEvent
auto get_t0_relative() const -> f32
Definition tof_packet.h:83