Subversion Repositories f9daq

Compare Revisions

Ignore whitespace Rev 179 → Rev 180

/drs/DrsChannel.h
0,0 → 1,12
#ifndef _DrsChannel_
#define _DrsChannel_
typedef struct {
float cfrac;
float threshold;
float twin[2];
float adcgate[2];
float vcut[2];
int edge;
} DrsChannel;
 
#endif
/drs/drs.C
7,309 → 7,361
//#include "TROOT.h"
 
#include <stdio.h>
#include <time.h>
 
#define DATA_PATH "./data/"
#define CFRAC 0.4
#define DWIDTH 1024
void drs(int nev=1000, int updfrq=20, const char *FileName="drs000.dat", int trgch=0, int debug=0)
#define NCH 4
#include "drs.h"
 
ClassImp (drs)
 
drs::drs( const char *FileName, int nch, DrsChannel* d, int trgch, int nev, int updfrq)
{
int i,ich,iev;
int stat;
char histname[128];
int debug=0;
int i,ich,iev;
int stat;
char histname[128];
// char FileName[300]="./data/n2.dat";
FILE *fin;
FILE *fin;
 
char recid[5]="SAMO";
unsigned short *srecid = (unsigned short *) &recid[0];
char recid[5]="SAMO";
unsigned short *srecid = (unsigned short *) &recid[0];
 
struct evrec {
unsigned long evn;
unsigned short tYear,tMonth,tDay,tHour,tMin,tSec,tmSec,rc;
} evrec;
struct evrec {
unsigned long evn;
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;
float dtdata[NCH][DWIDTH];
float tcdata[NCH][DWIDTH];
float tccalib[NCH];
float scaler[NCH];
float *t;
float *y;
float *ay;
 
short lwfm[4];
int nwfm[4];
int board;
int version;
short lwfm[NCH];
int nwfm[NCH];
int board;
int version;
 
unsigned short ichdat[4][DWIDTH];
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.}};
// float adcgate[4][2]={{124.,136.},{120.,140.},{120.,140.},{70.,90.}};
// 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 }};
 
unsigned short ichdat[NCH][DWIDTH];
float chdat[NCH][DWIDTH];
float achdat[NCH][DWIDTH];
float chmax[NCH][2];
float chmin[NCH][2];
float letime[NCH],cftime[NCH],qdc[NCH];
 
 
// gROOT->Reset();
 
gStyle->SetOptStat(1111111);
gStyle->SetOptStat(1111111);
// gStyle->SetPalette(52);
 
TH1F *h1_chmax[4];
TH1F *h1_chmaxt[4];
TH1F *h1_chmin[4];
TH1F *h1_chmint[4];
TH1F *h1_letime[4][2];
TH1F *h1_cftime[4][2];
TH1F *h1_cftdif[4];
TH1F *h1_qdc[4];
TH2F *h2_dpo[4];
TH2F *h2_tdcadc[4];
TH2F *h2_ctdcadc[4];
TH2F *h2_ctalk;
TGraph *gr_wfm[4];
TCanvas *c_wfm= new TCanvas("c_wfm","WFM",50,50,700,700);
TLegend *leg = new TLegend(0.8, 0.8, 1, 1);
c_wfm->Divide(1,1);
c_wfm->cd(1);
TH1F *h1_chmax[NCH];
TH1F *h1_chmaxt[NCH];
TH1F *h1_chmin[NCH];
TH1F *h1_chmint[NCH];
TH1F *h1_letime[NCH];
TH1F *h1_cftime[NCH];
TH1F *h1_cftdif[NCH];
TH1F *h1_qdc[NCH];
TH2F *h2_dpo[NCH];
TH2F *h2_tdcadc[NCH];
TH2F *h2_ctdcadc[NCH];
TH2F *h2_ctalk;
TGraph *gr_wfm[NCH];
TCanvas *c_wfm= new TCanvas("c_wfm","WFM",50,50,700,700);
TLegend *leg = new TLegend(0.8, 0.8, 1, 1);
c_wfm->Divide(1,1);
c_wfm->cd(1);
 
