34 infile="", workspaceName="combined", modelConfigName="ModelConfig", dataName="obsData"
41 allowNegativeMu =
True
48 filename =
"results/example_combined_GaussExample_model.root"
49 fileExist =
not ROOT.gSystem.AccessPathName(filename)
50 print(
"does the .root file exists?: ", fileExist)
54 print(f
"will run standard hist2workspace example")
55 ROOT.gROOT.ProcessLine(
".! prepareHistFactory .")
56 ROOT.gROOT.ProcessLine(
".! hist2workspace config/example.xml")
57 print(f
"\n\n---------------------")
58 print(f
"Done creating example input")
59 print(f
"---------------------\n\n")
65 file = ROOT.TFile.Open(filename)
69 print(f
"StandardRooStatsDemoMacro: Input file {filename} is not found")
76 w = file.Get(workspaceName)
78 print(f
"workspace not found")
82 mc = w[modelConfigName]
88 if not data
or not mc:
90 print(f
"data or ModelConfig was not found")
96 firstPOI = mc.GetParametersOfInterest().first()
97 plc = ROOT.RooStats.ProfileLikelihoodCalculator(data, mc)
98 interval = plc.GetInterval()
99 plcUpperLimit = interval.UpperLimit(firstPOI)
101 print(f
"\n\n--------------------------------------")
102 print(
"Will generate sampling distribution at ", firstPOI.GetName(),
" = ", plcUpperLimit)
103 nPOI = mc.GetParametersOfInterest().getSize()
105 print(f
"not sure what to do with other parameters of interest, but here are their values")
106 mc.GetParametersOfInterest().
Print(
"v")
110 ts = ROOT.RooStats.ProfileLikelihoodTestStat(mc.GetPdf())
114 firstPOI.setMin(-1 * firstPOI.getMax())
117 poi = ROOT.RooArgSet()
118 poi.add(mc.GetParametersOfInterest())
121 sampler = ROOT.RooStats.ToyMCSampler(ts, nToyMC)
122 sampler.SetPdf(mc.GetPdf())
123 sampler.SetObservables(mc.GetObservables())
124 sampler.SetGlobalObservables(mc.GetGlobalObservables())
125 if not mc.GetPdf().canBeExtended()
and (data.numEntries() == 1):
126 print(f
"tell it to use 1 event")
127 sampler.SetNEventsPerToy(1)
129 firstPOI.setVal(plcUpperLimit)
130 sampler.SetParametersForTestStat(mc.GetParametersOfInterest())
132 firstPOI.setVal(plcUpperLimit)
133 allParameters = ROOT.RooArgSet()
134 allParameters.add(mc.GetParametersOfInterest())
135 allParameters.add(mc.GetNuisanceParameters())
136 allParameters.Print(
"v")
138 sampDist = sampler.GetSamplingDistribution(allParameters)
139 plot = ROOT.RooStats.SamplingDistPlot()
140 plot.AddSamplingDistribution(sampDist)
141 plot.GetTH1F(sampDist).GetYaxis().SetTitle(
142 "f(-log #lambda(#mu={:2f}) | #mu={:2f})".
format(plcUpperLimit, plcUpperLimit)
144 plot.SetAxisTitle(
"-log #lambda(#mu={:2f})".
format(plcUpperLimit))
146 c1 = ROOT.TCanvas(
"c1")
149 MIN = plot.GetTH1F(sampDist).GetXaxis().GetXmin()
150 MAX = plot.GetTH1F(sampDist).GetXaxis().GetXmax()
152 tmp_Form =
"2*ROOT::Math::chisquared_pdf(2*x,{:f},0)".
format(nPOI)
153 f = ROOT.TF1(
"f", tmp_Form, MIN, MAX)
158 c1.SaveAs(
"StandardTestStatDistributionDemo.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 format
void Print(GNN_Data &d, std::string txt="")