29 :
RooAbsReal{
name, title}, _params{
"!params",
"List of parameters", this}, _hasGradient{createGradient}
40 :
RooAbsReal{
name, title}, _params{
"!params",
"List of parameters", this}, _hasGradient{createGradient}
52 if (!param->isConstant()) {
53 floatingParamSet.
add(*param);
68 _params(
"!params", this, other._params),
71 _hasGradient(other._hasGradient),
72 _gradientVarBuffer(other._gradientVarBuffer),
73 _observables(other._observables)
81 std::stack<std::vector<double>> vectorBuffers;
82 std::map<RooFit::Detail::DataKey, std::span<const double>> spans;
89 for (
auto const &item : spans) {
90 std::size_t
n = item.second.size();
93 for (std::size_t i = 0; i <
n; ++i) {
100 for (
auto *param : paramSet) {
102 std::stringstream errorMsg;
103 errorMsg <<
"In creation of function " << funcName
104 <<
" wrapper: input param expected to be of type RooAbsReal.";
105 coutE(InputArguments) << errorMsg.str() << std::endl;
106 throw std::runtime_error(errorMsg.str().c_str());
108 if (spans.find(param) == spans.end()) {
112 _gradientVarBuffer.resize(_params.size());
117 auto found = spans.find(key);
118 return found != spans.end() ? found->second.size() : 0;
125 std::string gradName = funcName +
"_grad_0";
126 std::string requestName = funcName +
"_req";
127 std::string wrapperName = funcName +
"_derivativeWrapper";
132 std::stringstream bodyWithSigStrm;
133 bodyWithSigStrm <<
"double " << funcName <<
"(double* params, double const* obs) {\n" << funcBody <<
"\n}";
134 bool comp =
gInterpreter->Declare(bodyWithSigStrm.str().c_str());
136 std::stringstream errorMsg;
137 errorMsg <<
"Function " << funcName <<
" could not be compiled. See above for details.";
138 coutE(InputArguments) << errorMsg.str() << std::endl;
139 throw std::runtime_error(errorMsg.str().c_str());
147 gInterpreter->ProcessLine(
"#include <Math/CladDerivator.h>");
150 std::stringstream requestFuncStrm;
151 requestFuncStrm <<
"#pragma clad ON\n"
152 "void " << requestName <<
"() {\n"
153 " clad::gradient(" << funcName <<
", \"params\");\n"
157 comp =
gInterpreter->Declare(requestFuncStrm.str().c_str());
159 std::stringstream errorMsg;
160 errorMsg <<
"Function " << funcName <<
" could not be differentiated. See above for details.";
161 coutE(InputArguments) << errorMsg.str() << std::endl;
162 throw std::runtime_error(errorMsg.str().c_str());
168 std::stringstream dWrapperStrm;
169 dWrapperStrm <<
"void " << wrapperName <<
"(double* params, double const* obs, double* out) {\n"
170 " clad::array_ref<double> cladOut(out, " <<
_params.
size() <<
");\n"
171 " " << gradName <<
"(params, obs, cladOut);\n"
189 [](
RooAbsArg *obj) { return static_cast<RooAbsReal *>(obj)->getVal(); });
213 ctx.
addResult(param,
"params[" + std::to_string(idx) +
"]");
218 const char *
name = item.first->GetName();
222 if (item.second.size == 1) {
223 ctx.
addResult(
name,
"obs[" + std::to_string(item.second.idx) +
"]");
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
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...
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
const_iterator end() const
Storage_t::size_type size() const
const_iterator begin() const
RooAbsData is the common abstract base class for binned and unbinned datasets.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
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.
A wrapper class to store a C++ function of type 'double (*)(double*, double*)'.
std::vector< double > _gradientVarBuffer
void dumpGradient()
Prints the derivative code body to console.
RooFuncWrapper(const char *name, const char *title, std::string const &funcBody, RooArgSet const ¶mSet, const RooAbsData *data, RooSimultaneous const *simPdf, bool createGradient)
std::map< RooFit::Detail::DataKey, std::size_t > _nodeOutputSizes
std::map< RooFit::Detail::DataKey, ObsInfo > _obsInfos
std::string buildCode(RooAbsReal const &head)
void gradient(double *out) const override
double(*)(double *, double const *) Func
std::vector< double > _observables
void(*)(double *, double const *, double *) Grad
void declareAndDiffFunction(std::string funcName, std::string const &funcBody, bool createGradient)
void loadParamsAndData(std::string funcName, RooAbsArg const *head, RooArgSet const ¶mSet, const RooAbsData *data, RooSimultaneous const *simPdf)
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
void updateGradientVarBuffer() const
void dumpCode()
Prints the squashed code body to console.
RooSimultaneous facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
std::map< RooFit::Detail::DataKey, std::span< const double > > getDataSpans(RooAbsData const &data, std::string const &rangeName, RooSimultaneous const *simPdf, bool skipZeroWeights, bool takeGlobalObservablesFromData, std::stack< std::vector< double > > &buffers)
Extract all content from a RooFit datasets as a map of spans.
std::map< RooFit::Detail::DataKey, std::size_t > determineOutputSizes(RooAbsArg const &topNode, std::function< std::size_t(RooFit::Detail::DataKey)> const &inputSizeFunc)
Figure out the output size for each node in the computation graph that leads up to the top node,...
std::unique_ptr< T > compileForNormSet(T const &arg, RooArgSet const &normSet)