diff --git a/CombineTools/interface/CombineHarvester.h b/CombineTools/interface/CombineHarvester.h index 1f6403bc687..a4f87c7784f 100644 --- a/CombineTools/interface/CombineHarvester.h +++ b/CombineTools/interface/CombineHarvester.h @@ -337,6 +337,7 @@ class CombineHarvester { */ /**@{*/ double GetRate(); + std::map RateEvolution(RooFitResult const& fit); double GetObservedRate(); double GetUncertainty(); diff --git a/CombineTools/src/CombineHarvester_Evaluate.cc b/CombineTools/src/CombineHarvester_Evaluate.cc index 6a6dea751a4..dee308f46cd 100644 --- a/CombineTools/src/CombineHarvester_Evaluate.cc +++ b/CombineTools/src/CombineHarvester_Evaluate.cc @@ -580,6 +580,36 @@ void CombineHarvester::UpdateParameters(RooFitResult const* fit) { UpdateParameters(*fit); } +std::map CombineHarvester::RateEvolution(RooFitResult const& fit) { + auto lookup = GenerateProcSystMap(); + std::map rates; + auto backup = GetParameters(); + rates["prefit"] = GetRateInternal(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; + } + double rate = GetRateInternal(lookup); + // std::cout << "\t" << it->first << "\t" << rate << std::endl; + rates[it->first] = rate; + // reset parameters to prefit conditions + this->UpdateParameters(backup); + } + return rates; +} + std::vector CombineHarvester::GetParameters() const { std::vector params; for (auto const& it : params_) { diff --git a/CombineTools/src/CombineHarvester_Python.cc b/CombineTools/src/CombineHarvester_Python.cc index 93002b02a8d..aa1787f4dc9 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("RateEvolution", &CombineHarvester::RateEvolution) .def("UpdateParameters", Overload1_UpdateParameters) .def("RenameParameter", &CombineHarvester::RenameParameter) .def("RenameSystematic", &CombineHarvester::RenameSystematic)