for (i=0;i<4;i++) {
sprintf(histname,"chmax_%02d",i);
h1_chmax[i]=new TH1F(histname,histname,1100,-0.55,0.55);
sprintf(histname,"chmaxt_%02d",i);
h1_chmaxt[i]=new TH1F(histname,histname,DWIDTH,-0.1,204.7);
sprintf(histname,"chmin_%02d",i);
h1_chmin[i]=new TH1F(histname,histname,1100,-0.55,0.55);
sprintf(histname,"chmint_%02d",i);
h1_chmint[i]=new TH1F(histname,histname,DWIDTH,-0.1,204.7);
sprintf(histname,"letimep_%02d",i);
h1_letime[i][0]=new TH1F(histname,histname,500,twin[i][0],twin[i][1]);
sprintf(histname,"letimen_%02d",i);
h1_letime[i][1]=new TH1F(histname,histname,500,twin[i][0],twin[i][1]);
sprintf(histname,"cftimep_%02d",i);
h1_cftime[i][0]=new TH1F(histname,histname,500,twin[i][0],twin[i][1]);
sprintf(histname,"cftimen_%02d",i);
h1_cftime[i][1]=new TH1F(histname,histname,500,twin[i][0],twin[i][1]);
sprintf(histname,"cftdif_%02d",i);
h1_cftdif[i]=new TH1F(histname,histname,2000,twin[i][0],twin[i][1]);
sprintf(histname,"qdc_%02d",i);
h1_qdc[i]=new TH1F(histname,histname,500,-0.1,4.9);
sprintf(histname,"dpo_%02d",i);
h2_dpo[i]=new TH2F(histname,histname,DWIDTH,-0.1,204.7,1100,-0.55,0.55);
sprintf(histname,"tdcadc_%02d",i);
h2_tdcadc[i]=new TH2F(histname,histname,250,0.,0.5,400,twin[i][0],twin[i][1]);
sprintf(histname,"ctdcadc_%02d",i);
h2_ctdcadc[i]=new TH2F(histname,histname,250,0.,0.5,400,twin[i][0],twin[i][1]);
gr_wfm[i]=new TGraph(DWIDTH);
gr_wfm[i]->SetMinimum(-0.55);
gr_wfm[i]->SetMaximum(0.55);
gr_wfm[i]->SetLineColor(i+1);
gr_wfm[i]->SetMarkerColor(i+1);
sprintf(histname,"ch %d",i);
leg->AddEntry(gr_wfm[i], histname, "l");
if (i) gr_wfm[i]->Draw("LP"); else gr_wfm[i]->Draw("ALP");
}
leg->Draw();
h2_ctalk=new TH2F("ctalk","ctalk",250,0.,0.5,250,0.,0.5);
for (i=0; i<nch; i++) {
sprintf(histname,"chmax_%02d",i);
h1_chmax[i]=new TH1F(histname,histname,1100,-0.55,0.55);
sprintf(histname,"chmaxt_%02d",i);
h1_chmaxt[i]=new TH1F(histname,histname,DWIDTH,-0.1,204.7);
sprintf(histname,"chmin_%02d",i);
h1_chmin[i]=new TH1F(histname,histname,1100,-0.55,0.55);
sprintf(histname,"chmint_%02d",i);
h1_chmint[i]=new TH1F(histname,histname,DWIDTH,-0.1,204.7);
sprintf(histname,"letime_%02d",i);
h1_letime[i]=new TH1F(histname,histname,500,d[i].twin[0],d[i].twin[1]);
sprintf(histname,"cftime_%02d",i);
h1_cftime[i]=new TH1F(histname,histname,500,d[i].twin[0],d[i].twin[1]);
sprintf(histname,"cftdif_%02d",i);
h1_cftdif[i]=new TH1F(histname,histname,2000,d[i].twin[0],d[i].twin[1]);
sprintf(histname,"qdc_%02d",i);
h1_qdc[i]=new TH1F(histname,histname,500,-0.1,4.9);
sprintf(histname,"dpo_%02d",i);
h2_dpo[i]=new TH2F(histname,histname,DWIDTH,-0.1,204.7,1100,-0.55,0.55);
sprintf(histname,"tdcadc_%02d",i);
h2_tdcadc[i]=new TH2F(histname,histname,250,0.,0.5,400,d[i].twin[0],d[i].twin[1]);
sprintf(histname,"ctdcadc_%02d",i);
h2_ctdcadc[i]=new TH2F(histname,histname,250,0.,0.5,400,d[i].twin[0],d[i].twin[1]);
gr_wfm[i]=new TGraph(DWIDTH);
gr_wfm[i]->SetMinimum(-0.55);
gr_wfm[i]->SetMaximum(0.55);
gr_wfm[i]->SetLineColor(i+1);
gr_wfm[i]->SetMarkerColor(i+1);
sprintf(histname,"ch %d",i);
leg->AddEntry(gr_wfm[i], histname, "l");
if (i) gr_wfm[i]->Draw("LP"); else gr_wfm[i]->Draw("ALP");
gr_wfm[i]->GetHistogram()->SetTitle("WaveForms");
}
 
fin=fopen(FileName,"rb");
if (fin==NULL) {
printf("Error opening file %s\n",FileName);
return;
}
printf("%s, %lu\n",recid,sizeof(evrec));
leg->Draw();
h2_ctalk=new TH2F("ctalk","ctalk",250,0.,0.5,250,0.,0.5);
 
