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
27#include "RooFit.h"
28#include "Riostream.h"
29
30#include "RooFunctor.h"
31#include "RooRealBinding.h"
32#include "RooAbsReal.h"
33#include "RooAbsPdf.h"
34#include "RooArgSet.h"
35
36#include <assert.h>
37
38
39
40using namespace std;
41
43;
44
45
46////////////////////////////////////////////////////////////////////////////////
47
49{
51
52 _x = new Double_t[func.getDimension()] ;
53
54 _nobs = func.getDimension() ;
55 _npar = 0 ;
56 _binding = (RooAbsFunc*) &func ;
57}
58
59
60
61////////////////////////////////////////////////////////////////////////////////
62/// Store list of observables
63
64RooFunctor::RooFunctor(const RooAbsReal& func, const RooArgList& observables, const RooArgList& parameters)
65{
66 _nset.add(observables) ;
67
68 // Make list of all variables to be bound
69 RooArgList allVars(observables) ;
70 allVars.add(parameters) ;
71
72 // Create RooFit function binding
73 _binding = new RooRealBinding(func,allVars,&_nset,kFALSE,0) ;
75
76 // Allocate transfer array
77 _x = new Double_t[allVars.getSize()] ;
78 _nobs = observables.getSize() ;
79 _npar = parameters.getSize() ;
80}
81
82
83////////////////////////////////////////////////////////////////////////////////
84/// Store normalization set
85
86RooFunctor::RooFunctor(const RooAbsReal& func, const RooArgList& observables, const RooArgList& parameters, const RooArgSet& nset)
87{
88 _nset.add(nset) ;
89
90 // Make list of all variables to be bound
91 RooArgList allVars(observables) ;
92 allVars.add(parameters) ;
93
94 // Create RooFit function binding
95 _binding = new RooRealBinding(func,allVars,&_nset,kFALSE,0) ;
97
98 // Allocate transfer array
99 _x = new Double_t[allVars.getSize()] ;
100 _nobs = observables.getSize() ;
101 _npar = parameters.getSize() ;
102}
103
104
105
106////////////////////////////////////////////////////////////////////////////////
107
109 _ownBinding(other._ownBinding),
110 _nset(other._nset),
111 _binding(0),
112 _npar(other._npar),
113 _nobs(other._nobs)
114{
115 if (other._ownBinding) {
117 } else {
118 _binding = other._binding ;
119 }
120 _x = new Double_t[_nobs+_npar] ;
121}
122
123
124
125
126////////////////////////////////////////////////////////////////////////////////
127/// Destructor
128
130{
131 if (_ownBinding) delete _binding ;
132 delete[] _x ;
133}
134
135
136
137////////////////////////////////////////////////////////////////////////////////
138
140{
141 return (*_binding)(x) ;
142}
143
144////////////////////////////////////////////////////////////////////////////////
145
147{
148 return (*_binding)(&x) ;
149}
150
151////////////////////////////////////////////////////////////////////////////////
152
154{
155 for (int i=0 ; i<_nobs ; i++) {
156 _x[i] = x[i] ;
157 }
158 for (int i=0 ; i<_npar ; i++) {
159 _x[i+_nobs] = p[i] ;
160 }
161 return (*_binding)(_x) ;
162}
const Bool_t kFALSE
Definition: RtypesCore.h:101
double Double_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:100
#define ClassImp(name)
Definition: Rtypes.h:364
Int_t getSize() const
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
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:61
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:35
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:153
RooAbsFunc * _binding
Definition: RooFunctor.h:61
Int_t _npar
Transfer array ;.
Definition: RooFunctor.h:63
virtual ~RooFunctor()
Destructor.
Definition: RooFunctor.cxx:129
Double_t * _x
Definition: RooFunctor.h:62
Int_t _nobs
Number of parameters ;.
Definition: RooFunctor.h:64
RooArgSet _nset
Definition: RooFunctor.h:60
RooFunctor(const RooAbsFunc &func)
Definition: RooFunctor.cxx:48
Bool_t _ownBinding
Definition: RooFunctor.h:59
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