StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
stage_0_202109.cxx
1 #include <stdio.h>
2 #include "fcs_trg_base.h"
3 
4 
5 /*
6  Changed from 8-timebin sum to highest ADC + 1 closes timebin.
7 
8  Also added simple peak-finding -- the maximum of the data
9  can't be on timebin 0 or 7.
10 
11  202103 had a bug in the peak finder -- fixed in 202109
12 */
13 
14 
15 
16 void fcs_trg_base::stage_0_202109(adc_tick_t adc, geom_t geo, ped_gain_t *pg, u_int *dta_out)
17 {
18  int sum = 0 ;
19  int peak = 0 ;
20  int last = 0 ;
21 
22  for(int tb=0;tb<8;tb++) {
23  u_short radc = adc.d[tb] ;
24 
25  switch(tb) {
26  case 0 :
27  last = radc ;
28  sum = radc ;
29  peak = 0 ;
30  break ;
31  case 1 :
32  if(radc>sum) peak |= 1 ;
33  sum += radc ;
34  last = radc ;
35  break ;
36  case 2 :
37  sum += radc ;
38  last = radc ;
39  break ;
40  case 3 :
41  sum += radc ;
42  last = radc ;
43  break ;
44  case 4 :
45  sum += radc ;
46  last = radc ;
47  break ;
48  case 5 :
49  sum += radc ;
50  last = radc ;
51  break ;
52  case 6 :
53  sum += radc ;
54  last = radc ;
55  break ;
56  case 7 :
57  default :
58  //printf("radc %d, last %d, peak %d\n",radc,last,peak) ;
59 
60  if(radc>=last || peak==0) {
61  sum = 0 ;
62  }
63  else {
64  sum += radc ;
65 
66  sum -= pg?pg->ped:0 ; // ped is now only 3*ch_ped!
67  if(sum < 0) sum = 0 ;
68 
69  if(sum>0 && fcs_trgDebug>=2){
70  if(geo.det<2){
71  printf("ns=%1d det=%1d dep=%2d ch=%2d sum=%6d gain=%6d s*g=%6d pT=%6.3f\n",
72  geo.ns,geo.det,geo.dep,geo.ch,
73  sum,pg->gain,(sum*pg->gain)>>6,
74  0.00024711*((sum*pg->gain)>>6) );
75  }else{
76  printf("ns=%1d det=%1d dep=%2d ch=%2d sum=%6d gain=%6d s*g=%6d MIP=%5.3f\n",
77  geo.ns,geo.det,geo.dep,geo.ch,
78  sum,pg->gain,(sum*pg->gain)>>6,
79  float((sum*pg->gain)>>6)/100.0);
80  }
81  }
82 
83  sum *= pg?pg->gain:0x100 ; // note that in FY21+ gain==1.0 is 0x100
84  sum >>= 8 ; // see note above
85  }
86 
87  break ;
88  }
89  }
90 
91  //printf("... IN S0: %d\n",sum) ;
92 
93  *dta_out = sum ;
94 }