CMS 3D CMS Logo

RooFitFunction.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_Utilities_RooFitFunction_h
2 #define PhysicsTools_Utilities_RooFitFunction_h
3 
5 #include "RooAbsReal.h"
6 #include "RooListProxy.h"
7 #include "RooRealProxy.h"
8 
9 #include <iostream>
10 #include <vector>
11 
12 namespace root {
13  struct no_args;
14 
15  template <typename X, typename Expr>
16  class RooFitFunction : public RooAbsReal {
17  public:
18  RooFitFunction(const RooFitFunction<X, Expr>& other, const char* name = nullptr)
19  : RooAbsReal(other, name),
20  e_(other.e_),
21  x_(X::name(), this, other.x_),
22  parsPtrs_{other.parsPtrs_},
23  parsArgs_{"!pars", this, other.parsArgs_} {}
24  RooFitFunction(const char* name, const char* title, const Expr& e, RooAbsReal& x)
25  : RooAbsReal(name, title),
26  e_(e),
27  x_(X::name(), X::name(), this, x),
28  parsArgs_("!pars", "List of parameters", this) {}
30  const char* name, const char* title, const Expr& e, RooAbsReal& x, RooAbsReal& rA, funct::Parameter& a)
31  : RooFitFunction{name, title, e, x} {
32  add(rA, a);
33  }
34  RooFitFunction(const char* name,
35  const char* title,
36  const Expr& e,
37  RooAbsReal& x,
38  RooAbsReal& rA,
40  RooAbsReal& rB,
42  : RooFitFunction{name, title, e, x, rA, a} {
43  add(rB, b);
44  }
45  RooFitFunction(const char* name,
46  const char* title,
47  const Expr& e,
48  RooAbsReal& x,
49  RooAbsReal& rA,
51  RooAbsReal& rB,
53  RooAbsReal& rC,
55  : RooFitFunction{name, title, e, x, rA, a, rB, b} {
56  add(rC, c);
57  }
58  void add(RooAbsReal& rA, funct::Parameter& a) {
59  parsPtrs_.emplace_back(a.ptr());
60  parsArgs_.add(rA);
61  }
62  TObject* clone(const char* newName) const override { return new RooFitFunction<X, Expr>(*this, newName); }
63 
64  private:
65  Expr e_;
66  RooRealProxy x_;
67  std::vector<std::shared_ptr<double>> parsPtrs_;
68  RooListProxy parsArgs_;
69  Double_t evaluate() const override {
70  X::set(x_);
71  for (std::size_t i = 0; i < parsPtrs_.size(); ++i) {
72  *(parsPtrs_[i]) = static_cast<RooAbsReal const&>(parsArgs_[i]).getVal(parsArgs_.nset());
73  }
74  return e_();
75  }
76  };
77 
78 } // namespace root
79 
80 #endif
TObject * clone(const char *newName) const override
void add(RooAbsReal &rA, funct::Parameter &a)
RooListProxy parsArgs_
RooFitFunction(const char *name, const char *title, const Expr &e, RooAbsReal &x, RooAbsReal &rA, funct::Parameter &a, RooAbsReal &rB, funct::Parameter &b)
#define X(str)
Definition: MuonsGrabber.cc:38
string newName
Definition: mps_merge.py:86
RooFitFunction(const char *name, const char *title, const Expr &e, RooAbsReal &x)
RooFitFunction(const char *name, const char *title, const Expr &e, RooAbsReal &x, RooAbsReal &rA, funct::Parameter &a, RooAbsReal &rB, funct::Parameter &b, RooAbsReal &rC, funct::Parameter &c)
RooFitFunction(const char *name, const char *title, const Expr &e, RooAbsReal &x, RooAbsReal &rA, funct::Parameter &a)
double b
Definition: hdecay.h:118
RooFitFunction(const RooFitFunction< X, Expr > &other, const char *name=nullptr)
double a
Definition: hdecay.h:119
Double_t evaluate() const override
std::vector< std::shared_ptr< double > > parsPtrs_
float x