40 _absReal = std::make_unique<RooEvaluatorWrapper>(obj,
const_cast<RooAbsData *
>(
data),
false,
"", simPdf,
false);
50 if (!param->isConstant()) {
51 floatingParamSet.
add(*param);
83 std::stack<std::vector<double>> vectorBuffers;
84 std::map<RooFit::Detail::DataKey, std::span<const double>> spans;
87 spans = RooFit::Detail::BatchModeDataHelpers::getDataSpans(*
data,
"", simPdf,
true,
false, vectorBuffers);
91 for (
auto const &item : spans) {
92 std::size_t
n = item.second.size();
95 for (std::size_t
i = 0;
i <
n; ++
i) {
102 for (
auto *param : paramSet) {
104 std::stringstream errorMsg;
105 errorMsg <<
"In creation of function " <<
GetName()
106 <<
" wrapper: input param expected to be of type RooAbsReal.";
108 throw std::runtime_error(errorMsg.str().c_str());
110 if (spans.find(param) == spans.end()) {
117 _nodeOutputSizes = RooFit::Detail::BatchModeDataHelpers::determineOutputSizes(
119 auto found = spans.find(key);
120 return found != spans.end() ? found->second.size() : -1;
127 static int iFuncWrapper = 0;
128 auto funcName =
"roo_func_wrapper_" + std::to_string(iFuncWrapper++);
131 std::stringstream bodyWithSigStrm;
132 bodyWithSigStrm <<
"double " <<
funcName <<
"(double* params, double const* obs, double const* xlArr) {\n"
133 << funcBody <<
"\n}";
135 std::stringstream errorMsg;
136 errorMsg <<
"Function " <<
funcName <<
" could not be compiled. See above for details.";
138 throw std::runtime_error(errorMsg.str().c_str());
145 std::string gradName =
_funcName +
"_grad_0";
146 std::string requestName =
_funcName +
"_req";
152 std::stringstream requestFuncStrm;
153 requestFuncStrm <<
"#pragma clad ON\n"
154 "void " << requestName <<
"() {\n"
155 " clad::gradient(" <<
_funcName <<
", \"params\");\n"
160 std::stringstream errorMsg;
161 errorMsg <<
"Function " <<
GetName() <<
" could not be differentiated. See above for details.";
163 throw std::runtime_error(errorMsg.str().c_str());
173 std::fill(out, out +
_params.size(), 0.0);
181 [](
RooAbsArg *obj) { return static_cast<RooAbsReal *>(obj)->getVal(); });
207 ctx.
addResult(param,
"params[" + std::to_string(idx) +
"]");
212 const char *
name = item.first->GetName();
216 if (item.second.size == 1) {
217 ctx.
addResult(
name,
"obs[" + std::to_string(item.second.idx) +
"]");
237 std::ofstream outFile;
239 outFile <<
"#include <RooFit/Detail/MathFuncs.h>" << std::endl;
240 outFile << std::endl;
242 outFile << std::endl;
246 auto writeVector = [&](std::string
const &
name, std::span<const double>
vec) {
247 outFile <<
"std::vector<double> " <<
name <<
" = {";
248 for (std::size_t
i = 0;
i <
vec.size(); ++
i) {
252 if (
i <
vec.size() - 1)
258 outFile <<
"// clang-format off\n" << std::endl;
260 outFile << std::endl;
262 outFile << std::endl;
263 writeVector(
"auxConstantsVec",
_xlArr);
264 outFile << std::endl;
265 outFile <<
"// clang-format on\n" << std::endl;
268// To run as a ROOT macro
272 std::vector<double> gradientVec(parametersVec.size());
275 << R"((parametersVec.data(), observablesVec.data(), auxConstantsVec.data());
277 << R"(_grad_0(parametersVec.data(), observablesVec.data(), auxConstantsVec.data(), gradientVec.data());
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
RooFit::OwningPtr< RooArgSet > getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
RooAbsArg()
Default constructor.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Abstract base class for binned and unbinned datasets.
RooAbsReal()
coverity[UNINIT_CTOR] Default constructor
RooArgSet is a container object that can hold multiple RooAbsArg objects.
A class to maintain the context for squashing of RooFit models into code.
std::string assembleCode(std::string const &returnExpr)
Assemble and return the final code with the return expression and global statements.
void addResult(RooAbsArg const *key, std::string const &value)
A function to save an expression that includes/depends on the result of the input node.
void addVecObs(const char *key, int idx)
Since the squashed code represents all observables as a single flattened array, it is important to ke...
std::string const & getResult(RooAbsArg const &arg)
Gets the result for the given node using the node name.
std::map< RooFit::Detail::DataKey, std::size_t > _nodeOutputSizes
std::string const & funcName() const
double(*)(double *, double const *, double const *) Func
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
std::unique_ptr< RooAbsReal > _absReal
std::string buildCode(RooAbsReal const &head)
std::vector< double > _xlArr
std::vector< double > _observables
void loadParamsAndData(RooAbsArg const *head, RooArgSet const ¶mSet, const RooAbsData *data, RooSimultaneous const *simPdf)
void writeDebugMacro(std::string const &) const
Dumps a macro "filename.C" that can be used to test and debug the generated code and gradient.
void gradient(double *out) const override
std::map< RooFit::Detail::DataKey, ObsInfo > _obsInfos
std::vector< double > _gradientVarBuffer
void(*)(double *, double const *, double const *, double *) Grad
void updateGradientVarBuffer() const
std::stringstream _allCode
std::string declareFunction(std::string const &funcBody)
RooFuncWrapper(const char *name, const char *title, RooAbsReal &obj, const RooAbsData *data=nullptr, RooSimultaneous const *simPdf=nullptr, bool useEvaluator=false)
bool declareToInterpreter(std::string const &code)
Declare code to the interpreter and keep track of all declared code in this RooFuncWrapper.
Facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
const char * GetName() const override
Returns name of object.
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...