11,9 → 11,9 |
#define DATA_PATH "./data/" |
#define CFRAC 0.4 |
#define DWIDTH 1024 |
void drs(int nev=1000, int updfrq=20, const char *FileName="./data/x1.dat", int trgch=0, int debug=0) |
void drs(int nev=1000, int updfrq=20, const char *FileName="drs000.dat", int trgch=0, int debug=0) |
{ |
int i,j,ich,iev; |
int i,ich,iev; |
int stat; |
char histname[128]; |
// char FileName[300]="./data/n2.dat"; |
21,24 → 21,31 |
|
char recid[5]="SAMO"; |
unsigned short *srecid = (unsigned short *) &recid[0]; |
unsigned int * irecid; |
|
struct evrec { |
unsigned long evn; |
unsigned short tYear,tMonth,tDay,tHour,tMin,tSec,tmSec,reserved; |
unsigned short tYear,tMonth,tDay,tHour,tMin,tSec,tmSec,rc; |
} evrec; |
|
float dtdata[4][DWIDTH]; |
float tcdata[4][DWIDTH]; |
float tccalib[4]; |
float scaler[4]; |
float *t; |
float *y; |
float *ay; |
|
short lwfm[4]; |
int nwfm[4]; |
int board; |
int version; |
|
// int imin[4]={250,250,250,250}; |
// int imax[4]={750,750,750,750}; |
|
unsigned short ichdat[4][DWIDTH]; |
float chdat[4][DWIDTH],achdat[4][DWIDTH],chmax[4][2],chmin[4][2]; |
float chdat[4][DWIDTH]; |
float achdat[4][DWIDTH]; |
float chmax[4][2]; |
float chmin[4][2]; |
float letime[4][2],cftime[4][2],qdc[4]; |
// float threshold[4][2]={{0.,-0.02},{0.,0.},{0.,0.},{0.,-0.25}}; |
// float twin[4][2]={{120.,130.},{100.,150.},{100.,150.},{70.,90.}}; |
46,10 → 53,10 |
// float threshold[4][2]={{0.,-0.05},{0.,-0.05},{0.,-0.25},{0.,-0.25}}; |
// float twin[4][2]={{80.,100.},{80.,100.},{90.,110.},{50.,70.}}; |
// float adcgate[4][2]={{80.,110.},{80.,110.},{90.,110.},{50.,70.}}; |
float threshold[4][2]={{0.,-0.1},{0.,-0.05},{0.,-0.25},{0.,-0.25}}; |
float twin[4][2]={{100.,120.},{100.,120.},{40.,130.},{60.,80.}}; |
float adcgate[4][2]={{105.,125.},{105.,125.},{110.,130.},{60.,80.}}; |
float vcut[4][2]={{-1,1},{-1,1},{-1,1},{-1,1}}; |
float threshold[4][2]={{0.,-0.1 },{0.,-0.05 },{0.,-0.25 },{0.,-0.25}}; |
float twin[4][2] ={{100.,120.},{100.,120.},{40.,130. },{60.,80. }}; |
float adcgate[4][2] ={{105.,125.},{105.,125.},{110.,130.},{60.,80. }}; |
float vcut[4][2] ={{-1,1 },{-1,1 },{-1,1 },{-1,1 }}; |
|
// gROOT->Reset(); |
|
115,14 → 122,17 |
h2_ctalk=new TH2F("ctalk","ctalk",250,0.,0.5,250,0.,0.5); |
|
fin=fopen(FileName,"rb"); |
|
if (fin==NULL) { |
printf("Error opening file %s\n",FileName); |
return; |
} |
printf("%s, %lu\n",recid,sizeof(evrec)); |
|
|
for (i=0;i<4;i++){ |
nwfm[i]=0; |
for (j=0;j<DWIDTH;j++){ |
achdat[i][j]=0; |
for (ich=0;ich<4;ich++){ |
nwfm[ich]=0; |
for (i=0;i<DWIDTH;i++){ |
achdat[ich][i]=0; |
} |
} |
unsigned int trgcell = 0; |
137,9 → 147,15 |
else printf("%s\n",recid ); |
} |
switch (recid[0]){ |
case 'T': |
case 'D': // DRS |
version = atoi(&recid[3]); |
break; |
case 'T': // TIME |
switch (recid[1]){ |
case 'I': event=0; break; |
case 'I': |
event=0; |
if (version ==0) version++; |
break; |
case '#': trgcell = srecid[1]; break; |
} |
break; |
150,8 → 166,10 |
sscanf(recid,"C%d",&ich); |
ich=ich-1; |
if (event) { |
if (version>1) stat=fread(&scaler[ich],1,sizeof(float),fin); |
stat=fread(ichdat[ich],1,sizeof(ichdat[ich]),fin); |
} else { |
|
stat=fread(dtdata[ich],1,sizeof(float)*DWIDTH,fin); |
|
} |
159,10 → 177,13 |
case 'E': |
stat=fread(&evrec.evn,1,sizeof(evrec),fin); |
iev++; |
if (!version) { |
stat=fread(dtdata[0],1,sizeof(float)*DWIDTH,fin); |
} |
event=1; |
break; |
default: |
printf("Unknown header!\n"); |
printf("Unknown header! %s\n", recid); |
break; |
} |
|
183,8 → 204,7 |
if (event<1) continue; |
if (recid[0]!='C') continue; |
|
|
|
|
lwfm[ich]=0; |
qdc[ich]=0; |
chmax[ich][0]=-1; chmax[ich][1]=-1; |
193,99 → 213,94 |
cftime[ich][0]=-1.; cftime[ich][1]=-1.; |
|
|
lwfm[ich]=1; |
nwfm[ich]+=1; |
lwfm[ich]=1; |
nwfm[ich]+=1; |
|
float sum=0; |
for (i=0;i<DWIDTH;i++) { |
sum+= dtdata[ich][(i+trgcell)%DWIDTH]; |
tcdata[ich][i]=sum; |
} |
tccalib[ich]=tcdata[ich][(DWIDTH-trgcell)%DWIDTH]; |
|
|
t = &tcdata[ich][0]; |
y = &chdat[ich][0]; |
ay = &achdat[ich][0]; |
|
for (i=0;i<DWIDTH;i++) { |
tcdata[ich][i]-=(tccalib[ich]-tccalib[0]); // assume ich 0 is connected and always first in the data |
} |
float sum=0; |
for (i=0;i<DWIDTH;i++) { |
sum+= dtdata[ich][(i+trgcell)%DWIDTH]; |
if (version) t[i]=sum; |
else t[i]=dtdata[0][i]; // old format |
} |
tccalib[ich]=t[(DWIDTH-trgcell)%DWIDTH]; |
|
for (i=0;i<DWIDTH;i++) { |
// for (i=imin[ich];i<imax[ich];i++) { |
chdat[ich][i]=-0.5+(float)ichdat[ich][i]/0xFFFF; |
achdat[ich][i]+=chdat[ich][i]; |
if (chdat[ich][i]>chmax[ich][0]) { |
chmax[ich][0]=chdat[ich][i]; |
chmax[ich][1]=tcdata[ich][i]; |
} |
if (chdat[ich][i]<chmin[ich][0]) { |
chmin[ich][0]=chdat[ich][i]; |
chmin[ich][1]=tcdata[ich][i]; |
} |
float tdata = tcdata[ich][i]; |
float tdatap = tcdata[ich][i+1]; |
float tdatan = tcdata[ich][i-1]; |
|
if ((tdata>adcgate[ich][0])&&(tdata<adcgate[ich][1])) { |
qdc[ich]+=-chdat[ich][i]*(tdatap-tdatan)/2; |
} |
if ((tdata>twin[ich][0])&&(tdata<twin[ich][1])) { |
if ((chdat[ich][i]<threshold[ich][1])&&(letime[ich][1]<0.)) { |
letime[ich][1]=tdatan+(tdata-tdatan)* |
(threshold[ich][1]-chdat[ich][i-1])/(chdat[ich][i]-chdat[ich][i-1]); |
// preveri za 0!! |
} |
} |
for (i=0;i<DWIDTH;i++) { |
if (version) t[i]-=(tccalib[ich]-tccalib[0]); // assume ich 0 is connected and always first in the data |
y[i]=-0.5+(float)ichdat[ich][i]/0xFFFF; |
if (version) y[i]+=evrec.rc; |
h2_dpo[ich]->Fill(t[i],y[i]); |
gr_wfm[ich]->SetPoint(i,t[i],y[i]+0.05*(ich-1)); |
} |
|
|
for (i=0;i<DWIDTH;i++) { |
// accumulated waveforms |
ay[i]+=y[i]; |
|
// signal minumum |
if (y[i]>chmax[ich][0]) { |
chmax[ich][0]=y[i]; |
chmax[ich][1]=t[i]; |
} |
|
|
i=ich; |
|
|
for (j=0;j<DWIDTH;j++) { |
float tdata = tcdata[i][j]; |
float tdatap = tcdata[i][j+1]; |
float tdatan = tcdata[i][j-1]; |
h2_dpo[i]->Fill(tdata,chdat[i][j]); |
gr_wfm[i]->SetPoint(j,tdata,chdat[i][j]+0.05*(i-1)); |
if ((tdata>twin[i][0])&&(tdata<twin[i][1])) { |
if ((chmin[i][0]<threshold[i][1])&&(chdat[i][j]<chmin[i][0]*CFRAC)&&(cftime[i][1]<0.)) { |
cftime[i][1]=tdatan+(tdata-tdatan)* |
(chmin[i][0]*CFRAC-chdat[i][j-1])/(chdat[i][j]-chdat[i][j-1]); |
// preveri za 0!! |
} |
} |
|
// signal maximum |
if (y[i]<chmin[ich][0]) { |
chmin[ich][0]=y[i]; |
chmin[ich][1]=t[i]; |
} |
|
|
if ((chmax[i][1]>twin[i][0])&&(chmax[i][1]<twin[i][1])) { |
h1_chmax[i]->Fill(chmax[i][0]); |
if (chmax[i][0]>threshold[i][0]) h1_chmaxt[i]->Fill(chmax[i][1]); |
float t0 = t[i]; |
float t0p = t[i+1]; |
float t0n = t[i-1]; |
// charge in the range |
if ((t0>adcgate[ich][0])&&(t0<adcgate[ich][1])) { |
qdc[ich]+=-y[i]*(t0p-t0n)/2; |
} |
if ((chmin[i][1]>twin[i][0])&&(chmin[i][1]<twin[i][1])) { |
h1_chmin[i]->Fill(chmin[i][0]); |
if (chmin[i][0]<threshold[i][1]) h1_chmint[i]->Fill(chmin[i][1]); |
} |
|
for (i=1;i<DWIDTH-1;i++) { |
float t0 = t[i]; |
float t0p = t[i+1]; |
float t0n = t[i-1]; |
// leading edge in the range |
if ((t0>twin[ich][0])&&(t0<twin[ich][1])) { |
if ((y[i]<threshold[ich][1])&&(letime[ich][1]<0.)) { |
letime[ich][1]=t0n+(t0-t0n)*(threshold[ich][1]-y[i-1])/(y[i]-y[i-1]); |
} |
// constant fraction time in the range |
if ((chmin[ich][0]<threshold[ich][1])&&(y[i]<chmin[ich][0]*CFRAC)&&(cftime[ich][1]<0.)) { |
cftime[ich][1]=t0n+(t0-t0n)*(chmin[ich][0]*CFRAC-y[i-1])/(y[i]-y[i-1]); |
} |
} |
h1_qdc[i]->Fill(qdc[i]); |
h1_letime[i][1]->Fill(letime[i][1]); |
h1_cftime[i][1]->Fill(cftime[i][1]); |
//84,56 |
} |
|
if ((chmax[ich][1]>twin[ich][0])&&(chmax[ich][1]<twin[ich][1])) { |
h1_chmax[ich]->Fill(chmax[ich][0]); |
if (chmax[ich][0]>threshold[ich][0]) h1_chmaxt[ich]->Fill(chmax[ich][1]); |
} |
if ((chmin[ich][1]>twin[ich][0])&&(chmin[ich][1]<twin[ich][1])) { |
h1_chmin[ich]->Fill(chmin[ich][0]); |
if (chmin[ich][0]<threshold[ich][1]) h1_chmint[ich]->Fill(chmin[ich][1]); |
} |
h1_qdc[ich]->Fill(qdc[ich]); |
h1_letime[ich][1]->Fill(letime[ich][1]); |
h1_cftime[ich][1]->Fill(cftime[ich][1]); |
|
|
|
|
if (!(iev%updfrq)) { |
c_wfm->Update(); |
for (j=0;j<DWIDTH;j++) { |
achdat[i][j]/=nwfm[i]; |
gr_wfm[i]->SetPoint(j,tcdata[i][j],achdat[i][j]+0.05*(i-1)); |
for (i=0;i<DWIDTH;i++) { |
ay[i]/=nwfm[ich]; |
gr_wfm[ich]->SetPoint(i,t[i],ay[i]+0.05*(ich-1)); |
} |
printf("processing event %d\n",iev); |
} |
|
|
|
|
} |
|
|
printf("number of events: %d\n",iev); |
fclose(fin); |
|
296,6 → 311,5 |
TCanvas* c_cftdif= new TCanvas("c_cftdif","DPO",750,50,700,700); |
c_cftdif->Divide(2,2); |
for (i=0;i<4;i++) {c_cftdif->cd(i+1);h1_cftdif[i]->Draw();} |
|
return; |
} |