Dear ROOT experts,
In the following dummy code, I’m trying to use TConvolution to extract a gaussian smearing function between hMC and hData. Currently, the fit of f_conv is always empty and I don’t know where I did wrong. Any help please? Many thanks in advance!
void fitConvolution(){
gStyle->SetOptStat(0);
TH1F *hData = new TH1F("hData","Gaussian",100,-5,5.);
TH1F *hMC = new TH1F("hMC","Gaussian",100,-5,5.);
for (int i=0;i<1e7;i++)
{
if (i%1000000==0) std::cout << i << "-th entry." << std::endl;
hData->Fill(gRandom->Gaus(0.,1.));
hMC->Fill(gRandom->Gaus(0,0.9));
}
hData->Scale(1./hData->Integral());
hMC->Scale(1./hMC->Integral());
TF1 * fmc = new TF1("fmc", "gaus", -5, 5);
hMC->Fit(fmc, "R");
TF1 *fsmear = new TF1("fsmear", "gaus", -5, 5);
TF1Convolution *f_conv = new TF1Convolution(fmc,fsmear,-5,5,true);
f_conv->SetRange(-5.,5.);
f_conv->SetNofPointsFFT(1000);
TF1 *f = new TF1("f",*f_conv, -5., 5., f_conv->GetNpar());
f->SetParameters(1.,0.5,0.,1.);
new TCanvas("c","c",800,1000);
hData->Fit(f, "SR");
hData->Draw();
hMC->Draw("same");
f->Draw("same");
fsmear->Print();
}