Histogram fit with ROOFIT Gaussian

I’m trying to fit a Gaussian to my data using this code:

#ifndef __CINT__
#include "RooGlobalFunc.h"
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooDataHist.h"
#include "RooGaussian.h"
#include "RooChebychev.h"
#include "RooAddPdf.h"
#include "TCanvas.h"
#include "RooPlot.h"
#include "TTree.h"
#include "TH1D.h"
#include "TAxis.h"
#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>
using namespace RooFit ;

void p(){

TChain *h1 = new TChain("h1");                                      

RooRealVar M_phi("M_phi", "M_{phi}", 0.999461,1.039461, "GeV/c^{2}");

RooArgSet ntupleVarSet(M_phi);

RooDataSet dataSet("ntuple_of_B_candidates", "ntuple of B candidates",h1,ntupleVarSet);
RooRealVar sig_M_mean ("sig_M_mean", "sig_M_mean",1.02,0.1,1.4);
RooRealVar sig_M_sigma("sig_M_sigma", "sig_M_sigma",0.05,0,0.1);  
RooGaussian sig_lm("sig_lm", "sig_lm", M_phi, sig_M_mean, sig_M_sigma);

RooRealVar nsig("nsig","nsig", 200.,0.,1000000.);

RooArgList shapes;
RooArgList yields;
shapes.add(sig_lm); yields.add(nsig);
RooAddPdf lm_pdf("lm_pdf", "", shapes, yields);

lm_pdf.fitTo(dataSet, Extended(kTRUE),Minos(0),SumW2Error(kTRUE));
TCanvas *c1 = new TCanvas("c1","",550,400);
RooPlot *lm_frame = M_phi.frame();
lm_pdf.plotOn(lm_frame, LineColor(kBlue), LineStyle(kSolid));

Instead of getting a nice Gaussian, I get this:
mistake,jpg.pdf (17.3 KB)

I hope someone can help me out!
Thanks in advance :smiley:

@moneta, perhaps you can help here?

Thank you,

I’ve found that if I adjust the starting values for sigma and the mean, I get a reasonable Gaussian. Could this difficulty be because the data is composed of two Gaussians, and how can I fit them at the same time if so?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.