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