StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
tpc_rerun.C
1 /*
2  The example shows how to rerun the cluster finder
3  on the TPX (or TPC) cluster data...
4 */
5 
6 
7 #include <stdio.h>
8 #include <sys/types.h>
9 
10 #include <rtsLog.h>
11 #include <DAQ_READER/daqReader.h>
12 #include <DAQ_READER/daq_dta.h>
13 #include <DAQ_TPX/daq_tpx.h>
14 #include <DAQ_TPX/tpxGain.h>
15 
16 
17 int main(int argc, char *argv[])
18 {
19  rtsLogOutput(RTS_LOG_STDERR) ;
20 // rtsLogLevel(NOTE) ;
21 
22  daqReader *dr = new daqReader(argv[1]) ; // open file
23 
24  // need this specific construct so that the cluster finder can initialized!
25  daq_tpx *tpx = new daq_tpx(dr) ; // insert the TPX detector explicitly in the DAQ_READER
26  // set compatibility flsgs
27  tpx->fcf_run_compatibility = 10 ;
28  tpx->fcf_do_cuts = 1 ;
29 
30  // we'll skip this so that we can load our own gaons
31 // tpx->InitRun(123) ; // initialize the run with some dummy run number...
32 
33  // load our own gain file here
34  tpx->gain_algo->from_file((char *)"tpx_gains.txt.20191216.060513",0) ;
35 
36  while(dr->get(0,0)) { // zip through the input files...
37 
38 
39  int got_adc_data = 0 ;
40  daq_dta *dd, *sim_dta ;
41 
42 #define DUMP_CLD_IN_FILE
43 #ifdef DUMP_CLD_IN_FILE
44  // if you care, you can dump the in-file clusters here
45  dd = dr->det("tpx")->get("cld") ;
46  while(dd && dd->iterate()) {
47  for(u_int i=0;i<dd->ncontent;i++) {
48 
49 // Here we can blow off clusters we don't care about
50 // switch(dd->cld[i].flags) {
51 // case 0 : // normal
52 // case 1 : // normal
53 // case 2 : // normal
54 // case 3 : // should not really use
55 // continue ;
56 // default :
57 // break ;
58 // }
59 
60  printf("in file: row %2d: pad %f [%d:%d], tb %f [%d:%d], charge %d, flags 0x%X\n",dd->row,
61  dd->cld[i].pad,
62  dd->cld[i].p1,
63  dd->cld[i].p2,
64  dd->cld[i].tb,
65  dd->cld[i].t1,
66  dd->cld[i].t2,
67  dd->cld[i].charge,
68  dd->cld[i].flags) ;
69 
70  }
71 
72 
73 
74  }
75 
76 #endif
77 
78 #define DO_CLD
79 #ifdef DO_CLD
80  dd = dr->det("tpx")->get("adc") ; // get the ADC data
81  if(dd == 0) {
82  LOG(WARN,"No adc data in this event...") ;
83  continue ; // not there, skip...
84  }
85 
86 
87  sim_dta = dr->det("tpx")->put("adc_sim") ; // create the ADC data for simulation
88 
89 
90  // read input data and fill in the adc_sim
91  while(dd->iterate()) {
92  got_adc_data = 1 ;
93  daq_sim_adc_tb *sim_d = (daq_sim_adc_tb *) sim_dta->request(512) ; // ask for space
94 
95  // copy over
96  for(u_int i=0;i<dd->ncontent;i++) {
97  sim_d[i].adc = dd->adc[i].adc ;
98  sim_d[i].tb = dd->adc[i].tb ;
99  sim_d[i].track_id = 0xFFFF ; // should be 0xFFFF if you don;t have tracking...
100  }
101 
102  // wrap up this pad with the correct length & coordinates
103  sim_dta->finalize(dd->ncontent,dd->sec,dd->row,dd->pad) ;
104 
105  }
106 
107  if(!got_adc_data) {
108  LOG(WARN,"No ADC data in this event...") ;
109  continue ;
110  }
111  LOG(NOTE,"Doing adc data...") ;
112 
113  // OK, now we have the ADC data ready for re-clusterfinding so let's do it
114 
115 
116  dd = dr->det("tpx")->get("cld_sim") ; // this will rerun the cluster finder on the "adc_sim" data
117  if(dd == 0) continue ; // error
118 
119  // dump the newly found data out...
120  while(dd->iterate()) {
121  //printf("sec %2d, row %3d: %d clusters\n",dd->sec,dd->row,dd->ncontent) ;
122 
123  for(u_int i=0;i<dd->ncontent;i++) {
124 #if 0
125  u_short tid = dd->sim_cld[i].track_id ;
126 
127  daq_dta *dta = dr->det("tpx")->get("adc_sim") ;
128  while(dta && dta->iterate()) {
129  daq_sim_adc_tb *sim_d = (daq_sim_adc_tb *) dta->Void ;
130 
131  for(int i=0;i<dta->ncontent;i++) {
132  if(sim_d[i].track_id == tid) {
133  printf("%5d %d %d %d %d\n",tid,dta->row,dta->pad,sim_d[i].tb,sim_d[i].adc) ;
134  }
135  }
136  }
137 #endif
138 
139 #if 1
140 // Here we can blow off clusters we don't care about
141 // if(dd->sim_cld[i].cld.flags != 0) continue ;
142 // if((dd->sim_cld[i].cld.p2 - dd->sim_cld[i].cld.p1) != 2) continue ;
143 // switch(dd->sim_cld[i].cld.flags) {
144 // case 0 :
145 // case 2 :
146 // continue ;
147 // default:
148 // break ;
149 // }
150 //
151 // if(dd->sim_cld[i].cld.tb < 15.0)
152  printf("rerun: row %2d: pad %f [%d:%d], tb %f [%d:%d], charge %d, flags 0x%X: track %d, Q %d\n",dd->row,
153  dd->sim_cld[i].cld.pad,
154  dd->sim_cld[i].cld.p1,
155  dd->sim_cld[i].cld.p2,
156  dd->sim_cld[i].cld.tb,
157  dd->sim_cld[i].cld.t1,
158  dd->sim_cld[i].cld.t2,
159  dd->sim_cld[i].cld.charge,
160  dd->sim_cld[i].cld.flags,
161  dd->sim_cld[i].track_id,
162  dd->sim_cld[i].quality) ;
163 #endif
164  }
165  }
166 
167 #endif
168 
169  } // end of ebent
170 
171  return 0 ;
172  }