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

Update this fork with central repo changes #3

Merged
merged 9 commits into from
Jan 2, 2022
1 change: 0 additions & 1 deletion CombineTools/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<flags SKIP_FILES="$$(shell make -f ${CMSSW_BASE}/src/CombineHarvester/CombineTools/makeGitVersion)"/>
<use name="root"/>
<use name="rootmath"/>
<use name="roofit"/>
Expand Down
4 changes: 0 additions & 4 deletions CombineTools/makeGitVersion

This file was deleted.

21 changes: 17 additions & 4 deletions CombineTools/python/combine/CombineToolBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ def flush_queue(self):
'PWD': os.environ['PWD']
})
job_prefix_file.close()
if self.job_mode in ['script', 'lxbatch', 'SGE']:
for i, j in enumerate(range(0, len(self.job_queue), self.merge)):
script_name = 'job_%s_%i.sh' % (self.task_name, i)
# each job is given a slice from the list of combine commands of length 'merge'
Expand All @@ -257,10 +258,22 @@ def flush_queue(self):
logname = full_script.replace('.sh', '_%J.log')
run_command(self.dry_run, 'qsub -o %s %s %s' % (logname, self.bopts, full_script))
if self.job_mode == 'slurm':
for script in script_list:
full_script = os.path.abspath(script)
logname = full_script.replace('.sh', '_%A.log')
run_command(self.dry_run, 'sbatch -o %s %s %s' % (logname, self.bopts, full_script))
script_name = 'slurm_%s.sh' % self.task_name
if self.job_dir:
if not os.path.exists(self.job_dir):
os.makedirs(self.job_dir)
script_name = os.path.join(self.job_dir,script_name)
commands = []
jobs = 0
# each job is given a slice from the list of combine commands of length 'merge'
for j in range(0, len(self.job_queue), self.merge):
jobs += 1
commands += ["if [ ${SLURM_ARRAY_TASK_ID} -eq %i ]; then\n" % jobs,
]+[" %s\n" % ln for ln in self.job_queue[j:j + self.merge]]+["fi\n"]
self.create_job_script(commands, script_name, self.job_mode == "script")
full_script = os.path.abspath(script_name)
logname = full_script.replace('.sh', '_%A_%a.log')
run_command(self.dry_run, 'sbatch --array=1-%i -o %s %s %s' % (jobs, logname, self.bopts, full_script))
if self.job_mode == 'condor':
outscriptname = 'condor_%s.sh' % self.task_name
subfilename = 'condor_%s.sub' % self.task_name
Expand Down
53 changes: 29 additions & 24 deletions CombineTools/python/combine/Impacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def attach_args(self, group):
file""")
group.add_argument('--approx', default=None, choices=['hesse', 'robust'],
help="""Calculate impacts using the covariance matrix instead""")
group.add_argument('--noInitialFit', action='store_true', default=False, help="""Do not look for results from the initial Fit""")


def run_method(self):
if self.args.allPars:
Expand Down Expand Up @@ -128,27 +130,28 @@ def run_method(self):
sys.exit(0)

# Read the initial fit results
initialRes = {}
if self.args.approx is not None:
if self.args.approx == 'hesse':
fResult = ROOT.TFile('multidimfit_approxFit_%(name)s.root' % {'name': name})
rfr = fResult.Get('fit_mdf')
fResult.Close()
initialRes = utils.get_roofitresult(rfr, poiList, poiList)
elif self.args.approx == 'robust':
fResult = ROOT.TFile('robustHesse_approxFit_%(name)s.root' % {'name': name})
floatParams = fResult.Get('floatParsFinal')
rfr = fResult.Get('h_correlation')
rfr.SetDirectory(0)
fResult.Close()
initialRes = utils.get_robusthesse(floatParams, rfr, poiList, poiList)
elif self.args.splitInitial:
for poi in poiList:
initialRes.update(utils.get_singles_results(
'higgsCombine_initialFit_%(name)s_POI_%(poi)s.MultiDimFit.mH%(mh)s.root' % vars(), [poi], poiList))
else:
initialRes = utils.get_singles_results(
'higgsCombine_initialFit_%(name)s.MultiDimFit.mH%(mh)s.root' % vars(), poiList, poiList)
if not self.args.noInitialFit:
initialRes = {}
if self.args.approx is not None:
if self.args.approx == 'hesse':
fResult = ROOT.TFile('multidimfit_approxFit_%(name)s.root' % {'name': name})
rfr = fResult.Get('fit_mdf')
fResult.Close()
initialRes = utils.get_roofitresult(rfr, poiList, poiList)
elif self.args.approx == 'robust':
fResult = ROOT.TFile('robustHesse_approxFit_%(name)s.root' % {'name': name})
floatParams = fResult.Get('floatParsFinal')
rfr = fResult.Get('h_correlation')
rfr.SetDirectory(0)
fResult.Close()
initialRes = utils.get_robusthesse(floatParams, rfr, poiList, poiList)
elif self.args.splitInitial:
for poi in poiList:
initialRes.update(utils.get_singles_results(
'higgsCombine_initialFit_%(name)s_POI_%(poi)s.MultiDimFit.mH%(mh)s.root' % vars(), [poi], poiList))
else:
initialRes = utils.get_singles_results(
'higgsCombine_initialFit_%(name)s.MultiDimFit.mH%(mh)s.root' % vars(), poiList, poiList)

################################################
# Build the parameter list
Expand Down Expand Up @@ -180,10 +183,12 @@ def run_method(self):

prefit = utils.prefit_from_workspace(ws, 'w', paramList, self.args.setPhysicsModelParameters)
res = {}
res["POIs"] = []
if not self.args.noInitialFit:
res["POIs"] = []
res["params"] = []
for poi in poiList:
res["POIs"].append({"name": poi, "fit": initialRes[poi][poi]})
if not self.args.noInitialFit:
for poi in poiList:
res["POIs"].append({"name": poi, "fit": initialRes[poi][poi]})

missing = []
for param in paramList:
Expand Down
22 changes: 14 additions & 8 deletions CombineTools/src/CombineHarvester_Datacards.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "CombineHarvester/CombineTools/interface/Utilities.h"
#include "CombineHarvester/CombineTools/interface/TFileIO.h"
#include "CombineHarvester/CombineTools/interface/Algorithm.h"
#include "CombineHarvester/CombineTools/interface/GitVersion.h"
#include "CombineHarvester/CombineTools/interface/zstr.hpp"
namespace ch {

Expand Down Expand Up @@ -755,8 +754,8 @@ void CombineHarvester::WriteDatacard(std::string const& name,

std::ostream & txt_file = *txt_file_ptr;

txt_file << "# Datacard produced by CombineHarvester with git status: "
<< ch::GitVersion() << "\n";
//txt_file << "# Datacard produced by CombineHarvester with git status: "
// << ch::GitVersion() << "\n";

std::string dashes(80, '-');

Expand Down Expand Up @@ -930,6 +929,13 @@ void CombineHarvester::WriteDatacard(std::string const& name,
std::string sys_str_short = boost::lexical_cast<std::string>(sys_str_len);
std::string sys_str_long = boost::lexical_cast<std::string>(sys_str_len+9);

auto getProcLen = [](auto const& proc) -> std::string {
std::size_t proc_len = 15;
proc_len = std::max(proc_len, proc->process().size());
std::string proc_len_str = boost::lexical_cast<std::string>(proc_len);
return proc_len_str;
};

txt_file << format("%-"+sys_str_long+"s") % "bin";
for (auto const& proc : procs_) {
if (proc->shape()) {
Expand All @@ -940,14 +946,14 @@ void CombineHarvester::WriteDatacard(std::string const& name,
proc->process(), proc->mass(), "", 0);
TH1::AddDirectory(add_dir);
}
txt_file << format("%-15s ") % proc->bin();
txt_file << format("%-"+getProcLen(proc)+"s ") % proc->bin();
}
txt_file << "\n";

txt_file << format("%-"+sys_str_long+"s") % "process";

for (auto const& proc : procs_) {
txt_file << format("%-15s ") % proc->process();
txt_file << format("%-"+getProcLen(proc)+"s ") % proc->process();
}
txt_file << "\n";

Expand Down Expand Up @@ -981,14 +987,14 @@ void CombineHarvester::WriteDatacard(std::string const& name,
}
}
for (auto const& proc : procs_) {
txt_file << format("%-15s ") % p_ids[proc->process()];
txt_file << format("%-"+getProcLen(proc)+"s ") % p_ids[proc->process()];
}
txt_file << "\n";


txt_file << format("%-"+sys_str_long+"s") % "rate";
for (auto const& proc : procs_) {
txt_file << format("%-15.6g ") % proc->no_norm_rate();
txt_file << format("%-"+getProcLen(proc)+".6g ") % proc->no_norm_rate();
}
txt_file << "\n";
txt_file << dashes << "\n";
Expand Down Expand Up @@ -1081,7 +1087,7 @@ void CombineHarvester::WriteDatacard(std::string const& name,
}
txt_file << format("%-" + sys_str_short + "s %-7s ") % line[0] % line[1];
for (unsigned p = 0; p < procs_.size(); ++p) {
txt_file << format("%-15s ") % line[p + 2];
txt_file << format("%-"+getProcLen(procs_[p])+"s ") % line[p + 2];
}
txt_file << "\n";
}
Expand Down