rs601_HLFactoryexample.C

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'High Level Factory Example' RooStats tutorial macro #601
00004 // author: Danilo Piparo
00005 // date August. 2009
00006 //
00007 // This tutorial shows an example of creating a simple
00008 // model using the High Level model Factory.
00009 //
00010 //
00011 /////////////////////////////////////////////////////////////////////////
00012 
00013 #include <fstream>
00014 #include "TString.h"
00015 #include "TROOT.h"
00016 #include "RooGlobalFunc.h"
00017 #include "RooWorkspace.h"
00018 #include "RooRealVar.h"
00019 #include "RooAbsPdf.h"
00020 #include "RooDataSet.h"
00021 #include "RooPlot.h"
00022 #include "RooStats/HLFactory.h"
00023 
00024 
00025 // use this order for safety on library loading
00026 using namespace RooFit ;
00027 using namespace RooStats ;
00028 using namespace std;
00029 
00030 void rs601_HLFactoryexample() {
00031 
00032     // --- Build the datacard and dump to file---
00033 
00034     TString card_name("HLFavtoryexample.rs");
00035     ofstream ofile(card_name);
00036     ofile << "// The simplest card\n\n"
00037         << "gauss = Gaussian(mes[5.20,5.30],mean[5.28,5.2,5.3],width[0.0027,0.001,1]);\n"
00038         << "argus = ArgusBG(mes,5.291,argpar[-20,-100,-1]);\n"
00039         << "sum = SUM(nsig[200,0,10000]*gauss,nbkg[800,0,10000]*argus);\n\n";
00040 
00041     ofile.close();
00042 
00043     HLFactory hlf("HLFavtoryexample",
00044                   card_name,
00045                   false);
00046 
00047     // --- Take elements out of the internal workspace ---
00048 
00049     RooWorkspace* w = hlf.GetWs();
00050 
00051     RooRealVar* mes = dynamic_cast<RooRealVar*>(w->arg("mes"));
00052     RooAbsPdf* sum = dynamic_cast<RooAbsPdf*>(w->pdf("sum"));
00053     RooAbsPdf* argus = dynamic_cast<RooAbsPdf*>(w->pdf("argus"));
00054 //    RooRealVar* mean = dynamic_cast<RooRealVar*>(w->arg("mean"));
00055 //    RooRealVar* argpar = dynamic_cast<RooRealVar*>(w->arg("argpar"));
00056 
00057     // --- Generate a toyMC sample from composite PDF ---
00058     RooDataSet *data = sum->generate(*mes,2000) ;
00059 
00060     // --- Perform extended ML fit of composite PDF to toy data ---
00061     sum->fitTo(*data) ;
00062 
00063     // --- Plot toy data and composite PDF overlaid ---
00064     RooPlot* mesframe = mes->frame() ;
00065     data->plotOn(mesframe) ;
00066     sum->plotOn(mesframe) ;
00067     sum->plotOn(mesframe,Components(*argus),LineStyle(kDashed)) ;
00068 
00069     gROOT->SetStyle("Plain");
00070     mesframe->Draw()  ;
00071 }

Generated on Tue Jul 5 15:45:10 2011 for ROOT_528-00b_version by  doxygen 1.5.1