#include "stdio.h"
#include "TROOT.h"
#include "TSystem.h"
#include "TFile.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TF1.h"
#include "TMath.h"
#include "TStyle.h"
#include "TCanvas.h"
#include "TLine.h"
//kobayashi
#include "TTree.h"
//~ #define USE_ZLIB
#ifdef USE_ZLIB
# include "zlib.h"
#endif
// ------------------------------------------------------------------------------
#define POSMARG 1000
#define READBUFFERLENGTH 500000
// data format
#define MAXDATA 64
#define NCH 32
#define ANALYSE_CH 32
#define MPPC_1_CH 0
#define MPPC_2_CH 1
#define TRIGGER_CH 31
//~ #define ANALYSE_CH 8
//~ #define MPPC_1_CH 2
//~ #define MPPC_2_CH 5
#define REF_CH 0
#define TDC_BIN (25./1000.) //1 TDC bin in ns
#define MIKRO_BIN 0.3595/1000. //1 mikro step in mm
#define RUNREC_ID 1
#define ENDREC_ID 2
#define POSREC_ID 3
#define EVTREC_ID 4
//define testpulse
typedef struct {
unsigned long id,len;
unsigned long fver,time;
unsigned long nev,nch,ped,xy;
long nx,x0,dx,ny,y0,dy;
} RUNREC;
RUNREC *runrec;
RUNREC run;
typedef struct {
unsigned long id,len;
unsigned long time;
} ENDREC;
ENDREC *endrec;
typedef struct {
unsigned long id,len;
unsigned long time;
long ix,x,xset,iy,y,yset;
} POSREC;
POSREC *posrec;
POSREC pos;
typedef struct {
unsigned long id,len;
unsigned long nev;
unsigned short data[MAXDATA];
} EVTREC;
EVTREC *evtrec;
// ------------------------------------------------------------------------------
int d2r(char* dfile0="test", double qdcmi=0, double qdcma=4096, double tdcmi=-1.5, double tdcma=3, double adc_cor_min=200.0, double deltaT_ctdcdiff=0)
{
int dbg=0;
printf(" dat 2 root conversion program\nUsage:\nd2r(input file -.dat, TDC min [ps], TDC max [ps], QDC min, QDC max)\n\n");
char fullname[256], sbuff[256];
FILE *fp;
//Chanel information
//~ int chmapx[NCH]={7,6,5,4,3,2,1,0};
//~ int chmapx[NCH]={ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19};
int chmapx[NCH]; for(int i=0; i<NCH; i++) {chmapx[i]=i;};
//~ double padcenter[NCH][2]={ {201000, 210000},
//~ {183000, 210000},
//~ {165000, 210000},
//~ {147000, 210000},
//~ {129000, 210000},
//~ {111000, 210000},
//~ { 93000, 210000},
//~ { 75000, 210000} };
//~ // double tdcoffset[NCH]={57.78, 57.28, 57.86, 57.64, 56.06, 56.46, 57.5, 57.41};
//~ double tdcoffset[NCH]={2311*TDC_BIN, 2291*TDC_BIN, 2314*TDC_BIN, 2306*TDC_BIN,
//~ 2242*TDC_BIN, 2258*TDC_BIN, 2300*TDC_BIN, 2296*TDC_BIN};
double padcenter[NCH][2]; for(int i=0; i<NCH; i++) {padcenter[i][0]=0; padcenter[i][1]=0;};
double tdcoffset[NCH]; for(int i=0; i<NCH; i++) {tdcoffset[i]=0;};
sprintf(fullname, "d2r.ini");
if( (fp=fopen(fullname, "rt")) == NULL )
printf("Cannot open pad centers file %s !!!\n", fullname);
else {
printf("Opened pad centers file %s\n", fullname);
fgets(sbuff,256, fp);printf("%s", sbuff);
for(int i=0; i<NCH; i++)
fscanf(fp, "%lf %lf %lf\n", &padcenter[i][0], &padcenter[i][1], &tdcoffset[i]);
fclose(fp);
}
for(int i=0; i<NCH; i++) 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} };
double corpar[NCH][3]; for(int i=0; i<NCH; i++) {corpar[i][0]=0.0; corpar[i][1]=0.005; corpar[i][2]=0.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], htitle[256];
double adc,tdc;
TH1F *hadc[NCH], *hadc_cut[NCH], *hadc_cut_2[NCH];
TH1F *htdc[NCH], *htdc_cut[NCH], *htdc_cut_2[NCH], *hctdc[NCH];
TH2F *h2d[NCH], *hcor[NCH];
TH2F *hdiffcor[NCH][NCH];
TH2F *hdiffcor_low[NCH][NCH];
TH2F *hdiffcor_hi[NCH][NCH];
TH2F *hadccor;
TH2F *htdccor;
TH2F *hcoradctdc0, *hcoradctdc1, hcoradctdc01, hcoradctdc11;
TH1F *htesttdc1, *htesttdc2;
TTree *ftt;
TH1F *htdcdiff, *htdcdiff_cut, *htdcdiff_cut_2;
double ref_cut_1_lo = qdcmi;
double ref_cut_1_hi = qdcma;
double ref_cut_2_lo = tdcmi;
double ref_cut_2_hi = tdcma;
//kobayashi
double t_adc0, t_tdc0, t_adc1, t_tdc1, t_ctdc;
//data buffer
char readbuf[READBUFFERLENGTH];
runrec = (RUNREC *) readbuf;
endrec = (ENDREC *) readbuf;
posrec = (POSREC *) readbuf;
evtrec = (EVTREC *) readbuf;
//data file
#ifdef USE_ZLIB
gzFile dfp;
#else
FILE *dfp;
#endif
char dfile[256];
int ftype=0, fcount=1;
do {
switch(ftype++) {
case 0:
sprintf(dfile, "data/%s_file%02d.dat", dfile0, fcount);
break;
case 1:
sprintf(dfile, "data/%s_file%02d.dat.gz", dfile0, fcount);
break;
case 2:
sprintf(dfile, "data/%s_file%02d.gz", dfile0, fcount);
break;
default:
printf(" Cannot find data file for %s !!!\n", dfile0);
return -1;
}
#ifdef USE_ZLIB
dfp=gzopen(dfile,"rb");
#else
dfp=fopen(dfile,"rb");
#endif
} while(!dfp);
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();
rootfile = new TFile(fnameroot,"RECREATE",dfile0);
// -----------------------------------------------
// loop trough records
UInt_t rec_id, rec_len;
unsigned ulsize = 4;
int ceve=0;
int end_of_file = 0;
while(1) {
#ifdef USE_ZLIB
if(gzeof(dfp)) end_of_file = 1;
#else
if(feof(dfp)) end_of_file = 1;
#endif
#ifdef USE_ZLIB
gzread(dfp, (voidp)&readbuf, 2*ulsize);
#else
fread( (void*)&readbuf, 2*ulsize, 1, dfp);
#endif
rec_id=readbuf[0];
rec_len=readbuf[ulsize];
//kobayashi
if(rec_id == 4) rec_len = 140;
//~ if(dbg) printf("-----------------------------------------------\n");
//~ if(dbg) printf("[%d] rec_id = %d | rec_len = %d\n", ceve, rec_id, rec_len);
//printf("[%d] rec_id = %d | rec_len = %u\n", ceve, readbuf[0], readbuf[ulsize]);
switch(rec_id)
{
case RUNREC_ID:
#ifdef USE_ZLIB
gzread(dfp, (voidp)&readbuf[2*ulsize], (rec_len-2*ulsize));
#else
fread( (void*)&readbuf[2*ulsize], (rec_len-2*ulsize), 1, dfp);
#endif
run=*runrec;
if(dbg) {
printf("RUNREC_ID\n");
printf("id = %d, len = %d, time = %d\n", run.id, run.len, run.time);
printf("nev = %d, nch = %d\n", run.nev, run.nch);
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);
//~ break;
}
//create histograms
sprintf(hname, "htdcdiff");
htdcdiff = (TH1F*)gROOT->FindObject(hname);
if(htdcdiff) delete htdcdiff;
htdcdiff = new TH1F(hname, hname, 4096, -2048.5*TDC_BIN, 2047.5*TDC_BIN);
//~ htdcdiff = new TH1F(hname, hname, 4096, -0.5*TDC_BIN, 4095.5*TDC_BIN);
sprintf(hname, "htdcdiff_cut");
htdcdiff_cut = (TH1F*)gROOT->FindObject(hname);
if(htdcdiff_cut) delete htdcdiff_cut;
//~ htdcdiff_cut = new TH1F(hname, hname, 4096, -2048.5*TDC_BIN, 2047.5*TDC_BIN);
htdcdiff_cut = new TH1F(hname, hname, 4096, -2048.5*TDC_BIN, 2047.5*TDC_BIN);
//kobayashi
//~ htdcdiff_cut = new TH1F(hname, hname, 4096, -0.5*TDC_BIN, 4095.5*TDC_BIN);
sprintf(hname, "htdcdiff_cut_2");
htdcdiff_cut_2 = (TH1F*)gROOT->FindObject(hname);
if(htdcdiff_cut_2) delete htdcdiff_cut_2;
htdcdiff_cut_2 = new TH1F(hname, hname, 4096, -2048.5*TDC_BIN, 2047.5*TDC_BIN);
//~ htdcdiff_cut_2 = new TH1F(hname, hname, 4096, -0.5*TDC_BIN, 4095.5*TDC_BIN);
sprintf(hname, "hadccor");
hadccor = (TH2F*)gROOT->FindObject(hname);
if(hadccor) delete hadccor;
//~ hadccor = new TH2F(hname, hname, 256, 0, 4096, 256, 0, 4096);
hadccor = new TH2F(hname, hname, 256, 0, 4096, 256, -32768.5*TDC_BIN, 32767.5*TDC_BIN);
sprintf(hname, "htdccor");
htdccor = (TH2F*)gROOT->FindObject(hname);
if(htdccor) delete hadccor;
//~ htdccor = new TH2F(hname, hname, 512, 0, 1024*TDC_BIN, 512, 0, 1024*TDC_BIN);
htdccor = new TH2F(hname, hname, 512, 1024*TDC_BIN, 2048*TDC_BIN, 512, 1024*TDC_BIN, 2048*TDC_BIN);
//~ htdccor = new TH2F(hname, hname, 512, 0, 2048*TDC_BIN, 512, 0, 2048*TDC_BIN);
//~ htdccor = new TH2F(hname, hname, 11*20+1, 15.985, 27.035, 3*40+1, 15.990,19.015);
//~ htdccor = new TH2F(hname, hname, 512, 0, 2047.5*TDC_BIN, 3*40+1, 15.990,19.015);
//kobayashi
sprintf(hname, "hcoradctdc0");
hcoradctdc0 = (TH2F*)gROOT->FindObject(hname);
hcoradctdc0 = new TH2F(hname,hname,2000,0,2000,800,-10,10);
sprintf(hname, "hcoradctdc1");
hcoradctdc1 = (TH2F*)gROOT->FindObject(hname);
hcoradctdc1 = new TH2F(hname,hname,2000,0,2000,800,-10,10);
ftt = (TTree*)gROOT->FindObject("ftt");
if(ftt) delete ftt;
ftt = new TTree("ftt","ftt");
ftt->Branch("t_adc0",&t_adc0,"t_adc0/D");
ftt->Branch("t_adc1",&t_adc1,"t_adc1/D");
ftt->Branch("t_tdc0",&t_tdc0,"t_tdc0/D");
ftt->Branch("t_tdc1",&t_tdc1,"t_tdc1/D");
ftt->Branch("t_ctdc",&t_ctdc,"t_ctdc/D");
#ifdef testpulse
sprintf(hname, "htesttdc1");
htesttdc1 = (TH1F*)gROOT->FindObject(hname);
if(htesttdc1) delete htesttdc1;
htesttdc1 = new TH1F(hname, hname, 65536, -0.5*TDC_BIN, 65535.5*TDC_BIN);
sprintf(hname, "htesttdc2");
htesttdc2 = (TH1F*)gROOT->FindObject(hname);
if(htesttdc2) delete htesttdc2;
htesttdc2 = new TH1F(hname, hname, 65536, -0.5*TDC_BIN, 65535.5*TDC_BIN);
#endif
for(int i=0; i<ANALYSE_CH; i++) {
sprintf(hname, "hadc%d", i);
hadc[i] = (TH1F*)gROOT->FindObject(hname);
if(hadc[i]) delete hadc[i];
hadc[i] = new TH1F(hname, hname, 4096, -0.5, 4095.5);
sprintf(hname, "hadc_cut%d", i);
hadc_cut[i] = (TH1F*)gROOT->FindObject(hname);
if(hadc_cut[i]) delete hadc_cut[i];
hadc_cut[i] = new TH1F(hname, hname, 4096, -0.5, 4095.5);
sprintf(hname, "hadc_cut_2%d", i);
hadc_cut_2[i] = (TH1F*)gROOT->FindObject(hname);
if(hadc_cut_2[i]) delete hadc_cut_2[i];
hadc_cut_2[i] = new TH1F(hname, hname, 4096, -0.5, 4095.5);
sprintf(hname, "htdc%d", i);
htdc[i] = (TH1F*)gROOT->FindObject(hname);
if(htdc[i]) delete htdc[i];
//~ htdc[i] = new TH1F(hname, hname, 4096, -2048.5*TDC_BIN, 2047.5*TDC_BIN);
//~ htdc[i] = new TH1F(hname, hname, 4096, -0.5*TDC_BIN, 4095.5*TDC_BIN); //original
//~ htdc[i] = new TH1F(hname, hname, 65536/2, -0.5*TDC_BIN, 65535.5*TDC_BIN); //koba
//~ htdc[i] = new TH1F(hname, hname, 65536/2, -32768.5*TDC_BIN, 32767.5*TDC_BIN); //koba
htdc[i] = new TH1F(hname, hname, 65536, -32768.5*TDC_BIN, 32767.5*TDC_BIN);
//~ htdc[i] = new TH1F(hname, hname, 65536, -0.5*TDC_BIN, 65535.5*TDC_BIN);
sprintf(hname, "htdc_cut%d", i);
htdc_cut[i] = (TH1F*)gROOT->FindObject(hname);
if(htdc_cut[i]) delete htdc_cut[i];
//~ htdc_cut[i] = new TH1F(hname, hname, 4096, -2048.5*TDC_BIN, 2047.5*TDC_BIN);
//~ htdc_cut[i] = new TH1F(hname, hname, 4096, -0.5*TDC_BIN, 4095.5*TDC_BIN);//original
//~ htdc_cut[i] = new TH1F(hname, hname, 65536/2, -0.5*TDC_BIN, 65535.5*TDC_BIN); //koba
htdc_cut[i] = new TH1F(hname, hname, 65536/2, -32768.5*TDC_BIN, 32767.5*TDC_BIN); //koba
//~ htdc_cut[i] = new TH1F(hname, hname, 65536, -32768.5*TDC_BIN, 32767.5*TDC_BIN);
sprintf(hname, "htdc_cut_2%d", i);
htdc_cut_2[i] = (TH1F*)gROOT->FindObject(hname);
if(htdc_cut_2[i]) delete htdc_cut_2[i];
//~ htdc_cut_2[i] = new TH1F(hname, hname, 4096, -2048.5*TDC_BIN, 2047.5*TDC_BIN);
//~ htdc_cut_2[i] = new TH1F(hname, hname, 4096, -0.5*TDC_BIN, 4095.5*TDC_BIN);//original
htdc_cut_2[i] = new TH1F(hname, hname, 65536, -0.5*TDC_BIN, 65535.5*TDC_BIN); //koba
sprintf(hname, "hctdc%d", i);
hctdc[i] = (TH1F*)gROOT->FindObject(hname);
if(hctdc[i]) delete hctdc[i];
//~ hctdc[i] = new TH1F(hname, hname, 4096, -2048.5*TDC_BIN, 2047.5*TDC_BIN);
//~ hctdc[i] = new TH1F(hname, hname, 65536/2, -32768.5*TDC_BIN, 32767.5*TDC_BIN);
hctdc[i] = new TH1F(hname, hname, 65536, -32768.5*TDC_BIN, 32767.5*TDC_BIN);
sprintf(hname, "h2d%d", i);
h2d[i] = (TH2F*)gROOT->FindObject(hname);
if(h2d[i]) delete h2d[i];
h2d[i] = new TH2F(hname, hname, run.nx, (run.x0-0.5*run.dx)*MIKRO_BIN, (run.x0+(run.nx-0.5)*run.dx)*MIKRO_BIN,
run.ny, (run.y0-0.5*run.dy)*MIKRO_BIN, (run.y0+(run.ny-0.5)*run.dy)*MIKRO_BIN);
sprintf(hname, "hcor%d", i);
hcor[i] = (TH2F*)gROOT->FindObject(hname);
if(hcor[i]) delete hcor[i];
//~ hcor[i] = new TH2F(hname, hname, 256, 0-0.5, 1024-0.5, 200, 10-(TDC_BIN/2), 20-(TDC_BIN/2));
//~ hcor[i] = new TH2F(hname, hname, 512, 0-0.5, 1024-0.5, 4096, -32768.5*TDC_BIN, 32767.5*TDC_BIN);
//~ hcor[i] = new TH2F(hname, hname, 256, 0-0.5, 512-0.5, 160, -2-(TDC_BIN/2), 2-(TDC_BIN/2));
hcor[i] = new TH2F(hname, hname, 512, 0-0.5, 1024-0.5, 160, -1.5-(TDC_BIN/2), 2.5-(TDC_BIN/2));
for(int j=0; j<ANALYSE_CH; j++) {
sprintf(hname, "hdiffcor_%d_%d",i,j);
sprintf(htitle, "ch.%d - ch.%d",i,j);
hdiffcor[i][j] = (TH2F*)gROOT->FindObject(hname);
if(hdiffcor[i][j]) delete hdiffcor[i][j];
hdiffcor[i][j] = new TH2F(hname, htitle, 256, 0-0.5, 1024-0.5, 128, -6.4-(TDC_BIN/2), 6.4-(TDC_BIN/2));
sprintf(hname, "hdiffcor_low_%d_%d",i,j);
sprintf(htitle, "ch.%d - ch.%d",i,j);
hdiffcor_low[i][j] = (TH2F*)gROOT->FindObject(hname);
if(hdiffcor_low[i][j]) delete hdiffcor_low[i][j];
hdiffcor_low[i][j] = new TH2F(hname, htitle, 256, 0-0.5, 512-0.5, 128, -6.4-(TDC_BIN/2), 6.4-(TDC_BIN/2));
sprintf(hname, "hdiffcor_hi_%d_%d",i,j);
sprintf(htitle, "ch.%d - ch.%d",i,j);
hdiffcor_hi[i][j] = (TH2F*)gROOT->FindObject(hname);
if(hdiffcor_hi[i][j]) delete hdiffcor_hi[i][j];
hdiffcor_hi[i][j] = new TH2F(hname, htitle, 256, 0-0.5, 2048-0.5, 128, -6.4-(TDC_BIN/2), 6.4-(TDC_BIN/2));
}
}
break;
case POSREC_ID:
#ifdef USE_ZLIB
gzread(dfp, (voidp)&readbuf[2*ulsize], (rec_len-2*ulsize));
#else
fread( (void*)&readbuf[2*ulsize], (rec_len-2*ulsize), 1, dfp);
#endif
pos=*posrec;
if(dbg) {
printf("POSREC_ID\n");
printf("id = %d, len = %d, time = %d\n", posrec->id, posrec->len, posrec->time);
printf("ix = %d, x = %d, xset = %d\n", posrec->ix, posrec->x, posrec->xset);
printf("iy = %d, y = %d, yset = %d\n", posrec->iy, posrec->y, posrec->yset);
} else printf(" [%d,%d] %d, %d\n", pos.ix, pos.iy, pos.xset, pos.yset);
break;
case EVTREC_ID:
#ifdef USE_ZLIB
gzread(dfp, (voidp)&readbuf[2*ulsize], (rec_len-2*ulsize));
#else
fread( (void*)&readbuf[2*ulsize], (rec_len-2*ulsize), 1, dfp);
#endif
if(dbg) {
//~ printf("EVTREC_ID\n");
//~ printf("id = %d, len = %d, nev = %d\n", evtrec->id, evtrec->len, evtrec->nev);
//for(int datai = 0; datai < NCH; datai++) printf("%u ", evtrec->data[datai]);
//printf("\n");
//for(int datai = NCH; datai < NCH+NCH; datai++) printf("%u ", evtrec->data[datai]);
//printf("\n");
//break;
}
// events ------------------------------------------------------------------------------------------
// fill histograms
double tdc_noise_cut;
//~ double adc_cor_min;
double tdca[ANALYSE_CH];
double ctdca[ANALYSE_CH];
double adca[ANALYSE_CH];
double ctdcdiff, tdcdiff;
tdc_noise_cut = 5.0;
//~ adc_cor_min = 200.0;
for(int i=0; i<ANALYSE_CH; i++) {
tdc=((double)evtrec->data[i])*TDC_BIN + tdcoffset[i];
//~ tdc=((double)evtrec->data[i])*TDC_BIN;
adc=(double)evtrec->data[i+NCH];
//~ if(i==15) printf("aaaaaaaaaaa15 norma %f\n",tdc);
tdca[i]=tdc;
adca[i]=adc;
//~ if(ceve < 100) {
//~ printf("[%3d] tdc[%2d] = %lf | adc[%2d] = %lf\n", ceve, i, tdc, i, adc);
//~ }
}
for(int i=0; i<ANALYSE_CH; i++) {
if(0 < adca[i]) hadc[i]->Fill(adca[i]);
//~ if( (qdcmi < adca[i]) && (adca[i] < qdcma) )
if(0 < tdca[i]) htdc[i]->Fill(tdca[i]-tdca[TRIGGER_CH]);
//~ if(0 < tdca[i]) htdc[i]->Fill(tdca[i]);
hcor[i]->Fill(adca[i],tdca[i]-tdca[TRIGGER_CH]);
if(adca[i] > corpar[i][2]) {
ctdca[i] = tdca[i]-tdca[TRIGGER_CH] - (corpar[i][0] + corpar[i][1]/TMath::Sqrt(adca[i] - corpar[i][2]));
} else {
ctdca[i] = -999.9*(i+1);
}
//~ if(tdc_noise_cut < tdca[i])
double adc_max_cut = 1000;
if(adca[i] < adc_max_cut)
hctdc[i]->Fill( ctdca[i] );
//~ if(dbg && (i<4) && (1 < tdca[0] && (1 < tdca[1]))) printf("tdca[%d] = %lf | tdca[TRG] = %lf | ctdca[i] = %lf | adca[i] = %lf\n", i, tdca[i],tdca[TRIGGER_CH],ctdca[i],adca[i]);
if(dbg && (i<4) ) printf("[%4d] tdca[%d] = %lf | tdca[TRG] = %lf | ctdca[i] = %lf | adca[i] = %lf\n", ceve, i, tdca[i],tdca[TRIGGER_CH],ctdca[i],adca[i]);
if( (qdcmi < adca[i]) && (adca[i] < qdcma) && (tdcmi < tdca[i]) && (tdca[i] < tdcma)) {
h2d[i]->Fill(pos.xset*MIKRO_BIN, pos.yset*MIKRO_BIN);
}
}
//~ printf("aaaaaaaaaaa15 %f\n",((double)evtrec->data[15])); printf("aaaaaaaaaaa15 %f\n",((double)evtrec->data[15])*TDC_BIN);
//~ printf("aaaaaaaaaaa30 %d\n",evtrec->data[30]);
//~ printf("aaaaaaaaaaa31 %d\n",evtrec->data[31]);
//~ printf("aaaaaaaaaaa15 %f\n",tdca[15]);
//~ printf("aaaaaaaaaaa30 %d\n",tdca[30]);
//~ printf("aaaaaaaaaaa31 %d\n",tdca[31]);
//~
//kobayashi
ctdcdiff = ctdca[MPPC_2_CH] - ctdca[MPPC_1_CH] +deltaT_ctdcdiff;
tdcdiff = tdca[MPPC_2_CH] - tdca[MPPC_1_CH];
t_ctdc = ctdcdiff;
t_tdc0=tdca[0];
t_tdc1=tdca[1];
t_adc0=adca[15];
t_adc1=adca[1];
hcoradctdc0->Fill(adca[0],ctdcdiff);
hcoradctdc1->Fill(adca[1],ctdcdiff);
ftt->Fill();
#ifdef testpulse
htesttdc1->Fill(tdca[16]-tdca[14]);
htesttdc2->Fill(tdca[14]-tdca[15]);
#endif
//cut za timing:
#define CUT_1_CONDITION ( (qdcmi < adca[MPPC_1_CH]) && (adca[MPPC_1_CH] < qdcma) && (tdcmi < adca[MPPC_2_CH]) && (adca[MPPC_2_CH] < tdcma) )
//~ // cut za meritev efficiency:
//~ #define CUT_1_CONDITION ( (qdcmi < adca[MPPC_1_CH]) && (adca[MPPC_1_CH] < qdcma) )
//~ #define CUT_1_CONDITION ( (tdcmi < ctdcdiff) && (ctdcdiff < tdcma) )
//~ #define CUT_1_CONDITION ( (ref_cut_1_lo < adca[MPPC_1_CH]) && (adca[MPPC_1_CH] < ref_cut_1_hi) )
//~ #define CUT_1_CONDITION ( (qdcmi < tdca[MPPC_1_CH]) && (tdca[MPPC_1_CH] < qdcma) )
//~ #define CUT_1_CONDITION ( (ref_cut_1_lo < adca[REF_CH]) && (adca[REF_CH] < ref_cut_1_hi) && (ref_cut_1_lo < adca[MPPC_1_CH]) && (adca[MPPC_1_CH] < ref_cut_1_hi) )
// cut za meritev efficiency:
#define CUT_2_CONDITION ( (tdcmi < adca[REF_CH]) && (adca[REF_CH] < tdcma) )
//~ #define CUT_2_CONDITION ( (qdcmi < adca[MPPC_1_CH]) && (adca[MPPC_1_CH] < qdcma) && (tdcmi < adca[REF_CH]) && (adca[REF_CH] < tdcma) )
//~ #define CUT_2_CONDITION ( (ref_cut_1_lo < tdca[MPPC_1_CH]) && (tdca[MPPC_1_CH] < ref_cut_1_hi) )
//~ #define CUT_2_CONDITION ( (qdcmi < adca[REF_CH]) && (adca[REF_CH] < qdcma) && (tdcmi < tdca[REF_CH]) && (tdca[REF_CH] < tdcma) )
//~ #define CUT_2_CONDITION ( (ref_cut_1_lo < adca[MPPC_1_CH]) && (adca[MPPC_1_CH] < ref_cut_1_hi) && (ref_cut_2_lo < adca[MPPC_2_CH]) && (adca[MPPC_2_CH] < ref_cut_2_hi) )
//~ #define CUT_2_CONDITION ( (ref_cut_2_lo < adca[REF_CH]) && (adca[REF_CH] < ref_cut_2_hi) )
//~ #define CUT_2_CONDITION ( (ref_cut_1_lo < tdca[MPPC_1_CH]) && (tdca[MPPC_1_CH] < ref_cut_1_hi) && (ref_cut_2_lo < tdca[MPPC_2_CH]) && (tdca[MPPC_2_CH] < ref_cut_2_hi) )
//~ #define CUT_2_CONDITION ( (ref_cut_2_lo < tdca[REF_CH]) && (tdca[REF_CH] < ref_cut_2_hi) && (ref_cut_2_lo < tdca[MPPC_1_CH]) && (tdca[MPPC_1_CH] < ref_cut_2_hi) )
if( (tdc_noise_cut < tdca[MPPC_1_CH]) && (tdc_noise_cut < tdca[MPPC_2_CH])) {
//~ if( (qdcmi < adca[MPPC_1_CH]) && (tdcmi < adca[MPPC_2_CH]) )
htdcdiff->Fill(ctdcdiff);
if( CUT_1_CONDITION ) {
htdcdiff_cut->Fill(ctdcdiff);
//~ htdcdiff_cut->Fill(tdcdiff);
}
if( CUT_2_CONDITION ) {
htdcdiff_cut_2->Fill(ctdcdiff);
}
}
for(int i=0; i<ANALYSE_CH; i++) {
//~ if( CUT_1_CONDITION ) {
//~ if( ( (qdcmi < adca[REF_CH]) && (adca[REF_CH] < qdcma) ) ) {
//~ if( ( (-2 < ctdca[0]) && (ctdca[0] < 2) ) ) {
//~ htdc_cut[i]->Fill(tdca[i]-tdca[31]);
//~ htdc_cut[i]->Fill(ctdca[i]);
//~ hadc_cut[i]->Fill(adca[i]);
//~ }
if( (qdcmi < adca[i]) && (adca[i] < qdcma) && (adca[i] > corpar[i][2]) )
htdc_cut[i]->Fill(ctdca[i]);
if( (tdcmi < ctdca[i]) && (ctdca[i] < tdcma) )
hadc_cut[i]->Fill(adca[i]);
if( CUT_2_CONDITION ) {
htdc_cut_2[i]->Fill(tdca[i]);
hadc_cut_2[i]->Fill(adca[i]);
hadc_cut_2[i]->Fill(adca[i]);
}
}
//~ hadccor->Fill(adca[REF_CH], adca[MPPC_1_CH]);
hadccor->Fill(adca[REF_CH], tdca[8]-tdca[31]);
htdccor->Fill(tdca[MPPC_1_CH], tdca[MPPC_2_CH]);
// --------------- corelation plots for time-walk correction ---------------
if( (tdc_noise_cut<tdca[MPPC_1_CH]) && (tdc_noise_cut<tdca[MPPC_2_CH]) && (adc_cor_min<adca[MPPC_2_CH]) ) {
hdiffcor[MPPC_1_CH][MPPC_2_CH]->Fill(adca[MPPC_1_CH],tdca[MPPC_1_CH]-ctdca[MPPC_2_CH]);
hdiffcor_low[MPPC_1_CH][MPPC_2_CH]->Fill(adca[MPPC_1_CH],tdca[MPPC_1_CH]-ctdca[MPPC_2_CH]);
hdiffcor_hi[MPPC_1_CH][MPPC_2_CH]->Fill(adca[MPPC_1_CH],tdca[MPPC_1_CH]-ctdca[MPPC_2_CH]);
}
if( (tdc_noise_cut<tdca[MPPC_2_CH]) && (tdc_noise_cut<tdca[MPPC_1_CH]) && (adc_cor_min<adca[MPPC_1_CH]) ) {
hdiffcor[MPPC_2_CH][MPPC_1_CH]->Fill(adca[MPPC_2_CH],tdca[MPPC_2_CH]-ctdca[MPPC_1_CH]);
hdiffcor_low[MPPC_2_CH][MPPC_1_CH]->Fill(adca[MPPC_2_CH],tdca[MPPC_2_CH]-ctdca[MPPC_1_CH]);
hdiffcor_hi[MPPC_2_CH][MPPC_1_CH]->Fill(adca[MPPC_2_CH],tdca[MPPC_2_CH]-ctdca[MPPC_1_CH]);
}
// events ------------------------------------------------------------------------------------------
break;
case ENDREC_ID:
#ifdef USE_ZLIB
gzread(dfp, (voidp)&readbuf[2*ulsize], (rec_len-2*ulsize));
#else
fread( (void*)&readbuf[2*ulsize], (rec_len-2*ulsize), 1, dfp);
#endif
if(dbg) {
printf("ENDREC_ID\n");
printf("id = %d, len = %d, time = %d\n", endrec->id, endrec->len, endrec->time);
} else printf(" ENDREC\n");
fcount++;
switch(ftype-1) {
case 0:
sprintf(dfile, "data/%s_file%02d.dat", dfile0, fcount);
break;
case 1:
sprintf(dfile, "data/%s_file%02d.dat.gz", dfile0, fcount);
break;
case 2:
sprintf(dfile, "data/%s_file%02d.gz", dfile0, fcount);
break;
}
#ifdef USE_ZLIB
if(dfp) gzclose(dfp);
dfp=gzopen(dfile,"rb");
#else
if(dfp) fclose(dfp);
dfp=fopen(dfile,"rb");
#endif
if(!dfp) {
printf(" Cannot open data file: %s ---> Exiting\n", dfile);
end_of_file = 1;
} else {
printf(" Opened data file: %s\n", dfile);
end_of_file = 0;
}
break;
default:
printf("switch(rec_id): default !!!\n");
end_of_file = 1;
break;
}
ceve++;
if( (ceve%50000) == 0) printf(" Current event = %d\n", ceve);
if(dbg) if( ceve>dbg ) break;
if(end_of_file) break;
}
#ifdef USE_ZLIB
if(dfp) gzclose(dfp);
#else
if(dfp) fclose(dfp);
#endif
if(dbg) return 1;
if(rootfile) {
#ifdef testpulse
printf("<<< EASIROC Disc : %f [ps]\n", htesttdc1->GetRMS()*1000);
printf("<<< TEST Disc : %f [ps]\n", htesttdc2->GetRMS()*1000);
#endif
ftt->Write();
rootfile->Write();
//cout<<"maximum x value = " << htdcdiff->GetXaxis()->GetBinCenter( htdcdiff->GetMaximumBin()) <<endl;
printf("Saved to %s\n", fnameroot);
rootfile->Close();
}
gSystem->Exit(1);
return 1;
}