Logo ROOT   6.10/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 \file RooFunctor.cxx
20 \class RooFunctor
21 \ingroup Roofitcore
22 
23 Lightweight 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 
40 using namespace std;
41 
43 ;
44 
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 
49 {
50  _ownBinding = kFALSE ;
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 
64 RooFunctor::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) ;
74  _ownBinding = kTRUE ;
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 
86 RooFunctor::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) ;
96  _ownBinding = kTRUE ;
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 
153 Double_t RooFunctor::eval(const Double_t *x, const Double_t *p) const
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 }
RooFunctor(const RooAbsFunc &func)
Definition: RooFunctor.cxx:48
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
virtual ~RooFunctor()
Destructor.
Definition: RooFunctor.cxx:129
STL namespace.
Double_t eval(const Double_t *, const Double_t *) const
Definition: RooFunctor.cxx:153
Double_t x[n]
Definition: legend1.C:17
RooArgSet _nset
Definition: RooFunctor.h:60
Int_t _nobs
Number of parameters ;.
Definition: RooFunctor.h:64
Int_t getSize() const
UInt_t getDimension() const
Definition: RooAbsFunc.h:29
const Bool_t kFALSE
Definition: RtypesCore.h:92
#define ClassImp(name)
Definition: Rtypes.h:336
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
Lightweight interface adaptor that exports a RooAbsPdf as a functor.
Definition: RooFunctor.h:25
Lightweight interface adaptor that binds a RooAbsReal object to a subset of its servers and present i...
const Bool_t kTRUE
Definition: RtypesCore.h:91
Abstract interface for evaluating a real-valued function of one real variable and performing numerica...
Definition: RooAbsFunc.h:23
Double_t * _x
Definition: RooFunctor.h:62