Rev 40 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 40 | Rev 102 | ||
---|---|---|---|
Line 17... | Line 17... | ||
17 | #include "TF1.h" |
17 | #include "TF1.h" |
18 | #include "TMath.h" |
18 | #include "TMath.h" |
19 | #include "TStyle.h" |
19 | #include "TStyle.h" |
20 | #include "TCanvas.h" |
20 | #include "TCanvas.h" |
21 | #include "TLine.h" |
21 | #include "TLine.h" |
22 |
|
22 | //#include "zlib.h" |
23 | 23 | ||
24 | // ------------------------------------------------------------------------------ |
24 | // ------------------------------------------------------------------------------ |
25 | 25 | ||
26 | #define POSMARG 1000 |
26 | #define POSMARG 1000 |
27 | 27 | ||
Line 91... | Line 91... | ||
91 | 91 | ||
92 | // ------------------------------------------------------------------------------ |
92 | // ------------------------------------------------------------------------------ |
93 | 93 | ||
94 | int analysisThreshold(char* dfile0="test", int dbg=0, double tdcCut=5.0) |
94 | int analysisThreshold(char* dfile0="test", int dbg=0, double tdcCut=5.0) |
95 | { |
95 | { |
96 | const double c_tdcOffset = |
96 | const double c_tdcOffset = 93*TDC_BIN; // ns |
97 | 97 | ||
98 | printf(" Data to root conversion program\nUsage:\nd2r(input file name <without.dat>, debug on/off, TDC cut +-[ns])\n\n"); |
98 | printf(" Data to root conversion program\nUsage:\nd2r(input file name <without.dat>, debug on/off, TDC cut +-[ns])\n\n"); |
99 | 99 | ||
100 | char fullname[256]; |
100 | char fullname[256]; |
101 | char sbuff[256]; |
101 | char sbuff[256]; |
Line 127... | Line 127... | ||
127 | //data buffer |
127 | //data buffer |
128 | unsigned int readbuf[READBUFFERLENGTH]; |
128 | unsigned int readbuf[READBUFFERLENGTH]; |
129 | unsigned int buf[READBUFFERLENGTH]; |
129 | unsigned int buf[READBUFFERLENGTH]; |
130 | 130 | ||
131 | //data file |
131 | //data file |
132 | gzFile dfp |
132 | //gzFile dfp; |
- | 133 | FILE *dfp; |
|
133 | char dfile[256]; |
134 | char dfile[256]; |
134 | int ftype=0; |
135 | int ftype=0; |
135 | int fcount=1; |
136 | int fcount=1; |
136 | do { |
137 | do { |
137 | switch(ftype++) { |
138 | switch(ftype++) { |
138 | case 0: |
139 | case 0: |
139 | sprintf(dfile, " |
140 | sprintf(dfile, "E:/data/%s_file%02d.dat", dfile0, fcount); |
140 | break; |
141 | break; |
141 | case 1: |
142 | case 1: |
142 | sprintf(dfile, " |
143 | sprintf(dfile, "E:/data/%s_file%02d.dat.gz", dfile0, fcount); |
143 | break; |
144 | break; |
144 | case 2: |
145 | case 2: |
145 | sprintf(dfile, " |
146 | sprintf(dfile, "E:/data/%s_file%02d.gz", dfile0, fcount); |
146 | break; |
147 | break; |
147 | default: |
148 | default: |
148 | printf(" Cannot find data file for %s !!!\n", dfile0); |
149 | printf(" Cannot find data file for %s !!!\n", dfile0); |
149 | return -1; |
150 | return -1; |
150 | } |
151 | } |
151 |
|
152 | //dfp=gzopen(dfile,"rb"); |
- | 153 | dfp=fopen(dfile,"rb"); |
|
152 | } while(!dfp); |
154 | } while(!dfp); |
153 | printf("Opened data file %s\n", dfile); |
155 | printf("Opened data file %s\n", dfile); |
154 | 156 | ||
155 | //opens ROOT file |
157 | //opens ROOT file |
156 | char fnameroot[256]; |
158 | char fnameroot[256]; |
Line 175... | Line 177... | ||
175 | int nint; |
177 | int nint; |
176 | int nb; |
178 | int nb; |
177 | int status; |
179 | int status; |
178 | char hname[256]; |
180 | char hname[256]; |
179 | TH2F* htdc = new TH2F("htdc",";TDC channel;SiPM channel",512,-0.5,511.5,NCH,-0.5,NCH-0.5); |
181 | TH2F* htdc = new TH2F("htdc",";TDC channel;SiPM channel",512,-0.5,511.5,NCH,-0.5,NCH-0.5); |
180 |
|
182 | TH2F* h_correctedTDC = new TH2F("h_correctedTDC",";SiPM channel; t [ns]", |
181 | NCH, -0.5, NCH-0.5, |
183 | NCH, -0.5, NCH-0.5, |
182 | 101, 1.0, 2.0, |
- | |
183 | 33, -16.5*TDC_BIN, 16.5*TDC_BIN); |
184 | 33, -16.5*TDC_BIN, 16.5*TDC_BIN); |
184 | TH1F* hnhitsx[NCH]; // move to 2d with (channel, position) |
185 | TH1F* hnhitsx[NCH]; // move to 2d with (channel, position) |
185 | TH1F* hnhitsy[NCH]; //-||- |
186 | TH1F* hnhitsy[NCH]; //-||- |
186 | TH2F* h2d[NCH]; //-||- |
187 | TH2F* h2d[NCH]; //-||- |
187 | TH2F* h_threshold = new TH2F("h_threshold",";SiPM ch;Threshold[V]", |
188 | TH2F* h_threshold = new TH2F("h_threshold",";SiPM ch;Threshold[V]", |
Line 189... | Line 190... | ||
189 | 101, 1.0, 2.0); |
190 | 101, 1.0, 2.0); |
190 | TH2F* h_ch33 = new TH2F("h_ch33","ch. 33;x;y",100,20000,30000,100,0,10000); |
191 | 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 | TNtuple* nt = new TNtuple("nt", "nt", "ch:x:y:tdc"); |
192 | 193 | ||
193 | while(1) { |
194 | while(1) { |
194 |
|
195 | //if(gzeof(dfp)) end_of_file = 1; |
- | 196 | if(feof(dfp)) end_of_file = 1; |
|
195 | 197 | ||
196 | gzread |
198 | //gzread(dfp, (voidp)&readbuf, 2*ulsize); |
- | 199 | fread((void*)&readbuf, 2*ulsize, 1, dfp); |
|
197 | rec_id=readbuf[0]; |
200 | rec_id=readbuf[0]; |
198 | rec_len=readbuf[1]; |
201 | rec_len=readbuf[1]; |
199 | 202 | ||
200 | 203 | ||
201 | if(dbg) printf("-----------------------------------------------\n"); |
204 | if(dbg) printf("-----------------------------------------------\n"); |
Line 204... | Line 207... | ||
204 | double nSteps = 0; |
207 | double nSteps = 0; |
205 | switch(rec_id) |
208 | switch(rec_id) |
206 | { |
209 | { |
207 | case RUNREC_ID: |
210 | case RUNREC_ID: |
208 | if (dbg) printf("RUNREC\n"); |
211 | if (dbg) printf("RUNREC\n"); |
209 | gzread |
212 | //gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
- | 213 | fread((void*)&readbuf[2], (rec_len-2*ulsize), 1, dfp); |
|
210 | runrec = (RUNREC *) readbuf; |
214 | runrec = (RUNREC *) readbuf; |
211 | run=*runrec; |
215 | run=*runrec; |
212 | 216 | ||
213 | if(dbg) { |
217 | if(dbg) { |
214 | printf("RUNREC_ID\n"); |
218 | printf("RUNREC_ID\n"); |
Line 225... | Line 229... | ||
225 | 229 | ||
226 | //sprintf(hname, "htdc"); |
230 | //sprintf(hname, "htdc"); |
227 | //htdc = (TH2F*) gROOT->FindObject(hname); |
231 | //htdc = (TH2F*) gROOT->FindObject(hname); |
228 | //if (htdc) delete htdc; |
232 | //if (htdc) delete htdc; |
229 | //htdc = new TH2F("htdc",";TDC channel;SiPM channel",512,0,512,NCH,0,NCH); |
233 | //htdc = new TH2F("htdc",";TDC channel;SiPM channel",512,0,512,NCH,0,NCH); |
230 | h_correctedTDC = ( |
234 | h_correctedTDC = (TH2F*) gROOT->FindObject("h_correctedTDC"); |
231 | if (h_correctedTDC) delete h_correctedTDC; |
235 | if (h_correctedTDC) delete h_correctedTDC; |
232 | nSteps = (run.thUp - run.thLow)/double(run.thStep) + 1; |
236 | nSteps = (run.thUp - run.thLow)/double(run.thStep) + 1; |
233 | if (dbg) printf("nSteps %f\n", nSteps); |
237 | if (dbg) printf("nSteps %f\n", nSteps); |
234 | h_correctedTDC = new |
238 | h_correctedTDC = new TH2F("h_correctedTDC",";SiPM channel; t [ns]", |
235 | NCH, |
239 | NCH, |
236 | -0.5, |
240 | -0.5, |
237 | NCH-0.5, |
241 | 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+1, |
242 | 2*tdcCut+1, |
242 | (-tdcCut - 0.5)*TDC_BIN, |
243 | (-tdcCut - 0.5)*TDC_BIN, |
243 | (tdcCut + 0.5)*TDC_BIN); |
244 | (tdcCut + 0.5)*TDC_BIN); |
244 | //TH1F* gsumV673A[NCH/16] = new TH1F(hn,hname,256,-0.5,255.5); |
245 | //TH1F* gsumV673A[NCH/16] = new TH1F(hn,hname,256,-0.5,255.5); |
245 | for(int i=0; i<NCH; i++) { |
246 | for(int i=0; i<NCH; i++) { |
Line 297... | Line 298... | ||
297 | if (dbg) printf("RUNREC: all histos created.\n"); |
298 | if (dbg) printf("RUNREC: all histos created.\n"); |
298 | break; |
299 | break; |
299 | 300 | ||
300 | case POSREC_ID: |
301 | case POSREC_ID: |
301 | if (dbg) printf("POSREC\n"); |
302 | if (dbg) printf("POSREC\n"); |
302 | gzread |
303 | //gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
- | 304 | fread((void*)&readbuf[2], (rec_len-2*ulsize), 1, dfp); |
|
303 | posrec = (POSREC *) readbuf; |
305 | posrec = (POSREC *) readbuf; |
304 | pos=*posrec; |
306 | pos=*posrec; |
305 | 307 | ||
306 | if(dbg) { |
308 | if(dbg) { |
307 | printf("POSREC_ID\n"); |
309 | printf("POSREC_ID\n"); |
Line 311... | Line 313... | ||
311 | } else printf(" [%d,%d] %d, %d\n", pos.ix, pos.iy, pos.xset, pos.yset); |
313 | } else printf(" [%d,%d] %d, %d\n", pos.ix, pos.iy, pos.xset, pos.yset); |
312 | 314 | ||
313 | break; |
315 | break; |
314 | 316 | ||
315 | case EVTREC_ID: |
317 | case EVTREC_ID: |
316 | gzread |
318 | //gzread(dfp, (voidp)&readbuf[2], ulsize); // last field of event record |
- | 319 | fread((void*)&readbuf[2], ulsize, 1, dfp); |
|
317 | evtrec = (EVTREC *) readbuf; |
320 | evtrec = (EVTREC *) readbuf; |
318 | //evtrec->nev = buf[0]; |
321 | //evtrec->nev = buf[0]; |
319 | //if (rec_len < 0 || rec_len > 10000) { |
322 | //if (rec_len < 0 || rec_len > 10000) { |
320 | if (rec_len > READBUFFERLENGTH) { |
323 | if (rec_len > READBUFFERLENGTH) { |
321 | printf("Len %u\n", rec_len); |
324 | printf("Len %u\n", rec_len); |
322 | return(1); |
325 | return(1); |
323 | } |
326 | } |
324 | nb = rec_len - 3*ulsize; // no. of bytes to read |
327 | nb = rec_len - 3*ulsize; // no. of bytes to read |
325 | gzread |
328 | //gzread(dfp, (voidp)&buf, nb); |
- | 329 | fread((void*)&buf, nb, 1, dfp); |
|
326 | 330 | ||
327 | if(dbg) { |
331 | if(dbg) { |
328 | printf("EVTREC_ID\n"); |
332 | printf("EVTREC_ID\n"); |
329 | printf("id = %d, len = %d, nev = %d\n", evtrec->id, evtrec->len, evtrec->nev); |
333 | 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]); |
334 | //for(int datai = 0; datai < NCH; datai++) printf("%u ", evtrec->data[datai]); |
Line 368... | Line 372... | ||
368 | if (dbg) nt->Fill(channel, pos.ix, pos.iy, data); |
372 | if (dbg) nt->Fill(channel, pos.ix, pos.iy, data); |
369 | double tdcmin = tdcOffset[channel] - tdcCut; |
373 | double tdcmin = tdcOffset[channel] - tdcCut; |
370 | double tdcmax = tdcOffset[channel] + tdcCut; |
374 | double tdcmax = tdcOffset[channel] + tdcCut; |
371 | double time = data*TDC_BIN - tdcOffset[channel]; |
375 | double time = data*TDC_BIN - tdcOffset[channel]; |
372 | if((time >= -tdcCut) && (time <= tdcCut)) { |
376 | if((time >= -tdcCut) && (time <= tdcCut)) { |
373 | h_correctedTDC->Fill(channel, |
377 | h_correctedTDC->Fill(channel, time); |
374 | hnhitsx[channel]->Fill((pos.xset - OFFSETX) * MIKRO_BIN); |
378 | hnhitsx[channel]->Fill((pos.xset - OFFSETX) * MIKRO_BIN); |
375 | hnhitsy[channel]->Fill((pos.yset - OFFSETY) * MIKRO_BIN); |
379 | hnhitsy[channel]->Fill((pos.yset - OFFSETY) * MIKRO_BIN); |
376 | h2d[channel]->Fill((pos.xset - OFFSETX) * MIKRO_BIN, (pos.yset - OFFSETY) * MIKRO_BIN); |
380 | h2d[channel]->Fill((pos.xset - OFFSETX) * MIKRO_BIN, (pos.yset - OFFSETY) * MIKRO_BIN); |
377 | 381 | ||
378 |
|
382 | //if (position(pos.xset-OFFSETX, pos.yset-OFFSETY, channel)) { |
379 | h_ch33->Fill(pos.xset-OFFSETX, pos.yset-OFFSETY); |
383 | h_ch33->Fill(pos.xset-OFFSETX, pos.yset-OFFSETY); |
380 | h_threshold->Fill(channel, thr.threshold/1000.0); |
384 | h_threshold->Fill(channel, thr.threshold/1000.0); |
381 |
|
385 | //} |
382 | } |
386 | } |
383 | //gV673A->Fill(data,channel); |
387 | //gV673A->Fill(data,channel); |
384 | //gsumV673A[channel/16]->Fill(data); |
388 | //gsumV673A[channel/16]->Fill(data); |
385 | } |
389 | } |
386 | } |
390 | } |
Line 391... | Line 395... | ||
391 | } //while |
395 | } //while |
392 | 396 | ||
393 | break; |
397 | break; |
394 | 398 | ||
395 | case THRREC_ID: |
399 | case THRREC_ID: |
396 | status |
400 | //status = gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
- | 401 | status = fread((void*)&readbuf[2], (rec_len-2*ulsize), 1, dfp); |
|
397 | thrrec = (THRREC*) readbuf; |
402 | thrrec = (THRREC*) readbuf; |
398 | thr = *thrrec; |
403 | thr = *thrrec; |
399 | if (dbg) printf("THRREC id = %d len = %d threshold %d\n", |
404 | if (dbg) printf("THRREC id = %d len = %d threshold %d\n", |
400 | thrrec->id, thrrec->len, thrrec->threshold); |
405 | thrrec->id, thrrec->len, thrrec->threshold); |
401 | break; |
406 | break; |
402 | 407 | ||
403 | case ENDREC_ID: |
408 | case ENDREC_ID: |
404 | gzread |
409 | //gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
- | 410 | fread((void*)&readbuf[2], (rec_len-2*ulsize), 1, dfp); |
|
405 | endrec = (ENDREC *) readbuf; |
411 | endrec = (ENDREC *) readbuf; |
406 | 412 | ||
407 | if(dbg) { |
413 | if(dbg) { |
408 | printf("ENDREC_ID\n"); |
414 | printf("ENDREC_ID\n"); |
409 | printf("id = %d, len = %d, time = %d\n", endrec->id, endrec->len, endrec->time); |
415 | printf("id = %d, len = %d, time = %d\n", endrec->id, endrec->len, endrec->time); |
410 | } else printf(" ENDREC\n"); |
416 | } else printf(" ENDREC\n"); |
411 | 417 | ||
412 | fcount++; |
418 | fcount++; |
413 | switch(ftype-1) { |
419 | switch(ftype-1) { |
414 | case 0: |
420 | case 0: |
415 | sprintf(dfile, " |
421 | sprintf(dfile, "E:/data/%s_file%02d.dat", dfile0, fcount); |
416 | break; |
422 | break; |
417 | case 1: |
423 | case 1: |
418 | sprintf(dfile, " |
424 | sprintf(dfile, "E:/data/%s_file%02d.dat.gz", dfile0, fcount); |
419 | break; |
425 | break; |
420 | case 2: |
426 | case 2: |
421 | sprintf(dfile, " |
427 | sprintf(dfile, "E:/data/%s_file%02d.gz", dfile0, fcount); |
422 | break; |
428 | break; |
423 | } |
429 | } |
424 | 430 | ||
425 |
|
431 | //if(dfp) gzclose(dfp); |
- | 432 | if(dfp) fclose(dfp); |
|
426 | 433 | ||
427 |
|
434 | //dfp=gzopen(dfile,"rb"); |
- | 435 | dfp=fopen(dfile,"rb"); |
|
428 | if(!dfp) { |
436 | if(!dfp) { |
429 | printf(" Cannot open data file: %s ---> Exiting\n", dfile); |
437 | printf(" Cannot open data file: %s ---> Exiting\n", dfile); |
430 | end_of_file = 1; |
438 | end_of_file = 1; |
431 | } else { |
439 | } else { |
432 | printf(" Opened data file: %s\n", dfile); |
440 | printf(" Opened data file: %s\n", dfile); |
Line 446... | Line 454... | ||
446 | //if(dbg) if( ceve>dbg ) break; |
454 | //if(dbg) if( ceve>dbg ) break; |
447 | if (end_of_file) break; |
455 | if (end_of_file) break; |
448 | } |
456 | } |
449 | 457 | ||
450 | if(dfp) { |
458 | if(dfp) { |
451 | gzclose |
459 | //gzclose(dfp); |
- | 460 | fclose(dfp); |
|
452 | //delete dfp; |
461 | //delete dfp; |
453 | } |
462 | } |
454 | //if(dbg) return 0; |
463 | //if(dbg) return 0; |
455 | if(rootfile.IsOpen()) { |
464 | if(rootfile.IsOpen()) { |
456 | nt->Write(); |
465 | nt->Write(); |