Rev 291 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
291 | f9daq | 1 | #include "stdio.h" |
2 | #include "TROOT.h" |
||
3 | #include "TSystem.h" |
||
4 | #include "TFile.h" |
||
5 | #include "TH1F.h" |
||
6 | #include "TH2F.h" |
||
7 | #include "TF1.h" |
||
8 | #include "TMath.h" |
||
9 | #include "TStyle.h" |
||
10 | #include "TCanvas.h" |
||
11 | #include "TLine.h" |
||
12 | |||
13 | //kobayashi |
||
14 | #include "TTree.h" |
||
15 | |||
16 | //~ #define USE_ZLIB |
||
17 | #ifdef USE_ZLIB |
||
18 | # include "zlib.h" |
||
19 | #endif |
||
20 | // ------------------------------------------------------------------------------ |
||
21 | |||
22 | #define POSMARG 1000 |
||
23 | |||
24 | #define READBUFFERLENGTH 500000 |
||
25 | |||
26 | // data format |
||
27 | #define MAXDATA 64 |
||
28 | #define NCH 32 |
||
29 | #define ANALYSE_CH 32 |
||
30 | #define MPPC_1_CH 0 |
||
31 | #define MPPC_2_CH 1 |
||
32 | #define TRIGGER_CH 31 |
||
33 | //~ #define ANALYSE_CH 8 |
||
34 | //~ #define MPPC_1_CH 2 |
||
35 | //~ #define MPPC_2_CH 5 |
||
36 | #define REF_CH 0 |
||
37 | #define TDC_BIN (25./1000.) //1 TDC bin in ns |
||
38 | #define MIKRO_BIN 0.3595/1000. //1 mikro step in mm |
||
39 | |||
40 | #define RUNREC_ID 1 |
||
41 | #define ENDREC_ID 2 |
||
42 | #define POSREC_ID 3 |
||
43 | #define EVTREC_ID 4 |
||
44 | |||
45 | //define testpulse |
||
46 | typedef struct { |
||
47 | unsigned long id,len; |
||
48 | unsigned long fver,time; |
||
49 | unsigned long nev,nch,ped,xy; |
||
50 | long nx,x0,dx,ny,y0,dy; |
||
51 | } RUNREC; |
||
52 | RUNREC *runrec; |
||
53 | RUNREC run; |
||
54 | |||
55 | typedef struct { |
||
56 | unsigned long id,len; |
||
57 | unsigned long time; |
||
58 | } ENDREC; |
||
59 | ENDREC *endrec; |
||
60 | |||
61 | typedef struct { |
||
62 | unsigned long id,len; |
||
63 | unsigned long time; |
||
64 | long ix,x,xset,iy,y,yset; |
||
65 | } POSREC; |
||
66 | POSREC *posrec; |
||
67 | POSREC pos; |
||
68 | |||
69 | typedef struct { |
||
70 | unsigned long id,len; |
||
71 | unsigned long nev; |
||
72 | unsigned short data[MAXDATA]; |
||
73 | } EVTREC; |
||
74 | EVTREC *evtrec; |
||
75 | |||
76 | // ------------------------------------------------------------------------------ |
||
77 | |||
78 | int d2r(char* dfile0="test", double qdcmi=0, double qdcma=4096, double tdcmi=-1.5, double tdcma=3, double adc_cor_min=200.0, double deltaT_ctdcdiff=0) |
||
79 | { |
||
80 | int dbg=0; |
||
81 | printf(" dat 2 root conversion program\nUsage:\nd2r(input file -.dat, TDC min [ps], TDC max [ps], QDC min, QDC max)\n\n"); |
||
82 | |||
83 | char fullname[256], sbuff[256]; |
||
84 | FILE *fp; |
||
85 | |||
86 | //Chanel information |
||
87 | //~ int chmapx[NCH]={7,6,5,4,3,2,1,0}; |
||
88 | //~ int chmapx[NCH]={ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19}; |
||
89 | int chmapx[NCH]; for(int i=0; i<NCH; i++) {chmapx[i]=i;}; |
||
90 | |||
91 | //~ double padcenter[NCH][2]={ {201000, 210000}, |
||
92 | //~ {183000, 210000}, |
||
93 | //~ {165000, 210000}, |
||
94 | //~ {147000, 210000}, |
||
95 | //~ {129000, 210000}, |
||
96 | //~ {111000, 210000}, |
||
97 | //~ { 93000, 210000}, |
||
98 | //~ { 75000, 210000} }; |
||
99 | //~ // double tdcoffset[NCH]={57.78, 57.28, 57.86, 57.64, 56.06, 56.46, 57.5, 57.41}; |
||
100 | //~ double tdcoffset[NCH]={2311*TDC_BIN, 2291*TDC_BIN, 2314*TDC_BIN, 2306*TDC_BIN, |
||
101 | //~ 2242*TDC_BIN, 2258*TDC_BIN, 2300*TDC_BIN, 2296*TDC_BIN}; |
||
102 | double padcenter[NCH][2]; for(int i=0; i<NCH; i++) {padcenter[i][0]=0; padcenter[i][1]=0;}; |
||
103 | double tdcoffset[NCH]; for(int i=0; i<NCH; i++) {tdcoffset[i]=0;}; |
||
104 | sprintf(fullname, "d2r.ini"); |
||
105 | if( (fp=fopen(fullname, "rt")) == NULL ) |
||
106 | printf("Cannot open pad centers file %s !!!\n", fullname); |
||
107 | else { |
||
108 | printf("Opened pad centers file %s\n", fullname); |
||
109 | fgets(sbuff,256, fp);printf("%s", sbuff); |
||
110 | for(int i=0; i<NCH; i++) |
||
111 | fscanf(fp, "%lf %lf %lf\n", &padcenter[i][0], &padcenter[i][1], &tdcoffset[i]); |
||
112 | fclose(fp); |
||
113 | } |
||
114 | for(int i=0; i<NCH; i++) printf("%.2lf %.2lf %.2lf\n", padcenter[i][0], padcenter[i][1], tdcoffset[i]); |
||
115 | |||
116 | //TDC correction parameters |
||
117 | //~ double corpar[NCH][3]={ {-0.8, 25, 0}, |
||
118 | //~ {-0.8, 25, 0}, |
||
119 | //~ {-0.8, 25, 0}, |
||
120 | //~ {-0.8, 25, 0}, |
||
121 | //~ {-0.8, 25, 0}, |
||
122 | //~ {-0.8, 25, 0}, |
||
123 | //~ {-0.8, 25, 0}, |
||
124 | //~ {-0.8, 25, 0} }; |
||
125 | double corpar[NCH][3]; for(int i=0; i<NCH; i++) {corpar[i][0]=0.0; corpar[i][1]=0.005; corpar[i][2]=0.0;}; |
||
126 | sprintf(fullname, "data/%s_cor.txt", dfile0); |
||
127 | if( (fp=fopen(fullname, "rt")) == NULL ) |
||
128 | printf("Cannot open parameter file %s !!!\n", fullname); |
||
129 | else { |
||
130 | printf("Opened parameter file %s\n", fullname); |
||
131 | for(int i=0; i<NCH; i++) { |
||
132 | fscanf(fp, "%lf %lf %lf\n", &corpar[i][0], &corpar[i][1], &corpar[i][2]); |
||
133 | /*// check if parameters make sense |
||
134 | if( (corpar[i][0] < (tdcmi-0.2*tdcmi)) || ((tdcma+0.2*tdcma) < corpar[i][0]) || |
||
135 | (corpar[i][1] < 0) || (1e4*TDC_BIN < corpar[i][1]) || |
||
136 | (1e4 < TMath::Abs(corpar[i][2])) ) { |
||
137 | printf("Warning: parameters for ch%d out of limits -> using default!\n", i); |
||
138 | corpar[i][0]=2200*TDC_BIN; corpar[i][1]=1000*TDC_BIN; corpar[i][2]=-100*TDC_BIN; |
||
139 | }*/ |
||
140 | } |
||
141 | fclose(fp); |
||
142 | } |
||
143 | for(int i=0; i<NCH; i++) printf("%.2lf %.2lf %.2lf\n", corpar[i][0], corpar[i][1], corpar[i][2]); |
||
144 | |||
145 | |||
146 | //histograms |
||
147 | char hname[256], htitle[256]; |
||
148 | double adc,tdc; |
||
299 | f9daq | 149 | TH1F *hadc[NCH], *hadc_cut[NCH]; |
150 | TH1F *htdc[NCH], *htdc_cut[NCH], *hctdc[NCH]; |
||
151 | TH2F *hcor[NCH]; |
||
152 | TH1F *htdcdiff, *htdcdiff_cut; |
||
291 | f9daq | 153 | |
154 | double ref_cut_1_lo = qdcmi; |
||
155 | double ref_cut_1_hi = qdcma; |
||
156 | double ref_cut_2_lo = tdcmi; |
||
157 | double ref_cut_2_hi = tdcma; |
||
158 | |||
159 | //data buffer |
||
160 | char readbuf[READBUFFERLENGTH]; |
||
161 | runrec = (RUNREC *) readbuf; |
||
162 | endrec = (ENDREC *) readbuf; |
||
163 | posrec = (POSREC *) readbuf; |
||
164 | evtrec = (EVTREC *) readbuf; |
||
165 | |||
166 | //data file |
||
167 | #ifdef USE_ZLIB |
||
168 | gzFile dfp; |
||
169 | #else |
||
170 | FILE *dfp; |
||
171 | #endif |
||
172 | char dfile[256]; |
||
173 | int ftype=0, fcount=1; |
||
174 | do { |
||
175 | switch(ftype++) { |
||
176 | case 0: |
||
177 | sprintf(dfile, "data/%s_file%02d.dat", dfile0, fcount); |
||
178 | break; |
||
179 | case 1: |
||
180 | sprintf(dfile, "data/%s_file%02d.dat.gz", dfile0, fcount); |
||
181 | break; |
||
182 | case 2: |
||
183 | sprintf(dfile, "data/%s_file%02d.gz", dfile0, fcount); |
||
184 | break; |
||
185 | default: |
||
186 | printf(" Cannot find data file for %s !!!\n", dfile0); |
||
187 | return -1; |
||
188 | } |
||
189 | #ifdef USE_ZLIB |
||
190 | dfp=gzopen(dfile,"rb"); |
||
191 | #else |
||
192 | dfp=fopen(dfile,"rb"); |
||
193 | #endif |
||
194 | |||
195 | } while(!dfp); |
||
196 | printf("Opened data file %s\n", dfile); |
||
197 | |||
198 | //opens ROOT file |
||
199 | TFile *rootfile; char fnameroot[256]; |
||
200 | sprintf(fnameroot, "root/%s.root", dfile0); |
||
201 | //rootfile = (TFile *) gROOT->FindObjectAny(dfile0); |
||
202 | //if (rootfile!=NULL) {printf("!!!\n");rootfile->Close();} |
||
203 | //rootfile = new TFile(fnameroot); |
||
204 | //if(rootfile) rootfile->Close(); |
||
205 | rootfile = new TFile(fnameroot,"RECREATE",dfile0); |
||
206 | |||
207 | // ----------------------------------------------- |
||
208 | // loop trough records |
||
209 | UInt_t rec_id, rec_len; |
||
210 | unsigned ulsize = 4; |
||
211 | int ceve=0; |
||
212 | int end_of_file = 0; |
||
213 | |||
214 | while(1) { |
||
215 | #ifdef USE_ZLIB |
||
216 | if(gzeof(dfp)) end_of_file = 1; |
||
217 | #else |
||
218 | if(feof(dfp)) end_of_file = 1; |
||
219 | #endif |
||
220 | |||
221 | #ifdef USE_ZLIB |
||
222 | gzread(dfp, (voidp)&readbuf, 2*ulsize); |
||
223 | #else |
||
224 | fread( (void*)&readbuf, 2*ulsize, 1, dfp); |
||
225 | |||
226 | #endif |
||
227 | rec_id=readbuf[0]; |
||
228 | rec_len=readbuf[ulsize]; |
||
229 | //kobayashi |
||
230 | if(rec_id == 4) rec_len = 140; |
||
231 | |||
232 | //~ if(dbg) printf("-----------------------------------------------\n"); |
||
233 | //~ if(dbg) printf("[%d] rec_id = %d | rec_len = %d\n", ceve, rec_id, rec_len); |
||
234 | |||
235 | //printf("[%d] rec_id = %d | rec_len = %u\n", ceve, readbuf[0], readbuf[ulsize]); |
||
236 | switch(rec_id) |
||
237 | { |
||
238 | |||
239 | case RUNREC_ID: |
||
240 | #ifdef USE_ZLIB |
||
241 | gzread(dfp, (voidp)&readbuf[2*ulsize], (rec_len-2*ulsize)); |
||
242 | #else |
||
243 | fread( (void*)&readbuf[2*ulsize], (rec_len-2*ulsize), 1, dfp); |
||
244 | #endif |
||
245 | run=*runrec; |
||
246 | |||
247 | if(dbg) { |
||
248 | printf("RUNREC_ID\n"); |
||
249 | printf("id = %d, len = %d, time = %d\n", run.id, run.len, run.time); |
||
250 | printf("nev = %d, nch = %d\n", run.nev, run.nch); |
||
251 | printf("nx = %d, x0 = %d, dx = %d\n", run.nx, run.x0, run.dx); |
||
252 | printf("ny = %d, y0 = %d, dy = %d\n", run.ny, run.y0, run.dy); |
||
253 | |||
254 | //~ break; |
||
255 | } |
||
256 | |||
257 | //create histograms |
||
299 | f9daq | 258 | for(int i=0; i<ANALYSE_CH; i++) { |
291 | f9daq | 259 | sprintf(hname, "hadc%d", i); |
260 | hadc[i] = (TH1F*)gROOT->FindObject(hname); |
||
261 | if(hadc[i]) delete hadc[i]; |
||
262 | hadc[i] = new TH1F(hname, hname, 4096, -0.5, 4095.5); |
||
263 | |||
264 | sprintf(hname, "hadc_cut%d", i); |
||
265 | hadc_cut[i] = (TH1F*)gROOT->FindObject(hname); |
||
266 | if(hadc_cut[i]) delete hadc_cut[i]; |
||
267 | hadc_cut[i] = new TH1F(hname, hname, 4096, -0.5, 4095.5); |
||
268 | |||
269 | sprintf(hname, "htdc%d", i); |
||
270 | htdc[i] = (TH1F*)gROOT->FindObject(hname); |
||
271 | if(htdc[i]) delete htdc[i]; |
||
272 | htdc[i] = new TH1F(hname, hname, 65536, -32768.5*TDC_BIN, 32767.5*TDC_BIN); |
||
273 | //~ htdc[i] = new TH1F(hname, hname, 65536, -0.5*TDC_BIN, 65535.5*TDC_BIN); |
||
274 | |||
275 | sprintf(hname, "htdc_cut%d", i); |
||
276 | htdc_cut[i] = (TH1F*)gROOT->FindObject(hname); |
||
277 | if(htdc_cut[i]) delete htdc_cut[i]; |
||
299 | f9daq | 278 | htdc_cut[i] = new TH1F(hname, hname, 65536, -32768.5*TDC_BIN, 32767.5*TDC_BIN); |
279 | //~ htdc_cut[i] = new TH1F(hname, hname, 65536, -0.5*TDC_BIN, 65535.5*TDC_BIN); |
||
291 | f9daq | 280 | |
281 | sprintf(hname, "hctdc%d", i); |
||
282 | hctdc[i] = (TH1F*)gROOT->FindObject(hname); |
||
283 | if(hctdc[i]) delete hctdc[i]; |
||
284 | hctdc[i] = new TH1F(hname, hname, 65536, -32768.5*TDC_BIN, 32767.5*TDC_BIN); |
||
299 | f9daq | 285 | //~ hctdc[i] = new TH1F(hname, hname, 65536, -0.5*TDC_BIN, 65535.5*TDC_BIN); |
291 | f9daq | 286 | |
287 | sprintf(hname, "hcor%d", i); |
||
288 | hcor[i] = (TH2F*)gROOT->FindObject(hname); |
||
289 | if(hcor[i]) delete hcor[i]; |
||
299 | f9daq | 290 | //~ hcor[i] = new TH2F(hname, hname, 512, 0-0.5, 1024-0.5, 160, -1.5-(TDC_BIN/2), 2.5-(TDC_BIN/2)); |
291 | hcor[i] = new TH2F(hname, hname, 512, 0-0.5, 4096-0.5, (100/TDC_BIN)/8, -50-(TDC_BIN/2), 50-(TDC_BIN/2)); |
||
292 | //~ hcor[i] = new TH2F(hname, hname, 512, 0-0.5, 4096-0.5, 256, -32768.5*TDC_BIN, 32767.5*TDC_BIN); |
||
293 | //~ hcor[i] = new TH2F(hname, hname, 512, 0-0.5, 4096-0.5, 256, -0.5*TDC_BIN, 65535.5*TDC_BIN); |
||
291 | f9daq | 294 | } |
299 | f9daq | 295 | |
296 | sprintf(hname, "htdcdiff"); |
||
297 | htdcdiff = (TH1F*)gROOT->FindObject(hname); |
||
298 | if(htdcdiff) delete htdcdiff; |
||
299 | htdcdiff = new TH1F(hname, hname, 4096, -2048.5*TDC_BIN, 2047.5*TDC_BIN); |
||
291 | f9daq | 300 | |
299 | f9daq | 301 | sprintf(hname, "htdcdiff_cut"); |
302 | htdcdiff_cut = (TH1F*)gROOT->FindObject(hname); |
||
303 | if(htdcdiff_cut) delete htdcdiff_cut; |
||
304 | htdcdiff_cut = new TH1F(hname, hname, 4096, -2048.5*TDC_BIN, 2047.5*TDC_BIN); |
||
305 | |||
306 | |||
291 | f9daq | 307 | break; |
308 | |||
309 | case POSREC_ID: |
||
310 | #ifdef USE_ZLIB |
||
311 | gzread(dfp, (voidp)&readbuf[2*ulsize], (rec_len-2*ulsize)); |
||
312 | #else |
||
313 | fread( (void*)&readbuf[2*ulsize], (rec_len-2*ulsize), 1, dfp); |
||
314 | #endif |
||
315 | |||
316 | pos=*posrec; |
||
317 | |||
318 | if(dbg) { |
||
319 | printf("POSREC_ID\n"); |
||
320 | printf("id = %d, len = %d, time = %d\n", posrec->id, posrec->len, posrec->time); |
||
321 | printf("ix = %d, x = %d, xset = %d\n", posrec->ix, posrec->x, posrec->xset); |
||
322 | printf("iy = %d, y = %d, yset = %d\n", posrec->iy, posrec->y, posrec->yset); |
||
323 | } else printf(" [%d,%d] %d, %d\n", pos.ix, pos.iy, pos.xset, pos.yset); |
||
324 | |||
325 | break; |
||
326 | |||
327 | case EVTREC_ID: |
||
328 | #ifdef USE_ZLIB |
||
329 | gzread(dfp, (voidp)&readbuf[2*ulsize], (rec_len-2*ulsize)); |
||
330 | #else |
||
331 | fread( (void*)&readbuf[2*ulsize], (rec_len-2*ulsize), 1, dfp); |
||
332 | #endif |
||
333 | |||
334 | |||
335 | if(dbg) { |
||
336 | //~ printf("EVTREC_ID\n"); |
||
337 | //~ printf("id = %d, len = %d, nev = %d\n", evtrec->id, evtrec->len, evtrec->nev); |
||
338 | //for(int datai = 0; datai < NCH; datai++) printf("%u ", evtrec->data[datai]); |
||
339 | //printf("\n"); |
||
340 | //for(int datai = NCH; datai < NCH+NCH; datai++) printf("%u ", evtrec->data[datai]); |
||
341 | //printf("\n"); |
||
342 | //break; |
||
343 | } |
||
344 | // events ------------------------------------------------------------------------------------------ |
||
345 | // fill histograms |
||
346 | |||
347 | double tdc_noise_cut; |
||
348 | //~ double adc_cor_min; |
||
349 | double tdca[ANALYSE_CH]; |
||
350 | double ctdca[ANALYSE_CH]; |
||
351 | double adca[ANALYSE_CH]; |
||
352 | double ctdcdiff, tdcdiff; |
||
353 | |||
354 | |||
355 | tdc_noise_cut = 5.0; |
||
356 | //~ adc_cor_min = 200.0; |
||
357 | |||
358 | for(int i=0; i<ANALYSE_CH; i++) { |
||
359 | tdc=((double)evtrec->data[i])*TDC_BIN + tdcoffset[i]; |
||
360 | |||
361 | adc=(double)evtrec->data[i+NCH]; |
||
362 | tdca[i]=tdc; |
||
363 | adca[i]=adc; |
||
364 | } |
||
365 | for(int i=0; i<ANALYSE_CH; i++) { |
||
299 | f9daq | 366 | //~ if(0 < adca[i]) |
367 | hadc[i]->Fill(adca[i]); |
||
291 | f9daq | 368 | //~ if( (qdcmi < adca[i]) && (adca[i] < qdcma) ) |
299 | f9daq | 369 | //~ if(0 < tdca[i]) htdc[i]->Fill(tdca[i]-tdca[TRIGGER_CH]); |
370 | //~ if(0 < tdca[i]) |
||
371 | htdc[i]->Fill(tdca[i]-tdca[TRIGGER_CH]); |
||
372 | //~ hcor[i]->Fill(adca[i],tdca[i]); |
||
373 | hcor[i]->Fill(adca[i],tdca[i]-tdca[TRIGGER_CH]); |
||
291 | f9daq | 374 | |
375 | if(adca[i] > corpar[i][2]) { |
||
376 | ctdca[i] = tdca[i]-tdca[TRIGGER_CH] - (corpar[i][0] + corpar[i][1]/TMath::Sqrt(adca[i] - corpar[i][2])); |
||
377 | } else { |
||
378 | ctdca[i] = -999.9*(i+1); |
||
379 | } |
||
380 | //~ if(tdc_noise_cut < tdca[i]) |
||
299 | f9daq | 381 | //~ double adc_max_cut = 1000; |
382 | //~ if(adca[i] < adc_max_cut) |
||
291 | f9daq | 383 | hctdc[i]->Fill( ctdca[i] ); |
384 | |||
385 | //~ if(dbg && (i<4) && (1 < tdca[0] && (1 < tdca[1]))) printf("tdca[%d] = %lf | tdca[TRG] = %lf | ctdca[i] = %lf | adca[i] = %lf\n", i, tdca[i],tdca[TRIGGER_CH],ctdca[i],adca[i]); |
||
386 | if(dbg && (i<4) ) printf("[%4d] tdca[%d] = %lf | tdca[TRG] = %lf | ctdca[i] = %lf | adca[i] = %lf\n", ceve, i, tdca[i],tdca[TRIGGER_CH],ctdca[i],adca[i]); |
||
387 | } |
||
388 | |||
389 | |||
390 | //cut za timing: |
||
391 | #define CUT_1_CONDITION ( (qdcmi < adca[MPPC_1_CH]) && (adca[MPPC_1_CH] < qdcma) && (tdcmi < adca[MPPC_2_CH]) && (adca[MPPC_2_CH] < tdcma) ) |
||
392 | //~ // cut za meritev efficiency: |
||
393 | //~ #define CUT_1_CONDITION ( (qdcmi < adca[MPPC_1_CH]) && (adca[MPPC_1_CH] < qdcma) ) |
||
394 | |||
395 | //~ #define CUT_1_CONDITION ( (tdcmi < ctdcdiff) && (ctdcdiff < tdcma) ) |
||
396 | //~ #define CUT_1_CONDITION ( (ref_cut_1_lo < adca[MPPC_1_CH]) && (adca[MPPC_1_CH] < ref_cut_1_hi) ) |
||
397 | //~ #define CUT_1_CONDITION ( (qdcmi < tdca[MPPC_1_CH]) && (tdca[MPPC_1_CH] < qdcma) ) |
||
398 | //~ #define CUT_1_CONDITION ( (ref_cut_1_lo < adca[REF_CH]) && (adca[REF_CH] < ref_cut_1_hi) && (ref_cut_1_lo < adca[MPPC_1_CH]) && (adca[MPPC_1_CH] < ref_cut_1_hi) ) |
||
399 | |||
400 | |||
401 | // cut za meritev efficiency: |
||
402 | #define CUT_2_CONDITION ( (tdcmi < adca[REF_CH]) && (adca[REF_CH] < tdcma) ) |
||
403 | //~ #define CUT_2_CONDITION ( (qdcmi < adca[MPPC_1_CH]) && (adca[MPPC_1_CH] < qdcma) && (tdcmi < adca[REF_CH]) && (adca[REF_CH] < tdcma) ) |
||
404 | //~ #define CUT_2_CONDITION ( (ref_cut_1_lo < tdca[MPPC_1_CH]) && (tdca[MPPC_1_CH] < ref_cut_1_hi) ) |
||
405 | //~ #define CUT_2_CONDITION ( (qdcmi < adca[REF_CH]) && (adca[REF_CH] < qdcma) && (tdcmi < tdca[REF_CH]) && (tdca[REF_CH] < tdcma) ) |
||
406 | //~ #define CUT_2_CONDITION ( (ref_cut_1_lo < adca[MPPC_1_CH]) && (adca[MPPC_1_CH] < ref_cut_1_hi) && (ref_cut_2_lo < adca[MPPC_2_CH]) && (adca[MPPC_2_CH] < ref_cut_2_hi) ) |
||
407 | //~ #define CUT_2_CONDITION ( (ref_cut_2_lo < adca[REF_CH]) && (adca[REF_CH] < ref_cut_2_hi) ) |
||
408 | //~ #define CUT_2_CONDITION ( (ref_cut_1_lo < tdca[MPPC_1_CH]) && (tdca[MPPC_1_CH] < ref_cut_1_hi) && (ref_cut_2_lo < tdca[MPPC_2_CH]) && (tdca[MPPC_2_CH] < ref_cut_2_hi) ) |
||
409 | //~ #define CUT_2_CONDITION ( (ref_cut_2_lo < tdca[REF_CH]) && (tdca[REF_CH] < ref_cut_2_hi) && (ref_cut_2_lo < tdca[MPPC_1_CH]) && (tdca[MPPC_1_CH] < ref_cut_2_hi) ) |
||
410 | |||
411 | |||
412 | if( (tdc_noise_cut < tdca[MPPC_1_CH]) && (tdc_noise_cut < tdca[MPPC_2_CH])) { |
||
413 | //~ if( (qdcmi < adca[MPPC_1_CH]) && (tdcmi < adca[MPPC_2_CH]) ) |
||
414 | htdcdiff->Fill(ctdcdiff); |
||
415 | |||
416 | if( CUT_1_CONDITION ) { |
||
417 | htdcdiff_cut->Fill(ctdcdiff); |
||
418 | //~ htdcdiff_cut->Fill(tdcdiff); |
||
419 | } |
||
420 | } |
||
421 | |||
422 | for(int i=0; i<ANALYSE_CH; i++) { |
||
423 | |||
424 | //~ if( CUT_1_CONDITION ) { |
||
425 | //~ if( ( (qdcmi < adca[REF_CH]) && (adca[REF_CH] < qdcma) ) ) { |
||
426 | //~ if( ( (-2 < ctdca[0]) && (ctdca[0] < 2) ) ) { |
||
427 | //~ htdc_cut[i]->Fill(tdca[i]-tdca[31]); |
||
428 | //~ htdc_cut[i]->Fill(ctdca[i]); |
||
429 | //~ hadc_cut[i]->Fill(adca[i]); |
||
430 | //~ } |
||
431 | if( (qdcmi < adca[i]) && (adca[i] < qdcma) && (adca[i] > corpar[i][2]) ) |
||
432 | htdc_cut[i]->Fill(ctdca[i]); |
||
433 | if( (tdcmi < ctdca[i]) && (ctdca[i] < tdcma) ) |
||
299 | f9daq | 434 | hadc_cut[i]->Fill(adca[i]); |
291 | f9daq | 435 | } |
436 | |||
437 | // events ------------------------------------------------------------------------------------------ |
||
438 | |||
439 | break; |
||
440 | |||
441 | case ENDREC_ID: |
||
442 | #ifdef USE_ZLIB |
||
443 | gzread(dfp, (voidp)&readbuf[2*ulsize], (rec_len-2*ulsize)); |
||
444 | #else |
||
445 | fread( (void*)&readbuf[2*ulsize], (rec_len-2*ulsize), 1, dfp); |
||
446 | #endif |
||
447 | |||
448 | if(dbg) { |
||
449 | printf("ENDREC_ID\n"); |
||
450 | printf("id = %d, len = %d, time = %d\n", endrec->id, endrec->len, endrec->time); |
||
451 | } else printf(" ENDREC\n"); |
||
452 | |||
453 | fcount++; |
||
454 | switch(ftype-1) { |
||
455 | case 0: |
||
456 | sprintf(dfile, "data/%s_file%02d.dat", dfile0, fcount); |
||
457 | break; |
||
458 | case 1: |
||
459 | sprintf(dfile, "data/%s_file%02d.dat.gz", dfile0, fcount); |
||
460 | break; |
||
461 | case 2: |
||
462 | sprintf(dfile, "data/%s_file%02d.gz", dfile0, fcount); |
||
463 | break; |
||
464 | } |
||
465 | |||
466 | #ifdef USE_ZLIB |
||
467 | if(dfp) gzclose(dfp); |
||
468 | dfp=gzopen(dfile,"rb"); |
||
469 | #else |
||
470 | if(dfp) fclose(dfp); |
||
471 | dfp=fopen(dfile,"rb"); |
||
472 | #endif |
||
473 | |||
474 | if(!dfp) { |
||
475 | printf(" Cannot open data file: %s ---> Exiting\n", dfile); |
||
476 | end_of_file = 1; |
||
477 | } else { |
||
478 | printf(" Opened data file: %s\n", dfile); |
||
479 | end_of_file = 0; |
||
480 | } |
||
481 | |||
482 | break; |
||
483 | |||
484 | default: |
||
485 | printf("switch(rec_id): default !!!\n"); |
||
486 | end_of_file = 1; |
||
487 | break; |
||
488 | } |
||
489 | |||
490 | ceve++; |
||
491 | if( (ceve%50000) == 0) printf(" Current event = %d\n", ceve); |
||
492 | if(dbg) if( ceve>dbg ) break; |
||
493 | if(end_of_file) break; |
||
494 | } |
||
495 | |||
496 | |||
497 | #ifdef USE_ZLIB |
||
498 | if(dfp) gzclose(dfp); |
||
499 | #else |
||
500 | if(dfp) fclose(dfp); |
||
501 | #endif |
||
502 | |||
503 | if(dbg) return 1; |
||
504 | if(rootfile) { |
||
505 | rootfile->Write(); |
||
506 | //cout<<"maximum x value = " << htdcdiff->GetXaxis()->GetBinCenter( htdcdiff->GetMaximumBin()) <<endl; |
||
507 | printf("Saved to %s\n", fnameroot); |
||
508 | rootfile->Close(); |
||
509 | } |
||
510 | |||
511 | gSystem->Exit(1); |
||
512 | |||
513 | return 1; |
||
514 | } |