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
4 #include "RooAbsReal.h"
5 #include "RooRealProxy.h"
6 #include "RooAbsReal.h"
7 #include <iostream>
8 #include <vector>
9 
10 namespace root {
11  struct no_args;
12 
13  template <typename X, typename Expr>
14  class RooFitFunction : public RooAbsReal {
15  public:
16  RooFitFunction(const RooFitFunction<X, Expr>& other, const char* name = nullptr)
17  : RooAbsReal(other, name), e_(other.e_), x_(X::name(), this, other.x_) {
18  std::cout << ">>> making new RooFitFunction" << std::endl;
19  std::vector<std::pair<std::shared_ptr<double>, RooRealProxy> >::const_iterator i = other.pars_.begin(),
20  end = other.pars_.end();
21  for (; i != end; ++i) {
22  std::cout << ">>> adding par to RooFitFunction" << std::endl;
23  pars_.push_back(std::make_pair(i->first, RooRealProxy(i->second.GetName(), this, i->second)));
24  }
25  }
26  RooFitFunction(const char* name, const char* title, const Expr& e, RooAbsReal& x)
27  : RooAbsReal(name, title), e_(e), x_(X::name(), X::name(), this, x) {}
29  const char* name, const char* title, const Expr& e, RooAbsReal& x, RooAbsReal& rA, funct::Parameter& a)
30  : RooAbsReal(name, title), e_(e), x_(X::name(), X::name(), this, x) {
31  pars_.push_back(std::make_pair(a.ptr(), RooRealProxy(a.name().c_str(), a.name().c_str(), this, rA)));
32  }
33  RooFitFunction(const char* name,
34  const char* title,
35  const Expr& e,
36  RooAbsReal& x,
37  RooAbsReal& rA,
39  RooAbsReal& rB,
41  : RooAbsReal(name, title), e_(e), x_(X::name(), X::name(), this, x) {
42  pars_.push_back(std::make_pair(a.ptr(), RooRealProxy(a.name().c_str(), a.name().c_str(), this, rA)));
43  pars_.push_back(std::make_pair(b.ptr(), RooRealProxy(b.name().c_str(), b.name().c_str(), this, rB)));
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  : RooAbsReal(name, title), e_(e), x_(X::name(), X::name(), this, x) {
56  pars_.push_back(std::make_pair(a.ptr(), RooRealProxy(a.name().c_str(), a.name().c_str(), this, rA)));
57  pars_.push_back(std::make_pair(b.ptr(), RooRealProxy(b.name().c_str(), b.name().c_str(), this, rB)));
58  pars_.push_back(std::make_pair(c.ptr(), RooRealProxy(c.name().c_str(), c.name().c_str(), this, rC)));
59  }
60  ~RooFitFunction() override {}
61  void add(RooAbsReal& rA, funct::Parameter& a) {
62  pars_.push_back(std::make_pair(a.ptr(), RooRealProxy(a.name().c_str(), a.name().c_str(), this, rA)));
63  }
64  TObject* clone(const char* newName) const override { return new RooFitFunction<X, Expr>(*this, newName); }
65 
66  private:
67  Expr e_;
68  RooRealProxy x_;
69  std::vector<std::pair<std::shared_ptr<double>, RooRealProxy> > pars_;
70  Double_t evaluate() const override {
71  X::set(x_);
72  std::vector<std::pair<std::shared_ptr<double>, RooRealProxy> >::const_iterator i = pars_.begin(),
73  end = pars_.end();
74  for (; i != end; ++i)
75  *(i->first) = i->second;
76  return e_();
77  }
78  };
79 
80 } // namespace root
81 
82 #endif
TObject * clone(const char *newName) const override
void add(RooAbsReal &rA, funct::Parameter &a)
RooFitFunction(const char *name, const char *title, const Expr &e, RooAbsReal &x, RooAbsReal &rA, funct::Parameter &a, RooAbsReal &rB, funct::Parameter &b)
~RooFitFunction() override
#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)
std::vector< std::pair< std::shared_ptr< double >, RooRealProxy > > pars_
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
float x