Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
StandardProfileInspectorDemo.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_roostats
3## \notebook -js
4## Standard demo of the ProfileInspector class
5## StandardProfileInspectorDemo
6##
7## This is a standard demo that can be used with any ROOT file
8## prepared in the standard way. You specify:
9## - name for input ROOT file
10## - name of workspace inside ROOT file that holds model and data
11## - name of ModelConfig that specifies details for calculator tools
12## - name of dataset
13##
14## With the values provided below this script will attempt to run the
15## standard hist2workspace example and read the ROOT file
16## that it produces.
17##
18## The actual heart of the demo is only about 10 lines long.
19##
20## The ProfileInspector plots the conditional maximum likelihood estimate
21## of each nuisance parameter in the model vs. the parameter of interest.
22## (aka. profiled value of nuisance parameter vs. parameter of interest)
23## (aka. best fit nuisance parameter with p.o.i fixed vs. parameter of interest)
24##
25## \macro_image
26## \macro_output
27## \macro_code
28##
29## \authors Akeem Hart, Kyle Cranmer (C++ Version)
30
31import ROOT
32
33# -------------------------------------------------------
34# First part is just to access a user-defined file
35# or create the standard example file if it doesn't exist
36
37workspaceName = "combined"
38modelConfigName = "ModelConfig"
39dataName = "obsData"
40filename = "results/example_combined_GaussExample_model.root"
41# if file does not exists generate with histfactory
42if ROOT.gSystem.AccessPathName(filename):
43 # Normally this would be run on the command line
44 print("will run standard hist2workspace example")
45 ROOT.gROOT.ProcessLine(".! prepareHistFactory .")
46 ROOT.gROOT.ProcessLine(".! hist2workspace config/example.xml")
47 print("\n\n---------------------")
48 print("Done creating example input")
49 print("---------------------\n\n")
50
51file = ROOT.TFile.Open(filename)
52
53# -------------------------------------------------------
54# Tutorial starts here
55# -------------------------------------------------------
56
57# get the workspace out of the file
58
59w = file.Get(workspaceName)
60
61# get the modelConfig out of the file
62mc = w[modelConfigName]
63
64# get the modelConfig out of the file
65data = w[dataName]
66
67# -----------------------------
68# now use the profile inspector
69p = ROOT.RooStats.ProfileInspector()
70profile_plots = p.GetListOfProfilePlots(data, mc)
71
72# now make plots
73c1 = ROOT.TCanvas("c1", "ProfileInspectorDemo", 800, 200)
74n = len(profile_plots)
75if n > 4:
76 nx = int(n**0.5)
77 ny = ROOT.TMath.CeilNint(n / nx)
78 nx = ROOT.TMath.CeilNint(n**0.5)
79 c1.Divide(ny, nx)
80else:
81 c1.Divide(n)
82for i, plot in enumerate(profile_plots):
83 c1.cd(i + 1)
84 plot.Draw("al")
85
86c1.Update()
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