Rev 35 | 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" |
||
| 22 | #include "zlib.h" |
||
| 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 | { |
| 96 | const double c_tdcOffset = 1; // ns |
||
| 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 |
||
| 132 | gzFile dfp; |
||
| 133 | char dfile[256]; |
||
| 134 | int ftype=0; |
||
| 135 | int fcount=1; |
||
| 136 | do { |
||
| 137 | switch(ftype++) { |
||
| 138 | case 0: |
||
| 139 | sprintf(dfile, "./data/%s_file%02d.dat", dfile0, fcount); |
||
| 140 | break; |
||
| 141 | case 1: |
||
| 142 | sprintf(dfile, "./data/%s_file%02d.dat.gz", dfile0, fcount); |
||
| 143 | break; |
||
| 144 | case 2: |
||
| 145 | sprintf(dfile, "./data/%s_file%02d.gz", dfile0, fcount); |
||
| 146 | break; |
||
| 147 | default: |
||
| 148 | printf(" Cannot find data file for %s !!!\n", dfile0); |
||
| 149 | return -1; |
||
| 150 | } |
||
| 151 | dfp=gzopen(dfile,"rb"); |
||
| 152 | } while(!dfp); |
||
| 153 | printf("Opened data file %s\n", dfile); |
||
| 154 | |||
| 155 | //opens ROOT file |
||
| 156 | char fnameroot[256]; |
||
| 157 | sprintf(fnameroot, "root/%s.root", dfile0); |
||
| 158 | TFile rootfile(fnameroot,"RECREATE",dfile0); |
||
| 159 | if (rootfile.IsZombie()) { |
||
| 160 | std::cout << "Error opening file" << std::endl; |
||
| 161 | exit(-1); |
||
| 162 | } |
||
| 163 | if (rootfile.IsOpen()) std::cout << "ROOT file opened for writing." << std::endl; |
||
| 164 | |||
| 165 | // ----------------------------------------------- |
||
| 166 | // loop trough records |
||
| 167 | unsigned int rec_id, rec_len; |
||
| 168 | unsigned int ulsize = sizeof(unsigned int); |
||
| 169 | //unsigned int ulsize = 4; |
||
| 170 | if (dbg) printf("Size of unsigned int: %lu\n", sizeof(unsigned int)); |
||
| 171 | int ceve=0; |
||
| 172 | int end_of_file = 0; |
||
| 173 | |||
| 174 | int ii; |
||
| 175 | int nint; |
||
| 176 | int nb; |
||
| 177 | int status; |
||
| 178 | char hname[256]; |
||
| 179 | TH2F* htdc = new TH2F("htdc",";TDC channel;SiPM channel",512,-0.5,511.5,NCH,-0.5,NCH-0.5); |
||
| 180 | TH3F* h_correctedTDC = new TH3F("h_correctedTDC",";SiPM channel; ASD threshold [V]; t [ns]", |
||
| 181 | NCH, -0.5, NCH-0.5, |
||
| 182 | 101, 1.0, 2.0, |
||
| 183 | 33, -16.5*TDC_BIN, 16.5*TDC_BIN); |
||
| 184 | TH1F* hnhitsx[NCH]; // move to 2d with (channel, position) |
||
| 185 | TH1F* hnhitsy[NCH]; //-||- |
||
| 186 | TH2F* h2d[NCH]; //-||- |
||
| 187 | TH2F* h_threshold = new TH2F("h_threshold",";SiPM ch;Threshold[V]", |
||
| 188 | 64,-0.5,63.5, |
||
| 189 | 101, 1.0, 2.0); |
||
| 190 | TH2F* h_ch33 = new TH2F("h_ch33","ch. 33;x;y",100,20000,30000,100,0,10000); |
||
| 191 | TNtuple* nt = new TNtuple("nt", "nt", "ch:x:y:tdc"); |
||
| 192 | |||
| 193 | while(1) { |
||
| 194 | if(gzeof(dfp)) end_of_file = 1; |
||
| 195 | |||
| 196 | gzread(dfp, (voidp)&readbuf, 2*ulsize); |
||
| 197 | rec_id=readbuf[0]; |
||
| 198 | rec_len=readbuf[1]; |
||
| 199 | |||
| 200 | |||
| 201 | if(dbg) printf("-----------------------------------------------\n"); |
||
| 202 | if(dbg) printf("[%d] rec_id = %d | rec_len = %u\n", ceve, rec_id, rec_len); |
||
| 203 | |||
| 204 | double nSteps = 0; |
||
| 205 | switch(rec_id) |
||
| 206 | { |
||
| 207 | case RUNREC_ID: |
||
| 208 | if (dbg) printf("RUNREC\n"); |
||
| 209 | gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
||
| 210 | runrec = (RUNREC *) readbuf; |
||
| 211 | run=*runrec; |
||
| 212 | |||
| 213 | if(dbg) { |
||
| 214 | printf("RUNREC_ID\n"); |
||
| 215 | printf("id = %d, len = %d, time = %d\n", run.id, run.len, run.time); |
||
| 216 | printf("nev = %d, nch = %d\n", run.nev, run.nch); |
||
| 217 | printf("nx = %d, x0 = %d, dx = %d\n", run.nx, run.x0, run.dx); |
||
| 218 | printf("ny = %d, y0 = %d, dy = %d\n", run.ny, run.y0, run.dy); |
||
| 219 | printf("thLow = %d, thUp = %d, thStep = %d\n", run.thLow, run.thUp, run.thStep); |
||
| 220 | } |
||
| 221 | |||
| 222 | //create histograms |
||
| 223 | //nt = (TNtuple*) gROOT->FindObject("nt"); |
||
| 224 | //if (nt) delete nt; |
||
| 225 | |||
| 226 | //sprintf(hname, "htdc"); |
||
| 227 | //htdc = (TH2F*) gROOT->FindObject(hname); |
||
| 228 | //if (htdc) delete htdc; |
||
| 229 | //htdc = new TH2F("htdc",";TDC channel;SiPM channel",512,0,512,NCH,0,NCH); |
||
| 230 | h_correctedTDC = (TH3F*) gROOT->FindObject("h_correctedTDC"); |
||
| 231 | if (h_correctedTDC) delete h_correctedTDC; |
||
| 232 | nSteps = (run.thUp - run.thLow)/double(run.thStep) + 1; |
||
| 233 | if (dbg) printf("nSteps %d\n", nSteps); |
||
| 234 | h_correctedTDC = new TH3F("h_correctedTDC",";SiPM channel; ASD threshold [V]; t [ns]", |
||
| 235 | NCH, |
||
| 236 | -0.5, |
||
| 237 | NCH-0.5, |
||
| 238 | nSteps, |
||
| 239 | (run.thLow - 0.5*run.thStep)/1000.0, |
||
| 240 | (run.thUp + 0.5*run.thStep)/1000.0, |
||
| 241 | 2*tdcCut*TDC_BIN, |
||
| 242 | -tdcCut*TDC_BIN, |
||
| 243 | tdcCut*TDC_BIN); |
||
| 244 | //TH1F* gsumV673A[NCH/16] = new TH1F(hn,hname,256,-0.5,255.5); |
||
| 245 | for(int i=0; i<NCH; i++) { |
||
| 246 | /* |
||
| 247 | sprintf(hname, "htdcpos%d", i); |
||
| 248 | htdcpos[i] = (TH1F*)gROOT->FindObject(hname); |
||
| 249 | if(htdcpos[i]) delete htdcpos[i]; |
||
| 250 | htdcpos[i] = new TH1F(hname, hname, 512, 0, 512*TDC_BIN); |
||
| 251 | |||
| 252 | sprintf(hname, "htdc%d", i); |
||
| 253 | htdc[i] = (TH1F*)gROOT->FindObject(hname); |
||
| 254 | if(htdc[i]) delete htdc[i]; |
||
| 255 | htdc[i] = new TH1F(hname, hname, 512, 0*TDC_BIN, 512*TDC_BIN); |
||
| 256 | */ |
||
| 257 | |||
| 258 | sprintf(hname, "hnhitsx%d", i); |
||
| 259 | hnhitsx[i] = (TH1F*)gROOT->FindObject(hname); |
||
| 260 | if(hnhitsx[i]) delete hnhitsx[i]; |
||
| 261 | hnhitsx[i] = new TH1F(hname, hname, run.nx, |
||
| 262 | (run.x0 - OFFSETX - 0.5*run.dx)*MIKRO_BIN, |
||
| 263 | (run.x0 - OFFSETX + (run.nx-0.5)*run.dx)*MIKRO_BIN); |
||
| 264 | |||
| 265 | sprintf(hname, "hnhitsy%d", i); |
||
| 266 | hnhitsy[i] = (TH1F*)gROOT->FindObject(hname); |
||
| 267 | if(hnhitsy[i]) delete hnhitsy[i]; |
||
| 268 | //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); |
||
| 269 | hnhitsy[i] = new TH1F(hname, hname, run.ny, |
||
| 270 | (run.y0 - 0.5*run.dy - OFFSETY)*MIKRO_BIN, |
||
| 271 | (run.y0 + (run.ny-0.5)*run.dy - OFFSETY)*MIKRO_BIN); |
||
| 272 | //hnhitsy[i] = new TH1F(hname, hname, 100, 0,100); |
||
| 273 | |||
| 274 | sprintf(hname, "h2d%d", i); |
||
| 275 | h2d[i] = (TH2F*)gROOT->FindObject(hname); |
||
| 276 | if(h2d[i]) delete h2d[i]; |
||
| 277 | h2d[i] = new TH2F(hname, hname, run.nx, |
||
| 278 | (run.x0 - OFFSETX - 0.5*run.dx)*MIKRO_BIN, |
||
| 279 | (run.x0 - OFFSETX + (run.nx-0.5)*run.dx)*MIKRO_BIN, |
||
| 280 | run.ny, |
||
| 281 | (run.y0 - OFFSETY - 0.5*run.dy)*MIKRO_BIN, |
||
| 282 | (run.y0 - OFFSETY + (run.ny-0.5)*run.dy)*MIKRO_BIN); |
||
| 283 | } |
||
| 284 | |||
| 285 | if (h_threshold) delete h_threshold; |
||
| 286 | h_threshold = new TH2F("h_threshold",";SiPM ch;Threshold[V]",64,-0.5,63.5, |
||
| 287 | nSteps, |
||
| 288 | (run.thLow - 0.5*run.thStep)/1000.0, |
||
| 289 | (run.thUp + 0.5*run.thStep)/1000.0); |
||
| 290 | |||
| 291 | //h_threshold = new TH2F("h_threshold","Threshold scan;SiPM ch;Threshold[mV]",64,-0.5,63.5, |
||
| 292 | // 101,995,2005); |
||
| 293 | |||
| 294 | if (h_ch33) delete h_ch33; |
||
| 295 | h_ch33 = new TH2F("h_ch33","ch. 33;x;y",100,20000,30000,100,0,10000); |
||
| 296 | |||
| 297 | if (dbg) printf("RUNREC: all histos created.\n"); |
||
| 298 | break; |
||
| 299 | |||
| 300 | case POSREC_ID: |
||
| 301 | if (dbg) printf("POSREC\n"); |
||
| 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(1); |
||
| 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 - tdcOffset[channel]; |
||
| 37 | f9daq | 372 | if((time >= -tdcCut) && (time <= tdcCut)) { |
| 35 | f9daq | 373 | h_correctedTDC->Fill(channel, thr.threshold/1000.0, time); |
| 374 | hnhitsx[channel]->Fill((pos.xset - OFFSETX) * MIKRO_BIN); |
||
| 375 | hnhitsy[channel]->Fill((pos.yset - OFFSETY) * MIKRO_BIN); |
||
| 376 | h2d[channel]->Fill((pos.xset - OFFSETX) * MIKRO_BIN, (pos.yset - OFFSETY) * MIKRO_BIN); |
||
| 377 | |||
| 378 | if (position(pos.xset-OFFSETX, pos.yset-OFFSETY, channel)) { |
||
| 379 | h_ch33->Fill(pos.xset-OFFSETX, pos.yset-OFFSETY); |
||
| 380 | h_threshold->Fill(channel, thr.threshold/1000.0); |
||
| 381 | } |
||
| 382 | } |
||
| 383 | //gV673A->Fill(data,channel); |
||
| 384 | //gsumV673A[channel/16]->Fill(data); |
||
| 385 | } |
||
| 386 | } |
||
| 387 | if (last_dat) break; |
||
| 388 | } |
||
| 389 | } // if (recid== 0x140 || recid== 0x141) |
||
| 390 | ii += len; |
||
| 391 | } //while |
||
| 392 | |||
| 393 | break; |
||
| 394 | |||
| 395 | case THRREC_ID: |
||
| 396 | status = gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
||
| 397 | thrrec = (THRREC*) readbuf; |
||
| 398 | thr = *thrrec; |
||
| 399 | if (dbg) printf("THRREC id = %d len = %d threshold %d\n", |
||
| 400 | thrrec->id, thrrec->len, thrrec->threshold); |
||
| 401 | break; |
||
| 402 | |||
| 403 | case ENDREC_ID: |
||
| 404 | gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
||
| 405 | endrec = (ENDREC *) readbuf; |
||
| 406 | |||
| 407 | if(dbg) { |
||
| 408 | printf("ENDREC_ID\n"); |
||
| 409 | printf("id = %d, len = %d, time = %d\n", endrec->id, endrec->len, endrec->time); |
||
| 410 | } else printf(" ENDREC\n"); |
||
| 411 | |||
| 412 | fcount++; |
||
| 413 | switch(ftype-1) { |
||
| 414 | case 0: |
||
| 415 | sprintf(dfile, "./data/%s_file%02d.dat", dfile0, fcount); |
||
| 416 | break; |
||
| 417 | case 1: |
||
| 418 | sprintf(dfile, "./data/%s_file%02d.dat.gz", dfile0, fcount); |
||
| 419 | break; |
||
| 420 | case 2: |
||
| 421 | sprintf(dfile, "./data/%s_file%02d.gz", dfile0, fcount); |
||
| 422 | break; |
||
| 423 | } |
||
| 424 | |||
| 425 | if(dfp) gzclose(dfp); |
||
| 426 | |||
| 427 | dfp=gzopen(dfile,"rb"); |
||
| 428 | if(!dfp) { |
||
| 429 | printf(" Cannot open data file: %s ---> Exiting\n", dfile); |
||
| 430 | end_of_file = 1; |
||
| 431 | } else { |
||
| 432 | printf(" Opened data file: %s\n", dfile); |
||
| 433 | end_of_file = 0; |
||
| 434 | } |
||
| 435 | |||
| 436 | break; |
||
| 437 | |||
| 438 | default: |
||
| 439 | printf("switch(rec_id): default !!!\n"); |
||
| 440 | end_of_file = 1; |
||
| 441 | break; |
||
| 442 | } |
||
| 443 | |||
| 444 | ceve++; |
||
| 445 | if ( (ceve%50000) == 0) printf(" Current event = %d\n", ceve); |
||
| 446 | //if(dbg) if( ceve>dbg ) break; |
||
| 447 | if (end_of_file) break; |
||
| 448 | } |
||
| 449 | |||
| 450 | if(dfp) { |
||
| 451 | gzclose(dfp); |
||
| 452 | //delete dfp; |
||
| 453 | } |
||
| 454 | //if(dbg) return 0; |
||
| 455 | if(rootfile.IsOpen()) { |
||
| 456 | nt->Write(); |
||
| 457 | rootfile.Write(); |
||
| 458 | printf("Saved to %s\n", fnameroot); |
||
| 459 | rootfile.Close(); |
||
| 460 | //delete rootfile; |
||
| 461 | } |
||
| 462 | |||
| 463 | return 0; |
||
| 464 | } |
||
| 465 | |||
| 466 | int position(int x, int y, int channel) |
||
| 467 | { |
||
| 468 | int flag = 0; |
||
| 37 | f9daq | 469 | if ( (x > (padCenter[channel][0] - 5000)) && (x < (padCenter[channel][0] + 5000)) && |
| 470 | (y > (padCenter[channel][1] - 5000)) && (y < (padCenter[channel][1] + 5000)) ) flag = 1; |
||
| 35 | f9daq | 471 | return flag; |
| 472 | } |