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