Problem Fitting Gaussian data

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);
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");
``````

_ROOT Version:6.23/01

Let me see whether I understand:

you have some spectrum, coming from your ROOT file. This spectrum has a turn-on curve, followed by a steep decrease. You are adding a Gaussian on top between x=0.72…1.04, where the bulk of the `Fill()`s is around 0.85…0.91. That’s 2 bins of your histogram.

So you have two issues:

• Fitting a Gaussian on two bins won’t really work; you need higher resolution (and your stat uncertainty seems to suggest that you can afford smaller bins).
• You shouldn’t fit a Gaussian, but a tiny Gaussian (integral of about 5k) on top of a huuuge background (integral of about 450k). So you’ll need to model the background, and then either subtract the background first or fit background + Gauss.

But that’s going beyond the role of the ROTO forum - that’s what your advisor / physics group / post-doc / colleagues … should help with

Cheers, Axel.

• Why do you create `TFdata` when you already have `ff`?