Double_t erf( Double_t *x, Double_t *par){ //<=========== return 50.*TMath::Erfc((-x[0]+par[0])/par[1]); //<=========== } void Erf_fit_fphx(char* f_name = "calib_adc",int mode =0, int t_chan = 17, float gainfitmin = 20.0 , float gainfitmax = 40.0) { gStyle->SetOptFit(1); gStyle->SetOptStat(0); char cf_name[100],of_name[100],tmp[100]; double v0, dv; TH1F *hh[128]; // Histogram to hold number of hits versus amp for each channel TProfile *adc_v_amp[128]; // Histogram to hold number of hits versus amp for each channel TH2F *adc_v_amp_all; // Histogram to hold number of hits versus amp for each channel int mean_exp[128],dead_chan[30000],n_dead=0,vref,vth0,n_meas,n_steps; TLatex txt; int ampl, col_raw, col, adc; int chan_id, n_hits; ifstream cal_file; ofstream out_file; n_steps = 100; v0 = 3; n_meas = 64; dv =1; cout << dv << endl; TF1 *fit = new TF1("fit", (void *)erf, v0, v0+dv*n_meas, 2); int NCHAN = 128; int NAMP = 64; // Create histograms for each channel: for (int ichan = 0; ichan < NCHAN ; ichan++) { sprintf( tmp, "hist_%i", ichan ); hh[ichan] = new TH1F( tmp, tmp, n_meas, v0-0.5*dv, v0+(n_meas-0.5)*dv); hh[ichan]->SetMarkerColor(2); hh[ichan]->SetMarkerStyle(8); hh[ichan]->SetMarkerSize(1); hh[ichan]->SetMinimum(-5); hh[ichan]->SetMaximum(n_steps*1.1); mean_exp[ichan] = 0; sprintf( tmp, "gain_%i", ichan ); adc_v_amp[ichan] = new TProfile( tmp, tmp, 64, -0.5, 63.5); // adc_v_amp[ichan] = new TProfile( tmp, tmp, 8, -0.5, 7.5); } adc_v_amp_all = new TH2F( "adc_v_amp_all", "Gain for all Channels", 64, -0.5, 63.5, 8, -0.5, 7.5); // Open the input calibration text file: sprintf(cf_name,"%s.out",f_name); cout<<" File name = "<< cf_name<> chan_id >> ampl >> adc; nhits[chan_id][ampl]++; // adc_v_amp[chan_id]->Fill( adc, ampl ); adc_v_amp[chan_id]->Fill( ampl, adc ); adc_v_amp_all->Fill( ampl, adc ); } cal_file.close(); // Fill histogram with the number hits at each amplitude, and the mean_exp with the amplitude at // which there are n_steps/2 hits: for (int ichan=0; ichan (n_steps/2)) mean_exp[ichan] = iamp; hh[ichan]->SetBinContent(iamp+1, nhits[ichan][iamp]); if (nhits[ichan][iamp] != 0 && nhits[ichan][iamp] < n_steps) hh[ichan]->SetBinError(iamp + 1, sqrt((float)nhits[ichan][iamp]*(1.-((float)nhits[ichan][iamp]/(float)n_steps)))); else hh[ichan]->SetBinError(iamp+1,1.0); } } // Create output file with histograms: sprintf( of_name, "%s.fit", f_name ); out_file.open( of_name ); TH1F *mean = new TH1F( "mean", "Mean distribution;Threshold [e]", 200, 0, 50); TH1F *rms = new TH1F( "rms", "RMS distribution;Noise [e]", 200, 0., 5); TH2F *mean2d = new TH2F("mean2d","Mean distribution;Channel",128,-0.5,127.5,30,-0.5,30.); TH2F *rms2d = new TH2F("rms2d","RMS distribution;Channel",128,-0.5,127.5,30,-0.5,6.); TH1F *gain = new TH1F( "gain", "Gain distribution;Gain", 30, 0.0, 0.2); TH2F *gain2d = new TH2F( "gain2d", "Gain distribution;Channel", 128,-0.5,127.5,30,0.0,0.2); // TH1F *gain = new TH1F( "gain", "Gain distribution;Gain", 30, 0.0, 10.0); // TH2F *gain2d = new TH2F( "gain2d", "Gain distribution;Channel", 128,-0.5,127.5,30,0.0,10.0); // mean2d->SetMinimum(20); // mean2d->SetMaximum(70); // rms2d->SetMinimum(1.5); // rms2d->SetMaximum(6); mean->GetXaxis()->SetLabelSize(0.03); rms->GetXaxis()->SetLabelSize(0.03); mean->GetYaxis()->SetLabelSize(0.03); rms->GetYaxis()->SetLabelSize(0.03); mean2d->GetXaxis()->SetLabelSize(0.03); rms2d->GetXaxis()->SetLabelSize(0.03); mean2d->GetYaxis()->SetLabelSize(0.03); rms2d->GetYaxis()->SetLabelSize(0.03); mean2d->GetZaxis()->SetLabelSize(0.03); rms2d->GetZaxis()->SetLabelSize(0.03); mean2d->SetMarkerStyle(2); mean2d->SetMarkerColor(2); rms2d->SetMarkerStyle(2); rms2d->SetMarkerColor(2); if (mode) { hh[t_chan]->Draw(); fit->SetParameter(0, v0 + mean_exp[t_chan]*dv ); cout << v0 + mean_exp[t_chan]*dv << endl; fit->SetParameter(1, 6.*dv); hh[t_chan]->Fit("fit","RQ","same",v0+(mean_exp[t_chan]-20.)*dv,v0+(mean_exp[t_chan]+20.)*dv); break; } for (int ichan = 0; ichan < 128; ichan++) { adc_v_amp[ichan]->Fit("pol1","","",gainfitmin,gainfitmax); gain->Fill(pol1->GetParameter(1)); gain2d->Fill(ichan, pol1->GetParameter(1)); cout << "slope = " << pol1->GetParameter(1) << endl; if (mean_exp[ichan] >0) { fit->SetParameter( 0, v0 + mean_exp[ichan]*dv ); fit->SetParameter( 1, 1.4*dv ); if (mean_exp[ichan]!=0) { hh[ichan]->Fit("fit","RQMN","",v0+(mean_exp[ichan]-20.)*dv,v0+(mean_exp[ichan]+20.)*dv); mean->Fill(fit->GetParameter(0)); rms->Fill(fit->GetParameter(1)); mean2d->Fill(ichan, fit->GetParameter(0)); rms2d->Fill(ichan, fit->GetParameter(1)); } else { } out_file<GetParameter(0)<<" "<GetParError(0)<<" "<GetParameter(1)<<" "<GetParError(1)<Divide(2,3); // c1_1->SetPad(0.0,0.5,0.4,1.0); // c1_2->SetPad(0.4,0.5,0.8,1.0); // c1_3->SetPad(0.0,0.0,0.4,0.5); // c1_4->SetPad(0.4,0.0,0.8,0.5); c1_1->cd(); mean->SetLineColor(2); mean->SetLineWidth(2); mean->Draw(); mean->Fit("gaus","Q same"); c1_2->cd(); rms->SetLineColor(4); rms->SetLineWidth(2); rms->Draw(); rms->Fit("gaus","Q same"); //gStyle->SetOptStat(0); c1_3->cd(); mean2d->Draw("color4z"); // mean2d->Draw(""); gStyle->SetPalette(1); c1_4->cd(); rms2d->Draw("color4z"); gStyle->SetPalette(1); c1_5->cd(); adc_v_amp_all->Draw("color4z"); // adc_v_amp[17]->Draw(""); c1_6->cd(); gain2d->Draw("color4z"); c1->cd(); txt.SetTextSize(0.02); txt.DrawLatex(0.82,0.95,"Input file:"); txt.DrawLatex(0.82,0.90,cf_name); sprintf(tmp,"V_{REF} = %i",vref); txt.DrawLatex(0.82,0.82,tmp); sprintf(tmp,"V_{TH0} = %i",vth0); txt.DrawLatex(0.82,0.77,tmp); sprintf(tmp,"N_{STEP} = %i",n_steps); txt.DrawLatex(0.82,0.72,tmp); sprintf(tmp,"N_{MEAS} = %i",n_meas); txt.DrawLatex(0.82,0.67,tmp); sprintf(tmp,"Thr = %d #pm %d [e]",mean->GetFunction("gaus")->GetParameter(1),mean->GetFunction("gaus")->GetParameter(2)); txt.DrawLatex(0.80,0.60,tmp); sprintf(tmp,"Noise = %d #pm %d [e]",rms->GetFunction("gaus")->GetParameter(1),rms->GetFunction("gaus")->GetParameter(2)); txt.DrawLatex(0.80,0.56,tmp); sprintf(tmp,"%i dead pixel:",n_dead); txt.DrawLatex(0.80,0.48,tmp); for (int i=0;i 81) then { txt.DrawLatex(x_pos+0.05,y_pos,"..."); break; } } c1->cd(); sprintf(tmp,"%s.pdf",f_name); c1->Print(tmp); sprintf(tmp,"%s.gif",f_name); c1->Print(tmp); c1->Update(); }