for (ich=0;ich<4;ich++){
nwfm[ich]=0;
for (i=0;i<DWIDTH;i++){
achdat[ich][i]=0;
}
}
unsigned int trgcell = 0;
int event = -1;
iev=0;
while(!feof(fin)){
if (iev>=nev) break;
stat=fread(recid,1,4,fin);
if (debug){
if (recid[1]=='#') printf("%c%c%u\n",recid[0],recid[1],srecid[1]);
else printf("%s\n",recid );
}
switch (recid[0]){
case 'D': // DRS
version = atoi(&recid[3]);
break;
case 'T': // TIME
switch (recid[1]){
case 'I':
event=0;
if (version ==0) version++;
break;
case '#': trgcell = srecid[1]; break;
}
break;
case 'B':
board = srecid[1];
break;
case 'C':
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);
}
break;
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! %s\n", recid);
break;
}
fin=fopen(FileName,"rb");
if (fin==NULL) {
printf("Error opening file %s\n",FileName);
return;
}
printf("%s, %lu\n",recid,sizeof(evrec));
 
 
if (recid[0] == 'E'){
for ( i=0;i<4;i++){
if (!lwfm[i]) continue;
if ((chmin[i][0]>vcut[i][0])&&(chmin[i][0]<vcut[i][1])) {
h1_cftdif[i]->Fill(cftime[i][1]-cftime[trgch][1]+110.);
}
for (ich=0; ich<nch; ich++) {
nwfm[ich]=0;
for (i=0; i<DWIDTH; i++) {
achdat[ich][i]=0;
}
}
unsigned int trgcell = 0;
int event = -1;
 
iev=0;
time_t t0,told;
time(&t0);
told=t0-1;
while(!feof(fin)) {
if (iev>=nev) break;
stat=fread(recid,1,4,fin);
if (debug) {
if (recid[1]=='#') printf("%c%c%u\n",recid[0],recid[1],srecid[1]);
else printf("%s\n",recid );
}
switch (recid[0]) {
case 'D': // DRS
version = atoi(&recid[3]);
break;
case 'T': // TIME
switch (recid[1]) {
case 'I':
event=0;
if (version ==0) version++;
break;
case '#': trgcell = srecid[1]; break;
}
break;
case 'B':
board = srecid[1];
break;
case 'C':
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);
 
}
break;
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! %s\n", recid);
break;
}
 
 
if (recid[0] == 'E') {
for ( i=0; i<nch; i++) {
if (!lwfm[i]) continue;
if ((chmin[i][0]>d[i].vcut[0])&&(chmin[i][0]<d[i].vcut[1])) {
h1_cftdif[i]->Fill(cftime[i]-cftime[trgch]+110.);
}
// h2_tdcadc[i]->Fill(-chmin[i][0],letime[i][1]-cftime[trgch][1]+72);
// h2_ctdcadc[i]->Fill(-chmin[i][0],cftime[i][1]-cftime[trgch][1]+72);
h2_tdcadc[i]->Fill(-chmin[0][0],letime[i][1]-cftime[trgch][1]+72);
h2_ctdcadc[i]->Fill(-chmin[0][0],cftime[i][1]-cftime[trgch][1]+72);
}
h2_ctalk->Fill(-chmin[0][0],-chmin[1][0]);
}
if (event<1) continue;
if (recid[0]!='C') continue;
h2_tdcadc[i]->Fill(-chmin[0][0],letime[i]-cftime[trgch]+72);
h2_ctdcadc[i]->Fill(-chmin[0][0],cftime[i]-cftime[trgch]+72);
}
h2_ctalk->Fill(-chmin[0][0],-chmin[1][0]);
}
if (event<1) continue;
if (recid[0]!='C') continue;
if (ich>=nch) continue;
 
lwfm[ich]=0;
qdc[ich]=0;
chmax[ich][0]=-1; chmax[ich][1]=-1;
chmin[ich][0]=1; chmin[ich][1]=-1;
letime[ich][0]=-1.; letime[ich][1]=-1.;
cftime[ich][0]=-1.; cftime[ich][1]=-1.;
lwfm[ich]=0;
qdc[ich]=0;
chmax[ich][0]=-1; chmax[ich][1]=-1;
chmin[ich][0]=1; chmin[ich][1]=-1;
letime[ich]=-1.; letime[ich]=-1.;
cftime[ich]=-1.; cftime[ich]=-1.;
 
lwfm[ich]=1;
nwfm[ich]+=1;
 
t = &tcdata[ich][0];
y = &chdat[ich][0];
ay = &achdat[ich][0];
lwfm[ich]=1;
nwfm[ich]+=1;
 
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++) {
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];
}
// signal maximum
if (y[i]<chmin[ich][0]) {
chmin[ich][0]=y[i];
chmin[ich][1]=t[i];
}
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;
}
}
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]);
 
t = &tcdata[ich][0];
y = &chdat[ich][0];
ay = &achdat[ich][0];
 
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++) {
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];
}
 
