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
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
mps_fire.i
i
Definition: mps_fire.py:428
X
#define X(str)
Definition: MuonsGrabber.cc:38
funct::Parameter
Definition: Parameter.h:8
gather_cfg.cout
cout
Definition: gather_cfg.py:144
root::RooFitFunction::clone
TObject * clone(const char *newName) const override
Definition: RooFitFunction.h:64
root::RooFitFunction::RooFitFunction
RooFitFunction(const char *name, const char *title, const Expr &e, RooAbsReal &x, RooAbsReal &rA, funct::Parameter &a)
Definition: RooFitFunction.h:28
root::RooFitFunction::RooFitFunction
RooFitFunction(const RooFitFunction< X, Expr > &other, const char *name=nullptr)
Definition: RooFitFunction.h:16
Parameter.h
mps_fire.end
end
Definition: mps_fire.py:242
trackingPlots.other
other
Definition: trackingPlots.py:1467
root::RooFitFunction::RooFitFunction
RooFitFunction(const char *name, const char *title, const Expr &e, RooAbsReal &x, RooAbsReal &rA, funct::Parameter &a, RooAbsReal &rB, funct::Parameter &b)
Definition: RooFitFunction.h:33
b
double b
Definition: hdecay.h:118
a
double a
Definition: hdecay.h:119
root
Definition: RooFitFunction.h:10
root::RooFitFunction::RooFitFunction
RooFitFunction(const char *name, const char *title, const Expr &e, RooAbsReal &x)
Definition: RooFitFunction.h:26
root::RooFitFunction::evaluate
Double_t evaluate() const override
Definition: RooFitFunction.h:70
root::RooFitFunction::~RooFitFunction
~RooFitFunction() override
Definition: RooFitFunction.h:60
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
mps_merge.newName
string newName
Definition: mps_merge.py:86
root::RooFitFunction::add
void add(RooAbsReal &rA, funct::Parameter &a)
Definition: RooFitFunction.h:61
root::RooFitFunction::e_
Expr e_
Definition: RooFitFunction.h:67
root::RooFitFunction
Definition: RooFitFunction.h:14
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
root::RooFitFunction::pars_
std::vector< std::pair< std::shared_ptr< double >, RooRealProxy > > pars_
Definition: RooFitFunction.h:69
root::RooFitFunction::x_
RooRealProxy x_
Definition: RooFitFunction.h:68
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
root::RooFitFunction::RooFitFunction
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)
Definition: RooFitFunction.h:45