Hi,
I have a mass spectrum, and I inject Gaussian data into it within some region. I then want to fit that region with a gaussian function, but I get a bad fit (high chi-squared/ndf statistic). How can I make it better? I attach the script and the data, any help is greatly appreciated:
double Gauss(double* x, double* par){Double_t out = par[0] * TMath::Gaus(x[0],par[1],par[2]);return out;}
#include <ctime>
#include <iostream>
#include <cstdlib>
using namespace std;
string xdir="";
string figdir="figs/";
char nameX[]="m_{jjl} [TeV]";
char nameY[]="Events / TeV";
double Ymin=0.9;
double Ymax=1000000000.0-100000.0;
double YRMIN=-4.999;
double YRMAX=4.999;
double Xmin=400.0;
double Xmax=10000.0;
Xmin=Xmin*0.001;
Xmax=Xmax*0.001;
double NN=0.0;
gROOT->SetStyle("Plain");
TCanvas* c1 = new TCanvas("c","BPRE",10,10,600,600);
c1->Divide(1,1,0.005,0.005);
c1->SetTickx();
c1->SetTicky();
c1->SetTitle("");
c1->SetLineWidth(3);
c1->SetBottomMargin(0.1);
c1->SetTopMargin(0.05);
c1->SetRightMargin(0.01);
c1->SetFillColor(0);
TPad* pad1 = new TPad("pad1","pad1",0,0.3,1,0.97);
pad1->SetBottomMargin(0);
pad1->SetLeftMargin(0.13);
pad1->SetRightMargin(0.04);
pad1->SetTopMargin(0.02);
pad1->Draw();
pad1->cd();
pad1->SetLogy(1);
pad1->SetLogx(1);
TH1F *h=pad1->DrawFrame(Xmin,Ymin,Xmax,Ymax);
TAxis *ay = h->GetYaxis();
ay->SetLabelFont(42);
ay->SetLabelSize(0.05);
ay->SetTitleSize(0.06);
ay->SetNdivisions(505);
ay->SetTitle(nameY);
TAxis *ax=h->GetXaxis();
ax->SetTitle(nameX);
ax->SetTitleOffset(1.18);
ay->SetTitleOffset(0.8);
ax->SetLabelFont(42);
ay->SetLabelFont(42);
ax->SetLabelSize(0.12);
ax->SetTitleSize(0.14);
ax->Draw("same");ay->Draw("same");
string dir = xdir;
TFile *ff = new TFile("10percent.root");
ff->ls();
char name[] = "jjlmass_tev";
TH1* hh = (TH1*) ff->Get(name);
TH1* hhorg = (TH1*) hh->Clone();
TFile TFdata("10percent.root");
cout << TFdata.GetName()<< endl;
hh->SetTitle("");
hh->SetStats(0);
hh->SetLineWidth(2);
hh->Print("All");
hh->SetAxisRange(Ymin,Ymax,"y");
hh->SetAxisRange(Xmin,Xmax,"x");
hh->SetMarkerColor( 3 );
hh->SetMarkerStyle( 20 );
hh->SetMarkerSize( 0.8 );
TF1 bla("gauss",Gauss,0.88-(5.0*0.031691),0.88+(5.0*0.031691),3);
double a=0.1;
double b=0.88;
double c=0.031691;
bla.SetParameters(a,b,c);
bla.SetParNames("a","b","c");
int zet=1*4947;
cout << zet << endl;
for (int i=0; i<(zet); i++){hh->Fill(bla.GetRandom(0.88-(5.0*0.031691),0.88+(5.0*0.031691)));}
double MyMinX=Xmin;
double MyMaxX=Xmax;
hh->Draw("pe");
for (int i=0; i<200; i++){auto fithr=hh->Fit(&bla,"SMR0","");fithr->Print();}
bla.Draw("same");
Link to CERNBOX to download file, click on the “Download” button in the upper-right corner.
_ROOT Version:6.23/01