diff --git a/roofit/histfactory/inc/RooStats/HistFactory/Measurement.h b/roofit/histfactory/inc/RooStats/HistFactory/Measurement.h index 8907b200b8f3c..4ec2d8d8e6994 100644 --- a/roofit/histfactory/inc/RooStats/HistFactory/Measurement.h +++ b/roofit/histfactory/inc/RooStats/HistFactory/Measurement.h @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -699,6 +700,10 @@ class Measurement : public TNamed { const std::vector &GetFunctionObjects() const { return fFunctionObjects; } std::vector GetPreprocessFunctions() const; + using PreprocessFunctionCallback = std::function; + void AddPreprocessFunctionCallback(PreprocessFunctionCallback callback); + void ApplyPreprocessFunctionCallbacks(RooWorkspace &ws) const; + /// get vector of defined Asimov Datasets std::vector &GetAsimovDatasets() { return fAsimovDatasets; } /// add an Asimov Dataset @@ -772,6 +777,10 @@ class Measurement : public TNamed { /// List of Preprocess Function objects std::vector fFunctionObjects; + /// Programmatic preprocess callbacks, executed during workspace creation. + /// Transient because std::function is not ROOT-streamable. + std::vector fPreprocessFunctionCallbacks; //! + /// List of Asimov datasets to generate std::vector fAsimovDatasets; diff --git a/roofit/histfactory/src/HistoToWorkspaceFactoryFast.cxx b/roofit/histfactory/src/HistoToWorkspaceFactoryFast.cxx index 46f9dca1a0466..e4892497c57c7 100644 --- a/roofit/histfactory/src/HistoToWorkspaceFactoryFast.cxx +++ b/roofit/histfactory/src/HistoToWorkspaceFactoryFast.cxx @@ -870,6 +870,8 @@ RooArgList HistoToWorkspaceFactoryFast::createObservables(const TH1 *hist, RooWo proto.Print(); } + measurement.ApplyPreprocessFunctionCallbacks(proto); + RooArgSet likelihoodTerms("likelihoodTerms"); RooArgSet constraintTerms("constraintTerms"); vector likelihoodTermNames; diff --git a/roofit/histfactory/src/Measurement.cxx b/roofit/histfactory/src/Measurement.cxx index 9955131003768..f03f21b642e03 100644 --- a/roofit/histfactory/src/Measurement.cxx +++ b/roofit/histfactory/src/Measurement.cxx @@ -88,6 +88,22 @@ void Measurement::AddPreprocessFunction(std::string name, std::string expression AddFunctionObject(func); } +void Measurement::AddPreprocessFunctionCallback(PreprocessFunctionCallback callback) +{ + if (callback) { + fPreprocessFunctionCallbacks.push_back(callback); + } +} + +void Measurement::ApplyPreprocessFunctionCallbacks(RooWorkspace &ws) const +{ + for (const auto &callback : fPreprocessFunctionCallbacks) { + if (callback) { + callback(ws); + } + } +} + /// Returns a list of defined preprocess function expressions std::vector Measurement::GetPreprocessFunctions() const {