Rev 47 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 47 | Rev 50 | ||
---|---|---|---|
Line 101... | Line 101... | ||
101 | 101 | ||
102 | // ------------------------------------------------------------------------------ |
102 | // ------------------------------------------------------------------------------ |
103 | 103 | ||
104 | int analysisBias(char* dfile0="test", int dbg=0, double tdcCut=5.0) |
104 | int analysisBias(char* dfile0="test", int dbg=0, double tdcCut=5.0) |
105 | { |
105 | { |
106 | const double c_tdcOffset = |
106 | const double c_tdcOffset = 97*TDC_BIN; // ns, SiPM4 |
107 | 107 | ||
108 | printf(" Data to root conversion program\nUsage:\nd2r(input file name <without.dat>, debug on/off, TDC cut +-[ns])\n\n"); |
108 | printf(" Data to root conversion program\nUsage:\nd2r(input file name <without.dat>, debug on/off, TDC cut +-[ns])\n\n"); |
109 | 109 | ||
110 | char fullname[256]; |
110 | char fullname[256]; |
111 | char sbuff[256]; |
111 | char sbuff[256]; |
Line 184... | Line 184... | ||
184 | int ii; |
184 | int ii; |
185 | int nint; |
185 | int nint; |
186 | int nb; |
186 | int nb; |
187 | int status; |
187 | int status; |
188 | char hname[256]; |
188 | char hname[256]; |
- | 189 | // Full range TDC data for every channel |
|
189 | TH2F* htdc = new TH2F("htdc",";TDC channel;SiPM channel",512,-0.5,511.5,NCH,-0.5,NCH-0.5); |
190 | TH2F* htdc = new TH2F("htdc",";TDC channel;SiPM channel",512,-0.5,511.5,NCH,-0.5,NCH-0.5); |
- | 191 | // TDC data in specific time window |
|
190 | TH3F* h_correctedTDC = new TH3F("h_correctedTDC",";SiPM channel; ASD threshold [V]; t [ns]", |
192 | TH3F* h_correctedTDC = new TH3F("h_correctedTDC",";SiPM channel; ASD threshold [V]; t [ns]", |
191 | NCH, -0.5, NCH-0.5, |
193 | NCH, -0.5, NCH-0.5, |
192 | 101, 1.0, 2.0, |
194 | 101, 1.0, 2.0, |
193 | 33, -16.5*TDC_BIN, 16.5*TDC_BIN); |
195 | 33, -16.5*TDC_BIN, 16.5*TDC_BIN); |
- | 196 | // Hits distribution in every channel per stage position |
|
194 | TH1F* hnhitsx[NCH]; // move to 2d with (channel, position) |
197 | TH1F* hnhitsx[NCH]; // move to 2d with (channel, position) |
195 | TH1F* hnhitsy[NCH]; //-||- |
198 | TH1F* hnhitsy[NCH]; //-||- |
- | 199 | // 2d hits distribution |
|
196 | TH2F* h2d[NCH]; //-||- |
200 | TH2F* h2d[NCH]; //-||- |
- | 201 | int nBiasSteps = 20; |
|
- | 202 | double biasLow = 71.0; |
|
- | 203 | double biasUp = 73.0; |
|
197 | TH2F* h_bias = new TH2F("h_bias", "", 64, 0, 63, |
204 | TH2F* h_bias = new TH2F("h_bias", "", 64, 0, 63, nBiasSteps, biasLow, biasUp); |
- | 205 | int nSteps = 51; |
|
- | 206 | double thrLow = 1.0; |
|
- | 207 | double thrUp = 2.0; |
|
198 | TH2F* h_threshold = new TH2F("h_threshold",";SiPM ch;Threshold[V]", |
208 | TH2F* h_threshold = new TH2F("h_threshold",";SiPM ch;Threshold[V]", |
199 | 64,-0.5,63.5, |
209 | 64,-0.5,63.5, |
200 |
|
210 | nSteps, thrLow, thrUp); |
- | 211 | // Bias vs. ASD threshold per channel to estimate working point |
|
- | 212 | TH3F* h_biasThreshold = new TH3F("h_biasThreshold","", 64,-0.5, 63.5, |
|
- | 213 | 31, 71.0, 74.0, 51, 1.0, 2.0); |
|
201 | TH2F* h_ch33 = new TH2F("h_ch33","ch. 33;x;y",100,20000,30000,100,0,10000); |
214 | TH2F* h_ch33 = new TH2F("h_ch33","ch. 33;x;y",100,20000,30000,100,0,10000); |
202 | TNtuple* nt = new TNtuple("nt", "nt", "ch:x:y:tdc"); |
215 | TNtuple* nt = new TNtuple("nt", "nt", "ch:x:y:tdc"); |
203 | 216 | ||
204 | while(1) { |
217 | while(1) { |
205 | if(gzeof(dfp)) end_of_file = 1; |
218 | if(gzeof(dfp)) end_of_file = 1; |
Line 210... | Line 223... | ||
210 | 223 | ||
211 | 224 | ||
212 | if(dbg) printf("-----------------------------------------------\n"); |
225 | if(dbg) printf("-----------------------------------------------\n"); |
213 | if(dbg) printf("[%d] rec_id = %d | rec_len = %u\n", ceve, rec_id, rec_len); |
226 | if(dbg) printf("[%d] rec_id = %d | rec_len = %u\n", ceve, rec_id, rec_len); |
214 | 227 | ||
215 | int nSteps = 0; |
- | |
216 | int nBiasSteps = 0; |
- | |
- | 228 | ||
- | 229 | ||
217 | 230 | ||
218 | switch(rec_id) |
231 | switch(rec_id) |
219 | { |
232 | { |
220 | case RUNREC_ID: |
233 | case RUNREC_ID: |
221 | if (dbg) printf("RUNREC\n"); |
234 | if (dbg) printf("RUNREC\n"); |
Line 228... | Line 241... | ||
228 | printf("id = %d, len = %d, time = %d\n", run.id, run.len, run.time); |
241 | printf("id = %d, len = %d, time = %d\n", run.id, run.len, run.time); |
229 | printf("nev = %d, nch = %d\n", run.nev, run.nch); |
242 | printf("nev = %d, nch = %d\n", run.nev, run.nch); |
230 | printf("nx = %d, x0 = %d, dx = %d\n", run.nx, run.x0, run.dx); |
243 | printf("nx = %d, x0 = %d, dx = %d\n", run.nx, run.x0, run.dx); |
231 | printf("ny = %d, y0 = %d, dy = %d\n", run.ny, run.y0, run.dy); |
244 | printf("ny = %d, y0 = %d, dy = %d\n", run.ny, run.y0, run.dy); |
232 | printf("thLow = %d, thUp = %d, thStep = %d\n", run.thLow, run.thUp, run.thStep); |
245 | printf("thLow = %d, thUp = %d, thStep = %d\n", run.thLow, run.thUp, run.thStep); |
233 | } |
246 | } |
234 | 247 | ||
235 | //create histograms |
248 | //create histograms |
236 | //nt = (TNtuple*) gROOT->FindObject("nt"); |
249 | //nt = (TNtuple*) gROOT->FindObject("nt"); |
237 | //if (nt) delete nt; |
250 | //if (nt) delete nt; |
238 | 251 | ||
Line 278... | Line 291... | ||
278 | (run.x0 - OFFSETX - 0.5*run.dx)*MIKRO_BIN, |
291 | (run.x0 - OFFSETX - 0.5*run.dx)*MIKRO_BIN, |
279 | (run.x0 - OFFSETX + (run.nx-0.5)*run.dx)*MIKRO_BIN, |
292 | (run.x0 - OFFSETX + (run.nx-0.5)*run.dx)*MIKRO_BIN, |
280 | run.ny, |
293 | run.ny, |
281 | (run.y0 - OFFSETY - 0.5*run.dy)*MIKRO_BIN, |
294 | (run.y0 - OFFSETY - 0.5*run.dy)*MIKRO_BIN, |
282 | (run.y0 - OFFSETY + (run.ny-0.5)*run.dy)*MIKRO_BIN); |
295 | (run.y0 - OFFSETY + (run.ny-0.5)*run.dy)*MIKRO_BIN); |
283 | } |
296 | } |
284 | - | ||
285 | nBiasSteps = (run.biasUp - run.biasLow)/double(run.biasStep) + 1; |
- | |
286 | 297 | ||
- | 298 | nBiasSteps = (run.biasUp - run.biasLow)/double(run.biasStep) + 1; |
|
287 | h_correctedTDC = (TH3F*) gROOT->FindObject("h_correctedTDC"); |
299 | h_correctedTDC = (TH3F*) gROOT->FindObject("h_correctedTDC"); |
288 | if (h_correctedTDC) delete h_correctedTDC; |
300 | if (h_correctedTDC) delete h_correctedTDC; |
289 | nSteps = (run.thUp - run.thLow)/double(run.thStep) + 1; |
301 | nSteps = (run.thUp - run.thLow)/double(run.thStep) + 1; |
290 | if (dbg) printf("nSteps %d\n", nSteps); |
302 | if (dbg) printf("nSteps %d\n", nSteps); |
- | 303 | biasLow = (run.biasLow - 0.5*run.biasStep)/1000.0; |
|
- | 304 | biasUp = (run.biasUp + 0.5*run.biasStep)/1000.0; |
|
291 | h_correctedTDC = new TH3F("h_correctedTDC",";SiPM channel; ASD threshold [V]; t [ns]", |
305 | h_correctedTDC = new TH3F("h_correctedTDC",";SiPM channel; ASD threshold [V]; t [ns]", |
292 | NCH, |
- | |
293 | -0.5, |
- | |
294 | NCH-0.5, |
306 | NCH, -0.5, NCH-0.5, |
295 | nBiasSteps, |
307 | nBiasSteps, biasLow, biasUp, |
296 | (run.biasLow - 0.5*run.biasStep)/1000.0, |
- | |
297 | (run.biasUp + 0.5*run.biasStep)/1000.0, |
- | |
298 | 2*tdcCut+1, |
308 | 2*tdcCut+1, |
299 | -tdcCut*TDC_BIN - 0.5*TDC_BIN, |
309 | -tdcCut*TDC_BIN - 0.5*TDC_BIN, |
300 | tdcCut*TDC_BIN + 0.5*TDC_BIN); |
310 | tdcCut*TDC_BIN + 0.5*TDC_BIN); |
301 | 311 | ||
302 | h_bias = (TH2F*) gROOT->FindObject("h_bias"); |
312 | h_bias = (TH2F*) gROOT->FindObject("h_bias"); |
303 | if (h_bias) delete h_bias; |
313 | if (h_bias) delete h_bias; |
304 | h_bias = new TH2F("h_bias",";Channel; Bias [V]", 64, -0.5, 63.5, |
314 | h_bias = new TH2F("h_bias",";Channel; Bias [V]", 64, -0.5, 63.5, |
305 | nBiasSteps, |
315 | nBiasSteps, biasLow, biasUp); |
306 | (run.biasLow - 0.5*run.biasStep)/1000.0, |
- | |
307 | (run.biasUp + 0.5*run.biasStep)/1000.0); |
- | |
308 | - | ||
309 | 316 | ||
310 | if (h_threshold) delete h_threshold; |
317 | if (h_threshold) delete h_threshold; |
- | 318 | thrLow = (run.thLow - 0.5*run.thStep)/1000.0; |
|
- | 319 | thrUp = (run.thUp + 0.5*run.thStep)/1000.0; |
|
311 | h_threshold = new TH2F("h_threshold",";SiPM ch;Threshold[V]",64,-0.5,63.5, |
320 | h_threshold = new TH2F("h_threshold",";SiPM ch;Threshold[V]",64,-0.5,63.5, |
312 | nSteps, |
321 | nSteps, thrLow, thrUp); |
313 | (run.thLow - 0.5*run.thStep)/1000.0, |
- | |
314 | (run.thUp + 0.5*run.thStep)/1000.0); |
- | |
315 | 322 | ||
316 | //h_threshold = new TH2F("h_threshold","Threshold scan;SiPM ch;Threshold[mV]",64,-0.5,63.5, |
323 | //h_threshold = new TH2F("h_threshold","Threshold scan;SiPM ch;Threshold[mV]",64,-0.5,63.5, |
317 | // 101,995,2005); |
324 | // 101,995,2005); |
318 | 325 | ||
319 | if (h_ch33) delete h_ch33; |
326 | if (h_ch33) delete h_ch33; |
320 | h_ch33 = new TH2F("h_ch33","ch. 33;x;y",100,20000,30000,100,0,10000); |
327 | h_ch33 = new TH2F("h_ch33","ch. 33;x;y",100,20000,30000,100,0,10000); |
- | 328 | ||
- | 329 | h_biasThreshold = (TH3F*) gROOT->FindObject("h_biasThreshold"); |
|
- | 330 | if (h_biasThreshold) delete h_biasThreshold; |
|
- | 331 | h_biasThreshold = new TH3F("h_biasThreshold", ";Channel;Bias[V];Threshold[V]", |
|
- | 332 | 64, -0.5, 63.5, |
|
- | 333 | nBiasSteps, biasLow, biasUp, |
|
- | 334 | nSteps, thrLow, thrUp); |
|
321 | 335 | ||
322 | if (dbg) printf("RUNREC: all histos created.\n"); |
336 | if (dbg) printf("RUNREC: all histos created.\n"); |
323 | break; |
337 | break; |
324 | 338 | ||
325 | case POSREC_ID: |
339 | case POSREC_ID: |
326 | if (dbg) printf("POSREC\n"); |
340 | if (dbg) printf("POSREC\n"); |
327 | gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
341 | gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
328 | posrec = (POSREC *) readbuf; |
342 | posrec = (POSREC *) readbuf; |
329 | pos=*posrec; |
343 | pos=*posrec; |
330 | 344 | ||
331 | if(dbg) { |
345 | if(dbg) { |
332 | printf("POSREC_ID\n"); |
346 | printf("POSREC_ID\n"); |
333 | printf("id = %d, len = %d, time = %d\n", posrec->id, posrec->len, posrec->time); |
347 | printf("id = %d, len = %d, time = %d\n", posrec->id, posrec->len, posrec->time); |
334 | printf("ix = %d, x = %d, xset = %d\n", posrec->ix, posrec->x, posrec->xset); |
348 | printf("ix = %d, x = %d, xset = %d\n", posrec->ix, posrec->x, posrec->xset); |
335 | printf("iy = %d, y = %d, yset = %d\n", posrec->iy, posrec->y, posrec->yset); |
349 | printf("iy = %d, y = %d, yset = %d\n", posrec->iy, posrec->y, posrec->yset); |
336 | } else printf(" [%d,%d] %d, %d\n", pos.ix, pos.iy, pos.xset, pos.yset); |
350 | } else printf(" [%d,%d] %d, %d\n", pos.ix, pos.iy, pos.xset, pos.yset); |
Line 360... | Line 374... | ||
360 | } |
374 | } |
361 | 375 | ||
362 | nint = nb / ulsize; // no. of subrecords |
376 | nint = nb / ulsize; // no. of subrecords |
363 | if (dbg) printf("No. of subrecords %d \n", nint); |
377 | if (dbg) printf("No. of subrecords %d \n", nint); |
364 | ii=0; |
378 | ii=0; |
365 | while (ii<nint){ |
- | |
366 | int recid = buf[ii++]; |
- | |
367 | int len = buf[ii++]; |
- | |
368 | if (dbg) printf("Buffer pointer %d\n", ii); |
- | |
369 | unsigned int *dbuf = (unsigned int *)&buf[ii]; |
- | |
370 | //if (n%1000==0) |
- | |
371 | if (dbg) printf("%d 0x%03x Len=%d\n",evtrec->nev,recid,len); |
- | |
372 | //unsigned short edge; |
- | |
373 | //int nhits; |
- | |
374 | if (recid==0x140 || recid==0x141) { |
- | |
375 | for (int i=0; i<len; i++) { |
- | |
376 | int data = dbuf[i] & 0xFFFF ; |
- | |
377 | int edge_type = (dbuf[i]>>16)&0x1 ; |
- | |
378 | int overflow = (dbuf[i]>>17)&0x1 ; |
- | |
379 | int tdc_num = (dbuf[i]>>25)&0x1 ; |
- | |
380 | int channel = ((dbuf[i]>>18)&0x1F) | tdc_num<<5 ; |
- | |
381 | int ev_dat = (dbuf[i]>>23)&0x1 ; |
- | |
382 | int last_dat = (dbuf[i]>>30)&0x1 ; |
- | |
383 | int nval_dat = (dbuf[i]>>31)&0x1 ; |
- | |
384 | if (dbg){ |
- | |
385 | if (ev_dat) printf("Event %d\n",data); |
- | |
386 | else printf("ch=%d edge=%d ev=%d data=%d last=%d nval=%d\n", |
- | |
387 | channel, edge_type,ev_dat,data,last_dat,nval_dat); |
- | |
388 | } |
- | |
389 | if (!ev_dat){ |
- | |
390 | if (!edge_type && !overflow) { |
- | |
391 | htdc->Fill(data, channel); |
- | |
392 | if (dbg) printf("ch: %d tdc: %d\n", channel, data); |
- | |
393 | if (dbg) nt->Fill(channel, pos.ix, pos.iy, data); |
- | |
394 | double tdcmin = tdcOffset[channel] - tdcCut; |
- | |
395 | double tdcmax = tdcOffset[channel] + tdcCut; |
- | |
396 | double time = data*TDC_BIN - tdcOffset[channel]; |
- | |
397 | if(time >= -tdcCut and time <= tdcCut) { |
- | |
398 | h_correctedTDC->Fill(channel, bias.bias/1000.0, time); |
- | |
399 | hnhitsx[channel]->Fill((pos.xset - OFFSETX) * MIKRO_BIN); |
- | |
400 | hnhitsy[channel]->Fill((pos.yset - OFFSETY) * MIKRO_BIN); |
- | |
401 | h2d[channel]->Fill((pos.xset - OFFSETX) * MIKRO_BIN, (pos.yset - OFFSETY) * MIKRO_BIN); |
- | |
402 | 379 | ||
- | 380 | while (ii<nint){ |
|
- | 381 | int recid = buf[ii++]; |
|
- | 382 | int len = buf[ii++]; |
|
- | 383 | if (dbg) printf("Buffer pointer %d\n", ii); |
|
- | 384 | unsigned int *dbuf = (unsigned int *)&buf[ii]; |
|
- | 385 | //if (n%1000==0) |
|
- | 386 | if (dbg) printf("%d 0x%03x Len=%d\n",evtrec->nev,recid,len); |
|
- | 387 | //unsigned short edge; |
|
- | 388 | //int nhits; |
|
- | 389 | if (recid==0x140 || recid==0x141) { |
|
- | 390 | for (int i=0; i<len; i++) { |
|
- | 391 | int data = dbuf[i] & 0xFFFF ; |
|
- | 392 | int edge_type = (dbuf[i]>>16)&0x1 ; |
|
- | 393 | int overflow = (dbuf[i]>>17)&0x1 ; |
|
- | 394 | int tdc_num = (dbuf[i]>>25)&0x1 ; |
|
- | 395 | int channel = ((dbuf[i]>>18)&0x1F) | tdc_num<<5 ; |
|
- | 396 | int ev_dat = (dbuf[i]>>23)&0x1 ; |
|
- | 397 | int last_dat = (dbuf[i]>>30)&0x1 ; |
|
- | 398 | int nval_dat = (dbuf[i]>>31)&0x1 ; |
|
- | 399 | if (dbg){ |
|
- | 400 | if (ev_dat) printf("Event %d\n",data); |
|
- | 401 | else printf("ch=%d edge=%d ev=%d data=%d last=%d nval=%d\n", |
|
- | 402 | channel, edge_type,ev_dat,data,last_dat,nval_dat); |
|
- | 403 | } |
|
- | 404 | if (!ev_dat){ |
|
- | 405 | if (!edge_type && !overflow) { |
|
- | 406 | htdc->Fill(data, channel); |
|
- | 407 | if (dbg) printf("ch: %d tdc: %d\n", channel, data); |
|
- | 408 | if (dbg) nt->Fill(channel, pos.ix, pos.iy, data); |
|
- | 409 | //double tdcmin = tdcOffset[channel] - tdcCut; |
|
- | 410 | //double tdcmax = tdcOffset[channel] + tdcCut; |
|
- | 411 | double time = data*TDC_BIN - tdcOffset[channel]; |
|
- | 412 | h_biasThreshold->Fill(channel, bias.bias/1000.0, thr.threshold/1000.0); |
|
- | 413 | ||
- | 414 | if(time >= -tdcCut and time <= tdcCut) { |
|
- | 415 | h_correctedTDC->Fill(channel, bias.bias/1000.0, time); |
|
- | 416 | hnhitsx[channel]->Fill((pos.xset - OFFSETX) * MIKRO_BIN); |
|
- | 417 | hnhitsy[channel]->Fill((pos.yset - OFFSETY) * MIKRO_BIN); |
|
- | 418 | h2d[channel]->Fill((pos.xset - OFFSETX) * MIKRO_BIN, (pos.yset - OFFSETY) * MIKRO_BIN); |
|
- | 419 | ||
403 | if (position(pos.xset-OFFSETX, pos.yset-OFFSETY, channel)) { |
420 | if (position(pos.xset-OFFSETX, pos.yset-OFFSETY, channel)) { |
404 | h_ch33 |
421 | //h_ch33->Fill(pos.xset-OFFSETX, pos.yset-OFFSETY); |
405 | h_threshold->Fill(channel, thr.threshold/1000.0); |
422 | h_threshold->Fill(channel, thr.threshold/1000.0); |
406 | h_bias->Fill(channel, bias.bias/1000.0); |
423 | h_bias->Fill(channel, bias.bias/1000.0); |
407 | } |
424 | } |
- | 425 | ||
408 | } |
426 | } |
409 | //gV673A->Fill(data,channel); |
427 | //gV673A->Fill(data,channel); |
410 | //gsumV673A[channel/16]->Fill(data); |
428 | //gsumV673A[channel/16]->Fill(data); |
411 | } |
429 | } |
412 | } |
430 | } |
413 | if (last_dat) break; |
431 | if (last_dat) break; |
414 |
|
432 | } |
415 | } // if (recid== 0x140 || recid== 0x141) |
433 | } // if (recid== 0x140 || recid== 0x141) |
416 | ii += len; |
434 | ii += len; |
417 | } //while |
435 | } //while |
418 | 436 | ||
419 | break; |
437 | break; |
420 | 438 | ||
421 | case THRREC_ID: |
439 | case THRREC_ID: |
422 | status = gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
440 | status = gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |