我正在尝试使用以下代码使高斯适合我的数据:
#ifndef __CINT__
#include "RooGlobalFunc.h"
#endif
#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");
h1->AddFile("MC_Signal_Event.root");
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);
dataSet.Print("V");
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();
dataSet.plotOn(lm_frame,Binning(30));
lm_pdf.plotOn(lm_frame, LineColor(kBlue), LineStyle(kSolid));
lm_frame->Draw("HIST");
}
我得到的不是得到很好的高斯,而是(无法发布图像。高斯比数据宽/低)。
我希望有人能帮助我! 在此先感谢:D