// signal maximum
if (y[i]<chmin[ich][0]) {
chmin[ich][0]=y[i];
chmin[ich][1]=t[i];
}
float t0 = t[i];
float t0p = t[i+1];
float t0n = t[i-1];
// charge in the range
if ((t0>d[ich].adcgate[0])&&(t0<d[ich].adcgate[1])) {
qdc[ich]+=-y[i]*(t0p-t0n)/2;
}
}
 
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>d[ich].twin[0])&&(t0<d[ich].twin[1])) {
if ( ((!d[ich].edge)&&(y[i]<d[ich].threshold) ||
( d[ich].edge)&&(y[i]>d[ich].threshold ) )
&&(letime[ich]<0.)) {
letime[ich]=t0n+(t0-t0n)*(d[ich].threshold-y[i-1])/(y[i]-y[i-1]);
}
// constant fraction time in the range
if ( ( ((!d[ich].edge) && (chmin[ich][0]<d[ich].threshold)&&(y[i]<chmin[ich][0]*d[ich].cfrac)) ||
(( d[ich].edge) && (chmax[ich][0]>d[ich].threshold)&&(y[i]>chmax[ich][0]*d[ich].cfrac)) )
&&(cftime[ich]<0.)
 
) {
cftime[ich]=t0n+(t0-t0n)*(chmin[ich][0]*d[ich].cfrac-y[i-1])/(y[i]-y[i-1]);
}
}
}
 
if ((chmax[ich][1]>d[ich].twin[0])&&(chmax[ich][1]<d[ich].twin[1])) {
h1_chmax[ich]->Fill(chmax[ich][0]);
if (chmax[ich][0]>d[ich].threshold) h1_chmaxt[ich]->Fill(chmax[ich][1]);
}
if ((chmin[ich][1]>d[ich].twin[0])&&(chmin[ich][1]<d[ich].twin[1])) {
h1_chmin[ich]->Fill(chmin[ich][0]);
if (chmin[ich][0]<d[ich].threshold) h1_chmint[ich]->Fill(chmin[ich][1]);
}
h1_qdc[ich]->Fill(qdc[ich]);
h1_letime[ich]->Fill(letime[ich]);
h1_cftime[ich]->Fill(cftime[ich]);
time(&t0);
 
if ((t0!=told) || ((updfrq>0)&&(!(iev%updfrq) ) ) ) {
c_wfm->Update();
for (i=0; i<DWIDTH; i++) {
ay[i]/=nwfm[ich];
gr_wfm[ich]->SetPoint(i,t[i],ay[i]+0.00*(ich-1));
}
printf("processing event %d\n",iev);
told=t0;
}
}
// 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]);
}
}
}
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 (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);
 
printf("number of events: %d\n",iev);
fclose(fin);
TCanvas* c_dpo= new TCanvas("c_dpo","DPO",750,50,700,700);
c_dpo->Divide(2,2);
for (i=0; i<nch; i++) {c_dpo->cd(i+1); h2_dpo[i]->Draw("colz");}
 
TCanvas* c_dpo= new TCanvas("c_dpo","DPO",750,50,700,700);
c_dpo->Divide(2,2);
for (i=0;i<4;i++) {c_dpo->cd(i+1);h2_dpo[i]->Draw("colz");}
TCanvas* c_cftdif= new TCanvas("c_cftdif","DPO",750,50,700,700);
c_cftdif->Divide(2,2);
for (i=0; i<nch; i++) {c_cftdif->cd(i+1); h1_cftdif[i]->Draw();}
return;
}
 
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;
 
void drsana(int nev=1000, int updfrq=20, char *FileName="./data/x1.dat", int trgch=0){
 
// float threshold[nch][2]={{0.,-0.02},{0.,0.},{0.,0.},{0.,-0.25}};
// float twin[nch][2]={{120.,130.},{100.,150.},{100.,150.},{70.,90.}};
// float adcgate[nch][2]={{12nch.,136.},{120.,140.},{120.,140.},{70.,90.}};
// 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.05},{0.,-0.05},{0.,-0.25},{0.,-0.25}};
float twin[4][2]={{100.,120.},{100.,120.},{110.,130.},{60.,80.}};
float adcgate[4][2]={{105.,125.},{105.,125.},{110.,130.},{60.,80.}};
float vcut[4][2]={{-0.49,-0.07},{-1,1},{-1,1},{-1,1}};
int edge[4]={1,1,1,1};// 0 -- rising, 1 -- falling
 
DrsChannel c[2];
 
c[0].cfrac = CFRAC;
c[0].threshold = threshold[0][0];
c[0].twin[0] = twin[0][0];
c[0].twin[1] = twin[0][1];
 
c[0].adcgate[0] = adcgate[0][0];
c[0].adcgate[1] = adcgate[0][1];
 
c[0].vcut[0] = vcut[0][0];
c[0].vcut[1] = vcut[0][1];
 
c[0].edge = edge[0];
 
 
c[1].cfrac = CFRAC;
c[1].threshold = threshold[1][0];
c[1].twin[0] = twin[1][0];
c[1].twin[1] = twin[1][1];
 
c[1].adcgate[0] = adcgate[1][0];
c[1].adcgate[1] = adcgate[1][1];
 
c[1].vcut[0] = vcut[1][0];
c[1].vcut[1] = vcut[1][1];
 
c[1].edge = edge[1];
drs * d = new drs(FileName, 2, c, trgch, nev, updfrq );
}
/drs/drs.h
0,0 → 1,11
#ifndef _drs_
#define _drs_
#include "DrsChannel.h"
class drs {
public:
drs(const char *FileName, int nch, DrsChannel* ch, int trgch=0, int nev=1000, int updfrq=20 );
~drs(){};
ClassDef ( drs, 1 ) //
};
 
