Logo ROOT   6.08/07
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 \file RooFunctor1DBinding.cxx
15 \class RooFunctor1DBinding
16 \ingroup Roofit
17 
18 RooCFunction1Binding is a templated implementation of class RooAbsReal that binds
19 generic C(++) functions to a RooAbsReal argument thus allowing generic C++
20 functions to be used as RooFit functions. Instances of function binding
21 classes are fully functional RooFit function objects with one exception:
22 if the bound function is _not_ a standard TMath or MathMore function the
23 class cannot be persisted in a RooWorkspace without registering the function
24 pointer first using RooCFunction1Binding<T1,T2>::register().
25 **/
26 
27 #include "Riostream.h"
28 #include "RooFunctor1DBinding.h"
29 
30 using namespace std ;
31 
34  ;
35 
36 
38  RooAbsReal(name,title),
39  func(&ftor),
40  var("x","x",this,x)
41 {
42 }
43 
44 
46  RooAbsReal(other,name),
47  func(other.func),
48  var("x",this,other.var)
49 {
50  // Copy constructor
51 }
52 
53 
54 
55 void RooFunctor1DBinding::printArgs(ostream& os) const {
56  // Print object arguments and name/address of function pointer
57  os << "[ function=" << func << " " ;
58  for (Int_t i=0 ; i<numProxies() ; i++) {
59  RooAbsProxy* p = getProxy(i) ;
60  if (!TString(p->name()).BeginsWith("!")) {
61  p->print(os) ;
62  os << " " ;
63  }
64  }
65  os << "]" ;
66 }
67 
69  // Return value of embedded function using value of referenced variable x
70  return (*func)(var.arg().getVal()) ;
71  }
72 
73 
74 
76  RooAbsPdf(name,title),
77  func(&ftor),
78  var("x","x",this,x)
79 {
80 }
81 
82 
84  RooAbsPdf(other,name),
85  func(other.func),
86  var("x",this,other.var)
87 {
88  // Copy constructor
89 }
90 
91 
92 
93 void RooFunctor1DPdfBinding::printArgs(ostream& os) const {
94  // Print object arguments and name/address of function pointer
95  os << "[ function=" << func << " " ;
96  for (Int_t i=0 ; i<numProxies() ; i++) {
97  RooAbsProxy* p = getProxy(i) ;
98  if (!TString(p->name()).BeginsWith("!")) {
99  p->print(os) ;
100  os << " " ;
101  }
102  }
103  os << "]" ;
104 }
105 
107  // Return value of embedded function using value of referenced variable x
108  return (*func)(var.arg().getVal()) ;
109  }
110 
111 
112 
113 
114 namespace RooFit {
115 
117  return new RooFunctor1DBinding(name,name,ftor,var) ;
118  }
119 
121  return new RooFunctor1DPdfBinding(name,name,ftor,var) ;
122  }
123 
124 }
125 
126 
127 
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition: IFunction.h:133
virtual const char * name() const
Definition: RooAbsProxy.h:42
RooAbsPdf * bindPdf(const char *name, CFUNCD1D func, RooAbsReal &x)
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
int Int_t
Definition: RtypesCore.h:41
STL namespace.
RooCFunction1Binding is a templated implementation of class RooAbsReal that binds generic C(++) funct...
RooAbsReal * bindFunction(const char *name, CFUNCD1D func, RooAbsReal &x)
Double_t evaluate() const
Double_t x[n]
Definition: legend1.C:17
const ROOT::Math::IBaseFunctionOneDim * func
bool BeginsWith(const std::string &theString, const std::string &theSubstring)
RooAbsProxy is the abstact interface for proxy classes.
Definition: RooAbsProxy.h:32
void printArgs(std::ostream &os) const
Print object arguments, ie its proxies.
void printArgs(std::ostream &os) const
Print object arguments, ie its proxies.
#define ClassImp(name)
Definition: Rtypes.h:279
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
RooAbsProxy * getProxy(Int_t index) const
Return the nth proxy from the proxy list.
Definition: RooAbsArg.cxx:1254
Int_t numProxies() const
Return the number of registered proxies.
Definition: RooAbsArg.cxx:1267
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
const ROOT::Math::IBaseFunctionOneDim * func
const RooAbsReal & arg() const
Definition: RooRealProxy.h:43
virtual void print(std::ostream &os, Bool_t addContents=kFALSE) const
Print proxy name.
Definition: RooAbsProxy.cxx:75
char name[80]
Definition: TGX11.cxx:109