StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
tpxFCF.h
1 #ifndef _TPX_FCF_H_
2 #define _TPX_FCF_H_
3 
4 #include "tpxFCF_flags.h"
5 
6 // main tunable parameters
7 #define FCF_ADC_NOISE 4
8 #define FCF_ADC_MIN 4 // we additionally can kill 1d sequences where the maximum is below this
9 #define FCF_MIN_WIDTH 1
10 #define FCF_MIN_ADC_PAD_C 180
11 
12 
13 // timebins at which the gating grid opens & closes -- the gain is compromised if we cross them...
14 #define TPC_GG_OPEN 22
15 #define TPC_FF_CLOSE 380
16 
17 
18 #define FCF_MAX_CL 64 // max 1D clusters per pad
19 
20 // version/flavor reminders
21 #define FCF_V_FY08 0x0000 // used in the FY08 run; has the /32 "bug"
22 #define FCF_V_FY09 0x0001 // /32 bug fixed
23 
24 #define FCF_2D_V_FY13 0x1000 // first version of FCF_2D!
25 
26 
27 
28 //#define FCF_DEBUG
29 
30 #define FCF_DO_DOUBLE // timebins, pads, averages are double instead of u_int
31 //#define FCF_DO_INT // p1, t1 etc. are ints instead of shorts
32 
33 
34 #ifdef FCF_DO_DOUBLE
35  typedef float fcf_type;
36 #else
37  typedef int fcf_type;
38 #endif
39 
40 #ifdef FCF_DO_INT
41  typedef int fcf_short ;
42 #else
43  typedef short fcf_short ;
44 #endif
45 
46 
47 // forwad decls
48 class tpxGain ;
49 struct daq_cld ;
50 struct daq_sim_cld ;
51 struct daq_sim_adc_tb ;
52 
53 
54 struct tpxFCF_cl {
55  union {
56  unsigned int charge ;
57  fcf_type f_charge ;
58  } ;
59  union {
60  unsigned int t_ave ;
61  fcf_type f_t_ave ;
62  } ;
63 
64  fcf_type scharge ;
65  fcf_type p_ave ;
66 
67 
68  // extents
69  fcf_short t1, t_min ;
70  fcf_short t2, t_max ;
71 
72  fcf_short p1 ;
73  fcf_short p2 ;
74 
75  fcf_short flags ;
76  unsigned short track_id ;
77 
78  short quality ;
79  short sim_length ; // length of the corresponding sim data in *sim
80 
81  daq_sim_adc_tb *sim ; // for simulation, keep the pointer to the cluster data...
82 } ;
83 
84 
85 struct tpx_altro_struct ;
86 
87 class tpxFCF {
88 public:
89  tpxFCF() ;
90  ~tpxFCF() ;
91 
92  void config(unsigned int rb_mask, int modes=0, int rows=0, unsigned char *rowlen=0) ; // modes bitmask
93  int modes ; // bit mask: 1 run simulated; 2 run simulated with local id
94 
95  void apply_gains(int sector, tpxGain *gains) ;
96 
97  void start_evt() ;
98 
99  int do_pad(tpx_altro_struct *a, daq_sim_adc_tb *extra = 0) ;
100  int stage2(unsigned int *outbuff, int max_bytes) ;
101 
102 
103 
104  char do_cuts ;
105  char run_compatibility ;
106 
107  int ch_min ;
108 
109  static int fcf_decode(unsigned int *p_buff, daq_cld *dc, unsigned short version=0) ;
110  static int fcf_decode(unsigned int *p_buff, daq_sim_cld *sdc, unsigned short version=0) ;
111  static int afterburner(int cou, daq_cld *store[]) ;
112  static char *fcf_flags(u_char flags) ;
113 
114  // new functions for FY13 which assist in running FCF on any sector and rdo
115  void config2(int sec, int rdo, int modes=0, int rows=0, unsigned char *rowlen=0) ;
116  void apply_gains2(tpxGain *gains) ;
117  void start_evt2(int sec1, int rdo1) ;
118  void set_id(int id) {
119  my_id = id ;
120  }
121  int fcf_style ; // new for FY13!
122 
123 
124  const char *GetCVS() const { // Offline
125  static const char cvs[]="Tag $Name: $: $Id: tpxFCF.h,v 1.18 2016/01/12 16:20:23 tonko Exp $: built " __DATE__ " " __TIME__ ; return cvs;
126  }
127 
128  int sector ; // counts from 1
129  int rdo ; // counts from 1 but can be 0 if we want the whole sector
130  int row_count ; // will default to 45 in the constructor unless overriden!
131 
132  inline int is_pad_valid(int row, int pad)
133  {
134  s_static_storage *ss = get_static(row,pad) ;
135  if(ss==0) return 0 ;
136  if(ss->f & FCF_KILLED_PAD) return 0 ;
137  return 1 ;
138  }
139 
140  inline void event_debug()
141  {
142  for(int r=1;r<=row_count;r++) {
143  if(gain_storage[sector-1][r] == 0) continue ;
144 
145  for(int p=1;p<=tpx_rowlen[r];p++) {
146  s_static_storage *ss = get_static(r,p) ;
147 
148  stage1 *s1 = get_working(r,p) ;
149 
150  LOG(TERR,"S %2d: RP %d:%d : gain %f, t0 %f, flags 0x%X, count %d",sector,
151  r,p,ss->g,ss->t0,ss->f,s1->count) ;
152  }
153  }
154  }
155 
156 
157 protected:
158  unsigned char *tpx_rowlen ;
159 
160 
162  double g ;
163  double t0 ;
164 
165  unsigned short f ;
166  } ;
167 
168  static struct s_static_storage *gain_storage[24][256] ;
169 
170  inline struct s_static_storage *get_static(int row, int pad)
171  {
172  int s = sector -1 ;
173  if(gain_storage[s][row]==0) return 0 ;
174 
175  return gain_storage[s][row] + (pad-1) ;
176 
177  }
178 
179 
180 private:
181 
182  unsigned int *loc_buff ;
183  int cur_row ;
184  int cur_row_clusters ;
185 
186 
187 
188  int tpx_padplane ;
189 
190  int cl_marker ;
191 
192  struct stage1 { // per pad, indexed as (row,pad)
193  unsigned short count ; // count of 1D clusters found...
194  unsigned short f ; // initial flags: dead edge, broken RDO edge, etc.
195  double g ; // gain
196  double t0 ; // t0
197  struct tpxFCF_cl cl[FCF_MAX_CL] ;
198  } ;
199 
200 
201  struct stage1 *storage ; // where I will allocate storage
202 
203  void dump(tpxFCF_cl *cl, int row) ;
204 
205  inline struct stage1 *get_stage1(int row, int pad)
206  {
207  if(row_ix[row] < 0) return 0 ;
208 
209  return storage + row_ix[row] + (pad-1) ;
210 
211  }
212 
213 
214  int row_ix[256] ; // we exaggerate! normally was "46"
215 
216  unsigned int rbs ;
217  int my_id ;
218 
219 
220 // static const int max_tot_count = 1152 ; // maximum pads per RDO
221  static const int max_tot_count = 2000 ; // maximum pads per run really -- used in FY16
222 
223 
224 
225  struct stage1 *working_storage[24][256] ;
226 
227  inline struct stage1 *get_working(int row, int pad)
228  {
229 
230  int s = sector -1 ;
231 
232  if(working_storage[s][row]==0) {
233  int bytes = tpx_rowlen[row] * sizeof(stage1) ;
234 
235  working_storage[s][row] = (stage1 *) valloc(bytes) ;
236  }
237 
238  return working_storage[s][row] + (pad-1) ;
239  }
240 
241 
242 
243  unsigned int do_version ;
244  unsigned int read_version ;
245 } ;
246 
247 #endif
Definition: tpxFCF.h:87