#endif
/drs/drs010.ini
0,0 → 1,5
# ch. edge twin0 adcwin0 twin1 vcut0 threshold vcut1 cfrac
0 1 100 105 120 -0.5 0.25 0.5 0.4
1 0 60 65 90 -0.5 -0.05 0.5 0.4
2 0 100 105 120 -0.5 -0.05 0.5 0.4
3 0 100 105 120 -0.5 -0.05 0.5 0.4
/drs/drsgui.C
0,0 → 1,561
 
// Simple macro showing capabilities of triple slider
//Authors: Bertrand Bellenot, Ilka Antcheva
 
#include "TGButton.h"
#include "TRootEmbeddedCanvas.h"
#include "TGLayout.h"
#include "TF1.h"
#include "TMath.h"
#include "TCanvas.h"
#include "TGTextEntry.h"
#include "TGNumberEntry.h"
#include "TGLabel.h"
#include "TGTripleSlider.h"
#include "TGFrame.h"
#include "TGTab.h"
#include "TGButton.h"
#include "TGSlider.h"
#include "TGComboBox.h"
#include <TGFileDialog.h>
#include "DrsChannel.h"
#include "drs.h"
 
enum ETestCommandIdentifiers {
HId1,
HId2,
HId3,
 
VId1,
VId2,
VId3,
 
CFId1,
 
HCId1,
HCId2,
 
 
HSId1,
 
VSId1,
StartId
};
 
const char *filetypesdat[] = {
"data files", "*.dat",
"Text files", "*.[tT][xX][tT]",
0, 0
};
 
const char *filetypesini[] = {
"configuration files", "*.ini",
0, 0
};
 
TRootEmbeddedCanvas *fCanvas;
 
class TChannel {
private:
 
 
TGTripleHSlider *fTimingSlider;
TGTripleHSlider *fThresholdSlider;
 
TGLayoutHints *fBly, *fBfly1, *fBfly2, *fBfly3;
public:
TChannel( TGCompositeFrame *p, int ch);
~TChannel();
 
TGTextEntry *fTeh[7];
TGTextBuffer *fTbh[7];
TGCheckButton *fEdge;
 
void DoText(const char *text);
void DoSlider();
void HandleButtons();
 
ClassDef(TChannel, 0)
 
};
 
 
 
TChannel::~TChannel(){
 
 
 
}
 
TChannel::TChannel( TGCompositeFrame *p, int ch){
 
//--- layout for the frame: place at bottom, right aligned
fBfly1 = new TGLayoutHints(kLHintsTop | kLHintsCenterX, 5, 5, 5, 5);
fBfly2 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
fBfly3 = new TGLayoutHints(kLHintsTop | kLHintsRight, 5, 5, 5, 5);
fBly = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5);
 
 
TGVerticalFrame *fHframe1 = new TGVerticalFrame(p, 0, 0, 0);
 
 
 
TGHorizontalFrame * fThresholdFrame = new TGHorizontalFrame(fHframe1, 0, 0, 0);
 
//TGLabel *fLChannel = new TGLabel(fThresholdFrame, tmp);
TGLabel *fLThreshold = new TGLabel(fThresholdFrame, "Threshold:");
 
fThresholdSlider = new TGTripleHSlider(fThresholdFrame, 190, kDoubleScaleBoth, VSId1,
kHorizontalFrame,
p->GetDefaultFrameBackground(),
kFALSE, kFALSE, kFALSE, kFALSE);
fThresholdSlider->Connect("PointerPositionChanged()", "TChannel", this, "DoSlider()");
fThresholdSlider->Connect("PositionChanged()", "TChannel", this, "DoSlider()");
fThresholdSlider->SetRange(-1,1);
 
//fThresholdFrame->AddFrame(fLChannel, fBfly2);
fThresholdFrame->AddFrame(fLThreshold, fBfly2);
fThresholdFrame->AddFrame(fThresholdSlider, fBly);
 
TGHorizontalFrame * fTimeWinFrame = new TGHorizontalFrame(fHframe1, 0, 0, 0);
fEdge = new TGCheckButton(fTimeWinFrame, "&Positive Edge", HCId2);
fEdge->SetState(kButtonUp);
fEdge->SetToolTipText("Pointer position relative to slider position");
 
TGLabel *fLTiming = new TGLabel(fTimeWinFrame, "Time Window:");
 
fTimingSlider = new TGTripleHSlider(fTimeWinFrame, 190, kDoubleScaleBoth, HSId1,
kHorizontalFrame,
p->GetDefaultFrameBackground(),
kFALSE, kFALSE, kFALSE, kFALSE);
fTimingSlider->Connect("PointerPositionChanged()", "TChannel", this, "DoSlider()");
fTimingSlider->Connect("PositionChanged()", "TChannel", this, "DoSlider()");
fTimingSlider->SetRange(0,200);
 
 
 
