Rev 90 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
29 | f9daq | 1 | ////////////////////////////////////////// |
2 | // Data to root conversion root script |
||
3 | // |
||
4 | // Contributors: Rok Pestotnik, Rok Dolenec, Dino Tahirovic |
||
5 | // |
||
6 | // 3/1/2014 TDC cut relative to tdc offset |
||
7 | // 22/3/2014 reverted to 2d scan (l2d.cpp) |
||
8 | |||
9 | #include "stdio.h" |
||
10 | #include "TROOT.h" |
||
11 | #include "TFile.h" |
||
12 | #include "TNtuple.h" |
||
13 | #include "TH1F.h" |
||
14 | #include "TH2F.h" |
||
15 | #include "TF1.h" |
||
16 | #include "TMath.h" |
||
17 | #include "TStyle.h" |
||
18 | #include "TCanvas.h" |
||
19 | #include "TLine.h" |
||
90 | f9daq | 20 | //#include "zlib.h" |
29 | f9daq | 21 | |
22 | // ------------------------------------------------------------------------------ |
||
23 | |||
24 | #define POSMARG 1000 |
||
25 | |||
26 | #define READBUFFERLENGTH 10000 |
||
27 | |||
28 | // data format |
||
29 | #define MAXDATA 16 |
||
30 | #define NCH 64 |
||
31 | #define TDC_BIN 1.0416 // 1 TDC bin in ns |
||
32 | #define MIKRO_BIN 0.49609/1000. //1 mikro step in mm; stage MM3MF |
||
90 | f9daq | 33 | #define OFFSETX 0 // Right edge of SiPM+Lightguide |
34 | #define OFFSETY 0 // Lower edge of SiPM+Lightguide |
||
29 | f9daq | 35 | |
36 | #define RUNREC_ID 1 |
||
37 | #define ENDREC_ID 2 |
||
38 | #define POSREC_ID 3 |
||
39 | #define EVTREC_ID 4 |
||
40 | #define THRREC_ID 5 |
||
41 | |||
42 | typedef struct { |
||
43 | unsigned int id,len; |
||
44 | unsigned int fver,time; |
||
45 | unsigned int nev,nch,ped,xy; |
||
46 | int nx,x0,dx,ny,y0,dy; |
||
47 | } RUNREC; |
||
48 | RUNREC *runrec; |
||
49 | RUNREC run; |
||
50 | |||
51 | typedef struct { |
||
52 | unsigned int id,len; |
||
53 | unsigned int time; |
||
54 | } ENDREC; |
||
55 | ENDREC *endrec; |
||
56 | |||
57 | typedef struct { |
||
58 | unsigned int id,len; |
||
59 | unsigned int time; |
||
60 | int ix; |
||
61 | int x; |
||
62 | int xset; |
||
63 | int iy; |
||
64 | int y; |
||
65 | int yset; |
||
66 | } POSREC; |
||
67 | POSREC *posrec; |
||
68 | POSREC pos; |
||
69 | |||
70 | typedef struct { |
||
71 | unsigned int id; |
||
72 | unsigned int len; |
||
73 | unsigned int nev; |
||
74 | } EVTREC; |
||
75 | EVTREC *evtrec; |
||
76 | |||
77 | typedef struct { |
||
78 | unsigned int id; |
||
79 | unsigned int len; |
||
80 | unsigned int threshold; |
||
81 | } THRREC; |
||
82 | THRREC *thrrec; |
||
83 | THRREC thr; |
||
84 | |||
85 | double padCenter[NCH][2]; |
||
86 | |||
91 | f9daq | 87 | int analysisScan(char* dfile0="test", double c_tdcOffset=97, double tdcCut=5.0, int dbg=0); |
88 | |||
29 | f9daq | 89 | int position(int, int, int); |
90 | |||
91 | // ------------------------------------------------------------------------------ |
||
92 | |||
91 | f9daq | 93 | int main() |
29 | f9daq | 94 | { |
91 | f9daq | 95 | analysisScan(); |
96 | return 0; |
||
97 | } |
||
29 | f9daq | 98 | |
91 | f9daq | 99 | int analysisScan(char* dfile0, double c_tdcOffset, double tdcCut, int dbg) |
100 | { |
||
101 | |||
102 | //const double c_tdcOffset = +97*TDC_BIN; // ns, SiPM4 |
||
103 | c_tdcOffset *= TDC_BIN; |
||
29 | f9daq | 104 | printf(" Data to root conversion program\nUsage:\nd2r(input file name <without .dat>, debug on/off, TDC cut +-[ns])\n\n"); |
39 | f9daq | 105 | printf(" OFFSETS: \n x: %d\n y: %d\n t:%f\n", OFFSETX, OFFSETY, c_tdcOffset); |
29 | f9daq | 106 | |
107 | char fullname[256]; |
||
108 | char sbuff[256]; |
||
109 | FILE *fp; |
||
110 | |||
111 | //Chanel information |
||
112 | |||
113 | double tdcOffset[NCH]; |
||
40 | f9daq | 114 | sprintf(fullname, "sipmScan.ini"); |
29 | f9daq | 115 | if( (fp=fopen(fullname, "rt")) == NULL ) |
116 | printf("Cannot open pad centers file %s !!!\n", fullname); |
||
117 | else { |
||
118 | printf("Opened pad centers file %s\n", fullname); |
||
119 | char* result = fgets(sbuff,256, fp); |
||
120 | if (dbg) printf("Read buffer %s\n", result); |
||
121 | printf("%s", sbuff); |
||
122 | for(int i=0; i<NCH; i++) { |
||
123 | int channel; |
||
124 | int message = fscanf(fp, "%d %lf %lf %lf\n", &channel, &padCenter[i][0], &padCenter[i][1], &tdcOffset[i]); |
||
125 | if (dbg) printf("Read d2r.ini returned %d\n", message); |
||
126 | } |
||
127 | fclose(fp); |
||
128 | } |
||
129 | for(int i=0; i<NCH; i++) { |
||
130 | tdcOffset[i] += c_tdcOffset; |
||
131 | printf("%.2lf %.2lf %.2lf\n", padCenter[i][0], padCenter[i][1], tdcOffset[i]); |
||
132 | } |
||
133 | |||
134 | //TDC correction parameters |
||
135 | /* |
||
136 | double corpar[NCH][3]={ {-0.8, 25, 0}, |
||
137 | {-0.8, 25, 0}, |
||
138 | {-0.8, 25, 0}, |
||
139 | {-0.8, 25, 0}, |
||
140 | {-0.8, 25, 0}, |
||
141 | {-0.8, 25, 0}, |
||
142 | {-0.8, 25, 0}, |
||
143 | {-0.8, 25, 0} }; |
||
144 | sprintf(fullname, "data/%s_cor.txt", dfile0); |
||
145 | if( (fp=fopen(fullname, "rt")) == NULL ) |
||
146 | printf("Cannot open parameter file %s !!!\n", fullname); |
||
147 | else { |
||
148 | printf("Opened parameter file %s\n", fullname); |
||
149 | for(int i=0; i<NCH; i++) { |
||
150 | fscanf(fp, "%lf %lf %lf\n", &corpar[i][0], &corpar[i][1], &corpar[i][2]);*/ |
||
151 | /*// check if parameters make sense |
||
152 | if( (corpar[i][0] < (tdcmi-0.2*tdcmi)) || ((tdcma+0.2*tdcma) < corpar[i][0]) || |
||
153 | (corpar[i][1] < 0) || (1e4*TDC_BIN < corpar[i][1]) || |
||
154 | (1e4 < TMath::Abs(corpar[i][2])) ) { |
||
155 | printf("Warning: parameters for ch%d out of limits -> using default!\n", i); |
||
156 | corpar[i][0]=2200*TDC_BIN; corpar[i][1]=1000*TDC_BIN; corpar[i][2]=-100*TDC_BIN; |
||
157 | }*/ |
||
158 | /* } |
||
159 | fclose(fp); |
||
160 | }*/ |
||
161 | //for(int i=0; i<NCH; i++) printf("%.2lf %.2lf %.2lf\n", corpar[i][0], corpar[i][1], corpar[i][2]); |
||
162 | |||
163 | |||
164 | //histograms |
||
165 | char hname[256]; |
||
166 | //double tdc; |
||
167 | TH2F *htdc; |
||
90 | f9daq | 168 | TH2F* h_correctedTDC; |
29 | f9daq | 169 | TH1F *hnhitsx[NCH], *hnhitsy[NCH]; |
170 | TH2F *h2d[NCH]; |
||
171 | |||
172 | TNtuple *nt; |
||
173 | |||
174 | //data buffer |
||
175 | unsigned int readbuf[READBUFFERLENGTH]; |
||
176 | unsigned int buf[READBUFFERLENGTH]; |
||
177 | |||
178 | //data file |
||
90 | f9daq | 179 | //gzFile dfp; |
180 | FILE *dfp; |
||
29 | f9daq | 181 | char dfile[256]; |
182 | int ftype=0; |
||
183 | int fcount=1; |
||
184 | do { |
||
185 | switch(ftype++) { |
||
186 | case 0: |
||
187 | sprintf(dfile, "./data/%s_file%02d.dat", dfile0, fcount); |
||
188 | break; |
||
189 | case 1: |
||
190 | sprintf(dfile, "./data/%s_file%02d.dat.gz", dfile0, fcount); |
||
191 | break; |
||
192 | case 2: |
||
193 | sprintf(dfile, "./data/%s_file%02d.gz", dfile0, fcount); |
||
194 | break; |
||
195 | default: |
||
196 | printf(" Cannot find data file for %s !!!\n", dfile0); |
||
197 | return -1; |
||
198 | } |
||
90 | f9daq | 199 | //dfp=gzopen(dfile,"rb"); |
200 | dfp=fopen(dfile,"rb"); |
||
29 | f9daq | 201 | } while(!dfp); |
202 | printf("Opened data file %s\n", dfile); |
||
203 | |||
204 | //opens ROOT file |
||
205 | //TFile *rootfile; |
||
206 | char fnameroot[256]; |
||
207 | sprintf(fnameroot, "root/%s.root", dfile0); |
||
208 | //rootfile = (TFile *) gROOT->FindObjectAny(dfile0); |
||
209 | //if (rootfile!=NULL) {printf("!!!\n");rootfile->Close();} |
||
210 | //rootfile = new TFile(fnameroot); |
||
211 | //if(rootfile) rootfile->Close(); |
||
212 | TFile* rootfile = new TFile(fnameroot,"RECREATE",dfile0); |
||
213 | |||
214 | // ----------------------------------------------- |
||
215 | // loop trough records |
||
216 | unsigned int rec_id, rec_len; |
||
217 | unsigned int ulsize = sizeof(unsigned int); |
||
218 | //unsigned int ulsize = 4; |
||
219 | if (dbg) printf("Size of unsigned int: %lu\n", sizeof(unsigned int)); |
||
220 | int ceve=0; |
||
221 | int end_of_file = 0; |
||
222 | |||
223 | int ii; |
||
224 | int nint; |
||
225 | int nb; |
||
226 | int status; |
||
227 | |||
228 | while(1) { |
||
90 | f9daq | 229 | //if(gzeof(dfp)) end_of_file = 1; |
230 | if(feof(dfp)) end_of_file = 1; |
||
231 | |||
232 | //gzread(dfp, (voidp)&readbuf, 2*ulsize); |
||
233 | fread((void*)&readbuf, 2*ulsize, 1, dfp); |
||
29 | f9daq | 234 | rec_id=readbuf[0]; |
235 | rec_len=readbuf[1]; |
||
236 | |||
237 | |||
238 | if(dbg) printf("-----------------------------------------------\n"); |
||
239 | if(dbg) printf("[%d] rec_id = %d | rec_len = %u\n", ceve, rec_id, rec_len); |
||
240 | |||
241 | switch(rec_id) |
||
242 | { |
||
243 | case RUNREC_ID: |
||
90 | f9daq | 244 | //gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
245 | fread((void*)&readbuf[2], (rec_len-2*ulsize), 1, dfp); |
||
29 | f9daq | 246 | runrec = (RUNREC*) readbuf; |
247 | run = *runrec; |
||
248 | |||
249 | if(dbg) { |
||
250 | printf("RUNREC_ID\n"); |
||
251 | printf("id = %d, len = %d, time = %d\n", run.id, run.len, run.time); |
||
252 | printf("nev = %d, nch = %d\n", run.nev, run.nch); |
||
253 | printf("nx = %d, x0 = %d, dx = %d\n", run.nx, run.x0, run.dx); |
||
254 | printf("ny = %d, y0 = %d, dy = %d\n", run.ny, run.y0, run.dy); |
||
255 | } |
||
256 | |||
257 | //create histograms |
||
258 | nt = new TNtuple("nt", "nt", "ch:x:y:tdc"); |
||
259 | sprintf(hname, "htdc"); |
||
260 | htdc = (TH2F*) gROOT->FindObject(hname); |
||
261 | if (htdc) delete htdc; |
||
262 | htdc = new TH2F("htdc","Raw TDC;TDC channel;SiPM channel",512,0,512,NCH,0,NCH); |
||
263 | h_correctedTDC = (TH2F*) gROOT->FindObject("h_correctedTDC"); |
||
264 | if (h_correctedTDC) delete h_correctedTDC; |
||
265 | h_correctedTDC = new TH2F("h_correctedTDC","Corrected TDC;t [ns];SiPM channel",33, -16.5*TDC_BIN,16.5*TDC_BIN,NCH,0,NCH); |
||
266 | //TH1F* gsumV673A[NCH/16] = new TH1F(hn,hname,256,-0.5,255.5); |
||
267 | for(int i=0; i<NCH; i++) { |
||
268 | /* |
||
269 | sprintf(hname, "htdcpos%d", i); |
||
270 | htdcpos[i] = (TH1F*)gROOT->FindObject(hname); |
||
271 | if(htdcpos[i]) delete htdcpos[i]; |
||
272 | htdcpos[i] = new TH1F(hname, hname, 512, 0, 512*TDC_BIN); |
||
273 | |||
274 | sprintf(hname, "htdc%d", i); |
||
275 | htdc[i] = (TH1F*)gROOT->FindObject(hname); |
||
276 | if(htdc[i]) delete htdc[i]; |
||
277 | htdc[i] = new TH1F(hname, hname, 512, 0*TDC_BIN, 512*TDC_BIN); |
||
278 | */ |
||
279 | |||
280 | |||
281 | sprintf(hname, "hnhitsx%d", i); |
||
282 | hnhitsx[i] = (TH1F*)gROOT->FindObject(hname); |
||
283 | if(hnhitsx[i]) delete hnhitsx[i]; |
||
284 | hnhitsx[i] = new TH1F(hname, hname, run.nx, |
||
285 | (run.x0 - OFFSETX - 0.5*run.dx)*MIKRO_BIN, |
||
286 | (run.x0 - OFFSETX + (run.nx-0.5)*run.dx)*MIKRO_BIN); |
||
287 | |||
288 | sprintf(hname, "hnhitsy%d", i); |
||
289 | hnhitsy[i] = (TH1F*)gROOT->FindObject(hname); |
||
290 | if(hnhitsy[i]) delete hnhitsy[i]; |
||
291 | //hnhitsy[i] = new TH1F(hname, hname, run.ny, (run.y0-0.5*run.dy)*MIKRO_BIN, (run.y0+(run.ny-0.5)*run.dy)*MIKRO_BIN); |
||
292 | hnhitsy[i] = new TH1F(hname, hname, run.ny, |
||
293 | (run.y0 - 0.5*run.dy - OFFSETY)*MIKRO_BIN, |
||
294 | (run.y0 + (run.ny-0.5)*run.dy - OFFSETY)*MIKRO_BIN); |
||
295 | //hnhitsy[i] = new TH1F(hname, hname, 100, 0,100); |
||
296 | |||
297 | sprintf(hname, "h2d%d", i); |
||
298 | h2d[i] = (TH2F*)gROOT->FindObject(hname); |
||
299 | if(h2d[i]) delete h2d[i]; |
||
300 | h2d[i] = new TH2F(hname, hname, run.nx, |
||
301 | (run.x0 - OFFSETX - 0.5*run.dx)*MIKRO_BIN, |
||
302 | (run.x0 - OFFSETX + (run.nx-0.5)*run.dx)*MIKRO_BIN, |
||
303 | run.ny, |
||
304 | (run.y0 - OFFSETY - 0.5*run.dy)*MIKRO_BIN, |
||
305 | (run.y0 - OFFSETY + (run.ny-0.5)*run.dy)*MIKRO_BIN); |
||
306 | } |
||
307 | |||
308 | break; |
||
309 | |||
310 | case POSREC_ID: |
||
90 | f9daq | 311 | //gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
312 | fread((void*)&readbuf[2], (rec_len-2*ulsize), 1, dfp); |
||
29 | f9daq | 313 | posrec = (POSREC *) readbuf; |
314 | pos=*posrec; |
||
315 | |||
316 | if(dbg) { |
||
317 | printf("POSREC_ID\n"); |
||
318 | printf("id = %d, len = %d, time = %d\n", posrec->id, posrec->len, posrec->time); |
||
319 | printf("ix = %d, x = %d, xset = %d\n", posrec->ix, posrec->x, posrec->xset); |
||
320 | printf("iy = %d, y = %d, yset = %d\n", posrec->iy, posrec->y, posrec->yset); |
||
321 | } else printf(" [%d,%d] %d, %d\n", pos.ix, pos.iy, pos.xset, pos.yset); |
||
322 | |||
323 | break; |
||
324 | |||
325 | case EVTREC_ID: |
||
90 | f9daq | 326 | //gzread(dfp, (voidp)&readbuf[2], ulsize); // last field of event record |
327 | fread((void*)&readbuf[2], ulsize, 1, dfp); |
||
29 | f9daq | 328 | evtrec = (EVTREC *) readbuf; |
329 | //evtrec->nev = buf[0]; |
||
330 | //if (rec_len < 0 || rec_len > 10000) { |
||
331 | if (rec_len > READBUFFERLENGTH) { |
||
332 | printf("Len %u\n", rec_len); |
||
333 | return(0); |
||
334 | } |
||
335 | nb = rec_len - 3*ulsize; // no. of bytes to read |
||
90 | f9daq | 336 | //gzread(dfp, (voidp)&buf, nb); |
337 | fread((void*)&buf, nb, 1, dfp); |
||
29 | f9daq | 338 | |
339 | if(dbg) { |
||
340 | printf("EVTREC_ID\n"); |
||
341 | printf("id = %d, len = %d, nev = %d\n", evtrec->id, evtrec->len, evtrec->nev); |
||
342 | //for(int datai = 0; datai < NCH; datai++) printf("%u ", evtrec->data[datai]); |
||
343 | //printf("\n"); |
||
344 | //for(int datai = NCH; datai < NCH+NCH; datai++) printf("%u ", evtrec->data[datai]); |
||
345 | //printf("\n"); |
||
346 | break; |
||
347 | } |
||
348 | |||
349 | nint = nb / ulsize; // no. of subrecords |
||
350 | if (dbg) printf("No. of subrecords %d \n", nint); |
||
351 | ii=0; |
||
352 | while (ii<nint){ |
||
353 | int recid = buf[ii++]; |
||
354 | int len = buf[ii++]; |
||
355 | if (dbg) printf("Buffer pointer %d\n", ii); |
||
356 | unsigned int *dbuf = (unsigned int *)&buf[ii]; |
||
357 | //if (n%1000==0) |
||
90 | f9daq | 358 | if (dbg) printf("%d 0x%03x Len=%d\n",evtrec->nev,recid,len); |
29 | f9daq | 359 | //unsigned short edge; |
360 | //int nhits; |
||
90 | f9daq | 361 | if (recid==0x140 || recid==0x141) { |
29 | f9daq | 362 | for (int i=0; i<len; i++) { |
363 | int data = dbuf[i] & 0xFFFF ; |
||
364 | int edge_type = (dbuf[i]>>16)&0x1 ; |
||
365 | int overflow = (dbuf[i]>>17)&0x1 ; |
||
366 | int tdc_num = (dbuf[i]>>25)&0x1 ; |
||
367 | int channel = ((dbuf[i]>>18)&0x1F) | tdc_num<<5 ; |
||
368 | int ev_dat = (dbuf[i]>>23)&0x1 ; |
||
369 | int last_dat = (dbuf[i]>>30)&0x1 ; |
||
370 | int nval_dat = (dbuf[i]>>31)&0x1 ; |
||
371 | if (dbg){ |
||
372 | if (ev_dat) printf("Event %d\n",data); |
||
373 | else printf("ch=%d edge=%d ev=%d data=%d last=%d nval=%d\n", |
||
374 | channel, edge_type,ev_dat,data,last_dat,nval_dat); |
||
375 | } |
||
376 | if (!ev_dat){ |
||
377 | if (!edge_type && !overflow) { |
||
378 | htdc->Fill(data, channel); |
||
379 | if(dbg) printf("ch: %d tdc: %d\n", channel, data); |
||
380 | if (dbg) nt->Fill(channel, pos.ix, pos.iy, data); |
||
381 | double tdcmin=tdcOffset[channel] - tdcCut; |
||
382 | double tdcmax=tdcOffset[channel] + tdcCut; |
||
383 | double time = data*TDC_BIN; |
||
384 | if(time >= tdcmin && time <= tdcmax) { |
||
385 | h_correctedTDC->Fill((time - tdcOffset[channel]), channel); |
||
386 | hnhitsx[channel]->Fill((pos.xset - OFFSETX) * MIKRO_BIN); |
||
35 | f9daq | 387 | hnhitsy[channel]->Fill((pos.yset - OFFSETY) * MIKRO_BIN); |
29 | f9daq | 388 | //h_threshold->Fill(channel, thr.threshold); |
40 | f9daq | 389 | //if (position(pos.xset-OFFSETX, pos.yset-OFFSETY, channel)) { |
35 | f9daq | 390 | h2d[channel]->Fill((pos.xset - OFFSETX) * MIKRO_BIN, (pos.yset - OFFSETY) * MIKRO_BIN); |
40 | f9daq | 391 | //} |
29 | f9daq | 392 | } |
393 | //gV673A->Fill(data,channel); |
||
394 | //gsumV673A[channel/16]->Fill(data); |
||
395 | } |
||
396 | } |
||
397 | if (last_dat) break; |
||
398 | } |
||
399 | } // if (recid== 0x140 || recid== 0x141) |
||
400 | ii += len; |
||
401 | } //while |
||
402 | |||
403 | // events ------------------------------------------------------------------------------------------ |
||
404 | // fill histograms |
||
405 | /* |
||
406 | for(int i=0; i<NCH; i++) { |
||
407 | //tdc=((double)evtrec->data[i])*TDC_BIN - tdcoffset[i]; |
||
408 | //adc=(double)evtrec->data[i+NCH]-adcoffset[i]; |
||
409 | if (gNtWrite) nt->Fill(i,pos.ix,pos.iy,tdc); |
||
410 | //if( (qdcmi < adc) && (adc < qdcma) ) { |
||
411 | htdc[i]->Fill(tdc); |
||
412 | //} |
||
413 | //hadc[i]->Fill(adc); |
||
414 | //hcor[i]->Fill(adc,tdc); |
||
415 | //if(adc > corpar[i][2]) |
||
416 | //hctdc[i]->Fill( tdc - (corpar[i][0] + corpar[i][1]/TMath::Sqrt(adc - corpar[i][2])) ); |
||
417 | |||
418 | if( (abs(padcenter[i][0] - pos.xset) < POSMARG) && (abs(padcenter[i][1] - pos.yset) < POSMARG) ) { |
||
419 | htdcpos[i]->Fill(tdc); |
||
420 | //hadcpos[i]->Fill(adc); |
||
421 | //hcorpos[i]->Fill(adc,tdc); |
||
422 | //if(adc > corpar[i][2]) |
||
423 | //hctdcpos[i]->Fill( tdc - (corpar[i][0] + corpar[i][1]/TMath::Sqrt(adc - corpar[i][2])) ); |
||
424 | } |
||
425 | |||
426 | if((tdcmi < tdc) && (tdc < tdcma)) { |
||
427 | //hadc_cut[i]->Fill(adc); |
||
428 | hnhitsx[i]->Fill((pos.xset - OFFSETX) * MIKRO_BIN); |
||
429 | hnhitsy[i]->Fill((pos.yset - OFFSETY) * MIKRO_BIN); |
||
430 | h2d[i]->Fill((pos.xset - OFFSETX) * MIKRO_BIN, (pos.yset - OFFSETY) * MIKRO_BIN); |
||
431 | |||
432 | //if(i==4) adc1=adc; |
||
433 | //if(i==5) adc2=adc; |
||
434 | } |
||
435 | } */ |
||
436 | break; |
||
437 | |||
438 | case THRREC_ID: |
||
90 | f9daq | 439 | //status = gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
440 | status = fread((void*)&readbuf[2], (rec_len-2*ulsize), 1, dfp); |
||
29 | f9daq | 441 | thrrec = (THRREC*) readbuf; |
442 | thr = *thrrec; |
||
443 | if (dbg) printf("THRREC id = %d len = %d threshold %d\n", |
||
444 | thrrec->id, thrrec->len, thrrec->threshold); |
||
445 | break; |
||
446 | |||
447 | case ENDREC_ID: |
||
90 | f9daq | 448 | //gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
449 | fread((void*)&readbuf[2], (rec_len-2*ulsize), 1, dfp); |
||
29 | f9daq | 450 | endrec = (ENDREC *) readbuf; |
451 | |||
452 | if(dbg) { |
||
453 | printf("ENDREC_ID\n"); |
||
454 | printf("id = %d, len = %d, time = %d\n", endrec->id, endrec->len, endrec->time); |
||
455 | } else printf(" ENDREC\n"); |
||
456 | |||
457 | fcount++; |
||
458 | switch(ftype-1) { |
||
459 | case 0: |
||
460 | sprintf(dfile, "./data/%s_file%02d.dat", dfile0, fcount); |
||
461 | break; |
||
462 | case 1: |
||
463 | sprintf(dfile, "./data/%s_file%02d.dat.gz", dfile0, fcount); |
||
464 | break; |
||
465 | case 2: |
||
466 | sprintf(dfile, "./data/%s_file%02d.gz", dfile0, fcount); |
||
467 | break; |
||
468 | } |
||
469 | |||
90 | f9daq | 470 | //if(dfp) gzclose(dfp); |
471 | if(dfp) fclose(dfp); |
||
29 | f9daq | 472 | |
90 | f9daq | 473 | //dfp=gzopen(dfile,"rb"); |
474 | dfp=fopen(dfile,"rb"); |
||
29 | f9daq | 475 | if(!dfp) { |
476 | printf(" Cannot open data file: %s ---> Exiting\n", dfile); |
||
477 | end_of_file = 1; |
||
478 | } else { |
||
479 | printf(" Opened data file: %s\n", dfile); |
||
480 | end_of_file = 0; |
||
481 | } |
||
482 | |||
483 | break; |
||
484 | |||
485 | default: |
||
486 | printf("switch(rec_id): default !!!\n"); |
||
487 | end_of_file = 1; |
||
488 | break; |
||
489 | } |
||
490 | |||
491 | ceve++; |
||
492 | if( (ceve%50000) == 0) printf(" Current event = %d\n", ceve); |
||
493 | //if(dbg) if( ceve>dbg ) break; |
||
494 | if(end_of_file) break; |
||
495 | } |
||
496 | |||
497 | if(dfp) { |
||
90 | f9daq | 498 | //gzclose(dfp); |
499 | fclose(dfp); |
||
500 | //delete dfp; |
||
29 | f9daq | 501 | } |
502 | if(dbg) return 1; |
||
503 | if(rootfile) { |
||
504 | nt->Write(); |
||
505 | rootfile->Write(); |
||
506 | printf("Saved to %s\n", fnameroot); |
||
507 | rootfile->Close(); |
||
90 | f9daq | 508 | //delete rootfile; |
29 | f9daq | 509 | } |
510 | |||
511 | return 1; |
||
512 | } |
||
513 | |||
514 | int position(int x, int y, int channel) |
||
515 | { |
||
516 | int flag = 0; |
||
34 | f9daq | 517 | if ( (x > (padCenter[channel][0] - 5040)) && (x < (padCenter[channel][0] + 5040)) && |
518 | (y > (padCenter[channel][1] - 5040)) && (y < (padCenter[channel][1] + 5040)) ) flag = 1; |
||
29 | f9daq | 519 | return flag; |
520 | } |