Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to define merged channels in PostFitShapesFromWorkspace (+ a few random fixes) #295

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 0 additions & 149 deletions CombineTools/bin/LimitCompare.cpp

This file was deleted.

29 changes: 23 additions & 6 deletions CombineTools/bin/PostFitShapesFromWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ int main(int argc, char* argv[]) {
bool skip_proc_errs = false;
bool total_shapes = false;
std::vector<std::string> reverse_bins_;
std::vector<std::string> merged_bins_;

po::options_description help_config("Help");
help_config.add_options()
Expand Down Expand Up @@ -103,7 +104,8 @@ int main(int argc, char* argv[]) {
("total-shapes",
po::value<bool>(&total_shapes)->default_value(total_shapes)->implicit_value(true),
"Save signal- and background shapes added for all channels/categories")
("reverse-bins", po::value<vector<string>>(&reverse_bins_)->multitoken(), "List of bins to reverse the order for");
("reverse-bins", po::value<vector<string>>(&reverse_bins_)->multitoken(), "List of bins to reverse the order for")
("merged-channels", po::value<vector<string>>(&merged_bins_)->multitoken(), "List of [label]=[regex] for merged channels");


po::variables_map vm;
Expand Down Expand Up @@ -140,6 +142,8 @@ int main(int argc, char* argv[]) {
// Create CH instance and parse the workspace
ch::CombineHarvester cmb;
cmb.SetFlag("workspaces-use-clone", true);
cmb.SetFlag("filters-use-regex", true);

ch::ParseCombineWorkspace(cmb, *ws, "ModelConfig", data, false);

// Only evaluate in case parameters to freeze are provided
Expand Down Expand Up @@ -186,7 +190,16 @@ int main(int argc, char* argv[]) {
return no_shape;
});

auto bins = cmb.cp().bin_set();
auto bins = ch::Set2Vec(cmb.cp().bin_set());
auto bin_patterns = bins;
for (unsigned i = 0; i < merged_bins_.size(); ++i) {
vector<string> parts;
boost::split(parts, merged_bins_[i], boost::is_any_of("="));
if (parts.size() == 2) {
bins.push_back(parts[0]);
bin_patterns.push_back(parts[1]);
}
}

TFile outfile(output.c_str(), "RECREATE");
TH1::AddDirectory(false);
Expand Down Expand Up @@ -229,8 +242,10 @@ int main(int argc, char* argv[]) {
ch::WriteToTFile(&(iter.second), &outfile, "prefit/" + iter.first);
}
}
for (auto bin : bins) {
ch::CombineHarvester cmb_bin = cmb.cp().bin({bin});
for (unsigned ib = 0; ib < bins.size(); ++ib) {
std::string bin = bins[ib];
std::string bin_pattern = bin_patterns[ib];
ch::CombineHarvester cmb_bin = cmb.cp().bin({bin_pattern});
// This next line is a temporary fix for models with parameteric RooFit pdfs
// - we try and set the number of bins to evaluate the pdf to be the same as
// the number of bins in data
Expand Down Expand Up @@ -346,8 +361,10 @@ int main(int argc, char* argv[]) {
}


for (auto bin : bins) {
ch::CombineHarvester cmb_bin = cmb.cp().bin({bin});
for (unsigned ib = 0; ib < bins.size(); ++ib) {
std::string bin = bins[ib];
std::string bin_pattern = bin_patterns[ib];
ch::CombineHarvester cmb_bin = cmb.cp().bin({bin_pattern});
post_shapes[bin]["data_obs"] = cmb_bin.GetObservedShape();
for (auto proc : cmb_bin.process_set()) {
auto cmb_proc = cmb_bin.cp().process({proc});
Expand Down
1 change: 0 additions & 1 deletion CombineTools/python/combine/EnhancedCombine.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def attach_intercept_args(self, group):
group.add_argument(
'--setParameterRanges', help='Some other options will modify or add to the list of parameter ranges')


def attach_args(self, group):
CombineToolBase.attach_args(self, group)
group.add_argument(
Expand Down
6 changes: 6 additions & 0 deletions CombineTools/python/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ def MultiRatioSplit(split_points, gaps_low, gaps_high):
pad.Draw()
pads.append(pad)
pads.reverse()
pads[0].cd()
return pads


Expand Down Expand Up @@ -1191,6 +1192,9 @@ def FixTopRange(pad, fix_y, fraction):
if ymin == 0.:
print('Cannot adjust log-scale y-axis range if the minimum is zero!')
return
if fix_y <= 0:
print('Cannot adjust log-scale y-axis range if the maximum is zero!')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we maybe put "less than or equal to zero" here in the printout, just since that's what the check is doing?

return
maxval = (math.log10(fix_y) - fraction * math.log10(ymin)) / \
(1 - fraction)
maxval = math.pow(10, maxval)
Expand Down Expand Up @@ -1355,6 +1359,8 @@ def FixBoxPadding(pad, box, frac):
# Convert this to a normalised frame value
f_max_h = (a_max_h - ymin) / (ymax - ymin);
if R.gPad.GetLogy() and f_max_h > 0.:
if a_max_h <= 0. or ymin <= 0. or ymax <= 0.:
return
f_max_h = (math.log10(a_max_h) - math.log10(ymin)) / (math.log10(ymax) - math.log10(ymin))

if f_y1 - f_max_h < frac:
Expand Down
4 changes: 3 additions & 1 deletion CombineTools/src/CombineHarvester_Evaluate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,9 @@ TH1F CombineHarvester::GetObservedShape() {
tmp->SetBinErrorOption(TH1::kPoisson);
proc_shape = *tmp;
delete tmp;
proc_shape.Scale(1. / proc_shape.Integral());
if (proc_shape.Integral() > 0.) {
proc_shape.Scale(1. / proc_shape.Integral());
}
}
proc_shape.Scale(p_rate);
if (!shape_init) {
Expand Down