/* * roofit_test.c * * * Created by Benjamin Carlson on 8/13/13. * Copyright 2013 Carnegie Mellon University. All rights reserved. * */ //#include "roofit_test.h" #include #include #include #include #include #ifndef __CINT__ #include "RooGlobalFunc.h" #endif #include "RooRealVar.h" #include "RooDataSet.h" #include "RooDataHist.h" #include "RooGaussian.h" #include "RooConstVar.h" #include "RooFormulaVar.h" #include "RooProdPdf.h" #include "RooEfficiency.h" #include "RooPolynomial.h" #include "RooChi2Var.h" #include "RooMinuit.h" #include "RooChebychev.h" #include "RooCategory.h" #include "RooAddPdf.h" #include "RooFitResult.h" #include "RooExtendPdf.h" #include "RooArgList.h" #include "TCanvas.h" #include "TAxis.h" #include "RooPlot.h" #include "RooRealSumPdf.h" #ifndef __CINT__ #include "RooCFunction1Binding.h" #include "RooCFunction2Binding.h" #include "RooCFunction3Binding.h" #endif #include "RooTFnBinding.h" using namespace RooFit ; void fit_weighted(double wgt){ RooRealVar x1("x1","x1",8,11); RooRealVar sigma1("sigma1","sigma1",0.1,0.05,0.2) ; RooRealVar mean1("mean1","mean1",9.46,8,11) ; RooRealVar n1("yield1","number of events",1000,0,10000000) ; RooGaussian gauss1("gauss1","gauss1",x1,mean1,sigma1) ; RooExtendPdf egauss1("egauss1","extended gaussian PDF", gauss1,n1); RooRealVar w("w","w",wgt); // weight variable RooDataSet* data1 = egauss1.generate(x1,1000); data1->addColumn(w); RooDataSet *wdata = new RooDataSet("wdata","wdata",*data1->get(),Import(*data1), WeightVar("w")); RooFitResult* fitres= egauss1.fitTo(*wdata,Extended(kTRUE),Save(),SumW2Error(kFALSE),PrintEvalErrors(-1),PrintLevel(-1),Verbose(kFALSE)) ; double yield = ((RooRealVar*)fitres->floatParsFinal().find("yield1"))->getVal(); double yield_err = ((RooRealVar*)fitres->floatParsFinal().find("yield1"))->getError(); cout << "extended maximum likelihood: " << endl; printf("yield: %6.0f +/- %4.0f \t rel. error: %4.2f%%\n",yield, yield_err, yield_err/yield*100); } void roofit_test(){ fit_weighted(1.0); fit_weighted(4.0); }