Skip to content

select bins to plot in PostFitShapesFromWorkspace #336

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

Open
wants to merge 2 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
9 changes: 8 additions & 1 deletion 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::string selected_bins_="";

po::options_description help_config("Help");
help_config.add_options()
Expand Down Expand Up @@ -103,6 +104,7 @@ 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")
("selected-bins", po::value<string>(&selected_bins_)->default_value(selected_bins_), "List of bins to consider")
("reverse-bins", po::value<vector<string>>(&reverse_bins_)->multitoken(), "List of bins to reverse the order for");


Expand Down Expand Up @@ -186,7 +188,12 @@ int main(int argc, char* argv[]) {
return no_shape;
});

auto bins = cmb.cp().bin_set();
auto bins = cmb.cp().bin_set();
if(selected_bins_!="") {
vector<string> selected_bins_vec;
boost::split(selected_bins_vec, selected_bins_, boost::is_any_of(","));
bins = cmb.cp().bin(selected_bins_vec).bin_set();
}

TFile outfile(output.c_str(), "RECREATE");
TH1::AddDirectory(false);
Expand Down
68 changes: 68 additions & 0 deletions CombineTools/python/combine/PostFitShapesFromWorkspace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python

from __future__ import absolute_import
from __future__ import print_function
import sys
import re
import json
import ROOT
import CombineHarvester.CombineTools.combine.utils as utils

from CombineHarvester.CombineTools.combine.CombineToolBase import CombineToolBase
from six.moves import map


class PostFitShapesFromWorkspace(CombineToolBase):
description = 'Calculate nuisance parameter impacts'
requires_root = True

def __init__(self):
CombineToolBase.__init__(self)

def attach_intercept_args(self, group):
CombineToolBase.attach_intercept_args(self, group)
group.add_argument('-w', '--workspace', required=True)
group.add_argument('-f', '--fitresult', required=True)
group.add_argument('-d','--datacard', default="")
group.add_argument('--freeze', default="")
group.add_argument('-m', '--mass')
group.add_argument('--samples', default="")
group.add_argument('--covariance', action='store_true')
group.add_argument('--skip-proc-errs', action='store_true')
group.add_argument('--total-shapes', action='store_true')
group.add_argument('--postfit', action='store_true')

def attach_args(self, group):
CombineToolBase.attach_args(self, group)
group.add_argument('--outdir', '-o', help="""output directory for root files""")

def run_method(self):
wsFile = ROOT.TFile(self.args.workspace)
w = wsFile.Get('w')
pass_str = ' '.join(self.passthru)
bins = [ nameIdx.first for nameIdx in w.allCats()["CMS_channel"] ]
print("bins",bins)

extra_args_str = " --workspace %s --fitresult %s "%(self.args.workspace,self.args.fitresult)
if self.args.skip_proc_errs:
extra_args_str += " --skip-proc-errs "
if self.args.total_shapes:
extra_args_str += " --total-shapes "
if self.args.postfit:
extra_args_str += " --postfit "
if self.args.covariance:
extra_args_str += " --covariance "
if self.args.freeze!="":
extra_args_str += " --freeze %s "%(self.args.freeze)
if self.args.datacard!="":
extra_args_str += " --datacard %s "%(self.args.datacard)
if self.args.samples!="":
extra_args_str += " --samples %s "%(self.args.samples)

for b in bins:
outfile="%s/shapes_%s.root"%(self.args.outdir, b)
self.job_queue.append(
'PostFitShapesFromWorkspace %s --selected-bins %s --output %s'%(extra_args_str,b,outfile))
self.flush_queue()
sys.exit(0)

2 changes: 2 additions & 0 deletions CombineTools/scripts/combineTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from CombineHarvester.CombineTools.combine.T2W import T2W
from CombineHarvester.CombineTools.combine.FastScan import FastScan
from CombineHarvester.CombineTools.combine.TaylorExpand import TaylorExpand
from CombineHarvester.CombineTools.combine.PostFitShapesFromWorkspace import PostFitShapesFromWorkspace

ROOT.PyConfig.IgnoreCommandLineOptions = True
ROOT.gROOT.SetBatch(ROOT.kTRUE)
Expand All @@ -37,6 +38,7 @@ def register_method(parser, method_dict, method_class):
register_method(parser, methods, PrintWorkspace)
register_method(parser, methods, ModifyDataSet)
register_method(parser, methods, Impacts)
register_method(parser, methods, PostFitShapesFromWorkspace)
register_method(parser, methods, ImpactsFromScans)
register_method(parser, methods, CollectLimits)
register_method(parser, methods, CollectGoodnessOfFit)
Expand Down