Logo ROOT  
Reference Guide
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{
49
50 _x = new Double_t[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,kFALSE,0) ;
73
74 // Allocate transfer array
75 _x = new Double_t[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,kFALSE,0) ;
95
96 // Allocate transfer array
97 _x = new Double_t[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_t[_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
138{
139 return (*_binding)(x) ;
140}
141
142////////////////////////////////////////////////////////////////////////////////
143
145{
146 return (*_binding)(&x) ;
147}
148
149////////////////////////////////////////////////////////////////////////////////
150
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}
const Bool_t kFALSE
Definition: RtypesCore.h:101
const Bool_t kTRUE
Definition: RtypesCore.h:100
#define ClassImp(name)
Definition: Rtypes.h:375
winID h TVirtualViewer3D TVirtualGLPainter p
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Int_t getSize() const
Return the number of elements in the collection.
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:63
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:57
Lightweight interface adaptor that exports a RooAbsPdf as a functor.
Definition: RooFunctor.h:25
Double_t eval(const Double_t *, const Double_t *) const
Definition: RooFunctor.cxx:151
RooAbsFunc * _binding
Function binding.
Definition: RooFunctor.h:57
Int_t _npar
! Number of parameters ;
Definition: RooFunctor.h:59
virtual ~RooFunctor()
Destructor.
Definition: RooFunctor.cxx:127
Double_t * _x
! Transfer array ;
Definition: RooFunctor.h:58
Int_t _nobs
! Number of observables ;
Definition: RooFunctor.h:60
RooArgSet _nset
Normalization observables.
Definition: RooFunctor.h:56
RooFunctor(const RooAbsFunc &func)
Definition: RooFunctor.cxx:46
Bool_t _ownBinding
Do we own the binding function.
Definition: RooFunctor.h:55
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