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