diff --git a/CombineTools/interface/CombineHarvester.h b/CombineTools/interface/CombineHarvester.h index 1f6403bc687..b601ba187ea 100644 --- a/CombineTools/interface/CombineHarvester.h +++ b/CombineTools/interface/CombineHarvester.h @@ -337,6 +337,7 @@ class CombineHarvester { */ /**@{*/ double GetRate(); + std::map ShapeEvolution(RooFitResult const& fit); double GetObservedRate(); double GetUncertainty(); diff --git a/CombineTools/src/CombineHarvester_Evaluate.cc b/CombineTools/src/CombineHarvester_Evaluate.cc index 6a6dea751a4..0471bc7831a 100644 --- a/CombineTools/src/CombineHarvester_Evaluate.cc +++ b/CombineTools/src/CombineHarvester_Evaluate.cc @@ -576,6 +576,41 @@ void CombineHarvester::UpdateParameters(RooFitResult const& fit) { } } +std::map CombineHarvester::ShapeEvolution(RooFitResult const& fit) { + auto lookup = GenerateProcSystMap(); + std::map shapes; + auto backup = GetParameters(); + shapes["prefit"] = GetShapeInternal(lookup); + for (int i = 0; i < fit.floatParsFinal().getSize(); ++i) { + RooRealVar const* var = + dynamic_cast(fit.floatParsFinal().at(i)); + // check for failed cast here + auto it = params_.find(std::string(var->GetName())); + if (it != params_.end()) { + it->second->set_val(var->getVal()); + it->second->set_err_d(var->getErrorLo()); + it->second->set_err_u(var->getErrorHi()); + } else { + if (verbosity_ >= 1) { + LOGLINE(log(), + "Parameter " + std::string(var->GetName()) + " is not defined"); + } + continue; + } + auto shape = GetShapeInternal(lookup); + // std::cout << "\t" << it->first << "\t" << rate << std::endl; + shapes[it->first] = shape; + // reset parameters to prefit conditions + this->UpdateParameters(backup); + } + + // also safe postfit shape + this->UpdateParameters(fit); + shapes["total"] = GetShapeInternal(lookup); + this->UpdateParameters(backup); + return shapes; +} + void CombineHarvester::UpdateParameters(RooFitResult const* fit) { UpdateParameters(*fit); } diff --git a/CombineTools/src/CombineHarvester_Python.cc b/CombineTools/src/CombineHarvester_Python.cc index 93002b02a8d..34c63e50919 100644 --- a/CombineTools/src/CombineHarvester_Python.cc +++ b/CombineTools/src/CombineHarvester_Python.cc @@ -232,6 +232,9 @@ BOOST_PYTHON_MODULE(libCombineHarvesterCombineTools) py::to_python_converter, convert_cpp_map_to_py_dict>(); + py::to_python_converter, + convert_cpp_map_to_py_dict>(); + py::to_python_converter>(); @@ -338,6 +341,7 @@ BOOST_PYTHON_MODULE(libCombineHarvesterCombineTools) // Modification .def("GetParameter", Overload1_GetParameter, py::return_value_policy()) + .def("ShapeEvolution", &CombineHarvester::ShapeEvolution) .def("UpdateParameters", Overload1_UpdateParameters) .def("RenameParameter", &CombineHarvester::RenameParameter) .def("RenameSystematic", &CombineHarvester::RenameSystematic)