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 <vector>
8 #include <boost/type_traits.hpp>
9 #include <iostream>
10 namespace root {
11  struct no_args;
12 
13  template<typename X, typename Expr>
14  class RooFitFunction : public RooAbsReal {
15  public:
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<boost::shared_ptr<double>, RooRealProxy> >::const_iterator
20  i = other.pars_.begin(), 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,
27  const Expr & e, RooAbsReal & x) :
28  RooAbsReal(name, title), e_(e), x_(X::name(), X::name(), this, x) {
29  }
30  RooFitFunction(const char * name, const char * title,
31  const Expr & e, RooAbsReal & x,
32  RooAbsReal & rA, funct::Parameter & a) :
33  RooAbsReal(name, title), e_(e), x_(X::name(), X::name(), this, x) {
34  pars_.push_back(std::make_pair(a.ptr(), RooRealProxy(a.name().c_str(), a.name().c_str(), this, rA)));
35  }
36  RooFitFunction(const char * name, const char * title,
37  const Expr & e, RooAbsReal & x,
38  RooAbsReal & rA, funct::Parameter & a,
39  RooAbsReal & rB, funct::Parameter & b) :
40  RooAbsReal(name, title), e_(e), x_(X::name(), X::name(), this, x) {
41  pars_.push_back(std::make_pair(a.ptr(), RooRealProxy(a.name().c_str(), a.name().c_str(), this, rA)));
42  pars_.push_back(std::make_pair(b.ptr(), RooRealProxy(b.name().c_str(), b.name().c_str(), this, rB)));
43  }
44  RooFitFunction(const char * name, const char * title,
45  const Expr & e, RooAbsReal & x,
46  RooAbsReal & rA, funct::Parameter & a,
47  RooAbsReal & rB, funct::Parameter & b,
48  RooAbsReal & rC, funct::Parameter & c) :
49  RooAbsReal(name, title), e_(e), x_(X::name(), X::name(), this, x) {
50  pars_.push_back(std::make_pair(a.ptr(), RooRealProxy(a.name().c_str(), a.name().c_str(), this, rA)));
51  pars_.push_back(std::make_pair(b.ptr(), RooRealProxy(b.name().c_str(), b.name().c_str(), this, rB)));
52  pars_.push_back(std::make_pair(c.ptr(), RooRealProxy(c.name().c_str(), c.name().c_str(), this, rC)));
53  }
54  virtual ~RooFitFunction() { }
55  void add(RooAbsReal & rA, funct::Parameter & a) {
56  pars_.push_back(std::make_pair(a.ptr(), RooRealProxy(a.name().c_str(), a.name().c_str(), this, rA)));
57  }
58  virtual TObject* clone(const char* newName) const {
59  return new RooFitFunction<X, Expr>(* this, newName);
60  }
61  private:
62  Expr e_;
63  RooRealProxy x_;
64  std::vector<std::pair<boost::shared_ptr<double>, RooRealProxy> > pars_;
65  Double_t evaluate() const {
66  X::set(x_);
67  std::vector<std::pair<boost::shared_ptr<double>, RooRealProxy> >::const_iterator
68  i = pars_.begin(), end = pars_.end();
69  for(; i != end; ++i) *(i->first) = i->second;
70  return e_();
71  }
72 
73  };
74 
75 }
76 
77 #endif
const std::string & name() const
Definition: Parameter.h:13
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)
#define X(str)
Definition: MuonsGrabber.cc:48
boost::shared_ptr< double > ptr() const
Definition: Parameter.h:19
string newName
Definition: mps_merge.py:86
RooFitFunction(const char *name, const char *title, const Expr &e, RooAbsReal &x)
Double_t evaluate() const
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)
RooFitFunction(const RooFitFunction< X, Expr > &other, const char *name=0)
#define end
Definition: vmac.h:39
double b
Definition: hdecay.h:120
std::vector< std::pair< boost::shared_ptr< double >, RooRealProxy > > pars_
double a
Definition: hdecay.h:121
virtual TObject * clone(const char *newName) const