Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooFuncWrapper.h
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 * Authors:
4 * Garima Singh, CERN 2022
5 *
6 * Copyright (c) 2022, CERN
7 *
8 * Redistribution and use in source and binary forms,
9 * with or without modification, are permitted according to the terms
10 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
11 */
12
13#ifndef RooFit_RooFuncWrapper_h
14#define RooFit_RooFuncWrapper_h
15
16#include <RooAbsReal.h>
17#include <RooListProxy.h>
18
19#include <map>
20#include <memory>
21#include <string>
22
23class RooSimultaneous;
24
25namespace RooFit {
26
27namespace Experimental {
28
29/// @brief A wrapper class to store a C++ function of type 'double (*)(double*, double*)'.
30/// The parameters can be accessed as params[<relative position of param in paramSet>] in the function body.
31/// The observables can be accessed as obs[i + j], where i represents the observable position and j
32/// represents the data entry.
33class RooFuncWrapper final : public RooAbsReal {
34public:
35 RooFuncWrapper(const char *name, const char *title, RooAbsReal &obj, const RooAbsData *data = nullptr,
36 RooSimultaneous const *simPdf = nullptr, bool useEvaluator=false);
37
38 RooFuncWrapper(const RooFuncWrapper &other, const char *name = nullptr);
39
40 TObject *clone(const char *newname) const override { return new RooFuncWrapper(*this, newname); }
41
42 double defaultErrorLevel() const override { return 0.5; }
43
44 bool hasGradient() const override { return _hasGradient; }
45 void gradient(double *out) const override;
46
47 void gradient(const double *x, double *g) const;
48
49 std::size_t getNumParams() const { return _params.size(); }
50
51 void dumpCode();
52
53 void dumpGradient();
54
55 /// No constant term optimization is possible in code-generation mode.
56 void constOptimizeTestStatistic(ConstOpCode /*opcode*/, bool /*doAlsoTrackingOpt*/) override {}
57
58 std::string const &funcName() const { return _funcName; }
59
60 void createGradient();
61
62protected:
63 double evaluate() const override;
64
65private:
66 std::string buildCode(RooAbsReal const &head);
67
68 static std::string declareFunction(std::string const &funcBody);
69
70 void updateGradientVarBuffer() const;
71
72 void loadParamsAndData(RooAbsArg const *head, RooArgSet const &paramSet, const RooAbsData *data,
73 RooSimultaneous const *simPdf);
74
76
77 using Func = double (*)(double *, double const *, double const *);
78 using Grad = void (*)(double *, double const *, double const *, double *);
79
80 struct ObsInfo {
81 ObsInfo(std::size_t i, std::size_t n) : idx{i}, size{n} {}
82 std::size_t idx = 0;
83 std::size_t size = 0;
84 };
85
86 std::unique_ptr<RooAbsReal> _absReal;
88 std::string _funcName;
91 bool _hasGradient = false;
92 mutable std::vector<double> _gradientVarBuffer;
93 std::vector<double> _observables;
94 std::map<RooFit::Detail::DataKey, ObsInfo> _obsInfos;
95 std::map<RooFit::Detail::DataKey, std::size_t> _nodeOutputSizes;
96 std::vector<double> _xlArr;
97};
98
99} // namespace Experimental
100
101} // namespace RooFit
102
103#endif
#define g(i)
Definition RSha256.hxx:105
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
char name[80]
Definition TGX11.cxx:110
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
Storage_t::size_type size() const
Abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:57
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
A wrapper class to store a C++ function of type 'double (*)(double*, double*)'.
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
void dumpCode()
Prints the squashed code body to console.
TObject * clone(const char *newname) const override
double defaultErrorLevel() const override
std::string buildCode(RooAbsReal const &head)
void loadParamsAndData(RooAbsArg const *head, RooArgSet const &paramSet, const RooAbsData *data, RooSimultaneous const *simPdf)
void constOptimizeTestStatistic(ConstOpCode, bool) override
No constant term optimization is possible in code-generation mode.
void gradient(double *out) const override
void dumpGradient()
Prints the derivative code body to console.
std::map< RooFit::Detail::DataKey, ObsInfo > _obsInfos
std::vector< double > _gradientVarBuffer
void(*)(double *, double const *, double const *, double *) Grad
static std::string declareFunction(std::string const &funcBody)
Facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
Mother of all ROOT objects.
Definition TObject.h:41
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26