I have to generate data according to a distribution defined by me and then I have to fit said data. My code is as follows:
#define N 50000
#define XMin 0.0
#define XMax 2.0
#define Mu1 1.0
#define Sigma1 0.20
#define Mu2 1.50
#define Sigma2 0.10
#define a 0.3
#define b 0.2
#define t 3
#define NPar 7
#define BinDim 0.05
#define NBins (XMax-XMin)/BinDimDouble_t GeneratingFunction(Double_t *xx, Double_t *par);
void es(){
TH1D *histo=new TH1D(“h1”, “N gen”, NBins, XMin, XMax);TF1 *f1 = new TF1("f1",GeneratingFunction,XMin,XMax,NPar); f1 -> SetParameters(a,b,t,Mu1,Sigma1,Mu2,Sigma2); f1 -> SetParNames("a","b","t","Mu1","Sigma1","Mu2","Sigma2"); for(int i=0; i<N; i++){ histo -> Fill(f1->GetRandom()); } gStyle->SetOptFit(kTRUE); histo -> Fit(f1); histo -> Draw();
}
Double_t GeneratingFunction(Double_t *xx, Double_t *par){
Double_t first, second, third;
first = par[0]*TMath::Gaus(xx[0],par[3],par[4]);
second = par[1]*TMath::Gaus(xx[0],par[5],par[6]);
third = (1-par[0]-par[1])*TMath::Exp(-par[2]*xx[0]);
return first+second+third;
}
From the graph it’s obvious something is wrong here but I can’t seem to understand what; any help is very appreciated.
ROOT Version: 6.22/06
_Platform:_Ubuntu 20.10
Compiler: g++ (Ubuntu 10.2.0-13ubuntu1) 10.2.0