CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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/static_assert.hpp>
9 #include <boost/type_traits.hpp>
10 #include <iostream>
11 namespace root {
12  struct no_args;
13 
14  template<typename X, typename Expr>
15  class RooFitFunction : public RooAbsReal {
16  public:
17  RooFitFunction(const RooFitFunction<X, Expr> & other, const char* name=0) :
18  RooAbsReal(other, name), e_(other.e_), x_(X::name(), this, other.x_) {
19  std::cout << ">>> making new RooFitFunction" << std::endl;
20  std::vector<std::pair<boost::shared_ptr<double>, RooRealProxy> >::const_iterator
21  i = other.pars_.begin(), end = other.pars_.end();
22  for(; i != end; ++i) {
23  std::cout << ">>> adding par to RooFitFunction" << std::endl;
24  pars_.push_back(std::make_pair(i->first, RooRealProxy(i->second.GetName(), this, i->second)));
25  }
26  }
27  RooFitFunction(const char * name, const char * title,
28  const Expr & e, RooAbsReal & x) :
29  RooAbsReal(name, title), e_(e), x_(X::name(), X::name(), this, x) {
30  }
31  RooFitFunction(const char * name, const char * title,
32  const Expr & e, RooAbsReal & x,
33  RooAbsReal & rA, funct::Parameter & a) :
34  RooAbsReal(name, title), e_(e), x_(X::name(), X::name(), this, x) {
35  pars_.push_back(std::make_pair(a.ptr(), RooRealProxy(a.name().c_str(), a.name().c_str(), this, rA)));
36  }
37  RooFitFunction(const char * name, const char * title,
38  const Expr & e, RooAbsReal & x,
39  RooAbsReal & rA, funct::Parameter & a,
40  RooAbsReal & rB, funct::Parameter & b) :
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, const char * title,
46  const Expr & e, RooAbsReal & x,
47  RooAbsReal & rA, funct::Parameter & a,
48  RooAbsReal & rB, funct::Parameter & b,
49  RooAbsReal & rC, funct::Parameter & c) :
50  RooAbsReal(name, title), e_(e), x_(X::name(), X::name(), this, x) {
51  pars_.push_back(std::make_pair(a.ptr(), RooRealProxy(a.name().c_str(), a.name().c_str(), this, rA)));
52  pars_.push_back(std::make_pair(b.ptr(), RooRealProxy(b.name().c_str(), b.name().c_str(), this, rB)));
53  pars_.push_back(std::make_pair(c.ptr(), RooRealProxy(c.name().c_str(), c.name().c_str(), this, rC)));
54  }
55  virtual ~RooFitFunction() { }
56  void add(RooAbsReal & rA, funct::Parameter & a) {
57  pars_.push_back(std::make_pair(a.ptr(), RooRealProxy(a.name().c_str(), a.name().c_str(), this, rA)));
58  }
59  virtual TObject* clone(const char* newName) const {
60  return new RooFitFunction<X, Expr>(* this, newName);
61  }
62  private:
63  Expr e_;
64  RooRealProxy x_;
65  std::vector<std::pair<boost::shared_ptr<double>, RooRealProxy> > pars_;
66  Double_t evaluate() const {
67  X::set(x_);
68  std::vector<std::pair<boost::shared_ptr<double>, RooRealProxy> >::const_iterator
69  i = pars_.begin(), end = pars_.end();
70  for(; i != end; ++i) *(i->first) = i->second;
71  return e_();
72  }
73 
74  };
75 
76 }
77 
78 #endif
int i
Definition: DBlmapReader.cc:9
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
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:37
double b
Definition: hdecay.h:120
std::vector< std::pair< boost::shared_ptr< double >, RooRealProxy > > pars_
double a
Definition: hdecay.h:121
tuple cout
Definition: gather_cfg.py:145
virtual TObject * clone(const char *newName) const