StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
tpxGain.h
1 #ifndef _TPX_GAIN_HH_
2 #define _TPX_GAIN_HH_
3 
4 #include <stdio.h>
5 
6 #include "tpxCore.h"
7 
8 // clock types aka frequencies
9 #define TPX_CLOCK_TCU_LOC 9215889 // exactly
10 #define TPX_CLOCK_TCU_RHIC 9381000 // typical value
11 #define TPX_CLOCK_TCD_OLD 9434800 // exactly; with the old, pre FY11, TCD
12 #define TPX_CLOCK_TCD 9370000 // exactly
13 #define TPX_CLOCK_NEW_TCD 9383000 // exactly
14 
15 // default is TCU local
16 #define TPX_TCU_LOC_PED_STOP 96
17 #define TPX_TCU_LOC_START 97
18 #define TPX_TCU_LOC_STOP 101
19 #define TPX_TCU_LOC_TIME_0 98.668442 // measured with run 10346005
20 
21 // in the (rare) case we are running with RHIC I use some average
22 // note that this is not well defined yet!
23 #define TPX_TCU_RHIC_PED_STOP 97
24 #define TPX_TCU_RHIC_START 98
25 #define TPX_TCU_RHIC_STOP 102
26 #define TPX_TCU_RHIC_TIME_0 99.0 // some number....
27 
28 // new, FY11, TCD
29 //#define TPX_TCD_PED_STOP 177
30 //#define TPX_TCD_START 179
31 //#define TPX_TCD_STOP 182
32 //#define TPX_TCD_TIME_0 182.175466 // measured around Dec 2010
33 
34 
35 // was in FY11
36 //#define TPX_TCD_PED_STOP 173
37 //#define TPX_TCD_START 174
38 //#define TPX_TCD_STOP 177
39 //#define TPX_TCD_TIME_0 176.6
40 
41 //FY12
42 //#define TPX_TCD_PED_STOP 173
43 //define TPX_TCD_START 174
44 //#define TPX_TCD_STOP 177
45 //#define TPX_TCD_TIME_0 175.667713
46 
47 //FY13-FY17, TCD
48 //#define TPX_TCD_PED_STOP 173
49 //#define TPX_TCD_START 177
50 //#define TPX_TCD_STOP 180
51 //#define TPX_TCD_TIME_0 178.679
52 
53 //FY18, TCD
54 //#define TPX_TCD_PED_STOP 174
55 //#define TPX_TCD_START 178
56 //#define TPX_TCD_STOP 181
57 //#define TPX_TCD_TIME_0 179.679
58 
59 //FY21, TCD, God damn Alexei and his constantly changing tb
60 #define TPX_TCD_PED_STOP 174
61 #define TPX_TCD_START 179
62 #define TPX_TCD_STOP 181
63 #define TPX_TCD_TIME_0 179.679
64 
65 //FY22, TCD, New frequency
66 #define TPX_NEW_TCD_PED_STOP 175
67 #define TPX_NEW_TCD_START 178
68 #define TPX_NEW_TCD_STOP 182
69 #define TPX_NEW_TCD_TIME_0 178.679
70 
71 
72 
73 /* FY10 and previous value.
74  In FY11 this will change due to:
75  - longer cable from the TCD to the distribution box
76  - new TCD
77 */
78 #define TPX_TCD_OLD_START 100
79 #define TPX_TCD_OLD_STOP 103
80 #define TPX_TCD_OLD_TIME_0 100.84 // or perhaps 100.90?
81 
82 
83 
84 // accepted region: start must be the lowest, stop must be the highest
85 
86 //FY11
87 //#define TPX_PULSER_PED_START 170
88 //#define TPX_PULSER_PED_STOP 186
89 
90 //FY12
91 #define TPX_PULSER_PED_START 166
92 #define TPX_PULSER_PED_STOP 182
93 
94 
95 class tpxGain
96 {
97 public:
98  tpxGain() ;
99  ~tpxGain() ;
100 
101  // this is not just gains but any kind of per-pad information
102  struct gains {
103  float g ;
104  float t0 ;
105  } ;
106 
107  // main storage area, malloc in "add_sector"
108  struct gains *gains[24] ; // pointers to sector contribs, [46][183]
109 
110  // MUST be called FIRST, unless the default of 45 is needed!!!!
111  void set_row_max(int max) {
112  row_max = max ;
113  }
114 
115  // MUST be called SECOND -- before any other operation!!!
116  void add_sector(int sec1) {
117  int min_s, max_s ;
118 
119 // int bytes = sizeof(struct gains) * (TPX_MAX_PAD+1) * (row_max+1) ;
120 
121  if(sec1 <= 0) {
122  min_s = 0 ;
123  max_s = 23 ;
124  }
125  else {
126  min_s = sec1 - 1 ;
127  max_s = min_s ;
128  }
129 
130  for(int s=min_s;s<=max_s;s++) {
131  if(gains[s]) {
132 // free(gains[s]) ;
133  }
134 
135 // gains[s] = (struct gains *) malloc(bytes) ;
136 
137  }
138  }
139 
140  void set_gains(int s, int r, int p, float g, float t0) {
141  struct gains *gs = get_gains(s,r,p) ;
142 
143  gs->g = g ;
144  gs->t0 = t0 ;
145  }
146 
147  struct gains *get_gains(int s, int r, int p) {
148  if(gains[s-1]==0) { // not applied yet!
149  return &dummy_gain ;
150  }
151 
152  return (gains[s-1] + r*TPX_MAX_PAD + (p-1)) ;
153  }
154 
155  int from_file(const char *fname, int sector = 0) ;
156 
157 
158  // [sector 1-24][RDO 1-6][fee-index 0-35]
159  u_int bad_fee[25][7][37] ; // [x][y][36] contains the count!
160 
161  // sector 1..24
162  u_int bad_rdo_mask[25] ; // bad if set to 1
163 
164  void if_file() ;
165 
166  char *raw_gains_fname ;
167 
168  // below used while calculating only
169  struct aux {
170  short low_pulse ; // count of low gain
171  short noise ; // count of noisy
172  short high_pulse ; // count of pulse to high
173  //short wrong_peak ; // hm?
174  short cou ; // count of good events
175  short need ; // count of expected events!
176  u_int adc_store[20] ;
177  } *aux ; // [24][46][TPX_MAX_PAD]
178 
179 
180  struct aux *get_aux(int s, int r, int p) {
181  return (aux + (s-1)*46*TPX_MAX_PAD + r*TPX_MAX_PAD + (p-1)) ;
182  } ;
183 
184  struct means {
185  double g ;
186  double t0 ;
187  double g_rms ;
188  double t0_rms ;
189 
190  } *means ; // [24][46]
191 
192  struct means *get_means(int s, int r) {
193  return (means + (s-1)*46 + r) ;
194  } ;
195 
196 
197  struct fee_found_t {
198  u_int got_one ;
199  int ch_count[256][16] ;
200  } *fee_found ;
201 
202  struct fee_found_t *get_fee_found(int s, int rdo) {
203  return (fee_found + (s-1)*7 + rdo) ;
204  }
205 
206 
207 
208  // below used only during calculation
209  int to_file(const char *fname) ;
210 
211  void init(int sec=0) ; // zap's structs; assume all TPX
212  void accum(char *evbuff, int bytes) ; // parses one RDO's worth of pulser data
213  void ev_done() ; // marks an event done...
214 
215  void calc() ; // calculates gains and bad pads
216 
217  void compare(char *fname, int mysec=0) ; // compares in memory image with a given file
218  int summarize(char *fname, FILE *log_file=0, int gain_mode=0) ; // prints a summary of bad channels to stdout
219 
220  void free_store() ;
221 
222  u_int c_date ; // date of file as YYYYMMDD
223  u_int c_time ; // time of file as HHMMSS
224  u_int c_run ; // run of file
225 
226  int pulser_ped ; // first timebin with ped=0
227  int pulser_ped_stop ; // last timebin for ped calc
228  int pulser_start ; // timebin with peak
229  int pulser_stop ; // last timebin which we use for the mean
230  double pulser_time_0 ;
231 
232  void set_clock_mode(int mode) ;
233 
234 private:
235  void do_default(int sector) ;
236 
237  time_t load_time ;
238 
239  int tpx_pulser_peak[25][46] ;
240 
241  int sector ;
242  int events ;
243  int tb_start, tb_stop ; // timebin window
244 
245  int clock_mode ;
246 
247  struct gains dummy_gain ;
248 
249 // struct tpx_odd_fee_t tpx_odd_fee[256] ;
250 // int tpx_odd_fee_count ;
251 
252  int row_max ;
253 
254  //int charge_peak ; // peak of the charge
255 } ;
256 
257 #endif