147doFeldmanCousins = 
False 
  155ROOT.RooRandom.randomGenerator().SetSeed(4357)
 
  158wspace = ROOT.RooWorkspace(
"wspace")
 
  159wspace.factory(
"Poisson::on(non[0,1000], sum::splusb(s[40,0,100],b[100,0,300]))")
 
  160wspace.factory(
"Poisson::off(noff[0,5000], prod::taub(b,tau[5,3,7],rho[1,0,2]))")
 
  161wspace.factory(
"Poisson::onbar(nonbar[0,10000], bbar[1000,500,2000])")
 
  162wspace.factory(
"Poisson::offbar(noffbar[0,1000000], prod::lambdaoffbar(bbar, tau))")
 
  163wspace.factory(
"Gaussian::mcCons(rhonom[1.,0,2], rho, sigma[.2])")
 
  164wspace.factory(
"PROD::model(on,off,onbar,offbar,mcCons)")
 
  165wspace.defineSet(
"obs", 
"non,noff,nonbar,noffbar,rhonom")
 
  167wspace.factory(
"Uniform::prior_poi({s})")
 
  168wspace.factory(
"Uniform::prior_nuis({b,bbar,tau, rho})")
 
  169wspace.factory(
"PROD::prior(prior_poi,prior_nuis)")
 
  175wspace.defineSet(
"poi", 
"s")
 
  176wspace.defineSet(
"nuis", 
"b,tau,rho,bbar")
 
  195data = wspace[
"model"].generate(wspace.set(
"obs"), 1)
 
  202modelConfig = ROOT.RooStats.ModelConfig(
"FourBins")
 
  203modelConfig.SetWorkspace(wspace)
 
  204modelConfig.SetPdf(wspace[
"model"])
 
  205modelConfig.SetPriorPdf(wspace[
"prior"])
 
  206modelConfig.SetParametersOfInterest(wspace.set(
"poi"))
 
  207modelConfig.SetNuisanceParameters(wspace.set(
"nuis"))
 
  208wspace.Import(modelConfig)
 
  209wspace.writeToFile(
"FourBin.root")
 
  216plc = ROOT.RooStats.ProfileLikelihoodCalculator(data, modelConfig)
 
  217plc.SetConfidenceLevel(0.95)
 
  218plInt = plc.GetInterval()
 
  219msglevel = ROOT.RooMsgService.instance().globalKillBelow()
 
  220ROOT.RooMsgService.instance().setGlobalKillBelow(ROOT.RooFit.FATAL)
 
  221plInt.LowerLimit(wspace[
"s"])  
 
  222ROOT.RooMsgService.instance().setGlobalKillBelow(msglevel)
 
  225fc = ROOT.RooStats.FeldmanCousins(data, modelConfig)
 
  226fc.SetConfidenceLevel(0.95)
 
  228fc.FluctuateNumDataEntries(
False)
 
  229fc.UseAdaptiveSampling(
True)
 
  231fcInt = ROOT.RooStats.PointSetInterval()
 
  233    fcInt = fc.GetInterval()
 
  236bc = ROOT.RooStats.BayesianCalculator(data, modelConfig)
 
  237bc.SetConfidenceLevel(0.95)
 
  238bInt = ROOT.RooStats.SimpleInterval()
 
  239if doBayesian 
and len(wspace.set(
"poi")) == 1:
 
  240    bInt = bc.GetInterval()
 
  242    print(
"Bayesian Calc. only supports on parameter of interest")
 
  247fit = wspace[
"model"].fitTo(data, Save=
True)
 
  248ph = ROOT.RooStats.ProposalHelper()
 
  249ph.SetVariables(fit.floatParsFinal())
 
  250ph.SetCovMatrix(fit.covarianceMatrix())
 
  251ph.SetUpdateProposalParameters(ROOT.kTRUE)  
 
  253pf = ph.GetProposalFunction()
 
  255mc = ROOT.RooStats.MCMCCalculator(data, modelConfig)
 
  256mc.SetConfidenceLevel(0.95)
 
  257mc.SetProposalFunction(pf)
 
  258mc.SetNumBurnInSteps(500)  
 
  260mc.SetLeftSideTailFraction(0.5)  
 
  261mcInt = ROOT.RooStats.MCMCInterval()
 
  263    mcInt = mc.GetInterval()
 
  267c1 = ROOT.gROOT.Get(
"c1")
 
  269    c1 = ROOT.TCanvas(
"c1")
 
  271if doBayesian 
and doMCMC:
 
  274elif doBayesian 
or doMCMC:
 
  278lrplot = ROOT.RooStats.LikelihoodIntervalPlot(plInt)
 
  281if doBayesian 
and len(wspace.set(
"poi")) == 1:
 
  285    bc.SetScanOfPosterior(20)
 
  286    bplot = bc.GetPosteriorPlot()
 
  290    if doBayesian 
and len(wspace.set(
"poi")) == 1:
 
  294    mcPlot = ROOT.RooStats.MCMCIntervalPlot(mcInt)
 
  300    "Profile Likelihood interval on s = [{}, {}]".
format(plInt.LowerLimit(wspace[
"s"]), plInt.UpperLimit(wspace[
"s"]))
 
  304if doBayesian 
and len(wspace.set(
"poi")) == 1:
 
  305    print(
"Bayesian interval on s = [{}, {}]".
format(bInt.LowerLimit(), bInt.UpperLimit()))
 
  309        "Feldman Cousins interval on s = [{}, {}]".
format(fcInt.LowerLimit(wspace[
"s"]), fcInt.UpperLimit(wspace[
"s"]))
 
  314    print(
"MCMC interval on s = [{}, {}]".
format(mcInt.LowerLimit(wspace[
"s"]), mcInt.UpperLimit(wspace[
"s"])))
 
  320c1.SaveAs(
"FourBinInstructional.png")
 
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
 
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format