ROOT  6.06/09
Reference Guide
RooFunctor1DBinding.cxx
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * File: $Id$
5  * Authors: *
6  * WV, Wouter Verkerke, NIKHEF, verkerke@nikhef.nl *
7  * *
8  * Copyright (c) 2000-2008, NIKHEF, Regents of the University of California *
9  * and Stanford University. All rights reserved. *
10  * *
11  *****************************************************************************/
12 
13 //////////////////////////////////////////////////////////////////////////////
14 //
15 // BEGIN_HTML
16 // RooCFunction1Binding is a templated implementation of class RooAbsReal that binds
17 // generic C(++) functions to a RooAbsReal argument thus allowing generic C++
18 // functions to be used as RooFit functions. Instances of function binding
19 // classes are fully functional RooFit function objects with one exception:
20 // if the bound function is _not_ a standard TMath or MathMore function the
21 // class cannot be persisted in a RooWorkspace without registering the function
22 // pointer first using RooCFunction1Binding<T1,T2>::register().
23 // END_HTML
24 //
25 
26 #include "Riostream.h"
27 #include "RooFunctor1DBinding.h"
28 
29 using namespace std ;
30 
33  ;
34 
35 
36 RooFunctor1DBinding::RooFunctor1DBinding(const char *name, const char *title, const ROOT::Math::IBaseFunctionOneDim& ftor, RooAbsReal& x) :
37  RooAbsReal(name,title),
38  func(&ftor),
39  var("x","x",this,x)
40 {
41 }
42 
43 
45  RooAbsReal(other,name),
46  func(other.func),
47  var("x",this,other.var)
48 {
49  // Copy constructor
50 }
51 
52 
53 
54 void RooFunctor1DBinding::printArgs(ostream& os) const {
55  // Print object arguments and name/address of function pointer
56  os << "[ function=" << func << " " ;
57  for (Int_t i=0 ; i<numProxies() ; i++) {
58  RooAbsProxy* p = getProxy(i) ;
59  if (!TString(p->name()).BeginsWith("!")) {
60  p->print(os) ;
61  os << " " ;
62  }
63  }
64  os << "]" ;
65 }
66 
68  // Return value of embedded function using value of referenced variable x
69  return (*func)(var.arg().getVal()) ;
70  }
71 
72 
73 
75  RooAbsPdf(name,title),
76  func(&ftor),
77  var("x","x",this,x)
78 {
79 }
80 
81 
83  RooAbsPdf(other,name),
84  func(other.func),
85  var("x",this,other.var)
86 {
87  // Copy constructor
88 }
89 
90 
91 
92 void RooFunctor1DPdfBinding::printArgs(ostream& os) const {
93  // Print object arguments and name/address of function pointer
94  os << "[ function=" << func << " " ;
95  for (Int_t i=0 ; i<numProxies() ; i++) {
96  RooAbsProxy* p = getProxy(i) ;
97  if (!TString(p->name()).BeginsWith("!")) {
98  p->print(os) ;
99  os << " " ;
100  }
101  }
102  os << "]" ;
103 }
104 
106  // Return value of embedded function using value of referenced variable x
107  return (*func)(var.arg().getVal()) ;
108  }
109 
110 
111 
112 
113 namespace RooFit {
114 
116  return new RooFunctor1DBinding(name,name,ftor,var) ;
117  }
118 
120  return new RooFunctor1DPdfBinding(name,name,ftor,var) ;
121  }
122 
123 }
124 
125 
126 
virtual void print(std::ostream &os, Bool_t addContents=kFALSE) const
Print proxy name.
Definition: RooAbsProxy.cxx:74
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition: IFunction.h:133
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
RooAbsPdf * bindPdf(const char *name, CFUNCD1D func, RooAbsReal &x)
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
STL namespace.
RooAbsProxy * getProxy(Int_t index) const
Return the nth proxy from the proxy list.
Definition: RooAbsArg.cxx:1253
void printArgs(std::ostream &os) const
Print object arguments, ie its proxies.
const RooAbsReal & arg() const
Definition: RooRealProxy.h:43
Double_t evaluate() const
RooAbsReal * bindFunction(const char *name, CFUNCD1D func, RooAbsReal &x)
Double_t x[n]
Definition: legend1.C:17
const ROOT::Math::IBaseFunctionOneDim * func
bool BeginsWith(const std::string &theString, const std::string &theSubstring)
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
ClassImp(RooFunctor1DBinding) ClassImp(RooFunctor1DPdfBinding)
Int_t numProxies() const
Return the number of registered proxies.
Definition: RooAbsArg.cxx:1266
virtual const char * name() const
Definition: RooAbsProxy.h:42
double Double_t
Definition: RtypesCore.h:55
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
double func(double *x, double *p)
Definition: stressTF1.cxx:213
Namespace for new Math classes and functions.
#define name(a, b)
Definition: linkTestLib0.cpp:5
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
const ROOT::Math::IBaseFunctionOneDim * func
void printArgs(std::ostream &os) const
Print object arguments, ie its proxies.