Hello
I have two problems with a simple fit with a crystal ball. The fit seems to work but I have an incorrect value for integral: 0.849871. Maybe it’s the normalized value but i use getVal() witch return the raw value (i need this raw value for a ratio signa/background)
Threre is an other error (see below) that i don’t understand.
The file “LS.AOD.output.root” is attached
Here is the code
[code]
#ifndef CINT
#include “RooGlobalFunc.h”
#endif
#include “TFile.h”
#include “TH1.h”
#include “TF1.h”
#include “TCanvas.h”
#include “TPad.h”
#include “TStyle.h”
#include <Riostream.h>
#include <TROOT.h>
#include <TMath.h>
#include <TText.h>
#include <TPaveLabel.h>
//Roofit include
#include “RooCBShape.h”
#include “RooFit.h”
#include “RooRealVar.h”
#include “RooArgSet.h”
#include “RooProdPdf.h”
#include “RooAbsPdf.h”
#include “RooAbsData.h”
#include “RooDataSet.h”
#include “RooPlot.h”
#include “RooCmdArg.h”
#include “RooNLLVar.h”
#include “RooMinuit.h”
#include “RooDataHist.h”
#include “RooFitResult.h”
#include “RooHistPdf.h”
#include “RooGenericPdf.h”
#include “RooChi2Var.h”
using namespace RooFit;
//MuonMixingAOD.output.root
//LS.AOD.output.root
void MultipleFit(TString file = “LS.AOD.output.root”){
gROOT->Reset();
//Open the file
TFile *f = new TFile(file,“READ”);
// Get histo
TH1 t = (TH1)f->Get(“h_out1”);
//Some decorations
gStyle->SetCanvasBorderMode(0);
gStyle->SetCanvasColor(kWhite);
gStyle->SetFrameBorderMode(0);
gStyle->SetFrameFillColor(kWhite);
TCanvas *c = new TCanvas(“c”,“Fits”,1600,800);
//Variables
RooRealVar m(“m”,“invariant mass (GeV/c^{2})”,2.5,3.6);
RooDataHist *data = new RooDataHist(“data”,“data x”,m,t);
RooFitResult *res_crystal;
Float_t begin = 2.8;
Float_t end = 3.3;
//Define fit model
//Crystal ball fit
RooRealVar mean_cb(“mean_cb”,“mass”,3,2.9,3.2);
RooRealVar sigma_cb(“sigma_cb”,“width”,0.06,0,0.1);
RooRealVar alpha(“alpha”,“alpha”,1,0,2);
RooRealVar n(“n”,“n”,1,0,5);
RooCBShape *crystalball = new RooCBShape(“crystal ball”,“crystal ball PDF”,m,mean_cb,sigma_cb,alpha,n);
//Fit to data
res_crystal = crystalball->fitTo(*data,Range(begin,end),Save());
//Plot
RooPlot* mframe2 = m.frame(Title(“Crystal ball fit of J/#Psi invariant mass”));
data->plotOn(mframe2,DataError(RooAbsData::SumW2));
crystalball->plotOn(mframe2,LineColor(kRed));
mframe2->Draw();
c->Print(“fit.png”,“pngLandscape”);
// Write fit result in a LaTeX file
RooArgSet* params_crystal = crystalball->getParameters(m);
params_crystal->printLatex(OutputFile(“fit_result_crystal.tex”));
cout << "integral = " << crystalball->getVal()<< endl ;
// Chi 2 / nDOF for crystal ball
Int_t lower = t->GetXaxis()->FindFixBin(begin);
Int_t upper = t->GetXaxis()->FindFixBin(end);
RooChi2Var chi2_cb(“chi2_cb”,“chi2 of crystal ball”,*crystalball,*data);
cout << chi2_cb << endl;
Double_t val = chi2_cb.getVal();
Int_t range = upper-lower;
cout << range << endl;
Double_t new_chi2_crystal = val / (range - (res_crystal->floatParsFinal().getSize()));
} [/code]
LS.AOD.output.root (16.2 KB)