Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooFunctor.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$Id$
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17
18/**
19\file RooFunctor.cxx
20\class RooFunctor
21\ingroup Roofitcore
22
23Lightweight interface adaptor that exports a RooAbsPdf as a functor.
24**/
25
26#include "Riostream.h"
27
28#include "RooFunctor.h"
29#include "RooRealBinding.h"
30#include "RooAbsReal.h"
31#include "RooAbsPdf.h"
32#include "RooArgSet.h"
33
34#include <assert.h>
35
36
37
38using namespace std;
39
41;
42
43
44////////////////////////////////////////////////////////////////////////////////
45
47{
48 _ownBinding = false ;
49
50 _x = new double[func.getDimension()] ;
51
52 _nobs = func.getDimension() ;
53 _npar = 0 ;
54 _binding = (RooAbsFunc*) &func ;
55}
56
57
58
59////////////////////////////////////////////////////////////////////////////////
60/// Store list of observables
61
62RooFunctor::RooFunctor(const RooAbsReal& func, const RooArgList& observables, const RooArgList& parameters)
63{
64 _nset.add(observables) ;
65
66 // Make list of all variables to be bound
67 RooArgList allVars(observables) ;
68 allVars.add(parameters) ;
69
70 // Create RooFit function binding
71 _binding = new RooRealBinding(func,allVars,&_nset,false,0) ;
72 _ownBinding = true ;
73
74 // Allocate transfer array
75 _x = new double[allVars.getSize()] ;
76 _nobs = observables.getSize() ;
77 _npar = parameters.getSize() ;
78}
79
80
81////////////////////////////////////////////////////////////////////////////////
82/// Store normalization set
83
84RooFunctor::RooFunctor(const RooAbsReal& func, const RooArgList& observables, const RooArgList& parameters, const RooArgSet& nset)
85{
86 _nset.add(nset) ;
87
88 // Make list of all variables to be bound
89 RooArgList allVars(observables) ;
90 allVars.add(parameters) ;
91
92 // Create RooFit function binding
93 _binding = new RooRealBinding(func,allVars,&_nset,false,0) ;
94 _ownBinding = true ;
95
96 // Allocate transfer array
97 _x = new double[allVars.getSize()] ;
98 _nobs = observables.getSize() ;
99 _npar = parameters.getSize() ;
100}
101
102
103
104////////////////////////////////////////////////////////////////////////////////
105
107 _ownBinding(other._ownBinding),
108 _nset(other._nset),
109 _binding(0),
110 _npar(other._npar),
111 _nobs(other._nobs)
112{
113 if (other._ownBinding) {
115 } else {
116 _binding = other._binding ;
117 }
118 _x = new double[_nobs+_npar] ;
119}
120
121
122
123
124////////////////////////////////////////////////////////////////////////////////
125/// Destructor
126
128{
129 if (_ownBinding) delete _binding ;
130 delete[] _x ;
131}
132
133
134
135////////////////////////////////////////////////////////////////////////////////
136
137double RooFunctor::eval(const double *x) const
138{
139 return (*_binding)(x) ;
140}
141
142////////////////////////////////////////////////////////////////////////////////
143
144double RooFunctor::eval(double x) const
145{
146 return (*_binding)(&x) ;
147}
148
149////////////////////////////////////////////////////////////////////////////////
150
151double RooFunctor::eval(const double *x, const double *p) const
152{
153 for (int i=0 ; i<_nobs ; i++) {
154 _x[i] = x[i] ;
155 }
156 for (int i=0 ; i<_npar ; i++) {
157 _x[i+_nobs] = p[i] ;
158 }
159 return (*_binding)(_x) ;
160}
#define ClassImp(name)
Definition Rtypes.h:377
winID h TVirtualViewer3D TVirtualGLPainter p
Int_t getSize() const
Return the number of elements in the collection.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Abstract interface for evaluating a real-valued function of one real variable and performing numerica...
Definition RooAbsFunc.h:27
UInt_t getDimension() const
Definition RooAbsFunc.h:33
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:62
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
Lightweight interface adaptor that exports a RooAbsPdf as a functor.
Definition RooFunctor.h:25
RooAbsFunc * _binding
Function binding.
Definition RooFunctor.h:57
Int_t _npar
! Number of parameters ;
Definition RooFunctor.h:59
double * _x
! Transfer array ;
Definition RooFunctor.h:58
virtual ~RooFunctor()
Destructor.
Int_t _nobs
! Number of observables ;
Definition RooFunctor.h:60
bool _ownBinding
Do we own the binding function.
Definition RooFunctor.h:55
RooArgSet _nset
Normalization observables.
Definition RooFunctor.h:56
double eval(const double *, const double *) const
RooFunctor(const RooAbsFunc &func)
Lightweight interface adaptor that binds a RooAbsReal object to a subset of its servers and present i...
Double_t x[n]
Definition legend1.C:17