#include "TCanvas.h" #include "TStyle.h" #include "TGraphErrors.h" #include "TBackCompFitter.h" #include "TMatrixD.h" #include "TMath.h" void test() { gStyle->SetOptFit(1111); const Int_t N = 9; Float_t logE[N]; Float_t logEffi[N]; Float_t elogEffi[N]; Float_t j[N] = {352.05,609.35,1120.44,1238.32,1764.58,463.15,727.38,795.00,911.27}; Float_t k[N] = {8.59E-02,5.89E-02,3.88E-02,3.62E-02,2.84E-02,4.77E-02,4.09E-02,3.97E-02,3.79E-02}; Float_t n[N] = {8.62E-04,6.04E-04,1.12E-03,2.82E-03,8.64E-04,1.85E-03,1.11E-03,1.45E-03,3.86E-04}; for(int m =0; m < 9; m++ ) { logE[m] = TMath::Log(j[m]); logEffi[m] = TMath::Log(k[m]); // elogEffi[m] = n[m]*logEffi[m]; elogEffi[m] = n[m]/k[m]; cout << logE[m] << " " << logEffi[m] << " " << elogEffi[m] << endl; } TCanvas *myc = new TCanvas("myc","Fitting linear function"); myc->SetFillColor(42); myc->SetGrid(); // TGraph *gre3 = new TGraph(m,logE,logEffi); // gre3->Draw("a*"); TGraphErrors *gre2 = new TGraphErrors(N,logE,logEffi,0,elogEffi); gre2->SetTitle("Linear Fitting of U238 and Th232"); gre2->Draw("E1A*"); //Fit the graph with the predefined "pol1" function gre2->Fit("pol1"); TMatrixD cov(2,2,TVirtualFitter::GetFitter()->GetCovarianceMatrix() ); cov.Print(); }