Hello
I need to fit my histogram which contains Trigger Efficiency
First fit is gaus function, second just a line. Which one function will be good to fit empty space? Or its possible to fit it with one own function?
Here is the code.
#include "TH1.h"
#include "TF1.h"
#include "TMath.h"
Double_t fitf(Double_t *x, Double_t *par)
{
return 1;
}
void rysunek3()
{
TFile *file = new TFile("histograms.root","open");
TH1F *licz = (TH1F*) file -> Get("h_TRK50E0_TRK70E0");
TH1F *mian = (TH1F*) file -> Get("trk50E0");
licz -> Divide(mian);
licz -> Draw();
double x1,x2;
int nbins=licz->GetNbinsX();
for (int i = 1 ; i < nbins ; i++)
{
if (licz->GetBinContent(i) > 0.2 && licz->GetBinContent(i) < 0.22) {x1 = i;}
if (licz->GetBinContent(i) == 1.0){
x2 = i;
break;
}
}
Double_t par[13];
TF1 *func = new TF1("fitf",fitf,x2,x2+40,2);
TF1 *g1 = new TF1 ("g1","gaus",x1-20,x2-20);
func->SetParameters(1,1);
licz->Fit(func,"R");
licz->Fit(g1,"R+");
printf("x1 = %d, x2 = %d",x1,x2);
}