#include "RooRealVar.h" #include "RooDataSet.h" #include "RooGaussian.h" #include "TCanvas.h" #include "TAxis.h" #include "RooPlot.h" #include "RooAddPdf.h" #include "TH1.h" #include "RooGaussian.h" #include "RooFormulaVar.h" #include "RooAbsPdf.h" #include "TFormula.h" #include "RooEffProd.h" #include "TLine.h" #include "RooNumConvolution.h" #include "RooCFunction4Binding.h" //#if //#endif using namespace RooFit; void code() { RooRealVar x("x", "x", 0., 0.8); // read histogram TFile* file = new TFile("test.root"); TH1F* roothist1 = (TH1F*)file->Get("h1"); // Reading histogram from existing TH1 RooDataHist* hist = new RooDataHist("Rfit:x", "test", x, (TH1F*)roothist1); RooPlot* frame = x.frame(Name("xframe"), Title("test")); // peak RooRealVar mean("mean", "mean", 0.25, 0.30); RooRealVar sigma("sigma", "sigma", 0.15, 0.20); RooGaussian gauss("gauss", "gauss", x, mean, sigma); //computon RooRealVar hn("hn", "hn", 0.662);//ev RooRealVar re("re", "re", 0.00000000000000281794); RooRealVar me("me", "me", 0.511);//ev RooFormulaVar s("s", "@0/0.662", RooArgList(x)); RooFormulaVar ga("ga", "@0/@1", RooArgList(hn, me)); //my idea1 1 or 2 //TF1* f = new TF1("f", "1/[2]/[2]*([0] *( ([1]*[1])/(([2]*[2])*(1-[1])*(1-[1])) + [1]/(1-[1])*([1]-2/[2]) + 2)", 0, 0.8); //RooAbsReal* pdf = RooFit::bindFunction("pdf", f, x, me, s, ga); //my idea2 RooGenericPdf pdf("function", "function", "1/@2/@2*(@0 *( (@1*@1)/((@2*@2)*(1-@1)*(1-@1)) + @1/(1-@1)*(@1-2/@2) + 2))", RooArgList(me, s, ga)); RooNumConvPdf fff("model", "model", x, pdf, gauss); x.setBins(100); gauss.fitTo(*hist); pdf.fitTo(*hist); fff.fitTo(*hist); hist->plotOn(frame, DrawOption("B"), DataError(RooAbsData::None), XErrorSize(0), FillColor(kBlue)); gauss.plotOn(frame, Range(0.05, 0.8), LineColor(kMagenta)); pdf.plotOn(frame, Range(0.05, 0.8), LineColor(kBlack)); fff.plotOn(frame, Range(0.05, 0.8), LineColor(kYellow)); frame->GetYaxis()->SetTitleOffset(1.6); frame->Draw(); }