19,7 → 19,7 |
#include "TStyle.h" |
#include "TCanvas.h" |
#include "TLine.h" |
//#include "zlib.h" |
#include "zlib.h" |
|
// ------------------------------------------------------------------------------ |
|
93,7 → 93,7 |
|
int analysisThreshold(char* dfile0="test", int dbg=0, double tdcCut=5.0) |
{ |
const double c_tdcOffset = 93*TDC_BIN; // ns |
const double c_tdcOffset = 368*TDC_BIN; // ns |
|
printf(" Data to root conversion program\nUsage:\nd2r(input file name <without.dat>, debug on/off, TDC cut +-[ns])\n\n"); |
|
129,8 → 129,7 |
unsigned int buf[READBUFFERLENGTH]; |
|
//data file |
//gzFile dfp; |
FILE *dfp; |
gzFile dfp; |
char dfile[256]; |
int ftype=0; |
int fcount=1; |
137,20 → 136,19 |
do { |
switch(ftype++) { |
case 0: |
sprintf(dfile, "E:/data/%s_file%02d.dat", dfile0, fcount); |
sprintf(dfile, "./data/%s_file%02d.dat", dfile0, fcount); |
break; |
case 1: |
sprintf(dfile, "E:/data/%s_file%02d.dat.gz", dfile0, fcount); |
sprintf(dfile, "./data/%s_file%02d.dat.gz", dfile0, fcount); |
break; |
case 2: |
sprintf(dfile, "E:/data/%s_file%02d.gz", dfile0, fcount); |
sprintf(dfile, "./data/%s_file%02d.gz", dfile0, fcount); |
break; |
default: |
printf(" Cannot find data file for %s !!!\n", dfile0); |
return -1; |
} |
//dfp=gzopen(dfile,"rb"); |
dfp=fopen(dfile,"rb"); |
dfp=gzopen(dfile,"rb"); |
} while(!dfp); |
printf("Opened data file %s\n", dfile); |
|
179,8 → 177,9 |
int status; |
char hname[256]; |
TH2F* htdc = new TH2F("htdc",";TDC channel;SiPM channel",512,-0.5,511.5,NCH,-0.5,NCH-0.5); |
TH2F* h_correctedTDC = new TH2F("h_correctedTDC",";SiPM channel; t [ns]", |
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); |
TH1F* hnhitsx[NCH]; // move to 2d with (channel, position) |
TH1F* hnhitsy[NCH]; //-||- |
192,11 → 191,9 |
TNtuple* nt = new TNtuple("nt", "nt", "ch:x:y:tdc"); |
|
while(1) { |
//if(gzeof(dfp)) end_of_file = 1; |
if(feof(dfp)) end_of_file = 1; |
if(gzeof(dfp)) end_of_file = 1; |
|
//gzread(dfp, (voidp)&readbuf, 2*ulsize); |
fread((void*)&readbuf, 2*ulsize, 1, dfp); |
gzread(dfp, (voidp)&readbuf, 2*ulsize); |
rec_id=readbuf[0]; |
rec_len=readbuf[1]; |
|
209,8 → 206,7 |
{ |
case RUNREC_ID: |
if (dbg) printf("RUNREC\n"); |
//gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
fread((void*)&readbuf[2], (rec_len-2*ulsize), 1, dfp); |
gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
runrec = (RUNREC *) readbuf; |
run=*runrec; |
|
231,14 → 227,17 |
//htdc = (TH2F*) gROOT->FindObject(hname); |
//if (htdc) delete htdc; |
//htdc = new TH2F("htdc",";TDC channel;SiPM channel",512,0,512,NCH,0,NCH); |
h_correctedTDC = (TH2F*) gROOT->FindObject("h_correctedTDC"); |
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 %f\n", nSteps); |
h_correctedTDC = new TH2F("h_correctedTDC",";SiPM channel; t [ns]", |
h_correctedTDC = new TH3F("h_correctedTDC",";SiPM channel; ASD threshold [V]; t [ns]", |
NCH, |
-0.5, |
NCH-0.5, |
nSteps, |
(run.thLow - 0.5*run.thStep)/1000.0, |
(run.thUp + 0.5*run.thStep)/1000.0, |
2*tdcCut+1, |
(-tdcCut - 0.5)*TDC_BIN, |
(tdcCut + 0.5)*TDC_BIN); |
300,8 → 299,7 |
|
case POSREC_ID: |
if (dbg) printf("POSREC\n"); |
//gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
fread((void*)&readbuf[2], (rec_len-2*ulsize), 1, dfp); |
gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
posrec = (POSREC *) readbuf; |
pos=*posrec; |
|
315,8 → 313,7 |
break; |
|
case EVTREC_ID: |
//gzread(dfp, (voidp)&readbuf[2], ulsize); // last field of event record |
fread((void*)&readbuf[2], ulsize, 1, dfp); |
gzread(dfp, (voidp)&readbuf[2], ulsize); // last field of event record |
evtrec = (EVTREC *) readbuf; |
//evtrec->nev = buf[0]; |
//if (rec_len < 0 || rec_len > 10000) { |
325,8 → 322,7 |
return(1); |
} |
nb = rec_len - 3*ulsize; // no. of bytes to read |
//gzread(dfp, (voidp)&buf, nb); |
fread((void*)&buf, nb, 1, dfp); |
gzread(dfp, (voidp)&buf, nb); |
|
if(dbg) { |
printf("EVTREC_ID\n"); |
374,16 → 370,16 |
double tdcmax = tdcOffset[channel] + tdcCut; |
double time = data*TDC_BIN - tdcOffset[channel]; |
if((time >= -tdcCut) && (time <= tdcCut)) { |
h_correctedTDC->Fill(channel, time); |
h_correctedTDC->Fill(channel, thr.threshold/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)) { |
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); |
//} |
} |
} |
//gV673A->Fill(data,channel); |
//gsumV673A[channel/16]->Fill(data); |
} |
397,8 → 393,7 |
break; |
|
case THRREC_ID: |
//status = gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
status = fread((void*)&readbuf[2], (rec_len-2*ulsize), 1, dfp); |
status = gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
thrrec = (THRREC*) readbuf; |
thr = *thrrec; |
if (dbg) printf("THRREC id = %d len = %d threshold %d\n", |
406,8 → 401,7 |
break; |
|
case ENDREC_ID: |
//gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
fread((void*)&readbuf[2], (rec_len-2*ulsize), 1, dfp); |
gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
endrec = (ENDREC *) readbuf; |
|
if(dbg) { |
418,21 → 412,19 |
fcount++; |
switch(ftype-1) { |
case 0: |
sprintf(dfile, "E:/data/%s_file%02d.dat", dfile0, fcount); |
sprintf(dfile, "./data/%s_file%02d.dat", dfile0, fcount); |
break; |
case 1: |
sprintf(dfile, "E:/data/%s_file%02d.dat.gz", dfile0, fcount); |
sprintf(dfile, "./data/%s_file%02d.dat.gz", dfile0, fcount); |
break; |
case 2: |
sprintf(dfile, "E:/data/%s_file%02d.gz", dfile0, fcount); |
sprintf(dfile, "./data/%s_file%02d.gz", dfile0, fcount); |
break; |
} |
|
//if(dfp) gzclose(dfp); |
if(dfp) fclose(dfp); |
if(dfp) gzclose(dfp); |
|
//dfp=gzopen(dfile,"rb"); |
dfp=fopen(dfile,"rb"); |
dfp=gzopen(dfile,"rb"); |
if(!dfp) { |
printf(" Cannot open data file: %s ---> Exiting\n", dfile); |
end_of_file = 1; |
456,8 → 448,7 |
} |
|
if(dfp) { |
//gzclose(dfp); |
fclose(dfp); |
gzclose(dfp); |
//delete dfp; |
} |
//if(dbg) return 0; |