CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/PhysicsTools/Utilities/interface/RooFitFunction.h

Go to the documentation of this file.
00001 #ifndef PhysicsTools_Utilities_RooFitFunction_h
00002 #define PhysicsTools_Utilities_RooFitFunction_h
00003 #include "PhysicsTools/Utilities/interface/Parameter.h"
00004 #include "RooAbsReal.h"
00005 #include "RooRealProxy.h"
00006 #include "RooAbsReal.h"
00007 #include <vector>
00008 #include <boost/static_assert.hpp>
00009 #include <boost/type_traits.hpp>
00010 #include <iostream>
00011 namespace root {
00012   struct no_args;
00013   
00014   template<typename X, typename Expr>
00015   class RooFitFunction : public RooAbsReal {
00016   public:
00017     RooFitFunction(const RooFitFunction<X, Expr> & other, const char* name=0) :
00018       RooAbsReal(other, name), e_(other.e_), x_(X::name(), this, other.x_) {
00019       std::cout << ">>> making new RooFitFunction" << std::endl;
00020       std::vector<std::pair<boost::shared_ptr<double>, RooRealProxy> >::const_iterator 
00021         i = other.pars_.begin(), end = other.pars_.end();
00022       for(; i != end; ++i) {
00023         std::cout << ">>> adding par to RooFitFunction" << std::endl;
00024         pars_.push_back(std::make_pair(i->first, RooRealProxy(i->second.GetName(), this, i->second)));
00025       }
00026     }
00027     RooFitFunction(const char * name, const char * title,
00028                    const Expr & e, RooAbsReal & x) : 
00029       RooAbsReal(name, title), e_(e), x_(X::name(), X::name(), this, x) {
00030     } 
00031     RooFitFunction(const char * name, const char * title,
00032                    const Expr & e, RooAbsReal & x, 
00033                    RooAbsReal & rA, funct::Parameter & a) : 
00034       RooAbsReal(name, title), e_(e), x_(X::name(), X::name(), this, x) {
00035       pars_.push_back(std::make_pair(a.ptr(), RooRealProxy(a.name().c_str(), a.name().c_str(), this, rA)));
00036     } 
00037     RooFitFunction(const char * name, const char * title,
00038                    const Expr & e, RooAbsReal & x, 
00039                    RooAbsReal & rA, funct::Parameter & a,
00040                    RooAbsReal & rB, funct::Parameter & b) : 
00041       RooAbsReal(name, title), e_(e), x_(X::name(), X::name(), this, x) {
00042       pars_.push_back(std::make_pair(a.ptr(), RooRealProxy(a.name().c_str(), a.name().c_str(), this, rA)));
00043       pars_.push_back(std::make_pair(b.ptr(), RooRealProxy(b.name().c_str(), b.name().c_str(), this, rB)));
00044     } 
00045     RooFitFunction(const char * name, const char * title,
00046                    const Expr & e, RooAbsReal & x, 
00047                    RooAbsReal & rA, funct::Parameter & a,
00048                    RooAbsReal & rB, funct::Parameter & b,
00049                    RooAbsReal & rC, funct::Parameter & c) : 
00050       RooAbsReal(name, title), e_(e), x_(X::name(), X::name(), this, x) {
00051       pars_.push_back(std::make_pair(a.ptr(), RooRealProxy(a.name().c_str(), a.name().c_str(), this, rA)));
00052       pars_.push_back(std::make_pair(b.ptr(), RooRealProxy(b.name().c_str(), b.name().c_str(), this, rB)));
00053       pars_.push_back(std::make_pair(c.ptr(), RooRealProxy(c.name().c_str(), c.name().c_str(), this, rC)));
00054     } 
00055     virtual ~RooFitFunction() { }
00056     void add(RooAbsReal & rA, funct::Parameter & a) {
00057       pars_.push_back(std::make_pair(a.ptr(), RooRealProxy(a.name().c_str(), a.name().c_str(), this, rA)));      
00058     }
00059     virtual TObject* clone(const char* newName) const { 
00060       return new RooFitFunction<X, Expr>(* this, newName);
00061     }
00062   private:
00063     Expr e_;
00064     RooRealProxy x_;
00065     std::vector<std::pair<boost::shared_ptr<double>, RooRealProxy> > pars_;
00066     Double_t evaluate() const {
00067       X::set(x_);
00068       std::vector<std::pair<boost::shared_ptr<double>, RooRealProxy> >::const_iterator 
00069         i = pars_.begin(), end = pars_.end();
00070       for(; i != end; ++i) *(i->first) = i->second;
00071       return  e_();
00072     }
00073 
00074   };
00075 
00076 }
00077 
00078 #endif