File indexing completed on 2024-04-06 12:31:38
0001 #include "RooPlot.h"
0002 #include "RooRealVar.h"
0003 #include "RooGaussian.h"
0004 #include "RooDataHist.h"
0005 #include "RooAddPdf.h"
0006 #include "RooGlobalFunc.h"
0007 #include "CruijffPdf.h"
0008 #include "TH1F.h"
0009
0010 RooPlot* double_gauss_fit(TH1* histo, TString title = "",
0011 double min_mean1=-100, double max_mean1=100,
0012 double min_mean2=-100, double max_mean2=100,
0013 double min_sigma1=0.001, double max_sigma1=10,
0014 double min_sigma2=1, double max_sigma2=10)
0015 {
0016 using namespace RooFit;
0017 RooRealVar x("x","x",0);
0018 RooRealVar mean1("mean1","mean1",min_mean1,max_mean1);
0019 RooRealVar mean2("mean2","mean2",min_mean2,max_mean2);
0020 RooRealVar sigma1("sigma1","sigma1",min_sigma1,max_sigma1);
0021 RooRealVar sigma2("sigma2","sigma2",min_sigma2,max_sigma2);
0022 RooGaussian pdf1("gaus1","gaus1",x,mean1,sigma1);
0023 RooGaussian pdf2("gaus2","gaus2",x,mean2,sigma2);
0024 RooRealVar frac("frac","frac",0,1);
0025 RooAddPdf pdf("pdf","pdf",pdf1,pdf2,frac);
0026 RooDataHist data("data","data",x,histo);
0027 pdf.fitTo(data,RooFit::Minos(kFALSE));
0028 RooPlot* frame = x.frame();
0029 data.plotOn(frame);
0030 data.statOn(frame,What("N"));
0031 pdf.paramOn(frame,Format("NEA",AutoPrecision(2)));
0032 pdf.plotOn(frame);
0033 frame->SetTitle(title);
0034 frame->Draw();
0035 return frame;
0036 }
0037
0038
0039 RooPlot* cruijff_fit(TH1* histo, TString title = "",
0040 double min_mean=0, double max_mean=10,
0041 double min_sigmaL=0.001, double max_sigmaL=10,
0042 double min_sigmaR=0.001, double max_sigmaR=10)
0043 {
0044 using namespace RooFit;
0045 RooRealVar x("x","x",0);
0046 RooRealVar mean("mean","mean",min_mean,max_mean);
0047 RooRealVar sigmaL("sigmaL","sigmaL",min_sigmaL,max_sigmaL);
0048 RooRealVar sigmaR("sigmaR","sigmaR",min_sigmaR,max_sigmaR);
0049 RooRealVar alphaL("alphaL","alphaL",0,1);
0050 RooRealVar alphaR("alphaR","alphaR",0,1);
0051 CruijffPdf pdf("pdf","pdf",x,mean,sigmaL,sigmaR,alphaL,alphaR);
0052 RooDataHist data("data","data",x,histo);
0053 pdf.fitTo(data,RooFit::Minos(kFALSE));
0054 RooPlot* frame = x.frame();
0055 data.plotOn(frame);
0056 data.statOn(frame,What("N"));
0057 pdf.paramOn(frame,Format("NEA",AutoPrecision(2)));
0058 pdf.plotOn(frame);
0059 frame->SetTitle(title);
0060 frame->Draw();
0061 return frame;
0062 }
0063