#ifndef __CINT__ #include "RooGlobalFunc.h" #endif #include "RooRealVar.h" #include "RooDataSet.h" #include "RooDataHist.h" #include "RooGaussian.h" #include "RooConstVar.h" #include "RooCategory.h" #include "TCanvas.h" #include "TAxis.h" #include "RooPlot.h" #include "TFile.h" #include "TF1.h" using namespace RooFit ; void testMacro() { TFile *fIn = TFile::Open("inputFile.root"); TH1F * xHist = (TH1F*)fIn->Get("xHist"); //xHist->Draw(); RooRealVar PsProperDL("PsProperDL","PsProperDL",-0.5,0.5); PsProperDL.setBins(100); xHist->Rebin(6); //xHist->Draw(); cout << xHist->GetNbinsX() << endl; RooRealVar Pt("Pt","Pt",0.,30.); RooRealVar sigma1("sigma1","sigma1",0.007,-1.,1.); RooRealVar mean1("mean1","mean1",0.0,-1,1.); RooGaussian gaus1("gaus1","gaus1",PsProperDL,mean1,sigma1); RooRealVar sigma2("sigma2","sigma2",0.003,-1.,1.); RooRealVar mean2("mean2","mean2",0.0,-1,1.); RooGaussian gaus2("gaus2","gaus2",PsProperDL,mean2,sigma2); RooRealVar alpha("alpha", "alpha", 0.015, 0.001, 0.9); RooRealVar lambda("lambda", "lambda", 2.7, 0.001, 10.); RooGenericPdf powerlaw("powerlaw", "powerlaw", "(TMath::Abs(PsProperDL) > alpha ? TMath::Power(TMath::Abs(PsProperDL),-lambda) : TMath::Power(alpha,-lambda))", RooArgSet(PsProperDL, alpha, lambda)); RooRealVar *fracResolution1 = new RooRealVar("fracResolution1", "fracResolution1", 0.0001, 0.95); RooRealVar *fracResolution2 = new RooRealVar("fracResolution2", "fracResolution2", 0.0001, 0.95); RooAddPdf *Rx = new RooAddPdf("Rx", "Rx", RooArgSet(gaus1, gaus2, powerlaw), RooArgList(*fracResolution1, *fracResolution2), kTRUE); //++++++++++++++++++++++++++++ RooDataHist hist("hist","hist",PsProperDL,xHist); RooPlot *f1 = PsProperDL.frame(); cout << "Fitting Model..." << endl; // Fitting the PDF to histogram and plotting RooFitResult *fitRx= Rx->fitTo(hist,Save()); hist.plotOn(f1); Rx->plotOn(f1); f1->Draw(); // I need the ratio of PDF (in Blue) and Data-points, that's why I want to make a TF1 out of this PDF. // Code for TF1 double ppp[8] = {0.0}; // to store 8-parmas //RooRealVar var2("var2","var2",-10e6,10e6); RooArgList obs(PsProperDL,"obs"); RooArgSet RxPars ; RxPars=Rx->getParameters(PsProperDL); //RooArgList * RxPars = (RooArgList*)fitRx->floatParsFinal(); TF1 * RxFunc = (TF1*)Rx->asTF(obs,RxPars); //RxFunc->Eval(2.3); RxFunc->GetParameters(ppp) ; for (int ii=0; ii<8; ii++) cout << ppp[ii] << endl; RxFunc->Draw(); }