fHframe1->Resize(200, 25);
 
fEdge->Connect("Clicked()", "TChannel", this,
"HandleButtons()");
 
fTimeWinFrame->AddFrame(fEdge, fBfly2);
fTimeWinFrame->AddFrame(fLTiming, fBfly2);
fTimeWinFrame->AddFrame(fTimingSlider, fBly);
 
fHframe1->AddFrame(fThresholdFrame, fBly);
fHframe1->AddFrame(fTimeWinFrame, fBly);
 
 
 
 
TGHorizontalFrame *fNumbersFrame = new TGHorizontalFrame(fHframe1, 0, 0, 0);
 
for (int i=0; i<7; i++)
fTeh[i] = new TGTextEntry(fNumbersFrame, fTbh[i] = new TGTextBuffer(5), HId1+i);
 
fTeh[0]->SetToolTipText("Minimum (left) Value of Slider");
fTeh[1]->SetToolTipText("Pointer Position Value");
fTeh[2]->SetToolTipText("Maximum (right) Value of Slider");
fTeh[3]->SetToolTipText("Signal Cut 0");
fTeh[4]->SetToolTipText("Signal Threshold");
fTeh[5]->SetToolTipText("Signal Cut 1");
 
fTeh[6]->SetToolTipText("Constant Fraction Ratio");
 
for (int i=0; i<7; i++) {
fTbh[i]->AddText(0, "0.0");
fTeh[i]->Connect("TextChanged(char*)", "TChannel", this,
"DoText(char*)");
}
 
fNumbersFrame->Resize(100, 25);
 
 
 
for (int i=0; i<7; i++) { fNumbersFrame->AddFrame(fTeh[i], fBfly2); }
 
 
fHframe1->AddFrame(fNumbersFrame, fBly);
p->AddFrame(fHframe1, fBly);
 
 
 
 
fTimingSlider->SetPosition(60,120);
fTimingSlider->SetPointerPosition(65);
fThresholdSlider->SetPosition(-0.5,0.5);
fThresholdSlider->SetPointerPosition(0.25);
 
char buf[32];
sprintf(buf, "%.3f", fTimingSlider->GetMinPosition());
fTbh[0]->Clear();
fTbh[0]->AddText(0, buf);
sprintf(buf, "%.3f", fTimingSlider->GetPointerPosition());
fTbh[1]->Clear();
fTbh[1]->AddText(0, buf);
sprintf(buf, "%.3f", fTimingSlider->GetMaxPosition());
fTbh[2]->Clear();
fTbh[2]->AddText(0, buf);
sprintf(buf, "%.3f", fThresholdSlider->GetMinPosition());
fTbh[3]->Clear();
fTbh[3]->AddText(0, buf);
sprintf(buf, "%.3f", fThresholdSlider->GetPointerPosition());
fTbh[4]->Clear();
fTbh[4]->AddText(0, buf);
sprintf(buf, "%.3f", fThresholdSlider->GetMaxPosition());
fTbh[5]->Clear();
fTbh[5]->AddText(0, buf);
 
sprintf(buf, "0.25");
fTbh[6]->Clear();
fTbh[6]->AddText(0, buf);
 
 
}
 
 
class TDrsGui: public TGMainFrame {
 
private:
 
TGLayoutHints *fLcan;
TGComboBox *fTrgch;
TGVerticalFrame *fHframe0;
TGTextButton *fStart;
TGTextButton *fSelect;
TGTextEntry *fFile;
TGNumberEntry *fNeve;
TGNumberEntry *fUpdFrq;
TGTextBuffer *fFileText;
 
TChannel * fChannel[4];
TGLayoutHints *fBly;
public:
TDrsGui();
virtual ~TDrsGui();
 
void CloseWindow();
void StartAnalysis();
void HandleAction();
void LoadIni();
ClassDef(TDrsGui, 0)
};
 
