1#ifndef TOFEVENTS_H_INCLUDED
2#define TOFEVENTS_H_INCLUDED
23#include "tof_typedefs.h"
24#include "packets/monitoring.h"
25#include "packets/tof_packet.h"
26#include "events/tof_event_header.hpp"
27#include "calibration.h"
35#define N_CHN_PER_LTB 16
45static const f32 C_LIGHT_PADDLE = 15.4;
49static const u8 EVENTSTATUS_UNKNOWN = 0;
50static const u8 EVENTSTATUS_CRC32WRONG = 10;
51static const u8 EVENTSTATUS_TAILWRONG = 11;
52static const u8 EVENTSTATUS_CHIDWRONG = 12;
53static const u8 EVENTSTATUS_CELLSYNCERR = 13;
54static const u8 EVENTSTATUS_CHNSYNCERR = 14;
55static const u8 EVENTSTATUS_CELLANDCHNSYNCERR = 15;
56static const u8 EVENTSTATUS_ANYDATAMANGLING = 16;
57static const u8 EVENTSTATUS_INCOMPLETEREADOUT = 21;
58static const u8 EVENTSTATUS_INCOMPATIBLEDATA = 22;
59static const u8 EVENTSTATUS_EVENTTIMEOUT = 23;
60static const u8 EVENTSTATUS_GOODNOCRCORERRBITCHECK = 39;
61static const u8 EVENTSTATUS_GOODNOCRCCHECK = 40;
62static const u8 EVENTSTATUS_GOODNOERRBITCHECK = 41;
63static const u8 EVENTSTATUS_PERFECT = 42;
71enum class EventStatus : u8 {
72 Unknown = EVENTSTATUS_UNKNOWN,
73 Crc32Wrong = EVENTSTATUS_CRC32WRONG,
74 TailWrong = EVENTSTATUS_TAILWRONG,
75 ChannelIDWrong = EVENTSTATUS_CHIDWRONG,
76 CellSyncErrors = EVENTSTATUS_CELLSYNCERR,
77 ChnSyncErrors = EVENTSTATUS_CHNSYNCERR,
78 CellAndChnSyncErrors = EVENTSTATUS_CELLANDCHNSYNCERR,
79 AnyDataMangling = EVENTSTATUS_ANYDATAMANGLING,
80 IncompatibleData = EVENTSTATUS_INCOMPATIBLEDATA,
81 EventTimeOut = EVENTSTATUS_EVENTTIMEOUT,
82 GoodNoCRCOrErrBitCheck = EVENTSTATUS_GOODNOCRCORERRBITCHECK,
85 GoodNoCRCCheck = EVENTSTATUS_GOODNOCRCCHECK,
88 GoodNoErrBitCheck = EVENTSTATUS_GOODNOERRBITCHECK,
89 IncompleteReadout = EVENTSTATUS_INCOMPLETEREADOUT,
90 Perfect = EVENTSTATUS_PERFECT,
94std::ostream& operator<<(std::ostream& os,
const EventStatus& status);
97struct std::formatter<EventStatus> : std::formatter<std::string> {
99 constexpr auto parse(std::format_parse_context& ctx) {
103 auto format(
const EventStatus& status,
auto& ctx) {
104 std::ostringstream oss;
106 return std::format_to(ctx.out(),
"{}", oss.str());
113static const u8 TRIGGERTYPE_UNKNOWN = 0;
114static const u8 TRIGGERTYPE_GAPS = 4;
115static const u8 TRIGGERTYPE_ANY = 1;
116static const u8 TRIGGERTYPE_TRACK = 2;
117static const u8 TRIGGERTYPE_TRACKCENTRAL = 3;
118static const u8 TRIGGERTYPE_POISSON = 100;
119static const u8 TRIGGERTYPE_FORCED = 101;
129enum class TriggerType : u8 {
130 Unknown = TRIGGERTYPE_UNKNOWN,
132 Gaps = TRIGGERTYPE_GAPS,
133 Any = TRIGGERTYPE_ANY,
134 Track = TRIGGERTYPE_TRACK,
135 TrackCentral = TRIGGERTYPE_TRACKCENTRAL,
137 Poisson = TRIGGERTYPE_POISSON,
138 Forced = TRIGGERTYPE_FORCED,
141std::ostream& operator<<(std::ostream& os,
const TriggerType& t_type);
145static const u8 LTBTHRESHOLD_NOHIT = 0;
146static const u8 LTBTHRESHOLD_HIT = 1;
147static const u8 LTBTHRESHOLD_BETA = 2;
148static const u8 LTBTHRESHOLD_VETO = 3;
149static const u8 LTBTHRESHOLD_UNKNOWN = 255;
151enum class LTBThreshold : u8 {
152 NoHit = LTBTHRESHOLD_NOHIT,
154 Hit = LTBTHRESHOLD_HIT,
156 Beta = LTBTHRESHOLD_BETA,
158 Veto = LTBTHRESHOLD_VETO,
161 Unknown = LTBTHRESHOLD_UNKNOWN,
164std::ostream& operator<<(std::ostream& os,
const LTBThreshold& thresh);
176 static const u16 HEAD = 0xAAAA;
177 static const u16 TAIL = 0x5555;
178 static const u16 SIZE = 30;
194 static RBEventHeader from_bytestream(
const Vec<u8> &bytestream,
197 Vec<u8> get_channels()
const;
198 u8 get_nchan()
const;
199 Vec<u8> get_active_data_channels()
const;
200 bool has_ch9()
const;
201 u8 get_n_datachan()
const;
202 f32 get_fpga_temp()
const;
203 bool is_event_fragment()
const;
204 bool drs_lost_trigger()
const;
205 bool lost_lock()
const;
206 bool lost_lock_last_sec()
const;
207 bool is_locked()
const;
208 bool is_locked_last_sec()
const;
210 std::array<f32, 3> get_sine_fit()
const;
228 static const u16 HEAD = 0xAAAA;
229 static const u16 TAIL = 0x5555;
240 const Vec<u16>& get_channel_by_label(u8 channel)
const;
241 const Vec<u16>& get_channel_by_id(u8 channel)
const;
243 const Vec<u16>& get_channel_adc(u8 channel)
const;
246 static f32
calc_baseline(
const Vec<f32> &volts, usize min_bin, usize max_bin);
248 static RBEvent from_bytestream(
const Vec<u8> &bytestream,
251 std::string to_string()
const;
259 bool channel_check(u8 channel)
const;
260 Vec<u16> _empty_channel = Vec<u16>();
271 static const u16 HEAD = 0xAAAA;
272 static const u16 TAIL = 0x5555;
273 static const usize SIZE = 15;
284 static RBMissingHit from_bytestream(
const Vec<u8> &bytestream,
290static const u8 EVENT_QUALITY_UNKNOWN = 0;
291static const u8 EVENT_QUALITY_SILVER = 10;
292static const u8 EVENT_QUALITY_GOLD = 20;
293static const u8 EVENT_QUALITY_DIAMOND = 30;
294static const u8 EVENT_QUALITY_FOURLEAFCLOVER = 40;
303enum class EventQuality : u8 {
304 Unknown = EVENT_QUALITY_UNKNOWN,
305 Silver = EVENT_QUALITY_SILVER,
306 Gold = EVENT_QUALITY_GOLD,
307 Diamond = EVENT_QUALITY_DIAMOND,
312 FourLeafClover = EVENT_QUALITY_FOURLEAFCLOVER
315std::ostream& operator<<(std::ostream& os,
const EventQuality& qual);
319static const u8 COMPRESSION_LEVEL_UNKNOWN = 0;
320static const u8 COMPRESSION_LEVEL_NONE = 10;
322enum class CompressionLevel : u8 {
323 Unknown = COMPRESSION_LEVEL_UNKNOWN,
324 None = COMPRESSION_LEVEL_NONE,
327std::ostream& operator<<(std::ostream& os,
const CompressionLevel& level);
350 static const u16
HEAD = 0xAAAA;
352 static const u16
TAIL = 0x5555;
356 EventStatus event_status;
371 Vec<u16> channel_mask ;
383 Vec<u8> get_rb_link_ids()
const;
435 static const u16 HEAD = 0xAAAA;
436 static const u16 TAIL = 0x5555;
480 static u32 get_n_rbmissinghits(u32 mask);
481 static u32 get_n_rbevents(u32 mask);
501 bool passed_consistency_check();
517 static const u16 HEAD = 0xF0F0;
518 static const u16 TAIL = 0xF0F;
525 Gaps::ProtocolVersion version;
540 f32 get_time_a()
const;
541 f32 get_time_b()
const;
542 f32 get_peak_a()
const;
543 f32 get_peak_b()
const;
544 f32 get_charge_a()
const;
545 f32 get_charge_b()
const;
546 f32 get_charge_min_i()
const;
547 f32 get_x_pos()
const;
548 f32 get_t_avg()
const;
550 f64 get_timestamp48()
const;
556 static TofHit from_bytestream(
const Vec<u8> &bytestream,
560 std::string to_string()
const;
599 static const u16 HEAD = 0xAAAA;
600 static const u16 TAIL = 0x5555;
608 static RBWaveform from_bytestream(
const Vec<u8> &bytestream,
611 std::string to_string()
const;
622 static const u16 HEAD = 0xAAAA;
623 static const u16 TAIL = 0x5555;
625 Gaps::ProtocolVersion version ;
628 u16 trigger_sources ;
649 Vec<u16> channel_mask ;
656 u64 get_timestamp48()
const;
658 Vec<u8> get_rb_link_ids()
const;
678 std::string to_string()
const;
681std::ostream& operator<<(std::ostream& os,
const TofHit& pad);
685std::ostream& operator<<(std::ostream& os,
const TofEvent& et);
687std::ostream& operator<<(std::ostream& os,
const RBEvent& re);
689std::ostream& operator<<(std::ostream& os,
const RBEventHeader& rh);
691std::ostream& operator<<(std::ostream& os,
const RBWaveform& rh);
**
Definition caraspace.hpp:8
static const u16 TAIL
end struct marker
Definition events.h:352
static const u16 HEAD
begin struct marker
Definition events.h:350
u32 event_id
event_id as assigned by the MasterTriggerBoard
Definition events.h:358
u32 tiu_timestamp
Tracker (?) timestamp.
Definition events.h:362
u64 get_timestamp_abs48() const
Get absolute timestamp as sent by the GPS.
u64 get_timestamp_gps48() const
Vec< TriggerType > get_trigger_sources() const
Get the trigger sources from trigger source byte.
u32 timestamp
MTB timestamp.
Definition events.h:360
static MasterTriggerEvent from_bytestream(const Vec< u8 > &bytestream, u64 &pos)
u32 tiu_gps32
GAPS GPS clock value (slow)
Definition events.h:364
std::string to_string() const
String representation of the struct.
u32 crc
triggered paddles as seen by the MTB
Definition events.h:368
u32 tiu_gps16
GAPS GPS clock value (fast)
Definition events.h:366
static const usize SIZE
the struct has a fixed size of SIZE
Definition events.h:354
Vec< std::tuple< u8, u8, u8, LTBThreshold > > get_trigger_hits() const
Definition calibration.h:33
static f32 calc_baseline(const Vec< f32 > &volts, usize min_bin, usize max_bin)
Get the baseline for a single channel.
Vec< std::tuple< u8, u8, u8, LTBThreshold > > get_trigger_hits() const
u16 primary_charge
reconstructed primary charge
Definition events.h:647
Vec< TriggerType > get_trigger_sources() const
Get the trigger sources from trigger source byte.
u8 n_trigger_paddles
Definition events.h:632
u16 primary_beta
reconstructed primary beta
Definition events.h:645
static TofEvent from_tofpacket(const TofPacket &packet)
Vec< RBEvent > rb_events
Definition events.h:445
const RBEvent & get_rbevent(u8 board_id) const
Vec< u8 > get_rbids() const
Vec< RBMissingHit > missing_hits
Definition events.h:449
static TofEvent from_bytestream(const Vec< u8 > &bytestream, u64 &pos)
std::string to_string() const
string representation for printing
void set_paddle_len(f32 paddle_len)
Definition tof_packet.h:81