ROOT logo
/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 *    File: $Id: RooFunctor1DBinding.cxx 28963 2009-06-12 15:47:45Z wouter $
 * Authors:                                                                  *
 *   WV, Wouter Verkerke, NIKHEF, verkerke@nikhef.nl                         *
 *                                                                           *
 * Copyright (c) 2000-2008, NIKHEF, Regents of the University of California  *
 *                          and Stanford University. All rights reserved.    *
 *                                                                           *
 *****************************************************************************/

//////////////////////////////////////////////////////////////////////////////
// 
// BEGIN_HTML
// RooCFunction1Binding is a templated implementation of class RooAbsReal that binds 
// generic C(++) functions to a RooAbsReal argument thus allowing generic C++
// functions to be used as RooFit functions. Instances of function binding
// classes are fully functional RooFit function objects with one exception:
// if the bound function is _not_ a standard TMath or MathMore function the
// class cannot be persisted in a RooWorkspace without registering the function
// pointer first using RooCFunction1Binding<T1,T2>::register().
// END_HTML
//

#include "Riostream.h" 
#include "RooFunctor1DBinding.h" 

using namespace std ;

ClassImp(RooFunctor1DBinding) 
ClassImp(RooFunctor1DPdfBinding) 
  ;


RooFunctor1DBinding::RooFunctor1DBinding(const char *name, const char *title, const ROOT::Math::IBaseFunctionOneDim& ftor, RooAbsReal& x) :
  RooAbsReal(name,title), 
  func(&ftor),
  var("x","x",this,x) 
{ 
} 


RooFunctor1DBinding::RooFunctor1DBinding(const RooFunctor1DBinding& other, const char* name) :  
  RooAbsReal(other,name), 
  func(other.func),
  var("x",this,other.var)
{ 
  // Copy constructor
} 



void RooFunctor1DBinding::printArgs(ostream& os) const {
  // Print object arguments and name/address of function pointer
  os << "[ function=" << func << " " ;    
  for (Int_t i=0 ; i<numProxies() ; i++) {
    RooAbsProxy* p = getProxy(i) ;
    if (!TString(p->name()).BeginsWith("!")) {
      p->print(os) ;
      os << " " ;
    }
  }    
  os << "]" ;  
}

Double_t RooFunctor1DBinding::evaluate() const {
    // Return value of embedded function using value of referenced variable x
    return (*func)(var.arg().getVal()) ;
  }



RooFunctor1DPdfBinding::RooFunctor1DPdfBinding(const char *name, const char *title, const ROOT::Math::IBaseFunctionOneDim& ftor, RooAbsReal& x) :
  RooAbsPdf(name,title), 
  func(&ftor),
  var("x","x",this,x) 
{ 
} 


RooFunctor1DPdfBinding::RooFunctor1DPdfBinding(const RooFunctor1DPdfBinding& other, const char* name) :  
  RooAbsPdf(other,name), 
  func(other.func),
  var("x",this,other.var)
{ 
  // Copy constructor
} 



void RooFunctor1DPdfBinding::printArgs(ostream& os) const {
  // Print object arguments and name/address of function pointer
  os << "[ function=" << func << " " ;    
  for (Int_t i=0 ; i<numProxies() ; i++) {
    RooAbsProxy* p = getProxy(i) ;
    if (!TString(p->name()).BeginsWith("!")) {
      p->print(os) ;
      os << " " ;
    }
  }    
  os << "]" ;  
}

Double_t RooFunctor1DPdfBinding::evaluate() const {
    // Return value of embedded function using value of referenced variable x
    return (*func)(var.arg().getVal()) ;
  }




namespace RooFit {

  RooAbsReal* bindFunction(const char* name, const ROOT::Math::IBaseFunctionOneDim& ftor, RooAbsReal& var) {
    return new RooFunctor1DBinding(name,name,ftor,var) ;
  }

