epic-drich-beam-test-analysis
ePIC dRICH beam test analysis framework
Loading...
Searching...
No Matches
alcor_recodata.h
Go to the documentation of this file.
1#pragma once
2
3#include <iostream>
4#include <vector>
5#include <array>
6#include <map>
7#include <cmath>
8#include <sstream>
9#include "TTree.h"
10#include "triggers.h"
11#include "alcor_spilldata.h"
12#include "alcor_finedata.h"
13#include "parallel_streaming_framer.h"
14
35// ============================================================
36// alcor_recodata
37// ============================================================
38
53{
54private:
55 std::vector<trigger_event> triggers;
56 std::vector<trigger_event> *triggers_ptr = &triggers;
57
58 std::vector<alcor_finedata_struct> recodata;
59 std::vector<alcor_finedata_struct> *recodata_ptr = &recodata;
60
61 // ---- Hough-transform internals ----------------------------------------
62 std::vector<float> hough_r_bins;
63 float hough_cell_size = 3.2f;
64 float hough_x_min;
65 float hough_x_max;
66 float hough_y_min;
67 float hough_y_max;
68 int hough_nx;
69 int hough_ny;
70 std::vector<int> hough_accum;
72 std::unordered_map<int, std::vector<std::vector<int>>> hough_lut;
73
74public:
75 // ================================================================
76 // Constructors
77 // ================================================================
78
80 alcor_recodata() = default;
81
86 explicit alcor_recodata(const std::vector<alcor_finedata_struct> &d);
87
88 // ================================================================
92
93
95 inline std::vector<alcor_finedata_struct> get_recodata() const { return recodata; }
96
98 inline std::vector<alcor_finedata_struct> *get_recodata_ptr() { return recodata_ptr; }
99
101 inline alcor_finedata_struct get_recodata(int i) const { return recodata[i]; }
102
104 inline std::vector<alcor_finedata_struct> &get_recodata_link() { return recodata; }
105
107 inline alcor_finedata_struct &get_recodata_link(int i) { return recodata[i]; }
108
119 inline alcor_finedata get_finedata(int i) const { return alcor_finedata(recodata[i]); }
120
122 inline std::vector<trigger_event> get_triggers() const { return triggers; }
123
125 inline std::vector<trigger_event> *get_triggers_ptr() { return triggers_ptr; }
126
128 inline std::vector<trigger_event> &get_triggers_link() { return triggers; }
129
131
132 // ================================================================
137
138
140 inline uint32_t get_global_index(int i) const { return recodata[i].global_index; }
141
143 inline float get_hit_x(int i) const { return recodata[i].hit_x; }
144
146 inline float get_hit_y(int i) const { return recodata[i].hit_y; }
147
149 inline uint32_t get_hit_mask(int i) const { return recodata[i].hit_mask; }
150
157 inline float get_hit_t(int i) const { return get_finedata(i).get_time_ns(); }
158
160 inline float get_hit_r(int i) const { return get_hit_r(i, {0.f, 0.f}); }
161
163 inline float get_hit_r(int i, std::array<float, 2> v) const { return std::hypot(get_hit_x(i) - v[0], get_hit_y(i) - v[1]); }
164
166 inline float get_hit_phi(int i) const { return get_hit_phi(i, {0.f, 0.f}); }
167
169 inline float get_hit_phi(int i, std::array<float, 2> v) const { return std::atan2(get_hit_y(i) - v[1], get_hit_x(i) - v[0]); }
170
172 inline float get_hit_x_rnd(int i) const { return recodata[i].hit_x + (_rnd_(_global_gen_) * 3.0f - 1.5f); }
173
175 inline float get_hit_y_rnd(int i) const { return recodata[i].hit_y + (_rnd_(_global_gen_) * 3.0f - 1.5f); }
176
178 inline float get_hit_r_rnd(int i) const { return get_hit_r_rnd(i, {0.f, 0.f}); }
179
181 inline float get_hit_r_rnd(int i, std::array<float, 2> v) const { return std::hypot(get_hit_x_rnd(i) - v[0], get_hit_y_rnd(i) - v[1]); }
182
184 inline float get_hit_phi_rnd(int i) const { return get_hit_phi_rnd(i, {0.f, 0.f}); }
185
187 inline float get_hit_phi_rnd(int i, std::array<float, 2> v) const { return std::atan2(get_hit_y_rnd(i) - v[1], get_hit_x_rnd(i) - v[0]); }
188
190
191 // ================================================================
195
196
198 inline int get_hit_tdc(int i) const { return get_finedata(i).get_tdc(); }
199
201 inline int get_device(int i) const { return get_finedata(i).get_device(); }
202
204 inline int get_fifo(int i) const { return get_finedata(i).get_fifo(); }
205
207 inline int get_chip(int i) const { return get_finedata(i).get_chip(); }
208
210 inline int get_eo_channel(int i) const { return get_finedata(i).get_eo_channel(); }
211
213 inline int get_column(int i) const { return get_finedata(i).get_column(); }
214
216 inline int get_pixel(int i) const { return get_finedata(i).get_pixel(); }
217
219 inline int get_device_index(int i) const { return get_finedata(i).get_device_index(); }
220
222 inline int get_global_channel_index(int i) const { return get_finedata(i).get_global_channel_index(); }
223
225
226 // ================================================================
229
230
236 std::optional<trigger_event> get_trigger_by_index(uint8_t index) const;
237
239 inline std::optional<trigger_event> get_timing_trigger() const { return get_trigger_by_index(_TRIGGER_TIMING_); }
240
242
243 // ================================================================
246
247
249 inline void set_recodata(std::vector<alcor_finedata_struct> v) { recodata = v; }
250
252 inline void set_recodata(int i, alcor_finedata_struct v) { recodata[i] = v; }
253
255 inline void set_triggers(const std::vector<trigger_event> v) { triggers = v; }
256
258 inline void set_recodata_ptr(std::vector<alcor_finedata_struct> *v) { recodata_ptr = v; }
259
261 inline void set_triggers_ptr(std::vector<trigger_event> *v) { triggers_ptr = v; }
262
264 inline void set_global_index(int i, uint32_t v) { recodata[i].global_index = v; }
265
267 inline void set_hit_x(int i, float v) { recodata[i].hit_x = v; }
268
270 inline void set_hit_y(int i, float v) { recodata[i].hit_y = v; }
271
273 inline void set_hit_mask(int i, uint32_t v) { recodata[i].hit_mask = v; }
274
276 void set_recodata_link(std::vector<alcor_finedata_struct> &v);
277
279 void set_triggers_link(std::vector<trigger_event> &v);
280
282
283 // ================================================================
286
287
289 inline void add_hit_mask(int i, uint32_t v) { recodata[i].hit_mask |= v; }
290
292 inline void add_hit_mask_bit(int i, uint32_t v) { recodata[i].hit_mask |= encode_bit(v); }
293
295 inline void add_trigger(uint8_t index, uint16_t coarse, float fine_time = 0.) { triggers.emplace_back(index, coarse, fine_time); }
296
298 inline void add_trigger(trigger_event hit) { triggers.push_back(hit); }
299
301 inline int add_hit(const alcor_finedata_struct &hit)
302 {
303 recodata_ptr->push_back(hit);
304 return recodata_ptr->size() - 1;
305 }
306
308 inline int add_hit(const alcor_finedata &hit)
309 {
310 recodata_ptr->push_back(hit.get_data_struct());
311 return recodata_ptr->size() - 1;
312 }
313
315 inline int add_hit(uint32_t rollover,
316 uint16_t coarse,
317 uint8_t fine,
318 float hit_x,
319 float hit_y,
320 uint32_t global_index,
321 uint32_t hit_mask)
322 {
323 recodata_ptr->emplace_back(rollover, coarse, fine, hit_x, hit_y, global_index, hit_mask);
324 return recodata_ptr->size() - 1;
325 }
326
328
329 // ================================================================
332
333
335 inline bool check_trigger(uint8_t v) { return get_trigger_by_index(v).has_value(); }
336
339
342
345
348
351
353 inline bool check_hit_mask(int i, uint32_t v) { return (get_hit_mask(i) & v) != 0; }
354
356 inline bool is_afterpulse(int i) { return get_finedata(i).is_afterpulse(); }
357
359 inline bool is_cross_talk(int i) { return get_finedata(i).is_cross_talk(); }
360
362 inline bool is_ring_tagged(int i) { return check_hit_mask(i, encode_bits({_HITMASK_ring_tag_first, _HITMASK_ring_tag_second})); }
363
365
366 // ================================================================
369
370
375 void clear();
376
381 bool link_to_tree(TTree *input_tree);
382
387 void write_to_tree(TTree *output_tree);
388
390
391 // ================================================================
394
395
407 void find_rings(float_t distance_length_cut, float_t distance_time_cut);
408
423 void build_hough_lut(const std::map<int, std::array<float, 2>> &index_to_hit_xy,
424 float r_min, float r_max, float r_step, float cell_size);
425
440 void find_rings_hough(float threshold_fraction, int min_hits);
441
443};
hit_mask
Bit positions used inside alcor_data_struct::hit_mask.
Definition alcor_data.h:97
Represents a single calibrated ALCOR TDC hit with fine-time correction.
Definition alcor_finedata.h:103
alcor_finedata_struct get_data_struct() const
Returns a copy of the underlying alcor_finedata_struct.
Definition alcor_finedata.h:138
int get_fifo() const
Returns the FIFO number decoded from the calibration index.
Definition alcor_finedata.h:208
bool is_cross_talk() const
Checks whether the hit is flagged as cross-talk.
Definition alcor_finedata.h:296
int get_global_channel_index() const
Returns the global channel index stripped of TDC info.
Definition alcor_finedata.h:226
int get_column() const
Returns the column address decoded from the calibration index.
Definition alcor_finedata.h:217
int get_tdc() const
Returns the TDC index decoded from the calibration index.
Definition alcor_finedata.h:202
int get_device_index() const
Returns the per-device TDC index.
Definition alcor_finedata.h:223
int get_eo_channel() const
Returns the even/odd channel index decoded from the calibration index.
Definition alcor_finedata.h:214
float get_time_ns() const
Returns the calibrated hit time in nanoseconds.
Definition alcor_finedata.h:190
int get_chip() const
Returns the chip ID decoded from the calibration index.
Definition alcor_finedata.h:211
int get_device() const
Returns the readout device ID decoded from the calibration index.
Definition alcor_finedata.h:205
int get_pixel() const
Returns the pixel address decoded from the calibration index.
Definition alcor_finedata.h:220
bool is_afterpulse() const
Checks whether the hit is flagged as an afterpulse.
Definition alcor_finedata.h:299
Container and analysis engine for a collection of reconstructed ALCOR hits.
Definition alcor_recodata.h:53
void find_rings_hough(float threshold_fraction, int min_hits)
Find ring candidates using the pre-computed Hough LUT.
Definition alcor_recodata.cxx:184
void add_trigger(trigger_event hit)
Append a pre-built trigger_event.
Definition alcor_recodata.h:298
float get_hit_r_rnd(int i) const
Radial distance from the origin using randomised coordinates.
Definition alcor_recodata.h:178
alcor_finedata get_finedata(int i) const
Construct and return a full alcor_finedata object for hit i.
Definition alcor_recodata.h:119
void set_recodata_link(std::vector< alcor_finedata_struct > &v)
Rebind the active hit pointer to v (copies vector and rebinds pointer).
Definition alcor_recodata.cxx:7
float get_hit_x_rnd(int i) const
Pixel-randomised x-coordinate (uniform ±1.5 mm jitter within the pixel cell).
Definition alcor_recodata.h:172
void add_trigger(uint8_t index, uint16_t coarse, float fine_time=0.)
Append a trigger from its constituent fields.
Definition alcor_recodata.h:295
std::vector< trigger_event > get_triggers() const
Return a copy of the full trigger vector.
Definition alcor_recodata.h:122
void set_triggers_link(std::vector< trigger_event > &v)
Rebind the active trigger pointer to v (copies vector and rebinds pointer).
Definition alcor_recodata.cxx:13
float get_hit_r(int i, std::array< float, 2 > v) const
Radial distance from a custom centre v [mm].
Definition alcor_recodata.h:163
int add_hit(uint32_t rollover, uint16_t coarse, uint8_t fine, float hit_x, float hit_y, uint32_t global_index, uint32_t hit_mask)
Append a hit from individual fields (constructed in-place).
Definition alcor_recodata.h:315
int add_hit(const alcor_finedata_struct &hit)
Append a hit from an alcor_finedata_struct.
Definition alcor_recodata.h:301
int get_pixel(int i) const
Pixel address for hit i.
Definition alcor_recodata.h:216
void build_hough_lut(const std::map< int, std::array< float, 2 > > &index_to_hit_xy, float r_min, float r_max, float r_step, float cell_size)
Pre-compute the Hough-transform look-up table (LUT).
Definition alcor_recodata.cxx:116
float get_hit_y_rnd(int i) const
Pixel-randomised y-coordinate (uniform ±1.5 mm jitter within the pixel cell).
Definition alcor_recodata.h:175
uint32_t get_global_index(int i) const
Global channel index for hit i.
Definition alcor_recodata.h:140
float get_hit_r(int i) const
Radial distance from the detector origin [mm].
Definition alcor_recodata.h:160
int get_column(int i) const
Column address for hit i.
Definition alcor_recodata.h:213
bool is_timing_available()
True if a timing trigger is present.
Definition alcor_recodata.h:344
alcor_recodata()=default
Default constructor — creates an empty container.
int get_device_index(int i) const
Per-device flat index for hit i.
Definition alcor_recodata.h:219
float get_hit_t(int i) const
Calibrated hit time [ns] for hit i.
Definition alcor_recodata.h:157
bool link_to_tree(TTree *input_tree)
Attach the container to branches of an existing input TTree.
Definition alcor_recodata.cxx:46
alcor_finedata_struct & get_recodata_link(int i)
Return a mutable reference to the hit struct at index i.
Definition alcor_recodata.h:107
float get_hit_phi(int i) const
Azimuthal angle from the detector origin [rad].
Definition alcor_recodata.h:166
void set_recodata(int i, alcor_finedata_struct v)
Replace the hit at index i.
Definition alcor_recodata.h:252
bool is_first_frames()
True if the first-frames trigger is present.
Definition alcor_recodata.h:341
int get_fifo(int i) const
FIFO number for hit i.
Definition alcor_recodata.h:204
void set_recodata_ptr(std::vector< alcor_finedata_struct > *v)
Redirect the active hit pointer to an external vector.
Definition alcor_recodata.h:258
int get_hit_tdc(int i) const
TDC sub-channel index for hit i.
Definition alcor_recodata.h:198
int add_hit(const alcor_finedata &hit)
Append a hit from an alcor_finedata object (stores its underlying struct).
Definition alcor_recodata.h:308
int get_global_channel_index(int i) const
Global channel index stripped of TDC info for hit i.
Definition alcor_recodata.h:222
int get_chip(int i) const
Chip ID for hit i.
Definition alcor_recodata.h:207
void add_hit_mask(int i, uint32_t v)
OR v into the bitmask of hit i.
Definition alcor_recodata.h:289
void set_triggers_ptr(std::vector< trigger_event > *v)
Redirect the active trigger pointer to an external vector.
Definition alcor_recodata.h:261
std::vector< alcor_finedata_struct > get_recodata() const
Return a copy of the full hit vector.
Definition alcor_recodata.h:95
void set_global_index(int i, uint32_t v)
Overwrite the global channel index of hit i.
Definition alcor_recodata.h:264
void find_rings(float_t distance_length_cut, float_t distance_time_cut)
Cluster hits into ring candidates using DBSCAN in the (R, t) plane.
Definition alcor_recodata.cxx:81
float get_hit_r_rnd(int i, std::array< float, 2 > v) const
Radial distance from v using randomised coordinates.
Definition alcor_recodata.h:181
std::optional< trigger_event > get_trigger_by_index(uint8_t index) const
Look up the first trigger whose index field matches index.
Definition alcor_recodata.cxx:23
void set_triggers(const std::vector< trigger_event > v)
Replace the entire trigger collection.
Definition alcor_recodata.h:255
uint32_t get_hit_mask(int i) const
Hit quality / classification bitmask.
Definition alcor_recodata.h:149
bool is_afterpulse(int i)
True if hit i is flagged as an afterpulse (delegates to alcor_finedata).
Definition alcor_recodata.h:356
float get_hit_phi(int i, std::array< float, 2 > v) const
Azimuthal angle from a custom centre v [rad].
Definition alcor_recodata.h:169
bool is_cross_talk(int i)
True if hit i is flagged as optical cross-talk (delegates to alcor_finedata).
Definition alcor_recodata.h:359
std::vector< trigger_event > & get_triggers_link()
Return a mutable reference to the full trigger vector.
Definition alcor_recodata.h:128
bool is_embedded_tracking_available()
True if embedded tracking data are attached to this event.
Definition alcor_recodata.h:347
std::optional< trigger_event > get_timing_trigger() const
Return the timing trigger for this event, if present.
Definition alcor_recodata.h:239
alcor_recodata(const std::vector< alcor_finedata_struct > &d)
Construct a container pre-filled with an existing hit vector.
void set_recodata(std::vector< alcor_finedata_struct > v)
Replace the entire hit collection.
Definition alcor_recodata.h:249
float get_hit_phi_rnd(int i, std::array< float, 2 > v) const
Azimuthal angle from v using randomised coordinates [rad].
Definition alcor_recodata.h:187
void set_hit_x(int i, float v)
Overwrite the x-coordinate of hit i [mm].
Definition alcor_recodata.h:267
std::vector< trigger_event > * get_triggers_ptr()
Return the raw pointer to the active trigger vector (may be external).
Definition alcor_recodata.h:125
bool check_hit_mask(int i, uint32_t v)
True if any bit of v is set in the mask of hit i.
Definition alcor_recodata.h:353
bool is_start_of_spill()
True if the start-of-spill trigger is present.
Definition alcor_recodata.h:338
int get_device(int i) const
Readout device ID for hit i.
Definition alcor_recodata.h:201
void add_hit_mask_bit(int i, uint32_t v)
Set the bit at position v in the bitmask of hit i.
Definition alcor_recodata.h:292
bool is_ring_found()
True if at least one ring has been reconstructed.
Definition alcor_recodata.h:350
void write_to_tree(TTree *output_tree)
Create branches in output_tree for hits and triggers.
Definition alcor_recodata.cxx:69
bool check_trigger(uint8_t v)
True if a trigger with index v exists for this event.
Definition alcor_recodata.h:335
int get_eo_channel(int i) const
Even/odd channel index for hit i.
Definition alcor_recodata.h:210
void clear()
Clear all hits and triggers, resetting the container to an empty state. Does not reset the Hough LUT ...
Definition alcor_recodata.cxx:38
void set_hit_mask(int i, uint32_t v)
Overwrite the quality bitmask of hit i (full replacement).
Definition alcor_recodata.h:273
std::vector< alcor_finedata_struct > * get_recodata_ptr()
Return the raw pointer to the active hit vector (may be external).
Definition alcor_recodata.h:98
void set_hit_y(int i, float v)
Overwrite the y-coordinate of hit i [mm].
Definition alcor_recodata.h:270
alcor_finedata_struct get_recodata(int i) const
Return a copy of the hit struct at index i.
Definition alcor_recodata.h:101
std::vector< alcor_finedata_struct > & get_recodata_link()
Return a mutable reference to the full hit vector.
Definition alcor_recodata.h:104
float get_hit_phi_rnd(int i) const
Azimuthal angle from the origin using randomised coordinates [rad].
Definition alcor_recodata.h:184
float get_hit_x(int i) const
Hit x-coordinate from channel mapping [mm].
Definition alcor_recodata.h:143
bool is_ring_tagged(int i)
True if hit i has been associated with a reconstructed ring.
Definition alcor_recodata.h:362
float get_hit_y(int i) const
Hit y-coordinate from channel mapping [mm].
Definition alcor_recodata.h:146
Raw decoded hit data from an ALCOR TDC channel.
Definition alcor_finedata.h:24
Per-event trigger data attached to a decoded data frame.
Definition triggers.h:114
Header-only trigger definitions, registry, and TOML-based configuration reader.
@ _TRIGGER_FIRST_FRAMES_
First frames of a run.
Definition triggers.h:56
@ _TRIGGER_RING_FOUND_
Ring-finding trigger.
Definition triggers.h:59
@ _TRIGGER_TIMING_
Timing trigger.
Definition triggers.h:57
@ _TRIGGER_TRACKING_
Tracking trigger.
Definition triggers.h:58
@ _TRIGGER_START_OF_SPILL_
Start-of-spill signal.
Definition triggers.h:62
uint32_t encode_bits(const std::vector< uint8_t > &active_bits)
Encode multiple bits into a 32-bit mask.
Definition utility.h:62
uint32_t encode_bit(uint8_t active_bit)
Encode a single bit into a 32-bit mask.
Definition utility.h:52
std::uniform_real_distribution _rnd_(0.0, 1.0)
Uniform float distribution in [0, 1).
std::mt19937 _global_gen_(_global_rd_())
Mersenne-Twister 19937 engine seeded from _global_rd_.