void TDrsGui::StartAnalysis(){
const int nch=4;
DrsChannel c[nch];
 
for (int i=0; i<nch; i++) {
 
 
c[i].cfrac = atof(fChannel[i]->fTbh[6]->GetString());
c[i].threshold = atof( fChannel[i]->fTbh[4]->GetString());
c[i].twin[0] = atof( fChannel[i]->fTbh[0]->GetString());
c[i].twin[1] = atof( fChannel[i]->fTbh[2]->GetString());
 
c[i].adcgate[0] = atof( fChannel[i]->fTbh[1]->GetString());;
c[i].adcgate[1] = c[i].adcgate[0] + c[i].twin[1]-c[i].twin[0];
 
c[i].vcut[0] = atof( fChannel[i]->fTbh[3]->GetString());
c[i].vcut[1] = atof( fChannel[i]->fTbh[5]->GetString());
 
c[i].edge = fChannel[i]->fEdge->GetState();
 
 
 
printf("Ch.%d :",i);
for (int j=0; j<7; j++) printf("\t%f", atof( fChannel[i]->fTbh[j]->GetString()));
printf("%d\n", fChannel[i]->fEdge->GetState() );
 
}
printf("File: %s\n", fFileText->GetString() );
 
 
 
 
 
int nev=fNeve->GetIntNumber();
int updfrq=fUpdFrq->GetIntNumber();;
 
int trgch=fTrgch->GetSelected();
drs * d = new drs(fFileText->GetString(), nch, c, trgch, nev, updfrq );
 
 
}
void TDrsGui::LoadIni(){
static TString dir(".");
TGFileInfo fi;
fi.fFileTypes = filetypesini;
fi.fIniDir = StrDup(dir);
printf("fIniDir = %s\n", fi.fIniDir);
new TGFileDialog(gClient->GetRoot(), this, kFDOpen, &fi);
printf("Open file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir);
dir = fi.fIniDir;
FILE *fp= fopen(fi.fFilename,"r");
float f[10];
int j=0;
const int ndim=400;
char line[ndim];
int edge=0;
int ch=0;
float cfrac=1;
while (fgets(line,ndim,fp)!=NULL) {
if (line[0]=='#' ) continue;
printf("%d***********\n",j++);
sscanf(line,"%d%d%f%f%f%f%f%f%f",&ch,&edge,&f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6]);
printf("%d\t%d\t",ch, edge);
for (int i=0; i<7; i++) {
 
char buf[20];
sprintf(buf, "%.3f", f[i]);
fChannel[ch]->fTbh[i]->Clear();
fChannel[ch]->fTbh[i]->AddText(0, buf);
fChannel[ch]->fTeh[i]->SetCursorPosition(fChannel[ch]->fTeh[i]->GetCursorPosition());
fChannel[ch]->fTeh[i]->Deselect();
gClient->NeedRedraw(fChannel[ch]->fTeh[i]);
printf("%2.2f\t",f[i]);
 
}
if (!edge) fChannel[ch]->fEdge->SetState(kButtonUp);
else fChannel[ch]->fEdge->SetState(kButtonDown);
 
printf("\n");
}
 
fclose(fp);
 
 
}
 
 
void TDrsGui::HandleAction(){
static TString dir(".");
TGFileInfo fi;
fi.fFileTypes = filetypesdat;
fi.fIniDir = StrDup(dir);
printf("fIniDir = %s\n", fi.fIniDir);
new TGFileDialog(gClient->GetRoot(), this, kFDOpen, &fi);
printf("Open file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir);
dir = fi.fIniDir;
//char buf[32];
//sprintf(buf, "%.3f", fTimingSlider->GetMinPosition());
fFileText->Clear();
fFileText->AddText(0,fi.fFilename);
/*
fCanvas->GetCanvas()->Modified();
fCanvas->GetCanvas()->Update();
*/
fFile->SetCursorPosition(fFile->GetCursorPosition());
fFile->Deselect();
gClient->NeedRedraw(fFile);
}
//______________________________________________________________________________
TDrsGui::TDrsGui() : TGMainFrame(gClient->GetRoot(), 100, 100)
{
SetCleanup(kDeepCleanup);
// Create an embedded canvas and add to the main frame, centered in x and y
// and with 30 pixel margins all around
/*
fCanvas = new TRootEmbeddedCanvas("Canvas", this, 600, 400);
fLcan = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10, 10, 10, 10);
//AddFrame(fCanvas, fLcan);
fCanvas->GetCanvas()->SetFillColor(33);
fCanvas->GetCanvas()->SetFrameFillColor(41);
fCanvas->GetCanvas()->SetBorderMode(0);
fCanvas->GetCanvas()->SetGrid();
fCanvas->GetCanvas()->SetLogy();
*/
fHframe0 = new TGVerticalFrame(this, 0, 0, 0);
fHframe0->Resize(200, 50);
//--- layout for buttons: top align, equally expand horizontally
fBly = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5);
 
TGHorizontalFrame *fStartFrame = new TGHorizontalFrame(fHframe0, 0, 0, 0);
 
char tmp[20];
// combo box widget
fTrgch = new TGComboBox(fStartFrame,50);
for (int i = 0; i < 4; i++) {
sprintf(tmp, "Ch %i", i);
fTrgch->AddEntry(tmp, i);
}
fTrgch->Resize(50, 20);
fTrgch->Select(0);
TGLabel *fLTrgch = new TGLabel(fStartFrame, "Trg Channel:");
fNeve = new TGNumberEntry(fStartFrame, 5000, 5,999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative );
TGLabel *fLNeve = new TGLabel(fStartFrame, "Number of events:");
 
fUpdFrq = new TGNumberEntry(fStartFrame, 50, 5,999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative );
TGLabel *fLUpdFrq = new TGLabel(fStartFrame, "Update Frequency:");
 
fStartFrame->AddFrame(fLTrgch, fBly);
fStartFrame->AddFrame(fTrgch, fBly);
fStartFrame->AddFrame(fLNeve, fBly);
fStartFrame->AddFrame(fNeve, fBly);
fStartFrame->AddFrame(fLUpdFrq, fBly);
fStartFrame->AddFrame(fUpdFrq, fBly);
 
fHframe0->AddFrame(fStartFrame, fBly);
 
 
TGHorizontalFrame *fH = new TGHorizontalFrame(fHframe0, 0, 0, 0);
 
 
fStart = new TGTextButton(fH, "Start");
fStart->Connect("Clicked()", "TDrsGui", this, "StartAnalysis()");
 
fSelect = new TGTextButton(fH, "Select Analysis File");
fSelect->Connect("Clicked()", "TDrsGui", this, "HandleAction()");
 
fFile = new TGTextEntry(fH, fFileText = new TGTextBuffer(5), 1);
 
TGTextButton * fLoadIni = new TGTextButton(fH, "Load Ini File");
fLoadIni->Connect("Clicked()", "TDrsGui", this, "LoadIni()");
 
 
fH->AddFrame(fSelect, fBly);
fH->AddFrame(fFile, fBly);
fH->AddFrame(fLoadIni, fBly);
fH->AddFrame(fStart, fBly);
 
fHframe0->AddFrame(fH, fBly);
AddFrame(fHframe0, fBly);
 
//--------- create the Tab widget
TGTab *fTab = new TGTab(fHframe0, 300, 300);
TGLayoutHints *fL3 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
 
for (int ich=0; ich<4; ich++) {
char tmp[255];
sprintf(tmp,"Channel %d:",ich);
TGCompositeFrame *tf = fTab->AddTab(tmp);
fChannel[ich]= new TChannel( tf, ich);
 
}
fHframe0->AddFrame(fTab, fBly);
 
// Set main frame name, map sub windows (buttons), initialize layout
// algorithm via Resize() and map main frame
SetWindowName("DRS Analysis");
MapSubwindows();
Resize(GetDefaultSize());
MapWindow();
 
}
 
