diff --git a/CombineTools/bin/LimitCompare.cpp b/CombineTools/bin/LimitCompare.cpp deleted file mode 100644 index 9c6567dc202..00000000000 --- a/CombineTools/bin/LimitCompare.cpp +++ /dev/null @@ -1,149 +0,0 @@ -#include -#include -#include -#include -#include "TGraph.h" -#include "TCanvas.h" -#include "TStyle.h" -#include "TLegend.h" -#include "TTree.h" -#include "TFile.h" -#include "TAxis.h" -#include "TLatex.h" -#include "boost/lexical_cast.hpp" -#include "boost/algorithm/string.hpp" -#include "boost/format.hpp" -#include "boost/program_options.hpp" -#include "CombineHarvester/CombineTools/interface/Plotting.h" -#include "CombineHarvester/CombineTools/interface/Plotting_Style.h" -// #include "Core/interface/TextElement.h" -// #include "Utilities/interface/SimpleParamParser.h" -// #include "Utilities/interface/FnRootTools.h" - -namespace po = boost::program_options; - -using namespace std; - -void SetTGraphStyle(TGraph * gr, int color) { - gr->SetLineStyle(11.); - gr->SetLineWidth( 3.); - gr->SetLineColor(color); - gr->SetMarkerStyle(20); - gr->SetMarkerSize(1.3); - gr->SetMarkerColor(color); -} - -// "mh:limit","quantileExpected==0.5" - -TGraph ExtractExpected(TTree *limit) { - int n = limit->Draw("mh:limit", "quantileExpected==0.5", "goff"); - TGraph gr(n, limit->GetV1(), limit->GetV2()); - gr.Sort(); - return gr; -} - -struct Infos { - std::string file; - std::string label; - int color; -}; - -int main(int /*argc*/, char* argv[]) { - - std::string ch = argv[1]; - vector input; - input.push_back({"parametric/higgsCombineExpected"+ch+".Asymptotic.All.root", "Parametric", 2}); - input.push_back({"parametric-binned/higgsCombineExpected"+ch+".Asymptotic.All.root", "Binned", 4}); - // input.push_back({"parametric-asimov/higgsCombineExpected"+ch+".Asymptotic.All.root", "Parametric (asimov)", 5}); - // input.push_back({"parametric-binned-asimov/higgsCombineExpected"+ch+".Asymptotic.All.root", "Binned (asimov)", 6}); - - - vector graphs; - - for (auto const& in : input) { - TFile f(in.file.c_str()); - TTree *tree = (TTree*)f.Get("limit"); - graphs.push_back(ExtractExpected(tree)); - } - - for (unsigned i = 0; i < input.size(); ++i) { - SetTGraphStyle(&graphs[i], input[i].color); - } - - - ModTDRStyle(); - TCanvas canv("canv","canv",600,600); - canv.SetLogy(true); - gStyle->SetNdivisions(505); - canv.SetGridx(1); - canv.SetGridy(1); - TGraph & exp1 = graphs[0]; - exp1.GetXaxis()->SetLimits(exp1.GetX()[0]-.1, exp1.GetX()[exp1.GetN()-1]+.1); - - double min = 9999.; - double max = 0.; - for (int i = 0; i < exp1.GetN(); ++i) { - double x, y; - exp1.GetPoint(i, x, y); - if (y < min) min = y; - if (y > max) max = y; - } - exp1.SetMaximum(max*2.); - exp1.SetMinimum(min*0.5); - exp1.GetYaxis()->SetTitleSize(0.055); - exp1.GetYaxis()->SetTitleOffset(1.200); - exp1.GetYaxis()->SetLabelOffset(0.014); - exp1.GetYaxis()->SetLabelSize(0.040); - exp1.GetYaxis()->SetLabelFont(42); - exp1.GetYaxis()->SetTitleFont(42); - exp1.GetXaxis()->SetTitleSize(0.055); - exp1.GetXaxis()->SetTitleOffset(1.100); - exp1.GetXaxis()->SetLabelOffset(0.014); - exp1.GetXaxis()->SetLabelSize(0.040); - exp1.GetXaxis()->SetLabelFont(42); - exp1.GetXaxis()->SetTitleFont(42); - exp1.Draw("APL"); - - exp1.GetXaxis()->SetTitle("m_{#Phi} [GeV]"); - exp1.GetYaxis()->SetTitle("95% CL Limit on #sigma #times B [pb]"); - for (unsigned i = 1; i < input.size(); ++i) { - graphs[i].Draw("PLsame"); - } - // SetTGraphStyle(&obs1, 6); - // SetTGraphStyle(&exp2, 7); - // SetTGraphStyle(&obs2, 8); - - // obs1.Draw("PLsame"); - // // exp2.Draw("PLsame"); - // // obs2.Draw("PLsame"); - - TLegend *legend = new TLegend(0.62, 0.62, 0.93, 0.78, "", "brNDC"); - for (unsigned i = 0; i < input.size(); ++i) { - legend->AddEntry(&graphs[i], input[i].label.c_str(), "lP"); - } - legend->SetBorderSize(1); - legend->SetTextFont(42); - legend->SetLineColor(0); - legend->SetLineStyle(1); - legend->SetLineWidth(1); - legend->SetFillColor(0); - legend->SetFillStyle(1001); - legend->Draw(); - - TLatex *title_latex = new TLatex(); - title_latex->SetNDC(); - title_latex->SetTextSize(0.035); - title_latex->SetTextFont(62); - title_latex->SetTextAlign(31); - double height = 0.94; - title_latex->DrawLatex(0.95,height,"19.7 fb^{-1} (8 TeV)"); - title_latex->SetTextAlign(11); - title_latex->DrawLatex(0.17,height,"H#rightarrow#tau#tau"); - title_latex->SetTextSize(0.06); - title_latex->DrawLatex(0.78, 0.84, "#mu#tau_{h}"); - - canv.SaveAs((ch+"_comparison.pdf").c_str()); - - return 0; -} - diff --git a/CombineTools/bin/PostFitShapesFromWorkspace.cpp b/CombineTools/bin/PostFitShapesFromWorkspace.cpp index a7b626d1a25..bdc24f26696 100644 --- a/CombineTools/bin/PostFitShapesFromWorkspace.cpp +++ b/CombineTools/bin/PostFitShapesFromWorkspace.cpp @@ -47,6 +47,7 @@ int main(int argc, char* argv[]) { bool skip_proc_errs = false; bool total_shapes = false; std::vector reverse_bins_; + std::vector merged_bins_; po::options_description help_config("Help"); help_config.add_options() @@ -103,7 +104,8 @@ int main(int argc, char* argv[]) { ("total-shapes", po::value(&total_shapes)->default_value(total_shapes)->implicit_value(true), "Save signal- and background shapes added for all channels/categories") - ("reverse-bins", po::value>(&reverse_bins_)->multitoken(), "List of bins to reverse the order for"); + ("reverse-bins", po::value>(&reverse_bins_)->multitoken(), "List of bins to reverse the order for") + ("merged-channels", po::value>(&merged_bins_)->multitoken(), "List of [label]=[regex] for merged channels"); po::variables_map vm; @@ -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 @@ -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 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); @@ -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 @@ -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}); diff --git a/CombineTools/python/combine/EnhancedCombine.py b/CombineTools/python/combine/EnhancedCombine.py index a69e701337b..1b17459653f 100755 --- a/CombineTools/python/combine/EnhancedCombine.py +++ b/CombineTools/python/combine/EnhancedCombine.py @@ -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( diff --git a/CombineTools/python/plotting.py b/CombineTools/python/plotting.py index ee734c2496a..2afa00da6f2 100644 --- a/CombineTools/python/plotting.py +++ b/CombineTools/python/plotting.py @@ -383,6 +383,7 @@ def MultiRatioSplit(split_points, gaps_low, gaps_high): pad.Draw() pads.append(pad) pads.reverse() + pads[0].cd() return pads @@ -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!') + return maxval = (math.log10(fix_y) - fraction * math.log10(ymin)) / \ (1 - fraction) maxval = math.pow(10, maxval) @@ -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: diff --git a/CombineTools/src/CombineHarvester_Evaluate.cc b/CombineTools/src/CombineHarvester_Evaluate.cc index 6a6dea751a4..6933db3b4e1 100644 --- a/CombineTools/src/CombineHarvester_Evaluate.cc +++ b/CombineTools/src/CombineHarvester_Evaluate.cc @@ -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) {