4,7 → 4,8 |
// Contributors: Rok Pestotnik, Rok Dolenec, Dino Tahirovic |
// |
// 3/1/2014 TDC cut relative to tdc offset |
// |
// 5/3/2014 TH3F h_correctedTDC; commented 'delete' commands |
// 12/3/2014 declarations of all histos before while{} |
|
#include "stdio.h" |
#include "TROOT.h" |
12,6 → 13,7 |
#include "TNtuple.h" |
#include "TH1F.h" |
#include "TH2F.h" |
#include "TH3F.h" |
#include "TF1.h" |
#include "TMath.h" |
#include "TStyle.h" |
30,8 → 32,8 |
#define NCH 64 |
#define TDC_BIN 1.0416 // 1 TDC bin in ns |
#define MIKRO_BIN 0.49609/1000. //1 mikro step in mm; stage MM3MF |
#define OFFSETX 5100 // Right edge of SiPM+Lightguide |
#define OFFSETY 5200 // Lower edge of SiPM+Lightguide |
#define OFFSETX 5200 // Right edge of SiPM+Lightguide |
#define OFFSETY 5400 // Lower edge of SiPM+Lightguide |
|
#define RUNREC_ID 1 |
#define ENDREC_ID 2 |
101,9 → 103,8 |
|
int analysisBias(char* dfile0="test", int dbg=0, double tdcCut=5.0) |
{ |
const double c_tdcOffset = 1; // ns |
|
const double c_tdcOffset = +2.5; // ns |
|
printf(" Data to root conversion program\nUsage:\nd2r(input file name <without .dat>, debug on/off, TDC cut +-[ns])\n\n"); |
|
char fullname[256]; |
133,57 → 134,10 |
printf("%.2lf %.2lf %.2lf\n", padCenter[i][0], padCenter[i][1], tdcOffset[i]); |
} |
|
//TDC correction parameters |
/* |
double corpar[NCH][3]={ {-0.8, 25, 0}, |
{-0.8, 25, 0}, |
{-0.8, 25, 0}, |
{-0.8, 25, 0}, |
{-0.8, 25, 0}, |
{-0.8, 25, 0}, |
{-0.8, 25, 0}, |
{-0.8, 25, 0} }; |
sprintf(fullname, "data/%s_cor.txt", dfile0); |
if( (fp=fopen(fullname, "rt")) == NULL ) |
printf("Cannot open parameter file %s !!!\n", fullname); |
else { |
printf("Opened parameter file %s\n", fullname); |
for(int i=0; i<NCH; i++) { |
fscanf(fp, "%lf %lf %lf\n", &corpar[i][0], &corpar[i][1], &corpar[i][2]);*/ |
/*// check if parameters make sense |
if( (corpar[i][0] < (tdcmi-0.2*tdcmi)) || ((tdcma+0.2*tdcma) < corpar[i][0]) || |
(corpar[i][1] < 0) || (1e4*TDC_BIN < corpar[i][1]) || |
(1e4 < TMath::Abs(corpar[i][2])) ) { |
printf("Warning: parameters for ch%d out of limits -> using default!\n", i); |
corpar[i][0]=2200*TDC_BIN; corpar[i][1]=1000*TDC_BIN; corpar[i][2]=-100*TDC_BIN; |
}*/ |
/* } |
fclose(fp); |
}*/ |
//for(int i=0; i<NCH; i++) printf("%.2lf %.2lf %.2lf\n", corpar[i][0], corpar[i][1], corpar[i][2]); |
|
|
//histograms |
char hname[256]; |
//double tdc; |
TH2F *htdc; |
TH2F* h_correctedTDC; |
TH1F *hnhitsx[NCH], *hnhitsy[NCH]; |
TH2F *h2d[NCH]; |
TH2F *h_threshold; |
TH2F *h_ch33; |
TH2F *h_bias; |
|
TNtuple *nt; |
|
//data buffer |
unsigned int readbuf[READBUFFERLENGTH]; |
unsigned int buf[READBUFFERLENGTH]; |
|
|
|
|
|
//data file |
gzFile dfp; |
char dfile[256]; |
209,14 → 163,14 |
printf("Opened data file %s\n", dfile); |
|
//opens ROOT file |
//TFile *rootfile; |
char fnameroot[256]; |
sprintf(fnameroot, "root/%s.root", dfile0); |
//rootfile = (TFile *) gROOT->FindObjectAny(dfile0); |
//if (rootfile!=NULL) {printf("!!!\n");rootfile->Close();} |
//rootfile = new TFile(fnameroot); |
//if(rootfile) rootfile->Close(); |
TFile* rootfile = new TFile(fnameroot,"RECREATE",dfile0); |
TFile rootfile(fnameroot,"RECREATE",dfile0); |
if (rootfile.IsZombie()) { |
std::cout << "Error opening file" << std::endl; |
exit(-1); |
} |
if (rootfile.IsOpen()) std::cout << "ROOT file opened for writing." << std::endl; |
|
// ----------------------------------------------- |
// loop trough records |
230,8 → 184,22 |
int ii; |
int nint; |
int nb; |
int nSteps; |
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]", |
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]; //-||- |
TH2F* h2d[NCH]; //-||- |
TH2F* h_bias = new TH2F("h_bias", "", 64, 0, 63, 20, 71.0,73.0); |
TH2F* h_threshold = new TH2F("h_threshold",";SiPM ch;Threshold[V]", |
64,-0.5,63.5, |
101, 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"); |
|
while(1) { |
if(gzeof(dfp)) end_of_file = 1; |
244,9 → 212,13 |
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) |
{ |
case RUNREC_ID: |
if (dbg) printf("RUNREC\n"); |
gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
runrec = (RUNREC*) readbuf; |
run = *runrec; |
258,20 → 230,31 |
printf("nx = %d, x0 = %d, dx = %d\n", run.nx, run.x0, run.dx); |
printf("ny = %d, y0 = %d, dy = %d\n", run.ny, run.y0, run.dy); |
printf("thLow = %d, thUp = %d, thStep = %d\n", run.thLow, run.thUp, run.thStep); |
printf("biasLow = %d, biasUp = %d, biasStep = %d\n", run.biasLow, run.biasUp, run.biasStep); |
} |
|
//create histograms |
nt = new TNtuple("nt", "nt", "ch:x:y:tdc"); |
sprintf(hname, "htdc"); |
htdc = (TH2F*) gROOT->FindObject(hname); |
if (htdc) delete htdc; |
htdc = new TH2F("htdc","Raw TDC;TDC channel;SiPM channel",512,0,512,NCH,0,NCH); |
h_correctedTDC = (TH2F*) gROOT->FindObject("h_correctedTDC"); |
//nt = (TNtuple*) gROOT->FindObject("nt"); |
//if (nt) delete nt; |
|
//sprintf(hname, "htdc"); |
//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"); |
if (h_correctedTDC) delete h_correctedTDC; |
h_correctedTDC = new TH2F("h_correctedTDC","Corrected TDC;t [ns];SiPM channel",33, -16.5*TDC_BIN,16.5*TDC_BIN,NCH,0,NCH); |
nSteps = (run.thUp - run.thLow)/double(run.thStep) + 1; |
if (dbg) printf("nSteps %d\n", nSteps); |
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*TDC_BIN, |
-tdcCut*TDC_BIN, |
tdcCut*TDC_BIN); |
//TH1F* gsumV673A[NCH/16] = new TH1F(hn,hname,256,-0.5,255.5); |
h_bias = new TH2F("h_bias","",20, 71.0, 73.0, 33, -16.5*TDC_BIN, 16.5*TDC_BIN); |
for(int i=0; i<NCH; i++) { |
/* |
sprintf(hname, "htdcpos%d", i); |
285,7 → 268,6 |
htdc[i] = new TH1F(hname, hname, 512, 0*TDC_BIN, 512*TDC_BIN); |
*/ |
|
|
sprintf(hname, "hnhitsx%d", i); |
hnhitsx[i] = (TH1F*)gROOT->FindObject(hname); |
if(hnhitsx[i]) delete hnhitsx[i]; |
313,13 → 295,20 |
(run.y0 - OFFSETY + (run.ny-0.5)*run.dy)*MIKRO_BIN); |
} |
|
nBiasSteps = (run.biasUp - run.biasLow)/double(run.biasStep) + 1; |
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); |
|
|
if (h_threshold) delete h_threshold; |
nSteps = (run.thUp - run.thLow)/double(run.thStep) + 1; |
if (dbg) printf("nSteps %d\n", nSteps); |
h_threshold = new TH2F("h_threshold","Threshold scan;SiPM ch;Threshold[mV]",64,-0.5,63.5, |
h_threshold = new TH2F("h_threshold",";SiPM ch;Threshold[V]",64,-0.5,63.5, |
nSteps, |
run.thLow - 0.5*run.thStep, |
run.thUp + 0.5*run.thStep); |
(run.thLow - 0.5*run.thStep)/1000.0, |
(run.thUp + 0.5*run.thStep)/1000.0); |
|
//h_threshold = new TH2F("h_threshold","Threshold scan;SiPM ch;Threshold[mV]",64,-0.5,63.5, |
// 101,995,2005); |
327,9 → 316,11 |
if (h_ch33) delete h_ch33; |
h_ch33 = new TH2F("h_ch33","ch. 33;x;y",100,20000,30000,100,0,10000); |
|
if (dbg) printf("RUNREC: all histos created.\n"); |
break; |
|
case POSREC_ID: |
if (dbg) printf("POSREC\n"); |
gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
posrec = (POSREC *) readbuf; |
pos=*posrec; |
350,7 → 341,7 |
//if (rec_len < 0 || rec_len > 10000) { |
if (rec_len > READBUFFERLENGTH) { |
printf("Len %u\n", rec_len); |
return(0); |
return(1); |
} |
nb = rec_len - 3*ulsize; // no. of bytes to read |
gzread(dfp, (voidp)&buf, nb); |
399,17 → 390,17 |
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; |
if(time >= tdcmin && time <= tdcmax) { |
h_correctedTDC->Fill((time - tdcOffset[channel]), channel); |
double time = data*TDC_BIN - tdcOffset[channel]; |
if(time >= -tdcCut and time <= tdcCut) { |
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); |
//h_threshold->Fill(channel, thr.threshold); |
h_bias->Fill(bias.bias/1000.0, (time-tdcOffset[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); |
h_threshold->Fill(channel, thr.threshold/1000.0); |
h_bias->Fill(channel, bias.bias/1000.0); |
} |
} |
//gV673A->Fill(data,channel); |
422,39 → 413,6 |
ii += len; |
} //while |
|
// events ------------------------------------------------------------------------------------------ |
// fill histograms |
/* |
for(int i=0; i<NCH; i++) { |
//tdc=((double)evtrec->data[i])*TDC_BIN - tdcoffset[i]; |
//adc=(double)evtrec->data[i+NCH]-adcoffset[i]; |
if (gNtWrite) nt->Fill(i,pos.ix,pos.iy,tdc); |
//if( (qdcmi < adc) && (adc < qdcma) ) { |
htdc[i]->Fill(tdc); |
//} |
//hadc[i]->Fill(adc); |
//hcor[i]->Fill(adc,tdc); |
//if(adc > corpar[i][2]) |
//hctdc[i]->Fill( tdc - (corpar[i][0] + corpar[i][1]/TMath::Sqrt(adc - corpar[i][2])) ); |
|
if( (abs(padcenter[i][0] - pos.xset) < POSMARG) && (abs(padcenter[i][1] - pos.yset) < POSMARG) ) { |
htdcpos[i]->Fill(tdc); |
//hadcpos[i]->Fill(adc); |
//hcorpos[i]->Fill(adc,tdc); |
//if(adc > corpar[i][2]) |
//hctdcpos[i]->Fill( tdc - (corpar[i][0] + corpar[i][1]/TMath::Sqrt(adc - corpar[i][2])) ); |
} |
|
if((tdcmi < tdc) && (tdc < tdcma)) { |
//hadc_cut[i]->Fill(adc); |
hnhitsx[i]->Fill((pos.xset - OFFSETX) * MIKRO_BIN); |
hnhitsy[i]->Fill((pos.yset - OFFSETY) * MIKRO_BIN); |
h2d[i]->Fill((pos.xset - OFFSETX) * MIKRO_BIN, (pos.yset - OFFSETY) * MIKRO_BIN); |
|
//if(i==4) adc1=adc; |
//if(i==5) adc2=adc; |
} |
} */ |
break; |
|
case THRREC_ID: |
465,6 → 423,10 |
thrrec->id, thrrec->len, thrrec->threshold); |
break; |
|
case ENDREC_ID: |
gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
endrec = (ENDREC *) readbuf; |
|
case BIASREC_ID: |
status = gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
biasrec = (BIASREC*) readbuf; |
473,10 → 435,6 |
bias.id, bias.len, bias.bias); |
break; |
|
case ENDREC_ID: |
gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
endrec = (ENDREC *) readbuf; |
|
if(dbg) { |
printf("ENDREC_ID\n"); |
printf("id = %d, len = %d, time = %d\n", endrec->id, endrec->len, endrec->time); |
522,24 → 480,24 |
|
if(dfp) { |
gzclose(dfp); |
delete dfp; |
//delete dfp; |
} |
if(dbg) return 1; |
if(rootfile) { |
//if(dbg) return 0; |
if(rootfile.IsOpen()) { |
nt->Write(); |
rootfile->Write(); |
rootfile.Write(); |
printf("Saved to %s\n", fnameroot); |
rootfile->Close(); |
delete rootfile; |
rootfile.Close(); |
//delete rootfile; |
} |
|
return 1; |
return 0; |
} |
|
int position(int x, int y, int channel) |
{ |
int flag = 0; |
if ( (x > (padCenter[channel][0] - 5000)) && (x < (padCenter[channel][0] + 5000)) && |
(y > (padCenter[channel][1] - 5000)) && (y < (padCenter[channel][1] + 5000)) ) flag = 1; |
if ( (x > (padCenter[channel][0] - 5000)) and (x < (padCenter[channel][0] + 5000)) and |
(y > (padCenter[channel][1] - 5000)) and (y < (padCenter[channel][1] + 5000)) ) flag = 1; |
return flag; |
} |