Rev 50 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 50 | Rev 90 | ||
|---|---|---|---|
| Line 15... | Line 15... | ||
| 15 | #include "TF1.h" |
15 | #include "TF1.h" |
| 16 | #include "TMath.h" |
16 | #include "TMath.h" |
| 17 | #include "TStyle.h" |
17 | #include "TStyle.h" |
| 18 | #include "TCanvas.h" |
18 | #include "TCanvas.h" |
| 19 | #include "TLine.h" |
19 | #include "TLine.h" |
| 20 |
|
20 | //#include "zlib.h" |
| 21 | 21 | ||
| 22 | // ------------------------------------------------------------------------------ |
22 | // ------------------------------------------------------------------------------ |
| 23 | 23 | ||
| 24 | #define POSMARG 1000 |
24 | #define POSMARG 1000 |
| 25 | 25 | ||
| Line 28... | Line 28... | ||
| 28 | // data format |
28 | // data format |
| 29 | #define MAXDATA 16 |
29 | #define MAXDATA 16 |
| 30 | #define NCH 64 |
30 | #define NCH 64 |
| 31 | #define TDC_BIN 1.0416 // 1 TDC bin in ns |
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 |
32 | #define MIKRO_BIN 0.49609/1000. //1 mikro step in mm; stage MM3MF |
| 33 | #define OFFSETX |
33 | #define OFFSETX 0 // Right edge of SiPM+Lightguide |
| 34 | #define OFFSETY |
34 | #define OFFSETY 0 // Lower edge of SiPM+Lightguide |
| 35 | 35 | ||
| 36 | #define RUNREC_ID 1 |
36 | #define RUNREC_ID 1 |
| 37 | #define ENDREC_ID 2 |
37 | #define ENDREC_ID 2 |
| 38 | #define POSREC_ID 3 |
38 | #define POSREC_ID 3 |
| 39 | #define EVTREC_ID 4 |
39 | #define EVTREC_ID 4 |
| Line 82... | Line 82... | ||
| 82 | THRREC *thrrec; |
82 | THRREC *thrrec; |
| 83 | THRREC thr; |
83 | THRREC thr; |
| 84 | 84 | ||
| 85 | double padCenter[NCH][2]; |
85 | double padCenter[NCH][2]; |
| 86 | 86 | ||
| - | 87 | // Test if the hit(x,y) lies inside the coordinates of the channel |
|
| - | 88 | // file with pad centers (without offset) should be provided |
|
| 87 | int position(int, int, int); |
89 | int position(int, int, int); |
| 88 | 90 | ||
| 89 | // ------------------------------------------------------------------------------ |
91 | // ------------------------------------------------------------------------------ |
| 90 | 92 | ||
| 91 | int analysisScan(char* dfile0="test", int dbg= |
93 | int analysisScan(char* dfile0="test", double c_tdcOffset=97, double tdcCut=5.0, int dbg=0) |
| 92 | { |
94 | { |
| 93 | 95 | ||
| 94 |
|
96 | //const double c_tdcOffset = +98*TDC_BIN; // ns |
| - | 97 | c_tdcOffset *= TDC_BIN; //ns |
|
| - | 98 | ||
| 95 | printf(" Data to root conversion program\nUsage:\nd2r(input file name <without .dat>, debug on/off, TDC cut +-[ns])\n\n"); |
99 | printf(" Data to root conversion program\nUsage:\nd2r(input file name <without .dat>, debug on/off, TDC cut +-[ns])\n\n"); |
| 96 | printf(" OFFSETS: \n x: %d\n y: %d\n t:%f\n", OFFSETX, OFFSETY, c_tdcOffset); |
100 | printf(" OFFSETS: \n x: %d\n y: %d\n t:%f\n", OFFSETX, OFFSETY, c_tdcOffset); |
| 97 | 101 | ||
| 98 | char fullname[256]; |
102 | char fullname[256]; |
| 99 | char sbuff[256]; |
103 | char sbuff[256]; |
| Line 149... | Line 153... | ||
| 149 | /* } |
153 | /* } |
| 150 | fclose(fp); |
154 | fclose(fp); |
| 151 | }*/ |
155 | }*/ |
| 152 | //for(int i=0; i<NCH; i++) printf("%.2lf %.2lf %.2lf\n", corpar[i][0], corpar[i][1], corpar[i][2]); |
156 | //for(int i=0; i<NCH; i++) printf("%.2lf %.2lf %.2lf\n", corpar[i][0], corpar[i][1], corpar[i][2]); |
| 153 | 157 | ||
| 154 | 158 | ||
| 155 | //histograms |
159 | //histograms |
| 156 | char hname[256]; |
160 | char hname[256]; |
| 157 | //double tdc; |
161 | //double tdc; |
| 158 | TH2F *htdc; |
162 | TH2F *htdc; |
| 159 | TH2F* h_correctedTDC; |
163 | TH2F* h_correctedTDC; |
| 160 | TH1F *hnhitsx[NCH], *hnhitsy[NCH]; |
164 | TH1F *hnhitsx[NCH], *hnhitsy[NCH]; |
| 161 | TH2F *h2d[NCH]; |
165 | TH2F *h2d[NCH]; |
| 162 | 166 | ||
| 163 | TNtuple *nt; |
167 | TNtuple *nt; |
| 164 | 168 | ||
| 165 | //data buffer |
169 | //data buffer |
| 166 | unsigned int readbuf[READBUFFERLENGTH]; |
170 | unsigned int readbuf[READBUFFERLENGTH]; |
| 167 | unsigned int buf[READBUFFERLENGTH]; |
171 | unsigned int buf[READBUFFERLENGTH]; |
| 168 | - | ||
| 169 | - | ||
| 170 | - | ||
| 171 | - | ||
| 172 | 172 | ||
| 173 | //data file |
173 | //data file |
| 174 | gzFile dfp |
174 | //gzFile dfp; |
| - | 175 | FILE *dfp; |
|
| 175 | char dfile[256]; |
176 | char dfile[256]; |
| 176 | int ftype=0; |
177 | int ftype=0; |
| 177 | int fcount=1; |
178 | int fcount=1; |
| 178 | do { |
179 | do { |
| 179 | switch(ftype++) { |
180 | switch(ftype++) { |
| Line 188... | Line 189... | ||
| 188 | break; |
189 | break; |
| 189 | default: |
190 | default: |
| 190 | printf(" Cannot find data file for %s !!!\n", dfile0); |
191 | printf(" Cannot find data file for %s !!!\n", dfile0); |
| 191 | return -1; |
192 | return -1; |
| 192 | } |
193 | } |
| 193 |
|
194 | //dfp=gzopen(dfile,"rb"); |
| - | 195 | dfp=fopen(dfile,"rb"); |
|
| 194 | } while(!dfp); |
196 | } while(!dfp); |
| 195 | printf("Opened data file %s\n", dfile); |
197 | printf("Opened data file %s\n", dfile); |
| 196 | 198 | ||
| 197 | //opens ROOT file |
199 | //opens ROOT file |
| 198 | //TFile *rootfile; |
200 | //TFile *rootfile; |
| Line 217... | Line 219... | ||
| 217 | int nint; |
219 | int nint; |
| 218 | int nb; |
220 | int nb; |
| 219 | int status; |
221 | int status; |
| 220 | 222 | ||
| 221 | while(1) { |
223 | while(1) { |
| 222 |
|
224 | //if(gzeof(dfp)) end_of_file = 1; |
| - | 225 | if(feof(dfp)) end_of_file = 1; |
|
| 223 | 226 | ||
| 224 | gzread |
227 | //gzread(dfp, (voidp)&readbuf, 2*ulsize); |
| - | 228 | fread((void*)&readbuf, 2*ulsize, 1, dfp); |
|
| 225 | rec_id=readbuf[0]; |
229 | rec_id=readbuf[0]; |
| 226 | rec_len=readbuf[1]; |
230 | rec_len=readbuf[1]; |
| 227 | 231 | ||
| 228 | 232 | ||
| 229 | if(dbg) printf("-----------------------------------------------\n"); |
233 | if(dbg) printf("-----------------------------------------------\n"); |
| 230 | if(dbg) printf("[%d] rec_id = %d | rec_len = %u\n", ceve, rec_id, rec_len); |
234 | if(dbg) printf("[%d] rec_id = %d | rec_len = %u\n", ceve, rec_id, rec_len); |
| 231 | 235 | ||
| 232 | switch(rec_id) |
236 | switch(rec_id) |
| 233 | { |
237 | { |
| 234 | case RUNREC_ID: |
238 | case RUNREC_ID: |
| 235 | gzread |
239 | //gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
| - | 240 | fread((void*)&readbuf[2], (rec_len-2*ulsize), 1, dfp); |
|
| 236 | runrec = (RUNREC*) readbuf; |
241 | runrec = (RUNREC*) readbuf; |
| 237 | run = *runrec; |
242 | run = *runrec; |
| 238 | 243 | ||
| 239 | if(dbg) { |
244 | if(dbg) { |
| 240 | printf("RUNREC_ID\n"); |
245 | printf("RUNREC_ID\n"); |
| Line 296... | Line 301... | ||
| 296 | } |
301 | } |
| 297 | 302 | ||
| 298 | break; |
303 | break; |
| 299 | 304 | ||
| 300 | case POSREC_ID: |
305 | case POSREC_ID: |
| 301 | gzread |
306 | //gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
| - | 307 | fread((void*)&readbuf[2], (rec_len-2*ulsize), 1, dfp); |
|
| 302 | posrec = (POSREC *) readbuf; |
308 | posrec = (POSREC *) readbuf; |
| 303 | pos=*posrec; |
309 | pos=*posrec; |
| 304 | 310 | ||
| 305 | if(dbg) { |
311 | if(dbg) { |
| 306 | printf("POSREC_ID\n"); |
312 | printf("POSREC_ID\n"); |
| Line 310... | Line 316... | ||
| 310 | } else printf(" [%d,%d] %d, %d\n", pos.ix, pos.iy, pos.xset, pos.yset); |
316 | } else printf(" [%d,%d] %d, %d\n", pos.ix, pos.iy, pos.xset, pos.yset); |
| 311 | 317 | ||
| 312 | break; |
318 | break; |
| 313 | 319 | ||
| 314 | case EVTREC_ID: |
320 | case EVTREC_ID: |
| 315 | gzread |
321 | //gzread(dfp, (voidp)&readbuf[2], ulsize); // last field of event record |
| - | 322 | fread((void*)&readbuf[2], ulsize, 1, dfp); |
|
| 316 | evtrec = (EVTREC *) readbuf; |
323 | evtrec = (EVTREC *) readbuf; |
| 317 | //evtrec->nev = buf[0]; |
324 | //evtrec->nev = buf[0]; |
| 318 | //if (rec_len < 0 || rec_len > 10000) { |
325 | //if (rec_len < 0 || rec_len > 10000) { |
| 319 | if (rec_len > READBUFFERLENGTH) { |
326 | if (rec_len > READBUFFERLENGTH) { |
| 320 | printf("Len %u\n", rec_len); |
327 | printf("Len %u\n", rec_len); |
| 321 | return(0); |
328 | return(0); |
| 322 | } |
329 | } |
| 323 | nb = rec_len - 3*ulsize; // no. of bytes to read |
330 | nb = rec_len - 3*ulsize; // no. of bytes to read |
| 324 | gzread |
331 | //gzread(dfp, (voidp)&buf, nb); |
| - | 332 | fread((void*)&buf, nb, 1, dfp); |
|
| 325 | 333 | ||
| 326 | if(dbg) { |
334 | if(dbg) { |
| 327 | printf("EVTREC_ID\n"); |
335 | printf("EVTREC_ID\n"); |
| 328 | printf("id = %d, len = %d, nev = %d\n", evtrec->id, evtrec->len, evtrec->nev); |
336 | printf("id = %d, len = %d, nev = %d\n", evtrec->id, evtrec->len, evtrec->nev); |
| 329 | //for(int datai = 0; datai < NCH; datai++) printf("%u ", evtrec->data[datai]); |
337 | //for(int datai = 0; datai < NCH; datai++) printf("%u ", evtrec->data[datai]); |
| Line 340... | Line 348... | ||
| 340 | int recid = buf[ii++]; |
348 | int recid = buf[ii++]; |
| 341 | int len = buf[ii++]; |
349 | int len = buf[ii++]; |
| 342 | if (dbg) printf("Buffer pointer %d\n", ii); |
350 | if (dbg) printf("Buffer pointer %d\n", ii); |
| 343 | unsigned int *dbuf = (unsigned int *)&buf[ii]; |
351 | unsigned int *dbuf = (unsigned int *)&buf[ii]; |
| 344 | //if (n%1000==0) |
352 | //if (n%1000==0) |
| 345 |
|
353 | if (dbg) printf("%d 0x%03x Len=%d\n",evtrec->nev,recid,len); |
| 346 | //unsigned short edge; |
354 | //unsigned short edge; |
| 347 | //int nhits; |
355 | //int nhits; |
| 348 |
|
356 | if (recid==0x140 || recid==0x141) { |
| 349 | for (int i=0; i<len; i++) { |
357 | for (int i=0; i<len; i++) { |
| 350 | int data = dbuf[i] & 0xFFFF ; |
358 | int data = dbuf[i] & 0xFFFF ; |
| 351 | int edge_type = (dbuf[i]>>16)&0x1 ; |
359 | int edge_type = (dbuf[i]>>16)&0x1 ; |
| 352 | int overflow = (dbuf[i]>>17)&0x1 ; |
360 | int overflow = (dbuf[i]>>17)&0x1 ; |
| 353 | int tdc_num = (dbuf[i]>>25)&0x1 ; |
361 | int tdc_num = (dbuf[i]>>25)&0x1 ; |
| Line 421... | Line 429... | ||
| 421 | } |
429 | } |
| 422 | } */ |
430 | } */ |
| 423 | break; |
431 | break; |
| 424 | 432 | ||
| 425 | case THRREC_ID: |
433 | case THRREC_ID: |
| 426 | status |
434 | //status = gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
| - | 435 | status = fread((void*)&readbuf[2], (rec_len-2*ulsize), 1, dfp); |
|
| 427 | thrrec = (THRREC*) readbuf; |
436 | thrrec = (THRREC*) readbuf; |
| 428 | thr = *thrrec; |
437 | thr = *thrrec; |
| 429 | if (dbg) printf("THRREC id = %d len = %d threshold %d\n", |
438 | if (dbg) printf("THRREC id = %d len = %d threshold %d\n", |
| 430 | thrrec->id, thrrec->len, thrrec->threshold); |
439 | thrrec->id, thrrec->len, thrrec->threshold); |
| 431 | break; |
440 | break; |
| 432 | 441 | ||
| 433 | case ENDREC_ID: |
442 | case ENDREC_ID: |
| 434 | gzread |
443 | //gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
| - | 444 | fread((void*)&readbuf[2], (rec_len-2*ulsize), 1, dfp); |
|
| 435 | endrec = (ENDREC *) readbuf; |
445 | endrec = (ENDREC *) readbuf; |
| 436 | 446 | ||
| 437 | if(dbg) { |
447 | if(dbg) { |
| 438 | printf("ENDREC_ID\n"); |
448 | printf("ENDREC_ID\n"); |
| 439 | printf("id = %d, len = %d, time = %d\n", endrec->id, endrec->len, endrec->time); |
449 | printf("id = %d, len = %d, time = %d\n", endrec->id, endrec->len, endrec->time); |
| Line 450... | Line 460... | ||
| 450 | case 2: |
460 | case 2: |
| 451 | sprintf(dfile, "./data/%s_file%02d.gz", dfile0, fcount); |
461 | sprintf(dfile, "./data/%s_file%02d.gz", dfile0, fcount); |
| 452 | break; |
462 | break; |
| 453 | } |
463 | } |
| 454 | 464 | ||
| 455 |
|
465 | //if(dfp) gzclose(dfp); |
| - | 466 | if(dfp) fclose(dfp); |
|
| 456 | 467 | ||
| 457 |
|
468 | //dfp=gzopen(dfile,"rb"); |
| - | 469 | dfp=fopen(dfile,"rb"); |
|
| 458 | if(!dfp) { |
470 | if(!dfp) { |
| 459 | printf(" Cannot open data file: %s ---> Exiting\n", dfile); |
471 | printf(" Cannot open data file: %s ---> Exiting\n", dfile); |
| 460 | end_of_file = 1; |
472 | end_of_file = 1; |
| 461 | } else { |
473 | } else { |
| 462 | printf(" Opened data file: %s\n", dfile); |
474 | printf(" Opened data file: %s\n", dfile); |
| Line 476... | Line 488... | ||
| 476 | //if(dbg) if( ceve>dbg ) break; |
488 | //if(dbg) if( ceve>dbg ) break; |
| 477 | if(end_of_file) break; |
489 | if(end_of_file) break; |
| 478 | } |
490 | } |
| 479 | 491 | ||
| 480 | if(dfp) { |
492 | if(dfp) { |
| 481 | gzclose |
493 | //gzclose(dfp); |
| - | 494 | fclose(dfp); |
|
| 482 |
|
495 | //delete dfp; |
| 483 | } |
496 | } |
| 484 | if(dbg) return 1; |
497 | if(dbg) return 1; |
| 485 | if(rootfile) { |
498 | if(rootfile) { |
| 486 | nt->Write(); |
499 | nt->Write(); |
| 487 | rootfile->Write(); |
500 | rootfile->Write(); |
| 488 | printf("Saved to %s\n", fnameroot); |
501 | printf("Saved to %s\n", fnameroot); |
| 489 | rootfile->Close(); |
502 | rootfile->Close(); |
| 490 |
|
503 | //delete rootfile; |
| 491 | } |
504 | } |
| 492 | 505 | ||
| 493 | return 1; |
506 | return 1; |
| 494 | } |
507 | } |
| 495 | 508 | ||