Subversion Repositories f9daq

Rev

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