  RooAbsPdf*  bindPdf(const char* name, const ROOT::Math::IBaseFunctionOneDim& ftor, RooAbsReal& var) {
    return new RooFunctor1DPdfBinding(name,name,ftor,var) ;
  }

}



 RooFunctor1DBinding.cxx:1
 RooFunctor1DBinding.cxx:2
 RooFunctor1DBinding.cxx:3
 RooFunctor1DBinding.cxx:4
 RooFunctor1DBinding.cxx:5
 RooFunctor1DBinding.cxx:6
 RooFunctor1DBinding.cxx:7
 RooFunctor1DBinding.cxx:8
 RooFunctor1DBinding.cxx:9
 RooFunctor1DBinding.cxx:10
 RooFunctor1DBinding.cxx:11
 RooFunctor1DBinding.cxx:12
 RooFunctor1DBinding.cxx:13
 RooFunctor1DBinding.cxx:14
 RooFunctor1DBinding.cxx:15
 RooFunctor1DBinding.cxx:16
 RooFunctor1DBinding.cxx:17
 RooFunctor1DBinding.cxx:18
 RooFunctor1DBinding.cxx:19
 RooFunctor1DBinding.cxx:20
 RooFunctor1DBinding.cxx:21
 RooFunctor1DBinding.cxx:22
 RooFunctor1DBinding.cxx:23
 RooFunctor1DBinding.cxx:24
 RooFunctor1DBinding.cxx:25
 RooFunctor1DBinding.cxx:26
 RooFunctor1DBinding.cxx:27
 RooFunctor1DBinding.cxx:28
 RooFunctor1DBinding.cxx:29
 RooFunctor1DBinding.cxx:30
 RooFunctor1DBinding.cxx:31
 RooFunctor1DBinding.cxx:32
 RooFunctor1DBinding.cxx:33
 RooFunctor1DBinding.cxx:34
 RooFunctor1DBinding.cxx:35
 RooFunctor1DBinding.cxx:36
 RooFunctor1DBinding.cxx:37
 RooFunctor1DBinding.cxx:38
 RooFunctor1DBinding.cxx:39
 RooFunctor1DBinding.cxx:40
 RooFunctor1DBinding.cxx:41
 RooFunctor1DBinding.cxx:42
 RooFunctor1DBinding.cxx:43
 RooFunctor1DBinding.cxx:44
 RooFunctor1DBinding.cxx:45
 RooFunctor1DBinding.cxx:46
 RooFunctor1DBinding.cxx:47
 RooFunctor1DBinding.cxx:48
 RooFunctor1DBinding.cxx:49
 RooFunctor1DBinding.cxx:50
 RooFunctor1DBinding.cxx:51
 RooFunctor1DBinding.cxx:52
 RooFunctor1DBinding.cxx:53
 RooFunctor1DBinding.cxx:54
 RooFunctor1DBinding.cxx:55
 RooFunctor1DBinding.cxx:56
 RooFunctor1DBinding.cxx:57
 RooFunctor1DBinding.cxx:58
 RooFunctor1DBinding.cxx:59
 RooFunctor1DBinding.cxx:60
 RooFunctor1DBinding.cxx:61
 RooFunctor1DBinding.cxx:62
 RooFunctor1DBinding.cxx:63
 RooFunctor1DBinding.cxx:64
 RooFunctor1DBinding.cxx:65
 RooFunctor1DBinding.cxx:66
 RooFunctor1DBinding.cxx:67
 RooFunctor1DBinding.cxx:68
 RooFunctor1DBinding.cxx:69
 RooFunctor1DBinding.cxx:70
 RooFunctor1DBinding.cxx:71
 RooFunctor1DBinding.cxx:72
 RooFunctor1DBinding.cxx:73
 RooFunctor1DBinding.cxx:74
 RooFunctor1DBinding.cxx:75
 RooFunctor1DBinding.cxx:76
 RooFunctor1DBinding.cxx:77
 RooFunctor1DBinding.cxx:78
 RooFunctor1DBinding.cxx:79
 RooFunctor1DBinding.cxx:80
 RooFunctor1DBinding.cxx:81
 RooFunctor1DBinding.cxx:82
 RooFunctor1DBinding.cxx:83
 RooFunctor1DBinding.cxx:84
 RooFunctor1DBinding.cxx:85
 RooFunctor1DBinding.cxx:86
 RooFunctor1DBinding.cxx:87
 RooFunctor1DBinding.cxx:88
 RooFunctor1DBinding.cxx:89
 RooFunctor1DBinding.cxx:90
 RooFunctor1DBinding.cxx:91
 RooFunctor1DBinding.cxx:92
 RooFunctor1DBinding.cxx:93
 RooFunctor1DBinding.cxx:94
 RooFunctor1DBinding.cxx:95
 RooFunctor1DBinding.cxx:96
 RooFunctor1DBinding.cxx:97
 RooFunctor1DBinding.cxx:98
 RooFunctor1DBinding.cxx:99
 RooFunctor1DBinding.cxx:100
 RooFunctor1DBinding.cxx:101
 RooFunctor1DBinding.cxx:102
 RooFunctor1DBinding.cxx:103
 RooFunctor1DBinding.cxx:104
 RooFunctor1DBinding.cxx:105
 RooFunctor1DBinding.cxx:106
 RooFunctor1DBinding.cxx:107
 RooFunctor1DBinding.cxx:108
 RooFunctor1DBinding.cxx:109
 RooFunctor1DBinding.cxx:110
 RooFunctor1DBinding.cxx:111
 RooFunctor1DBinding.cxx:112
 RooFunctor1DBinding.cxx:113
 RooFunctor1DBinding.cxx:114
 RooFunctor1DBinding.cxx:115
 RooFunctor1DBinding.cxx:116
 RooFunctor1DBinding.cxx:117
 RooFunctor1DBinding.cxx:118
 RooFunctor1DBinding.cxx:119
 RooFunctor1DBinding.cxx:120
 RooFunctor1DBinding.cxx:121
 RooFunctor1DBinding.cxx:122
 RooFunctor1DBinding.cxx:123
 RooFunctor1DBinding.cxx:124
 RooFunctor1DBinding.cxx:125
 RooFunctor1DBinding.cxx:126