Subversion Repositories f9daq

Compare Revisions

Ignore whitespace Rev 91 → Rev 102

/sipmScan/src/analysisThreshold.cpp
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 = 368*TDC_BIN; // ns
const double c_tdcOffset = 93*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,7 → 129,8
unsigned int buf[READBUFFERLENGTH];
//data file
gzFile dfp;
//gzFile dfp;
FILE *dfp;
char dfile[256];
int ftype=0;
int fcount=1;
136,19 → 137,20
do {
switch(ftype++) {
case 0:
sprintf(dfile, "./data/%s_file%02d.dat", dfile0, fcount);
sprintf(dfile, "E:/data/%s_file%02d.dat", dfile0, fcount);
break;
case 1:
sprintf(dfile, "./data/%s_file%02d.dat.gz", dfile0, fcount);
sprintf(dfile, "E:/data/%s_file%02d.dat.gz", dfile0, fcount);
break;
case 2:
sprintf(dfile, "./data/%s_file%02d.gz", dfile0, fcount);
sprintf(dfile, "E:/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=gzopen(dfile,"rb");
dfp=fopen(dfile,"rb");
} while(!dfp);
printf("Opened data file %s\n", dfile);
177,9 → 179,8
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);
TH3F* h_correctedTDC = new TH3F("h_correctedTDC",";SiPM channel; ASD threshold [V]; t [ns]",
TH2F* h_correctedTDC = new TH2F("h_correctedTDC",";SiPM channel; 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]; //-||-
191,9 → 192,11
TNtuple* nt = new TNtuple("nt", "nt", "ch:x:y:tdc");
while(1) {
if(gzeof(dfp)) end_of_file = 1;
//if(gzeof(dfp)) end_of_file = 1;
if(feof(dfp)) end_of_file = 1;
 
gzread(dfp, (voidp)&readbuf, 2*ulsize);
//gzread(dfp, (voidp)&readbuf, 2*ulsize);
fread((void*)&readbuf, 2*ulsize, 1, dfp);
rec_id=readbuf[0];
rec_len=readbuf[1];
206,7 → 209,8
{
case RUNREC_ID:
if (dbg) printf("RUNREC\n");
gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize));
//gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize));
fread((void*)&readbuf[2], (rec_len-2*ulsize), 1, dfp);
runrec = (RUNREC *) readbuf;
run=*runrec;
227,17 → 231,14
//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 = (TH3F*) gROOT->FindObject("h_correctedTDC");
h_correctedTDC = (TH2F*) 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 TH3F("h_correctedTDC",";SiPM channel; ASD threshold [V]; t [ns]",
h_correctedTDC = new TH2F("h_correctedTDC",";SiPM channel; 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);
299,7 → 300,8
case POSREC_ID:
if (dbg) printf("POSREC\n");
gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize));
//gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize));
fread((void*)&readbuf[2], (rec_len-2*ulsize), 1, dfp);
posrec = (POSREC *) readbuf;
pos=*posrec;
313,7 → 315,8
break;
case EVTREC_ID:
gzread(dfp, (voidp)&readbuf[2], ulsize); // last field of event record
//gzread(dfp, (voidp)&readbuf[2], ulsize); // last field of event record
fread((void*)&readbuf[2], ulsize, 1, dfp);
evtrec = (EVTREC *) readbuf;
//evtrec->nev = buf[0];
//if (rec_len < 0 || rec_len > 10000) {
322,7 → 325,8
return(1);
}
nb = rec_len - 3*ulsize; // no. of bytes to read
gzread(dfp, (voidp)&buf, nb);
//gzread(dfp, (voidp)&buf, nb);
fread((void*)&buf, nb, 1, dfp);
if(dbg) {
printf("EVTREC_ID\n");
370,15 → 374,15
double tdcmax = tdcOffset[channel] + tdcCut;
double time = data*TDC_BIN - tdcOffset[channel];
if((time >= -tdcCut) && (time <= tdcCut)) {
h_correctedTDC->Fill(channel, thr.threshold/1000.0, time);
h_correctedTDC->Fill(channel, 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);
393,7 → 397,8
break;
case THRREC_ID:
status = gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize));
//status = gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize));
status = fread((void*)&readbuf[2], (rec_len-2*ulsize), 1, dfp);
thrrec = (THRREC*) readbuf;
thr = *thrrec;
if (dbg) printf("THRREC id = %d len = %d threshold %d\n",
401,7 → 406,8
break;
case ENDREC_ID:
gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize));
//gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize));
fread((void*)&readbuf[2], (rec_len-2*ulsize), 1, dfp);
endrec = (ENDREC *) readbuf;
if(dbg) {
412,19 → 418,21
fcount++;
switch(ftype-1) {
case 0:
sprintf(dfile, "./data/%s_file%02d.dat", dfile0, fcount);
sprintf(dfile, "E:/data/%s_file%02d.dat", dfile0, fcount);
break;
case 1:
sprintf(dfile, "./data/%s_file%02d.dat.gz", dfile0, fcount);
sprintf(dfile, "E:/data/%s_file%02d.dat.gz", dfile0, fcount);
break;
case 2:
sprintf(dfile, "./data/%s_file%02d.gz", dfile0, fcount);
sprintf(dfile, "E:/data/%s_file%02d.gz", dfile0, fcount);
break;
}
if(dfp) gzclose(dfp);
//if(dfp) gzclose(dfp);
if(dfp) fclose(dfp);
dfp=gzopen(dfile,"rb");
//dfp=gzopen(dfile,"rb");
dfp=fopen(dfile,"rb");
if(!dfp) {
printf(" Cannot open data file: %s ---> Exiting\n", dfile);
end_of_file = 1;
448,7 → 456,8
}
 
if(dfp) {
gzclose(dfp);
//gzclose(dfp);
fclose(dfp);
//delete dfp;
}
//if(dbg) return 0;