Logo ROOT  
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 /** \class RooFunctor1DBinding
14  \ingroup Roofit
15 
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 **/
24 
25 /** \class RooFunctor1DPdfBinding
26  \ingroup Roofit
27 **/
28 
29 #include "Riostream.h"
30 #include "RooFunctor1DBinding.h"
31 
32 using namespace std ;
33 
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 
40  RooAbsReal(name,title),
41  func(&ftor),
42  var("x","x",this,x)
43 {
44 }
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 
49  RooAbsReal(other,name),
50  func(other.func),
51  var("x",this,other.var)
52 {
53  // Copy constructor
54 }
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 
58 void RooFunctor1DBinding::printArgs(ostream& os) const {
59  // Print object arguments and name/address of function pointer
60  os << "[ function=" << func << " " ;
61  for (Int_t i=0 ; i<numProxies() ; i++) {
62  RooAbsProxy* p = getProxy(i) ;
63  if (!TString(p->name()).BeginsWith("!")) {
64  p->print(os) ;
65  os << " " ;
66  }
67  }
68  os << "]" ;
69 }
70 
71 ////////////////////////////////////////////////////////////////////////////////
72 
74  // Return value of embedded function using value of referenced variable x
75  return (*func)(var.arg().getVal()) ;
76  }
77 
78 ////////////////////////////////////////////////////////////////////////////////
79 
81  RooAbsPdf(name,title),
82  func(&ftor),
83  var("x","x",this,x)
84 {
85 }
86 
87 ////////////////////////////////////////////////////////////////////////////////
88 
90  RooAbsPdf(other,name),
91  func(other.func),
92  var("x",this,other.var)
93 {
94  // Copy constructor
95 }
96 
97 ////////////////////////////////////////////////////////////////////////////////
98 
99 void RooFunctor1DPdfBinding::printArgs(ostream& os) const {
100  // Print object arguments and name/address of function pointer
101  os << "[ function=" << func << " " ;
102  for (Int_t i=0 ; i<numProxies() ; i++) {
103  RooAbsProxy* p = getProxy(i) ;
104  if (!TString(p->name()).BeginsWith("!")) {
105  p->print(os) ;
106  os << " " ;
107  }
108  }
109  os << "]" ;
110 }
111 
112 ////////////////////////////////////////////////////////////////////////////////
113 
115  // Return value of embedded function using value of referenced variable x
116  return (*func)(var.arg().getVal()) ;
117  }
118 
119 namespace RooFit {
120 
122  return new RooFunctor1DBinding(name,name,ftor,var) ;
123  }
124 
126  return new RooFunctor1DPdfBinding(name,name,ftor,var) ;
127  }
128 
129 }
RooAbsProxy::print
virtual void print(std::ostream &os, Bool_t addContents=kFALSE) const
Print proxy name.
Definition: RooAbsProxy.cxx:74
RooAbsArg::numProxies
Int_t numProxies() const
Return the number of registered proxies.
Definition: RooAbsArg.cxx:1275
RooFunctor1DPdfBinding::RooFunctor1DPdfBinding
RooFunctor1DPdfBinding()
Definition: RooFunctor1DBinding.h:61
RooTemplateProxy::arg
const T & arg() const
Return reference to object held in proxy.
Definition: RooTemplateProxy.h:259
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
RooFunctor1DPdfBinding::evaluate
Double_t evaluate() const
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
Definition: RooFunctor1DBinding.cxx:114
RooFunctor1DBinding::var
RooRealProxy var
Definition: RooFunctor1DBinding.h:49
RooAbsReal::getVal
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:91
RooAbsProxy::name
virtual const char * name() const
Definition: RooAbsProxy.h:40
x
Double_t x[n]
Definition: legend1.C:17
RooFunctor1DPdfBinding::func
const ROOT::Math::IBaseFunctionOneDim * func
Definition: RooFunctor1DBinding.h:74
RooAbsReal
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:61
RooAbsArg::getProxy
RooAbsProxy * getProxy(Int_t index) const
Return the nth proxy from the proxy list.
Definition: RooAbsArg.cxx:1262
TString
Basic string class.
Definition: TString.h:136
RooFunctor1DBinding
RooCFunction1Binding is a templated implementation of class RooAbsReal that binds generic C(++) funct...
Definition: RooFunctor1DBinding.h:33
RooFunctor1DBinding::evaluate
Double_t evaluate() const
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
Definition: RooFunctor1DBinding.cxx:73
RooFit::bindFunction
RooAbsReal * bindFunction(const char *name, CFUNCD1D func, RooAbsReal &x)
Definition: RooCFunction1Binding.cxx:59
RooFunctor1DBinding.h
RooFunctor1DPdfBinding
Definition: RooFunctor1DBinding.h:59
RooFit
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: RooCFunction1Binding.h:29
RooFunctor1DPdfBinding::var
RooRealProxy var
Definition: RooFunctor1DBinding.h:75
TString::BeginsWith
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:615
RooFunctor1DBinding::printArgs
void printArgs(std::ostream &os) const
Print object arguments, ie its proxies.
Definition: RooFunctor1DBinding.cxx:58
ROOT::Math::IBaseFunctionOneDim
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition: IFunction.h:135
Double_t
double Double_t
Definition: RtypesCore.h:59
RooFunctor1DBinding::func
const ROOT::Math::IBaseFunctionOneDim * func
Definition: RooFunctor1DBinding.h:48
name
char name[80]
Definition: TGX11.cxx:110
RooAbsProxy
RooAbsProxy is the abstact interface for proxy classes.
Definition: RooAbsProxy.h:30
RooAbsPdf
Definition: RooAbsPdf.h:43
RooFit::bindPdf
RooAbsPdf * bindPdf(const char *name, CFUNCD1D func, RooAbsReal &x)
Definition: RooCFunction1Binding.cxx:67
Riostream.h
RooFunctor1DBinding::RooFunctor1DBinding
RooFunctor1DBinding()
Definition: RooFunctor1DBinding.h:35
int
RooFunctor1DPdfBinding::printArgs
void printArgs(std::ostream &os) const
Print object arguments, ie its proxies.
Definition: RooFunctor1DBinding.cxx:99