103,7 → 103,7 |
|
int analysisBias(char* dfile0="test", int dbg=0, double tdcCut=5.0) |
{ |
const double c_tdcOffset = 372*TDC_BIN; // ns, SiPM4 |
const double c_tdcOffset = 97*TDC_BIN; // ns, SiPM4 |
|
printf(" Data to root conversion program\nUsage:\nd2r(input file name <without.dat>, debug on/off, TDC cut +-[ns])\n\n"); |
|
186,18 → 186,31 |
int nb; |
int status; |
char hname[256]; |
// Full range TDC data for every channel |
TH2F* htdc = new TH2F("htdc",";TDC channel;SiPM channel",512,-0.5,511.5,NCH,-0.5,NCH-0.5); |
TH3F* h_correctedTDC = new TH3F("h_correctedTDC",";SiPM channel; ASD threshold [V]; t [ns]", |
// TDC data in specific time window |
TH3F* h_correctedTDC = new TH3F("h_correctedTDC",";SiPM channel; ASD threshold [V]; t [ns]", |
NCH, -0.5, NCH-0.5, |
101, 1.0, 2.0, |
33, -16.5*TDC_BIN, 16.5*TDC_BIN); |
// Hits distribution in every channel per stage position |
TH1F* hnhitsx[NCH]; // move to 2d with (channel, position) |
TH1F* hnhitsy[NCH]; //-||- |
// 2d hits distribution |
TH2F* h2d[NCH]; //-||- |
TH2F* h_bias = new TH2F("h_bias", "", 64, 0, 63, 20, 71.0,73.0); |
int nBiasSteps = 20; |
double biasLow = 71.0; |
double biasUp = 73.0; |
TH2F* h_bias = new TH2F("h_bias", "", 64, 0, 63, nBiasSteps, biasLow, biasUp); |
int nSteps = 51; |
double thrLow = 1.0; |
double thrUp = 2.0; |
TH2F* h_threshold = new TH2F("h_threshold",";SiPM ch;Threshold[V]", |
64,-0.5,63.5, |
101, 1.0, 2.0); |
nSteps, thrLow, thrUp); |
// Bias vs. ASD threshold per channel to estimate working point |
TH3F* h_biasThreshold = new TH3F("h_biasThreshold","", 64,-0.5, 63.5, |
31, 71.0, 74.0, 51, 1.0, 2.0); |
TH2F* h_ch33 = new TH2F("h_ch33","ch. 33;x;y",100,20000,30000,100,0,10000); |
TNtuple* nt = new TNtuple("nt", "nt", "ch:x:y:tdc"); |
|
212,8 → 225,8 |
if(dbg) printf("-----------------------------------------------\n"); |
if(dbg) printf("[%d] rec_id = %d | rec_len = %u\n", ceve, rec_id, rec_len); |
|
int nSteps = 0; |
int nBiasSteps = 0; |
|
|
|
switch(rec_id) |
{ |
283,18 → 296,15 |
} |
|
nBiasSteps = (run.biasUp - run.biasLow)/double(run.biasStep) + 1; |
|
h_correctedTDC = (TH3F*) gROOT->FindObject("h_correctedTDC"); |
if (h_correctedTDC) delete h_correctedTDC; |
nSteps = (run.thUp - run.thLow)/double(run.thStep) + 1; |
if (dbg) printf("nSteps %d\n", nSteps); |
biasLow = (run.biasLow - 0.5*run.biasStep)/1000.0; |
biasUp = (run.biasUp + 0.5*run.biasStep)/1000.0; |
h_correctedTDC = new TH3F("h_correctedTDC",";SiPM channel; ASD threshold [V]; t [ns]", |
NCH, |
-0.5, |
NCH-0.5, |
nBiasSteps, |
(run.biasLow - 0.5*run.biasStep)/1000.0, |
(run.biasUp + 0.5*run.biasStep)/1000.0, |
NCH, -0.5, NCH-0.5, |
nBiasSteps, biasLow, biasUp, |
2*tdcCut+1, |
-tdcCut*TDC_BIN - 0.5*TDC_BIN, |
tdcCut*TDC_BIN + 0.5*TDC_BIN); |
302,16 → 312,13 |
h_bias = (TH2F*) gROOT->FindObject("h_bias"); |
if (h_bias) delete h_bias; |
h_bias = new TH2F("h_bias",";Channel; Bias [V]", 64, -0.5, 63.5, |
nBiasSteps, |
(run.biasLow - 0.5*run.biasStep)/1000.0, |
(run.biasUp + 0.5*run.biasStep)/1000.0); |
|
nBiasSteps, biasLow, biasUp); |
|
if (h_threshold) delete h_threshold; |
thrLow = (run.thLow - 0.5*run.thStep)/1000.0; |
thrUp = (run.thUp + 0.5*run.thStep)/1000.0; |
h_threshold = new TH2F("h_threshold",";SiPM ch;Threshold[V]",64,-0.5,63.5, |
nSteps, |
(run.thLow - 0.5*run.thStep)/1000.0, |
(run.thUp + 0.5*run.thStep)/1000.0); |
nSteps, thrLow, thrUp); |
|
//h_threshold = new TH2F("h_threshold","Threshold scan;SiPM ch;Threshold[mV]",64,-0.5,63.5, |
// 101,995,2005); |
319,6 → 326,13 |
if (h_ch33) delete h_ch33; |
h_ch33 = new TH2F("h_ch33","ch. 33;x;y",100,20000,30000,100,0,10000); |
|
h_biasThreshold = (TH3F*) gROOT->FindObject("h_biasThreshold"); |
if (h_biasThreshold) delete h_biasThreshold; |
h_biasThreshold = new TH3F("h_biasThreshold", ";Channel;Bias[V];Threshold[V]", |
64, -0.5, 63.5, |
nBiasSteps, biasLow, biasUp, |
nSteps, thrLow, thrUp); |
|
if (dbg) printf("RUNREC: all histos created.\n"); |
break; |
|
362,60 → 376,64 |
nint = nb / ulsize; // no. of subrecords |
if (dbg) printf("No. of subrecords %d \n", nint); |
ii=0; |
while (ii<nint){ |
int recid = buf[ii++]; |
int len = buf[ii++]; |
if (dbg) printf("Buffer pointer %d\n", ii); |
unsigned int *dbuf = (unsigned int *)&buf[ii]; |
//if (n%1000==0) |
if (dbg) printf("%d 0x%03x Len=%d\n",evtrec->nev,recid,len); |
//unsigned short edge; |
//int nhits; |
if (recid==0x140 || recid==0x141) { |
for (int i=0; i<len; i++) { |
int data = dbuf[i] & 0xFFFF ; |
int edge_type = (dbuf[i]>>16)&0x1 ; |
int overflow = (dbuf[i]>>17)&0x1 ; |
int tdc_num = (dbuf[i]>>25)&0x1 ; |
int channel = ((dbuf[i]>>18)&0x1F) | tdc_num<<5 ; |
int ev_dat = (dbuf[i]>>23)&0x1 ; |
int last_dat = (dbuf[i]>>30)&0x1 ; |
int nval_dat = (dbuf[i]>>31)&0x1 ; |
if (dbg){ |
if (ev_dat) printf("Event %d\n",data); |
else printf("ch=%d edge=%d ev=%d data=%d last=%d nval=%d\n", |
channel, edge_type,ev_dat,data,last_dat,nval_dat); |
} |
if (!ev_dat){ |
if (!edge_type && !overflow) { |
htdc->Fill(data, channel); |
if (dbg) printf("ch: %d tdc: %d\n", channel, data); |
if (dbg) nt->Fill(channel, pos.ix, pos.iy, data); |
double tdcmin = tdcOffset[channel] - tdcCut; |
double tdcmax = tdcOffset[channel] + tdcCut; |
double time = data*TDC_BIN - tdcOffset[channel]; |
if(time >= -tdcCut and time <= tdcCut) { |
h_correctedTDC->Fill(channel, bias.bias/1000.0, time); |
hnhitsx[channel]->Fill((pos.xset - OFFSETX) * MIKRO_BIN); |
hnhitsy[channel]->Fill((pos.yset - OFFSETY) * MIKRO_BIN); |
h2d[channel]->Fill((pos.xset - OFFSETX) * MIKRO_BIN, (pos.yset - OFFSETY) * MIKRO_BIN); |
|
if (position(pos.xset-OFFSETX, pos.yset-OFFSETY, channel)) { |
h_ch33->Fill(pos.xset-OFFSETX, pos.yset-OFFSETY); |
h_threshold->Fill(channel, thr.threshold/1000.0); |
h_bias->Fill(channel, bias.bias/1000.0); |
} |
} |
//gV673A->Fill(data,channel); |
//gsumV673A[channel/16]->Fill(data); |
} |
} |
if (last_dat) break; |
} |
} // if (recid== 0x140 || recid== 0x141) |
ii += len; |
} //while |
while (ii<nint){ |
int recid = buf[ii++]; |
int len = buf[ii++]; |
if (dbg) printf("Buffer pointer %d\n", ii); |
unsigned int *dbuf = (unsigned int *)&buf[ii]; |
//if (n%1000==0) |
if (dbg) printf("%d 0x%03x Len=%d\n",evtrec->nev,recid,len); |
//unsigned short edge; |
//int nhits; |
if (recid==0x140 || recid==0x141) { |
for (int i=0; i<len; i++) { |
int data = dbuf[i] & 0xFFFF ; |
int edge_type = (dbuf[i]>>16)&0x1 ; |
int overflow = (dbuf[i]>>17)&0x1 ; |
int tdc_num = (dbuf[i]>>25)&0x1 ; |
int channel = ((dbuf[i]>>18)&0x1F) | tdc_num<<5 ; |
int ev_dat = (dbuf[i]>>23)&0x1 ; |
int last_dat = (dbuf[i]>>30)&0x1 ; |
int nval_dat = (dbuf[i]>>31)&0x1 ; |
if (dbg){ |
if (ev_dat) printf("Event %d\n",data); |
else printf("ch=%d edge=%d ev=%d data=%d last=%d nval=%d\n", |
channel, edge_type,ev_dat,data,last_dat,nval_dat); |
} |
if (!ev_dat){ |
if (!edge_type && !overflow) { |
htdc->Fill(data, channel); |
if (dbg) printf("ch: %d tdc: %d\n", channel, data); |
if (dbg) nt->Fill(channel, pos.ix, pos.iy, data); |
//double tdcmin = tdcOffset[channel] - tdcCut; |
//double tdcmax = tdcOffset[channel] + tdcCut; |
double time = data*TDC_BIN - tdcOffset[channel]; |
h_biasThreshold->Fill(channel, bias.bias/1000.0, thr.threshold/1000.0); |
|
if(time >= -tdcCut and time <= tdcCut) { |
h_correctedTDC->Fill(channel, bias.bias/1000.0, time); |
hnhitsx[channel]->Fill((pos.xset - OFFSETX) * MIKRO_BIN); |
hnhitsy[channel]->Fill((pos.yset - OFFSETY) * MIKRO_BIN); |
h2d[channel]->Fill((pos.xset - OFFSETX) * MIKRO_BIN, (pos.yset - OFFSETY) * MIKRO_BIN); |
|
if (position(pos.xset-OFFSETX, pos.yset-OFFSETY, channel)) { |
//h_ch33->Fill(pos.xset-OFFSETX, pos.yset-OFFSETY); |
h_threshold->Fill(channel, thr.threshold/1000.0); |
h_bias->Fill(channel, bias.bias/1000.0); |
} |
|
} |
//gV673A->Fill(data,channel); |
//gsumV673A[channel/16]->Fill(data); |
} |
} |
if (last_dat) break; |
} |
} // if (recid== 0x140 || recid== 0x141) |
ii += len; |
} //while |
|
break; |
|
case THRREC_ID: |