Commit d070c487 authored by Marcel Rieger's avatar Marcel Rieger
Browse files

Plot updates.

parent 85a15a5b
......@@ -314,10 +314,11 @@ class HHModel(PhysicsModel):
raise Exception("invalid mass value '{}', please provide a valid value using the "
"--mass option".format(self.options.mass))
if self.modelBuilder.out.var("MH"):
self.modelBuilder.out.var("MH").removeRange()
self.modelBuilder.out.var("MH").setVal(self.options.mass)
self.modelBuilder.out.var("MH").setConstant(True)
else:
self.modelBuilder.doVar("MH[%g]" % self.options.mass)
self.modelBuilder.doVar("MH[%f]" % self.options.mass)
self.modelBuilder.out.var("MH").setConstant(True)
# add objects for kl dependent theory uncertainties
if self.doklDependentUnc:
......
......@@ -422,7 +422,7 @@ def plot_exclusion_and_bestfit_2d(
for g in graphs:
r.setup_graph(g, props={"LineColor": colors.dark_grey_trans_70, "LineStyle": 3,
"LineWidth": 1})
draw_objs.append((g, "SAME,L"))
draw_objs.append((g, "SAME,C"))
# draw labels at automatic positions
all_positions = []
......@@ -465,13 +465,13 @@ def plot_exclusion_and_bestfit_2d(
observed_limits[scan_parameter2],
observed_limits["limit"],
levels=[1.],
frame_kwargs=[{"mode": "edge"}],
frame_kwargs=[{"mode": "edge"}] + [{"mode": "contour+"}],
)[0]
# draw them
for g in obs_contours:
# create an inverted graph to close the outer polygon
g_inv = invert_graph(g, padding=1000.)
g_inv = invert_graph(g, x_axis=h_dummy.GetXaxis(), y_axis=h_dummy.GetYaxis())
r.setup_graph(g, props={"LineStyle": 1})
r.setup_graph(g_inv, props={"LineStyle": 1, "FillColor": colors.blue_signal_trans})
draw_objs.append((g, "SAME,L"))
......@@ -606,35 +606,70 @@ def get_auto_contour_levels(values, steps=(1,)):
return levels
def invert_graph(g, x_min=None, x_max=None, y_min=None, y_max=None, padding=0.):
ROOT = import_ROOT()
def repeat_graph(g, n):
points = sum((n * [p] for p in zip(*get_graph_points(g))), [])
g_repeated = g.__class__(len(points))
for i, (x, y) in enumerate(points):
g_repeated.SetPoint(i, x, y)
return g_repeated
def invert_graph(g, x_min=None, x_max=None, y_min=None, y_max=None, x_axis=None, y_axis=None,
offset=0.):
# get all graph values
x_values, y_values = get_graph_points(g)
# get default extrema
x_min = (min(x_values) if x_min is None else x_min) - padding
x_max = (max(x_values) if x_max is None else x_max) + padding
y_min = (min(y_values) if y_min is None else y_min) - padding
y_max = (max(y_values) if y_max is None else y_max) + padding
# copy the graph with prepended extrema
g_inv = ROOT.TGraph(g.GetN() + 5)
g_inv.SetPoint(0, x_min, y_min)
g_inv.SetPoint(1, x_min, y_max)
g_inv.SetPoint(2, x_max, y_max)
g_inv.SetPoint(3, x_max, y_min)
g_inv.SetPoint(4, x_min, y_min)
# copy remaining points
for i, (x, y) in enumerate(zip(x_values, y_values)):
g_inv.SetPoint(i + 5, x, y)
# get default frame values
if x_min is None:
if x_axis:
x_min = x_axis.GetXmin() - 0.01 * (x_axis.GetXmax() - x_axis.GetXmin())
else:
x_min = min(x_values)
if x_max is None:
if x_axis:
x_max = x_axis.GetXmax() + 0.01 * (x_axis.GetXmax() - x_axis.GetXmin())
else:
x_max = max(x_values)
if y_min is None:
if y_axis:
y_min = y_axis.GetXmin() - 0.01 * (y_axis.GetXmax() - y_axis.GetXmin())
else:
y_min = min(y_values)
if y_max is None:
if y_axis:
y_max = y_axis.GetXmax() + 0.01 * (y_axis.GetXmax() - y_axis.GetXmin())
else:
y_max = max(y_values)
# define outer "frame" points
bl = (x_min - offset, y_min - offset)
tl = (x_min - offset, y_max + offset)
tr = (x_max + offset, y_max + offset)
br = (x_max + offset, y_min - offset)
corners = [tr, br, bl, tl]
# find the corner that is closest to the graph start point
dist = lambda x, y: ((x - x_values[0])**2. + (y - y_values[0])**2.)**0.5
start_index = min(list(range(4)), key=lambda i: dist(corners[i][0], corners[i][1]))
# to invert the graph, create a new graph whose points start with an outer frame consisting of
# the 4 corners, the graph points itself, the first point of the graph again to close it, and
# ending with the closest corner again
points = (2 * corners)[start_index:start_index + 5]
points.extend(zip(x_values, y_values))
points.append((x_values[0], y_values[0]))
points.append(corners[start_index])
# copy the graph and fill points
g_inv = g.__class__(len(points))
for i, (x, y) in enumerate(points):
g_inv.SetPoint(i, x, y)
return g_inv
def locate_xsec_labels(graphs, level, label_width, pad_width, pad_height, x_min, x_max, y_min,
y_max, other_positions=None):
y_max, other_positions=None, min_points=10):
positions = []
other_positions = other_positions or []
......@@ -661,6 +696,10 @@ def locate_xsec_labels(graphs, level, label_width, pad_width, pad_height, x_min,
x_values, y_values = get_graph_points(g)
n_points = len(x_values)
# skip when there are not enough points
if n_points < min_points:
continue
# compute the line contour and number of blocks
line_contour = np.array([x_values, y_values]).T
n_blocks = int(np.ceil(n_points / label_width)) if label_width > 1 else 1
......
......@@ -244,9 +244,7 @@ def plot_likelihood_scans_1d(
# set y range
y_max_value = max([
d["values"]["dnll2"][
(d["values"][poi] >= x_min) & (d["values"][poi] <= x_max)
]
d["values"]["dnll2"][(d["values"][poi] >= x_min) & (d["values"][poi] <= x_max)].max()
for d in data
])
if y_log:
......@@ -886,7 +884,7 @@ def evaluate_likelihood_scan_1d(poi_values, dnll2_values, poi_min=None):
def get_intersections(v):
def minimize(bounds):
objective = lambda x: (interp(x) - v) ** 2.0
res = minimize_1d(objective, bounds)
res = minimize_1d(objective, bounds, start=poi_min)
return res.x[0] if res.status == 0 and (bounds[0] < res.x[0] < bounds[1]) else None
return (
......@@ -987,10 +985,6 @@ def evaluate_likelihood_scan_2d(
# helper to get the outermost intersection of the nll curve with a certain value
def get_intersections(v, n_poi):
def minimize(bounds):
res = minimize_1d(objective, bounds)
return res.x[0] if res.status == 0 and (bounds[0] < res.x[0] < bounds[1]) else None
if n_poi == 1:
poi_values_min, poi_values_max = poi1_values_min, poi1_values_max
poi_min = poi1_min
......@@ -1000,6 +994,10 @@ def evaluate_likelihood_scan_2d(
poi_min = poi2_min
objective = lambda x: (interp(poi1_min, x) - v) ** 2.0
def minimize(bounds):
res = minimize_1d(objective, bounds, start=poi_min)
return res.x[0] if res.status == 0 and (bounds[0] < res.x[0] < bounds[1]) else None
return (
minimize((poi_min, poi_values_max - 1e-4)),
minimize((poi_values_min + 1e-4, poi_min)),
......
......@@ -226,7 +226,7 @@ def find_poly_bin_center(poly_bin, n=1000):
# helper to extract contours
def get_contours(x_values, y_values, z_values, levels, frame_kwargs=None, min_points=5):
def get_contours(x_values, y_values, z_values, levels, frame_kwargs=None, min_points=10):
ROOT = import_ROOT()
# remove nans in z_values
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment