00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 Double_t fitf(Double_t *x, Double_t *par)
00011 {
00012 Double_t arg = 0;
00013 if (par[2] != 0) arg = (x[0] - par[1])/par[2];
00014
00015 Double_t fitval = par[0]*TMath::Exp(-0.5*arg*arg);
00016 return fitval;
00017 }
00018 void myfit()
00019 {
00020 TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
00021 dir.ReplaceAll("myfit.C","../hsimple.C");
00022 dir.ReplaceAll("/./","/");
00023 if (!gInterpreter->IsLoaded(dir.Data())) gInterpreter->LoadMacro(dir.Data());
00024 TFile *hsimple = (TFile*)gROOT->ProcessLineFast("hsimple(1)");
00025 if (!hsimple) return;
00026
00027 TCanvas *c1 = new TCanvas("c1","the fit canvas",500,400);
00028
00029 TH1F *hpx = (TH1F*)hsimple->Get("hpx");
00030
00031
00032 TF1 *func = new TF1("fitf",fitf,-2,2,3);
00033
00034
00035 func->SetParameters(100,0,1);
00036 func->SetParNames("Constant","Mean_value","Sigma");
00037
00038
00039 hpx->Fit(func,"r");
00040
00041
00042 printf("Integral of function = %g\n",func->Integral(-2,2));
00043 }