StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fcs_trg_base.h
1 #ifndef _FCS_TRG_BASE_H_
2 #define _FCS_TRG_BASE_H_
3 
4 #include <sys/types.h>
5 typedef unsigned int u_int;
6 typedef unsigned short u_short;
7 typedef unsigned char u_char;
8 
9 // serial links stage_1 --> stage_2 --> stage_3
10 struct link_t {
11  u_short d[8] ; // make them 16 bits because we might have 12 bits eventually
12 } ;
13 
14 // data links from ADC --> stage_0
15 struct adc_tick_t {
16  u_short d[8] ;
17 } ;
18 
19 struct geom_t {
20  u_char ns ;
21  u_char det ;
22  u_char dep ;
23  u_char ch ;
24 } ;
25 
26 struct ped_gain_t {
27  u_short ped ;
28  u_short gain ;
29 } ;
30 
31 
32 
33 class fcs_trg_base {
34 public:
35 // static const int XING_COU = 20 ; // maximum xings we will look at in simulation and verification
36  static const int XING_COU = 40 ; // maximum xings we will look at in simulation and verification
37  static const int DET_COU = 4 ; // including Trigger DEPs
38  static const int ADC_DET_COU = 3 ; // dets with ADCs (just 3)
39  static const int NS_COU = 2 ;
40  static const int DEP_COU = 24 ;
41  static const int DEP_HCAL_COU = 9 ;
42  static const int DEP_ECAL_COU = 24 ;
43  static const int DEP_PRE_COU = 6 ;
44  static const int DEP_HCAL_TRG_COU = 8 ;
45  static const int DEP_ECAL_TRG_COU = 20 ;
46  static const int DEP_PRE_TRG_COU = 6 ;
47 
48  fcs_trg_base() ;
49  virtual ~fcs_trg_base() ;
50 
51  // stage_0 and stage_1 are running in DEP/ADC
52  void stage_0(adc_tick_t adc, geom_t geo, ped_gain_t *pg, u_int *to_s1) ;
53  void stage_0_201900(adc_tick_t adc, geom_t geo, ped_gain_t *pg, u_int *to_s1) ;
54  void stage_0_202101(adc_tick_t adc, geom_t geo, ped_gain_t *pg, u_int *to_s1) ;
55  void stage_0_202103(adc_tick_t adc, geom_t geo, ped_gain_t *pg, u_int *to_s1) ;
56  void stage_0_202109(adc_tick_t adc, geom_t geo, ped_gain_t *pg, u_int *to_s1) ;
57 
58  void stage_1(u_int from_s0[], geom_t geo, link_t to_s2[]) ;
59  void stage_1_201900(u_int from_s0[], geom_t geo, link_t to_s2[]) ;
60  void stage_1_202201(u_int from_s0[], geom_t geo, link_t to_s2[]) ;
61 
62  void stage_2(link_t ecal[], link_t hcal[], link_t pres[], geom_t geo, link_t output[], u_short* s2_to_dsm) ;
63  void stage_2_201900(link_t ecal[], link_t hcal[], link_t pres[], geom_t geo, link_t output[]) ;
64  void stage_2_202201(link_t ecal[], link_t hcal[], link_t pres[], geom_t geo, link_t output[]) ;
65  void stage_2_TAMU_202202(link_t ecal[], link_t hcal[], link_t pres[], geom_t geo, link_t output[]) ;
66  void stage_2_JP6_202204(link_t ecal[], link_t hcal[], link_t pres[], geom_t geo, link_t output[]) ;
67  void stage_2_JP6Carl_202205(link_t ecal[], link_t hcal[], link_t pres[], geom_t geo, link_t output[]) ;
68  void stage_2_JP5_202206(link_t ecal[], link_t hcal[], link_t pres[], geom_t geo, link_t output[]) ;
69  void stage_2_202207(link_t ecal[], link_t hcal[], link_t pres[], geom_t geo, link_t output[], u_short* s2_to_dsm) ;
70  void stage_2_202203(link_t ecal[], link_t hcal[], link_t pres[], geom_t geo, link_t output[]) ;
71  void stage_2_tonko_202101(link_t ecal[], link_t hcal[], link_t pres[], geom_t geo, link_t output[]) ;
72  void stage_2_tonko_202104(link_t ecal[], link_t hcal[], link_t pres[], geom_t geo, link_t output[]) ;
73 
74  // stage_3 is running in DEP/IO (1 Main) connected to STAR Trigger RAT/DSM
75  void stage_3(link_t from_s2[], u_short *to_dsm) ;
76  void stage_3_201900(link_t from_s2[], u_short *to_dsm) ;
77  void stage_3_202201(link_t from_s2[], u_short *to_dsm) ;
78  void stage_3_202203(link_t from_s2[], u_short *to_dsm) ;
79  void stage_3_202207(link_t from_s2[], u_short *to_dsm) ;
80  void stage_3_tonko_202101(link_t from_s2[], u_short *to_dsm) ;
81 
82  virtual u_int get_version() ;
83 
84  void init(const char* fname) ;
85 
86  void run_start(u_int run) ;
87 
88  void start_event() ;
89 
90  void fill_event(int det, int ns, int dep, int ch, u_short *adc, int t_cou) ;
91 
92  int verify_event_io() ;
93 
94  u_int run_event_sim(int xing, int type) ; // returns DSM bits
95 
96  int verify_event_sim(int xing) ;
97 
98  int dump_event_sim(int xing) ;
99 
100  int end_event() ;
101 
102  int run_stop() ; // for statistics dumps et...
103 
104 
105  u_char want_stage_2_io ; // only if I have full events
106  u_char want_stage_3_io ; // only for eother full events or in sector 11
107  u_char want_stage_1_sim ;
108 
109  // cleared at run start; logged at run stop
110  struct errors_t {
111  u_int sim_s1 ;
112  u_int sim_s2 ;
113  u_int sim_s3 ;
114 
115  // I/O errors
116  u_int io_s1_to_s2[4] ;
117  u_int io_s2_to_s3 ;
118 
119  } errs, good ;
120 
121  // only for S3
122  struct statistics_t {
123  u_int self_trgs ;
124 
125  int tcd_marker ;
126  int self_trg_marker ;
127  } statistics ;
128 
129  u_char self_trigger ; // for debugging
130  u_int dbg_xing ; // for debugging
131 
132  u_int run_number ; // for logging
133  u_int evts ; // for logging
134 
135  u_char got_one ; // helper
136 
137  // log_level for various printfs
138  int log_level ;
139 
140  // will change invocation to invocation when running in real-time!
141  u_char realtime ; // 1 when in STAR DAQ, 0 when running from DAQ file (default)
142  u_char sim_mode ; // 1 when running simulated data (e.g. for Akio et al)
143 
144 
145 
146 // u_char det ;
147 // u_char ns ;
148 // u_char dep ;
149 
150  u_char id ; // used in realtime to identify the thread
151 
152 
153  u_short tb_cou[NS_COU][DET_COU][DEP_COU] ; // filled event by event; used as a "presence" marker too; det,ns,dep
154 
155 
156  // data from DAQ file; used for replay/bitchecking or full simulation
157  struct in_t {
158  // DEP/ADC data for each DEP/ADC
159  struct {
160  // ADC data
161  adc_tick_t adc[32] ;
162 
163  // stage_1 data sent by the DEP/ADC (ns,det,dep)
164  link_t s1_to_s2 ;
165  } s1[NS_COU][ADC_DET_COU][DEP_COU] ;
166 
167 
168  // Stage_2 DEP data for each of the 2 DEP/Stage_2
169  struct {
170  // stage_2 data received by the stage_2 DEP/IO from a stage_1 DEP/ADC
171  link_t s2_from_s1[34] ; // stage_1 data _received_ by stage_2; ns,ch
172 
173  // stage_2 data sent by DEP/ADC in stage_2 (ns,ch)
174  link_t s2_to_s3[2] ; // stage_2 data _sent_ to stage_3; ns,ch
175 
176  link_t s2_to_dsm ; // new for FY22 -- direct link to Trigger
177  } s2[NS_COU] ;
178 
179 
180  // Stage_3 DEP data, just 1
181  struct {
182  // stage_2 data received by stage_3 DEP (ch)
183  link_t s3_from_s2[NS_COU*2] ; // stage_3 data _received_ from stage_2
184 
185  link_t dsm_out ; // DSM output sent
186  } s3 ;
187 
188  } d_in[XING_COU] ;
189 
190 
191  // Outputs from local algorithm processing in C
192  struct sim_t {
193  // output from stage_1; emulation
194  struct {
195  link_t s1_to_s2 ;
196 
197  } s1[NS_COU][ADC_DET_COU][DEP_COU] ;
198 
199  //output from stage_2 emulation ;
200  struct {
201  link_t s2_to_s3[2] ;
202 
203  u_short s2_to_dsm ; // new in FY22
204 
205  } s2[NS_COU] ;
206 
207  // output from stage_3 emulation
208  struct {
209  u_short dsm_out ;
210  } s3 ;
211 
212  } d_out ;
213 
214  // if there's any output to DSM
215  int trg_xing ; // normally 5
216  u_short s3_to_dsm ;
217  u_short s2_to_dsm[2] ; // North/South
218 
219  // statics below
220  static u_int data_format ; // 0:pre FY21, 1=FY21
221 
222 
223  // Stage versions for this invocation
224  static u_int stage_version[4] ;
225 
226 
227 
228  // event markers; defaults set in init(), normally
229  static struct marker_t {
230  int last_xing ; // last valid xing
231 
232  // used in DEP/ADC
233  int adc_start ;
234  int s1_out_start ;
235 
236  // used in stage_2 DEP/Trg
237  int s2_in_start ;
238  int s2_to_s3_start ;
239 
240 
241  // used in stage_3 DEP/Trg
242  int s3_in_start ;
243  int dsm_out_start ;
244 
245  } marker ;
246 
247  static int fcs_trgDebug ;
248 
249  static int run_type ;
250 
251  // per event
252  u_int event_bad ;
253 
254  u_char s2_io_ns_bad ;
255  u_char s2_io_ch_bad ; //0.33
256 
257  u_char s3_io_ch_bad ; //0..3
258 
259  u_char s1_dep_bad ; //0..19
260  u_char s1_det_bad ; //0..2
261  u_char s1_ns_bad ;
262 
263  u_char s2_ns_bad ;
264  u_char s2_ch_bad ; //0..1
265 
266  // stage_x algo params (same as in firmware)
267  static u_short stage_params[4][32] ; // [stage][param_ix] ;
268 
269  // for use by stage_0; loaded in init()
270  static ped_gain_t p_g[NS_COU][ADC_DET_COU][DEP_COU][32] ;
271 
272 
273  // for use by stage_1:
274  // various thresholds indexed by det
275  static u_short ht_threshold[ADC_DET_COU] ;
276 
277 
278  // for use by stage_2:
279  static unsigned long long s2_ch_mask[NS_COU] ; // up to 34 bits
280  static u_char s2_ch_phase[NS_COU][34] ; // phase used to align data
281 
282  static int fcs_readPresMaskFromText;
283  static u_int PRES_MASK[15][9][6];
284 
285  // for use by stage_3
286  static u_char s3_ch_mask ; // if '1' corresponding input masked
287  static u_char s3_ch_phase[4] ; // phasing of the 4 inputs
288  static u_char s3_out_phase ; // phasing of the 1 output to Trigger
289 
290  // various thresholds
291  static u_short EM_HERATIO_THR ;
292  static u_short HAD_HERATIO_THR ;
293  static u_short EMTHR0 ;
294  static u_short EMTHR1 ;
295  static u_short EMTHR2 ;
296  static u_short EMTHR3 ; //obsolete for 202207
297  static u_short ELETHR0 ;
298  static u_short ELETHR1 ;
299  static u_short ELETHR2 ;
300  static u_short HADTHR0 ;
301  static u_short HADTHR1 ;
302  static u_short HADTHR2 ;
303  static u_short HADTHR3 ; //obsolete for 202207
304  static u_short JETTHR1 ; //obsolete for 202207
305  static u_short JETTHR2 ; //obsolete for 202207
306  static u_short JPATHR2 ;
307  static u_short JPATHR1 ;
308  static u_short JPATHR0 ;
309  static u_short JPBCTHR2 ;
310  static u_short JPBCTHR1 ;
311  static u_short JPBCTHR0 ;
312  static u_short JPBCTHRD ;
313  static u_short JPDETHR2 ;
314  static u_short JPDETHR1 ;
315  static u_short JPDETHR0 ;
316  static u_short JPDETHRD ;
317  static u_short ETOTTHR ;
318  static u_short HTOTTHR ;
319  static u_short EHTTHR ;
320  static u_short HHTTHR ;
321  static u_short PHTTHR ;
322 
323  // Ecal and Hcal 4x4 sums, Ecal+nearest Hcal sum, and Pres(EPD) hit pattern at stage2
324  u_int e2x2[2][16][10];
325  u_int h2x2[2][10][6];
326  u_int esum[2][15][9];
327  u_int epdcoin[2][15][9];
328  u_int hsum[2][9][5];
329  u_int padc[2][6][32];
330  u_int phit[2][6][32];
331  u_int sum [2][15][9];
332  u_int summax[2][15][9];
333  float ratio[2][15][9];
334  float ratiomax[2][15][9];
335  u_int em[2][15][9];
336  u_int had[2][15][9];
337  u_int jet[2][6];
338  u_int etot[2];
339  u_int htot[2];
340  u_int dsmout;
341 };
342 
343 #endif