/// \file /// \ingroup tutorial_roofit /// \notebook -js /// /// Likelihood and minimization: working with the profile likelihood estimator /// /// \macro_image /// \macro_output /// \macro_code /// /// \date 07/2008 /// \author Wouter Verkerke #include "RooRealVar.h" #include "RooDataSet.h" #include "RooGaussian.h" #include "RooConstVar.h" #include "RooAddPdf.h" #include "RooMinimizer.h" #include "TCanvas.h" #include "TAxis.h" #include "RooPlot.h" using namespace RooFit; void test_asTF() { int E_min = 20; int E_max = 145; RooRealVar mes("mes","Energy (keV)",E_min,E_max); TFile *file_sumBkg = new TFile("allBKG_twoGaus_lowXe133_set45.root","read"); TH1D *xe127 = (TH1D *)file_sumBkg->Get("h_xe127"); TH1D *xe133 = (TH1D *)file_sumBkg->Get("h_xe133"); TH1D *h_all = new TH1D("h_all","h_all",3000,0,3000); h_all->Add(xe127,xe133); RooDataHist h_xe127("h_xe127","h_xe127",mes,xe127); RooDataHist h_xe133("h_xe133","h_xe133",mes,xe133); RooHistPdf pdf_Xe127("pdf_Xe127","pdf_Xe127",mes,h_xe127,0); RooHistPdf pdf_Xe133("pdf_Xe133","pdf_Xe133",mes,h_xe133,0); int input_xe127 = 36; int input_xe133 = 2000; RooRealVar nbkg_xe127("nbkg_xe127","#xe127 events",input_xe127, 0.1*input_xe127, input_xe127*10); RooRealVar nbkg_xe133("nbkg_xe133","#xe133 events",input_xe133, 0.1*input_xe133, input_xe133*10); RooAddPdf model("model","model",RooArgList(pdf_Xe127, pdf_Xe133), RooArgList(nbkg_xe127, nbkg_xe133)); RooDataSet *data = model.generate(mes,2000); model.fitTo(*data); // plot RooPlot* xframe = mes.frame(Title("try")); data->plotOn(xframe, Name("fake Data"), MarkerColor(kBlack), LineColor(kBlack)); model.plotOn(xframe,Components("pdf_Xe127"), Name("Xe127 bkg"), LineColor(kViolet-3)); model.plotOn(xframe,Components("pdf_Xe133"), Name("Xe133 bkg"), LineColor(kMagenta-3)); model.plotOn(xframe, Name("Fit"), LineColor(4)); //--------------// // draw // //--------------// gStyle->SetOptStat(0); TCanvas* c = new TCanvas("c","c",1); gPad->SetLogy(); xframe->Draw(); // asTF TCanvas* c1 = new TCanvas("c1","c1",1); TF1* func = model.asTF(RooArgList(mes), RooArgList(nbkg_xe127, nbkg_xe133)); cout << " 20~60: " << func->Integral(20,60) << endl; cout << " 60~145 " << func->Integral(60,140) << endl; cout << " 90: " << func->Eval(90) << endl; cout << " 60~145 " << func->Integral(89,91) << endl; // func->Draw(""); }