void fit_tdc(const char *type="ADC",
const char *iname="HIST.root",
const char *oname="PS.ps")
{
gROOT->SetStyle("Plain");
gStyle->SetOptStat(0);
gSystem->Load("../libFemCalib.so");
TFile *input = new TFile(iname);
TPostScript *ofile = new TPostScript(oname,111);
ofile->NewPage();
TCanvas *fem = new TCanvas("fem","",600,800);
fem->Divide(2,4);
const int NPMT = 32;
double para0[NPMT];
double para1[NPMT];
double tmp;
int xmin = 500;
int xmax = 4000;
float tdc_conv[NPMT];
int j=1;
int femid=1;
char hist[50];
char file[50];
char histname[50];
TH1F *tdcgain;
if(type=="TDC0"){
tdcgain = new TH1F("tdcgain","tdc0 gain factor [ps/ch]",100,3,13);
}else if(type=="TDC1"){
tdcgain = new TH1F("tdcgain","tdc1 gain factor [ps/ch]",100,3,13);
}
TF1 *f1;
for (int i=0; i<NPMT; i++){
if(type=="ADC"){
sprintf(hist,"adc_%d",i);
TH1F *fig = gROOT->FindObject(hist);
fig->SetXTitle("DAC Value");
fig->SetYTitle("ADC [ch]");
sprintf(histname,"FEM%d_ADC_%dch",femid,j-1);
fig->SetTitle(histname);
fig->SetMarkerSize(0.5);
}
else if(type=="TDC0"){
sprintf(hist,"tdc0_%d",i);
TH1F *fia = gROOT->FindObject(hist);
fia->SetXTitle("Delay [ps]");
fia->SetYTitle("TDC0 [ch]");
sprintf(histname,"FEM%d_TDC0_%dch",femid,j-1);
fia->SetTitle(histname);
fia->SetMarkerSize(0.5);
}
else if(type=="TDC1"){
sprintf(hist,"tdc1_%d",i);
TH1F *fib = gROOT->FindObject(hist);
fib->SetXTitle("Delay [ps]");
fib->SetYTitle("TDC1 [ch]");
sprintf(histname,"FEM%d_TDC1_%dch",femid,j-1);
fib->SetTitle(histname);
fib->SetMarkerSize(0.5);
}
else{
cout << "input ADC or TDC0 or TDC1 !" << endl;
return 0;
}
fem->cd(j);
gPad->SetGrid();
// frequency of external clock = 9.38258 [MHz]
// 1 clock of external clock = 106.5805 [ns]
// 1 delay of GTM = (1clk)*4/256 = [ns]
float clock = 106.5805;
float
min=116; <- set minimun TP_Delay
float max=128; <- set maximun TP_Delay
//float min=180;
//float max=193;
//float min=116;
//float max=128;
TH1F *frame = fem->
DrawFrame((min*clock*4./256.)-5,-20,(max*clock*4./256.)+5,3200);
frame->Draw();
char num[256];
TText *t[2];
f1 = new TF1("f1","pol1");
f1->SetLineColor(2);
f1->SetLineWidth(0.5);
f1->SetParameters(0.,0.);
if(type=="ADC") fig->Draw("same");
else if(type=="TDC0") {
//fia->SetAxisRange(176,215);
//fia->SetMaximum(3100);
//fia->SetMinimum(-5);
fia->Draw("same");
fia->Fit("f1","","",min*clock*4./256.,max*clock*4./256.);
cout << f1->GetParameter(0) << " " <<
f1->GetParameter(1)<<endl;
sprintf(num,"pedestal %f", f1->GetParameter(0));
t[0] = new TText((max*clock*4./256.)-8,2300, num);
t[0]->SetTextSize(0.1);
t[0]->Draw("same");
sprintf(num,"slope [ps/ch] %f", -1*1000/f1->GetParameter(1));
t[1] = new TText((max*clock*4./256.)-8,2000, num);
t[1]->SetTextSize(0.1);
t[1]->Draw("same");
tdcgain->Fill(-1*1000/f1->GetParameter(1));
tdc_conv[i] = -1/f1->GetParameter(1);
}
else if(type=="TDC1") {
//fib->SetAxisRange(176,215);
//fib->SetMaximum(3100);
//fib->SetMinimum(-5);
fib->Draw("same");
fib->Fit("f1","","",min*clock*4./256.,max*clock*4./256.);
cout << f1->GetParameter(0) << " " <<
f1->GetParameter(1)<<endl;
sprintf(num,"pedestal %f", f1->GetParameter(0));
t[0] = new TText((max*clock*4./256.)-8,2300, num);
t[0]->SetTextSize(0.1);
t[0]->Draw("same");
sprintf(num,"slope [ps/ch] %f", -1*1000/f1->GetParameter(1));
t[1] = new TText((max*clock*4./256.)-8,2000, num);
t[1]->SetTextSize(0.1);
t[1]->Draw("same");
tdcgain->Fill(-1*1000/f1->GetParameter(1));
tdc_conv[i] = -1/f1->GetParameter(1);
}
j++;
if(j%9==0 && i!=NPMT){
fem.Update();
ofile->NewPage();
cout << "FEM #" << femid << " was printed"
<< endl;
j=1;
femid++;
if(i==127) break;
}
}
ofstream fout("tdc_conv.dat");
for(int i=0; i<NPMT; i++){
fout<<"0.0 "<<tdc_conv[i]<<" 0.0 0.0 0.0 1.0
0"<<endl;
}
fout.close();
fem->Clear();
gStyle->SetOptStat(1111);
//float tmean = tdcgain->GetMean();
//float trms = tdcgain->GetRMS();
//tdcgain->SetAxisRange(tmean-5*trms, tmean+5*trms);
tdcgain->Draw();
fem->Update();
ofile.Close();
}