Go to the source code of this file.
Functions | |
void | PrepareWorkspace_GaussOverFlat (TString fileName="WS_GaussOverFlat.root") |
void PrepareWorkspace_GaussOverFlat | ( | TString | fileName = "WS_GaussOverFlat.root" |
) |
Definition at line 3 of file PrepareWorkspace_GaussOverFlat.C.
00004 { 00005 // In this macro a PDF model is built assuming signal has a Gaussian 00006 // PDF and the background a flat PDF. The parameter of interest is 00007 // the signal yield and we assume for it a flat prior. In this 00008 // macro, no systematic uncertainty is considered (see 00009 // PrepareWorkspace_GaussOverFlat_withSystematics.C). All needed 00010 // objects are stored in a ROOT file (within a RooWorkspace 00011 // container); this ROOT file can then be fed as input to various 00012 // statistical methods. 00013 00014 using namespace RooFit; 00015 using namespace RooStats; 00016 00017 // use an observable for this shape-based analysis 00018 RooRealVar* mass = new RooRealVar("mass","mass",0,500,"GeV/c^{2}"); 00019 mass->setBins(100); 00020 RooArgSet* observables = new RooArgSet(*mass,"observables"); 00021 00022 // signal (Gaussian) and background (flat) PDFs 00023 RooAbsPdf* sigPdf = new RooGaussian("sigPdf","signal PDF",*mass,RooConst(200),RooConst(50)); 00024 RooAbsPdf* bkgPdf = new RooPolynomial("bkgPdf","background PDF",*mass,RooFit::RooConst(0)); 00025 00026 // S+B model: the sum of both shapes weighted with the yields 00027 RooRealVar* S = new RooRealVar("S","signal yield",0,0,60); 00028 RooRealVar* B = new RooRealVar("B","background yield",10); 00029 RooAbsPdf* model = new RooAddPdf("model","S+B PDF",RooArgList(*sigPdf,*bkgPdf),RooArgList(*S,*B)); 00030 00031 // B-only model: the same as with a signal yield fixed to 0 00032 RooAbsPdf* modelBkg = new RooExtendPdf("modelBkg","B-only PDF",*bkgPdf,*B); 00033 00034 // assume a flat prior on our parameter of interest (POI) which is the signal yield 00035 RooAbsPdf* priorPOI = new RooPolynomial("priorPOI","flat prior on the POI",*S,RooFit::RooConst(0)); 00036 RooArgSet* POI = new RooArgSet(*S,"POI"); 00037 00038 // different options are shown for the data generation from the model 00039 00040 // unbinned data with Poisson fluctuations 00041 // RooAbsData* data = (RooDataSet*) model->generate(*observables,RooFit::Extended(),Name("data")); 00042 00043 // binned data with Poisson fluctuations 00044 // RooAbsData* data = (RooDataHist*) model->generateBinned(*observables,Extended(),Name("data")); 00045 00046 // binned without any fluctuations (average case) 00047 RooAbsData* data = (RooDataHist*) model->generateBinned(*observables,Name("data"),ExpectedData()); 00048 00049 // control plot of the generated data 00050 // RooPlot* plot = mass->frame(); 00051 // data->plotOn(plot); 00052 // plot->Draw(); 00053 00054 // use a RooWorkspace to store the pdf models, prior informations, list of parameters,... 00055 RooWorkspace myWS("myWS"); 00056 myWS.import(*data,Rename("data")); 00057 myWS.import(*model,RecycleConflictNodes()); 00058 myWS.import(*modelBkg,RecycleConflictNodes()); 00059 myWS.import(*priorPOI,RecycleConflictNodes()); 00060 myWS.defineSet("observables",*observables,kTRUE); 00061 myWS.defineSet("POI",*POI,kTRUE); 00062 00063 // store the workspace in a ROOT file 00064 TFile file(fileName,"RECREATE"); 00065 file.cd(); 00066 myWS.Write(); 00067 file.Write(); 00068 file.Close(); 00069 00070 std::cout << "\nRooFit model initialized and stored in " << fileName << std::endl; 00071 }