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