Go to the source code of this file.
Functions | |
void | PrepareWorkspace_Poisson_withSystematics (TString fileName="WS_Poisson_withSystematics.root") |
void PrepareWorkspace_Poisson_withSystematics | ( | TString | fileName = "WS_Poisson_withSystematics.root" |
) |
Definition at line 3 of file PrepareWorkspace_Poisson_withSystematics.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. It 00008 // is also assumed there is a systematic uncertainty on the number 00009 // of expected background events. The parameter of interest is the 00010 // signal yield and we assume for it a flat prior. All needed 00011 // objects are stored in a ROOT file (within a RooWorkspace 00012 // container); this ROOT file can then be fed as input to various 00013 // 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",100,0,1500); 00029 RooRealVar* B = new RooRealVar("B","background yield",1000,0,3000); 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 // take the background yield as a nuisance parameter (assume an uncertainty of 20%) 00036 RooAbsPdf* priorNuisance = new RooGaussian("priorNuisance","prior probability on B",*B,RooConst(B->getVal()),RooConst(B->getVal()*0.20)); 00037 RooArgSet* parameters = new RooArgSet(*B,"parameters"); 00038 00039 // assume a flat prior on our parameter of interest (POI) which is the signal yield 00040 RooAbsPdf* priorPOI = new RooPolynomial("priorPOI","flat prior on the POI",*S,RooFit::RooConst(0)); 00041 RooArgSet* POI = new RooArgSet(*S,"POI"); 00042 00043 // different options are shown for the data generation from the model 00044 00045 // binned data with a fixed number of events 00046 // RooAbsData* data = (RooDataHist*) model->generateBinned(*observables,S->getVal(),Name("data")); 00047 00048 // binned data with Poisson fluctuations 00049 // RooAbsData* data = (RooDataHist*) model->generateBinned(*observables,Extended(),Name("data")); 00050 00051 // binned without any fluctuations (average case) 00052 RooAbsData* data = (RooDataHist*) model->generateBinned(*observables,Name("data"),ExpectedData()); 00053 00054 // control plot of the generated data 00055 // RooPlot* plot = x->frame(); 00056 // data->plotOn(plot); 00057 // plot->Draw(); 00058 00059 // use a RooWorkspace to store the pdf models, prior informations, list of parameters,... 00060 RooWorkspace myWS("myWS"); 00061 myWS.import(*data,Rename("data")); 00062 myWS.import(*model,RecycleConflictNodes()); 00063 myWS.import(*modelBkg,RecycleConflictNodes()); 00064 myWS.import(*priorPOI,RecycleConflictNodes()); 00065 myWS.import(*priorNuisance,RecycleConflictNodes()); 00066 myWS.defineSet("observables",*observables,kTRUE); 00067 myWS.defineSet("parameters",*parameters,kTRUE); 00068 myWS.defineSet("POI",*POI,kTRUE); 00069 00070 // store the workspace in a ROOT file 00071 TFile file(fileName,"RECREATE"); 00072 file.cd(); 00073 myWS.Write(); 00074 file.Write(); 00075 file.Close(); 00076 00077 std::cout << "\nRooFit model initialized and stored in " << fileName << std::endl; 00078 }