//______________________________________________________________________________
TDrsGui::~TDrsGui()
{
// Clean up
 
Cleanup();
}
 
//______________________________________________________________________________
void TDrsGui::CloseWindow()
{
// Called when window is closed via the window manager.
 
delete this;
}
 
//______________________________________________________________________________
void TChannel::DoText(const char * /*text*/)
{
// Handle text entry widgets.
 
TGTextEntry *te = (TGTextEntry *) gTQSender;
Int_t id = te->WidgetId();
 
switch (id) {
case HId1:
fTimingSlider->SetPosition(atof(fTbh[0]->GetString()),
fTimingSlider->GetMaxPosition());
break;
case HId2:
fTimingSlider->SetPointerPosition(atof(fTbh[1]->GetString()));
break;
case HId3:
fTimingSlider->SetPosition(fTimingSlider->GetMinPosition(),
atof(fTbh[2]->GetString()));
break;
 
case VId1:
fThresholdSlider->SetPosition(atof(fTbh[3]->GetString()),
fThresholdSlider->GetMaxPosition());
break;
case VId2:
fThresholdSlider->SetPointerPosition(atof(fTbh[4]->GetString()));
break;
case VId3:
fThresholdSlider->SetPosition(fThresholdSlider->GetMinPosition(),
atof(fTbh[5]->GetString()));
break;
 
default:
break;
}
/*
 
 
fCanvas->GetCanvas()->Modified();
fCanvas->GetCanvas()->Update();
 
*/
}
 
//______________________________________________________________________________
void TChannel::DoSlider()
{
// Handle slider widgets.
 
char buf[32];
 
float values[6]={
fTimingSlider->GetMinPosition(),fTimingSlider->GetPointerPosition(),fTimingSlider->GetMaxPosition(),
fThresholdSlider->GetMinPosition(),fThresholdSlider->GetPointerPosition(),fThresholdSlider->GetMaxPosition()
};
 
for (int i=0; i<6; i++) {
sprintf(buf, "%.3f", values[i]);
fTbh[i]->Clear();
fTbh[i]->AddText(0, buf);
fTeh[i]->SetCursorPosition(fTeh[i]->GetCursorPosition());
fTeh[i]->Deselect();
gClient->NeedRedraw(fTeh[i]);
}
 
 
/*
 
fCanvas->GetCanvas()->Modified();
fCanvas->GetCanvas()->Update();
*/
}
 
//______________________________________________________________________________
void TChannel::HandleButtons()
{
// Handle different buttons.
 
TGButton *btn = (TGButton *) gTQSender;
Int_t id = btn->WidgetId();
 
switch (id) {
case HCId1:
// fTimingSlider->SetConstrained(fTrigger->GetState());
break;
case HCId2:
fTimingSlider->SetRelative(fEdge->GetState());
break;
default:
break;
}
}
 
 
void drsgui()
{
new TDrsGui();
}