Commit 9a2e35ec authored by Marcel Rieger's avatar Marcel Rieger
Browse files

Update sample check in model, plot updates.

parent 313bc090
......@@ -139,7 +139,7 @@ colors = DotDict(
yellow=798,
pink=222,
cyan=7,
orange=807,
orange=797,
red_cream=46,
blue_cream=38,
blue_signal=(67, 118, 201),
......
......@@ -578,29 +578,35 @@ class HHModel(PhysicsModel):
super(HHModel, self).done()
# get the labels of ggF and VBF samples and store a flag to check if they were matched
matches = OrderedDict(
(s.label, [])
for s in self.ggf_formula.sample_list + self.vbf_formula.sample_list
)
matches_ggf = OrderedDict((s.label, []) for s in self.ggf_formula.sample_list)
matches_vbf = OrderedDict((s.label, []) for s in self.vbf_formula.sample_list)
# go through the scaling map and match to samples
for sample_name in self.scalingMap:
matches = matches_ggf if sample_name.startswith("ggHH_") else matches_vbf
for sample_label in matches:
if sample_name.startswith(sample_label):
matches[sample_label].append(sample_name)
break
# print matches
max_len = max(len(label) for label in matches)
max_len = max(len(label) for label in list(matches_ggf.keys()) + list(matches_vbf.keys()))
print("Matching signal samples:")
for label, names in matches.items():
for label, names in list(matches_ggf.items()) + list(matches_vbf.items()):
print(" {}{} -> {}".format(label, " " * (max_len - len(label)), ", ".join(names)))
# complain about samples that were not matched by any process
unmatched_samples = [label for label, names in matches.items() if not names]
if unmatched_samples:
raise Exception("{} HH signal samples were not matched by any process: {}".format(
len(unmatched_samples), ", ".join(unmatched_samples)))
unmatched_ggf_samples = [label for label, names in matches_ggf.items() if not names]
unmatched_vbf_samples = [label for label, names in matches_vbf.items() if not names]
msg = []
if len(unmatched_ggf_samples) not in [0, len(self.ggf_formula.sample_list)]:
msg.append("{} ggF HH signal samples were not matched by any process: {}".format(
len(unmatched_ggf_samples), ", ".join(unmatched_ggf_samples)))
if len(unmatched_vbf_samples) not in [0, len(self.vbf_formula.sample_list)]:
msg.append("{} VBF HH signal samples were not matched by any process: {}".format(
len(unmatched_vbf_samples), ", ".join(unmatched_vbf_samples)))
if msg:
raise Exception("\n".join(msg))
# ggf samples with keys (kl, kt), ordered by kl
......
......@@ -669,7 +669,7 @@ def plot_nuisance_likelihood_scans(
skip_parameters=None,
only_parameters=None,
parameters_per_page=1,
scan_points=201,
scan_points=101,
x_min=-2.,
x_max=2,
y_log=False,
......@@ -803,7 +803,7 @@ def plot_nuisance_likelihood_scans(
legend_cols = min(int(math.ceil(len(legend_entries) / 4.)), 3)
legend_rows = int(math.ceil(len(legend_entries) / float(legend_cols)))
legend = r.routines.create_legend(pad=pad, width=legend_cols * 210, n=legend_rows,
props={"NColumns": legend_cols, "TextSize": 18})
props={"NColumns": legend_cols, "TextSize": 16})
r.fill_legend(legend, legend_entries)
draw_objs.append(legend)
legend_box = r.routines.create_legend_box(legend, pad, "trl",
......@@ -1001,7 +1001,6 @@ def evaluate_likelihood_scan_2d(
poi_values_min, poi_values_max = poi2_values_min, poi2_values_max
poi_min = poi2_min
_interp = lambda x: interp(poi1_min, x)
objective = lambda x: (_interp(x) - v) ** 2.0
def minimize(bounds):
# get a good starting point within the bounds and close to poi_min
......@@ -1012,6 +1011,7 @@ def evaluate_likelihood_scan_2d(
else:
start = poi_min
# minimize
objective = lambda x: (_interp(x) - v) ** 2.0
res = minimize_1d(objective, bounds, start=start)
return res.x[0] if res.status == 0 and (bounds[0] < res.x[0] < bounds[1]) else None
......
......@@ -187,7 +187,7 @@ class HTCondorWorkflow(law.htcondor.HTCondorWorkflow):
default=law.NO_INT,
significant=False,
description="number of CPUs to request; empty value leads to the cluster default setting; "
"default: empty",
"no default",
)
htcondor_flavor = luigi.ChoiceParameter(
default="cern",
......@@ -206,7 +206,7 @@ class HTCondorWorkflow(law.htcondor.HTCondorWorkflow):
default=law.NO_STR,
significant=False,
description="the name of an accounting group on the cluster to handle user priority; not "
"used when empty; default: empty",
"used when empty; no default",
)
exclude_params_branch = {
......@@ -394,7 +394,7 @@ class CommandTask(AnalysisTask):
custom_args = luigi.Parameter(
default="",
description="custom arguments that are forwarded to the underlying command; they might not "
"be encoded into output file paths; default: empty",
"be encoded into output file paths; no default",
)
exclude_index = True
......@@ -488,7 +488,7 @@ class PlotTask(AnalysisTask):
default=law.NO_STR,
significant=False,
description="a command to execute after the task has run to visualize plots right in the "
"terminal; default: empty",
"terminal; no default",
)
campaign = luigi.Parameter(
default=law.NO_STR,
......
......@@ -573,13 +573,13 @@ class MultiDatacardTask(DatacardTask):
cls=luigi.IntParameter,
significant=False,
description="indices of datacard sequences in multi_datacards for reordering; not used "
"when empty; default: empty",
"when empty; no default",
)
datacard_names = law.CSVParameter(
default=(),
significant=False,
description="names of datacard sequences for plotting purposes; applied before reordering "
"with datacard_order; default: empty",
"with datacard_order; no default",
brace_expand=True,
)
......@@ -1149,7 +1149,7 @@ class POIPlotTask(PlotTask, POITask):
default=(),
significant=False,
description="comma-separated list of parameters that are shown in the plot even if they "
"are 1; default: empty",
"are 1; no default",
)
def get_shown_parameters(self):
......
......@@ -25,7 +25,7 @@ class PlotExclusionAndBestFit(POIScanTask, MultiDatacardTask, POIPlotTask):
cls=luigi.IntParameter,
default=tuple(),
significant=False,
description="comma-separated vertical positions of horizontal lines; default: empty",
description="comma-separated vertical positions of horizontal lines; no default",
)
left_margin = luigi.IntParameter(
default=law.NO_INT,
......@@ -153,7 +153,7 @@ class PlotExclusionAndBestFit2D(POIScanTask, POIPlotTask):
default=law.NO_STR,
choices=[law.NO_STR, ""] + list(br_hh.keys()),
description="name of a branching ratio defined in dhi.config.br_hh to scale the cross "
"section when --xsec is set; choices: '',{}; default: empty".format(",".join(br_hh.keys())),
"section when --xsec is set; choices: '',{}; no default".format(",".join(br_hh.keys())),
)
z_min = None
z_max = None
......
......@@ -141,13 +141,13 @@ class PlotUpperLimits(UpperLimitsBase, POIPlotTask):
default=law.NO_STR,
choices=[law.NO_STR, "", "pb", "fb"],
description="convert limits to cross sections in this unit; only supported for r POIs; "
"choices: '',pb,fb; default: empty",
"choices: '',pb,fb; no default",
)
br = luigi.ChoiceParameter(
default=law.NO_STR,
choices=[law.NO_STR, ""] + list(br_hh.keys()),
description="name of a branching ratio defined in dhi.config.br_hh to scale the cross "
"section when xsec is used; choices: '',{}; default: empty".format(",".join(br_hh.keys())),
"section when xsec is used; choices: '',{}; no default".format(",".join(br_hh.keys())),
)
y_log = luigi.BoolParameter(
default=False,
......@@ -541,7 +541,7 @@ class PlotUpperLimitsAtPoint(POIPlotTask, MultiDatacardTask):
cls=luigi.IntParameter,
default=tuple(),
significant=False,
description="comma-separated vertical positions of horizontal lines; default: empty",
description="comma-separated vertical positions of horizontal lines; no default",
)
left_margin = luigi.IntParameter(
default=law.NO_INT,
......
......@@ -31,8 +31,9 @@ class FitDiagnostics(POITask, CombineCommandTask, law.LocalWorkflow, HTCondorWor
skip_save = law.CSVParameter(
default=tuple(),
choices=SAVE_FLAGS,
sort=True,
description="comma-separated flags to skip passing to combine as '--save<flag>'; "
"choices: {}; no default".format(",".join(SAVE_FLAGS)),
"choices: {}; no default".format(",".join(SAVE_FLAGS)),
)
force_n_pois = 1
......@@ -56,7 +57,7 @@ class FitDiagnostics(POITask, CombineCommandTask, law.LocalWorkflow, HTCondorWor
if not self.skip_b_only:
parts.append("withBOnly")
if self.skip_save:
parts.append(map("no{}".format, self.skip_save))
parts.append(map("no{}".format, sorted(self.skip_save)))
postfix = self.join_postfix(parts)
return {
......@@ -195,11 +196,18 @@ class PlotNuisanceLikelihoodScans(POIPlotTask):
significant=False,
description="patterns of parameters to skip; no default",
)
mc_stats = luigi.BoolParameter(
default=False,
significant=False,
description="when True, include MC stats nuisances as well; default: False",
)
parameters_per_page = luigi.IntParameter(
default=1,
description="number of parameters per page; creates a single page when < 1; default: 1",
)
mc_stats_patterns = ["*prop_bin*"]
file_type = "pdf"
y_min = None
y_max = None
......@@ -232,6 +240,11 @@ class PlotNuisanceLikelihoodScans(POIPlotTask):
fit_result = inputs["collection"][0]["result"]
fit_diagnostics = inputs["collection"][0]["diagnostics"]
# skip parameter patterns
skip_parameters = list(self.skip_parameters)
if not self.mc_stats:
skip_parameters.extend(self.mc_stats_patterns)
# open the result file to load the workspace and other objects
with fit_result.load("READ", formatter="root") as result_file:
# get workspace
......@@ -250,7 +263,7 @@ class PlotNuisanceLikelihoodScans(POIPlotTask):
fit_diagnostics_path=fit_diagnostics.path,
fit_name="fit_s",
only_parameters=self.only_parameters,
skip_parameters=self.skip_pameters,
skip_parameters=skip_parameters,
parameters_per_page=self.parameters_per_page,
x_min=self.x_min,
x_max=self.x_max,
......
......@@ -24,8 +24,7 @@ class PullsAndImpactsBase(POITask):
)
skip_parameters = law.CSVParameter(
default=(),
description="comma-separated parameter names to be skipped; supports patterns; "
"default: empty",
description="comma-separated parameter names to be skipped; supports patterns; no default",
)
mc_stats = luigi.BoolParameter(
default=False,
......@@ -33,7 +32,7 @@ class PullsAndImpactsBase(POITask):
"default: False",
)
mc_stats_patterns = ["prop_bin*"]
mc_stats_patterns = ["*prop_bin*"]
force_n_pois = 1
allow_parameter_values_in_pois = True
......@@ -271,7 +270,7 @@ class PlotPullsAndImpacts(PullsAndImpactsBase, POIPlotTask):
order_parameters = law.CSVParameter(
default=(),
description="list of parameters or files containing parameters line-by-line for ordering; "
"supports patterns; default: empty",
"supports patterns; no default",
)
order_by_impact = luigi.BoolParameter(
default=False,
......
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