void fit_dr(void) { // // plot the number of fits to a cdc segment that result in prob > prob_cut (currently set to 0.01). // #include #include gROOT->Reset(); //TTree *Bfield = (TTree *) gROOT->FindObject("Bfield"); gStyle->SetPalette(1,0); gStyle->SetOptStat(kFALSE); gStyle->SetOptFit(kFALSE); // gStyle->SetOptFit(1111); gStyle->SetPadRightMargin(0.15); gStyle->SetPadLeftMargin(0.15); gStyle->SetPadBottomMargin(0.15); gStyle->SetFillColor(0); // char string[256]; Int_t j,jj; #define npts 6; // input data set first point (actually -1) to -10 so that it is not plotted. // use offset on x-axis to make data visible and give negative y-values for reference (not plotted) Double_t temp[npts]={-60,-53,-22,0,25,40}; Double_t xerr[npts]={0.1,0.1,0.1,0.1,0.1}; // Dark rates vs temperature at fixed overvoltage. Double_t dr2V[npts]={0,800,4000,30000,400000,0}; Double_t dr3V[npts]={-1,1500,7000,50000,650000,-1}; Double_t dr_err[npts]={1,1,1,1,1,1}; Double_t xmin=-60; Double_t xmax=40; Double_t ymin=100; Double_t ymax=5e6; // TCanvas *c1 = new TCanvas("c1","Dark rates vs temperature at fixed overvoltage",200,10,700,700); c1->SetBorderMode(0); c1->SetFillColor(0); c1->SetGridx(); c1->SetLogy(); c1->SetGridy(); c1->SetBorderMode(0); c1->SetFillColor(0); TGraph *dr2 = new TGraph (npts,temp,dr2V); TGraph *dr3 = new TGraph (npts,temp,dr3V); TLegend *leg = new TLegend(0.15,0.8,0.75,0.9); dr2->SetTitle(""); dr2->GetXaxis()->SetRangeUser(xmin,xmax); dr2->GetYaxis()->SetRangeUser(ymin,ymax); dr2->GetXaxis()->SetTitleSize(0.04); dr2->GetYaxis()->SetTitleSize(0.04); dr2->GetYaxis()->SetTitleOffset(1.5); dr2->GetXaxis()->SetTitle("Temperature (degC)"); dr2->GetYaxis()->SetTitle("Dark Rate (Hz)"); dr2->GetXaxis()->SetNdivisions(6); dr2->SetMarkerColor(2); dr2->SetMarkerStyle(20); dr2->Draw("AP"); dr3->SetMarkerColor(4); dr3->SetMarkerStyle(20); dr3->Draw("P"); Double_t xminfit = -40; Double_t xmaxfit = 27; Double_t T0=20; Double_t a=500000; Double_t b=0.04; // Double_t c=-0.001; Int_t npar=2; TF1 *exp1 = new TF1("exp1",exp1,xminfit-T0,xmaxfit,npar); // exp1->SetParameters(a,b,c); exp1->SetParameters(a,b); exp1->SetLineColor(2); dr2->Fit("exp1","","",xminfit,xmaxfit); exp1->Draw("same"); a = exp1->GetParameter(0); b = exp1->GetParameter(1); // c = exp1->GetParameter(2); // sprintf (string,"#Delta V=2V, a=%.0f, b=%.3f, c=%.5f\n",a,b,c); sprintf (string,"#Delta V=2V, a=%.0f, b=%.3f\n",a,b); leg->AddEntry(dr2,string,"p"); printf ("string=%s\n",string); t1 = new TLatex(0.2,0.7,string); t1->SetTextColor(1); t1->SetNDC(); t1->SetTextSize(0.03); // t1->Draw(); Double_t a=500000; Double_t b=0.04; Double_t c=-0.001; Int_t npar=3; exp1->SetParameters(a,b,c); exp1->SetLineColor(4); dr3->Fit("exp1","","",xminfit,xmaxfit); exp1->DrawCopy("same"); a = exp1->GetParameter(0); b = exp1->GetParameter(1); // c = exp1->GetParameter(2); // sprintf (string,"#Delta V=3V, a=%.0f, b=%.3f, c=%.5f\n",a,b,c); sprintf (string,"#Delta V=3V, a=%.0f, b=%.3f\n",a,b); leg->AddEntry(dr3,string,"p"); printf ("string=%s\n",string); t1 = new TLatex(0.2,0.65,string); t1->SetTextColor(1); t1->SetNDC(); t1->SetTextSize(0.03); // t1->Draw(); leg->Draw(); // c1->SaveAs("fit_dr.eps"); c1->SaveAs("fit_dr.gif"); } Double_t exp1 (Double_t *x, Double_t *par) { Double_t a=par[0]; Double_t b=par[1]; // Double_t c=par[2]; Double_t c=0; Double_t T0=20; Double_t x1=x[0]-T0; char string[256]; Double_t exp1 = a*exp(b*x1 + c*x1*x1); /*sprintf (string,"exp1=%f a=%f b=%f c=%f\n",exp1,a,b,c); printf ("string=%s",string);*/ return exp1; }