Logo ROOT  
Reference Guide
RooRealBinding.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\file RooRealBinding.cxx
19\class RooRealBinding
20\ingroup Roofitcore
21
22Lightweight interface adaptor that binds a RooAbsReal object to a subset
23of its servers and present it as a simple array oriented interface.
24**/
25
26
27#include "RooFit.h"
28#include "Riostream.h"
29
30#include "RooRealBinding.h"
31#include "RooAbsReal.h"
32#include "RooArgSet.h"
33#include "RooAbsRealLValue.h"
34#include "RooNameReg.h"
35#include "RooMsgService.h"
36
37#include <assert.h>
38
39
40
41using namespace std;
42
44;
45
46
47////////////////////////////////////////////////////////////////////////////////
48/// Construct a lightweight function binding of RooAbsReal func to
49/// variables 'vars'. Use the provided nset as normalization set to
50/// be passed to RooAbsReal::getVal() If rangeName is not null, use
51/// the range of with that name as range associated with the
52/// variables of this function binding. If clipInvalid is true,
53/// values requested to the function binding that are outside the
54/// defined range of the variables are clipped to fit in the defined
55/// range.
56
57RooRealBinding::RooRealBinding(const RooAbsReal& func, const RooArgSet &vars, const RooArgSet* nset, Bool_t clipInvalid, const TNamed* rangeName) :
58 RooAbsFunc(vars.getSize()), _func(&func), _vars(0), _nset(nset), _clipInvalid(clipInvalid), _xsave(0), _rangeName(rangeName), _funcSave(0)
59{
60 // allocate memory
62 if(0 == _vars) {
64 return;
65 }
66 // check that all of the arguments are real valued and store them
67 RooAbsArg *var = 0;
68 TIterator* iter = vars.createIterator() ;
69 Int_t index(0) ;
70 while((var=(RooAbsArg*)iter->Next())) {
71 _vars[index]= dynamic_cast<RooAbsRealLValue*>(var);
72 if(0 == _vars[index]) {
73 oocoutE((TObject*)0,InputArguments) << "RooRealBinding: cannot bind to " << var->GetName() << endl ;
75 }
76 index++ ;
77 }
78 delete iter ;
80}
81
82
83////////////////////////////////////////////////////////////////////////////////
84/// Construct a lightweight function binding of RooAbsReal func to
85/// variables 'vars'. Use the provided nset as normalization set to
86/// be passed to RooAbsReal::getVal() If rangeName is not null, use
87/// the range of with that name as range associated with the
88/// variables of this function binding. If clipInvalid is true,
89/// values requested to the function binding that are outside the
90/// defined range of the variables are clipped to fit in the defined
91/// range.
92
94 RooAbsFunc(other), _func(other._func), _nset(nset?nset:other._nset), _xvecValid(other._xvecValid),
95 _clipInvalid(other._clipInvalid), _xsave(0), _rangeName(other._rangeName), _funcSave(other._funcSave)
96{
97 // allocate memory
99
100 for(unsigned int index=0 ; index<getDimension() ; index++) {
101 _vars[index]= other._vars[index] ;
102 }
103}
104
105
106////////////////////////////////////////////////////////////////////////////////
107/// Destructor
108
110{
111 if(0 != _vars) delete[] _vars;
112 if (_xsave) delete[] _xsave ;
113}
114
115
116
117////////////////////////////////////////////////////////////////////////////////
118/// Save value of all variables
119
121{
122 if (!_xsave) {
123 _xsave = new Double_t[getDimension()] ;
124 RooArgSet* comps = _func->getComponents() ;
125 RooFIter iter = comps->fwdIterator() ;
126 RooAbsArg* arg ;
127 while ((arg=iter.next())) {
128 if (dynamic_cast<RooAbsReal*>(arg)) {
129 _compList.push_back((RooAbsReal*)(arg)) ;
130 _compSave.push_back(0) ;
131 }
132 }
133 delete comps ;
134 }
136
137 // Save components
138 list<RooAbsReal*>::iterator ci = _compList.begin() ;
139 list<Double_t>::iterator si = _compSave.begin() ;
140 while(ci!=_compList.end()) {
141 *si = (*ci)->_value ;
142 ++si ; ++ci ;
143 }
144
145 for (UInt_t i=0 ; i<getDimension() ; i++) {
146 _xsave[i] = _vars[i]->getVal() ;
147 }
148}
149
150////////////////////////////////////////////////////////////////////////////////
151/// Restore value of all variables to previously
152/// saved values by saveXVec()
153
155{
156 if (!_xsave) {
157 return ;
158 }
160
161 // Restore components
162 list<RooAbsReal*>::iterator ci = _compList.begin() ;
163 list<Double_t>::iterator si = _compSave.begin() ;
164 while (ci!=_compList.end()) {
165 (*ci)->_value = *si ;
166 ++ci ; ++si ;
167 }
168
169 for (UInt_t i=0 ; i<getDimension() ; i++) {
170 _vars[i]->setVal(_xsave[i]) ;
171 }
172}
173
174
175
176////////////////////////////////////////////////////////////////////////////////
177/// Load the vector of variable values into the RooRealVars associated
178/// as variables with the bound RooAbsReal function
179
180void RooRealBinding::loadValues(const Double_t xvector[]) const
181{
182 _xvecValid = kTRUE ;
183 const char* range = RooNameReg::instance().constStr(_rangeName) ;
184 for(UInt_t index= 0; index < _dimension; index++) {
185 if (_clipInvalid && !_vars[index]->isValidReal(xvector[index])) {
187 } else {
188 _vars[index]->setVal(xvector[index],range);
189 }
190 }
191
192}
193
194
195////////////////////////////////////////////////////////////////////////////////
196/// Evaluate the bound RooAbsReal at the variable values provided in xvector
197
199{
200 assert(isValid());
201 _ncall++ ;
202 loadValues(xvector);
203 //cout << getName() << "(x=" << xvector[0] << ")=" << _func->getVal(_nset) << " (nset = " << (_nset? *_nset:RooArgSet()) << ")" << endl ;
204 return _xvecValid ? _func->getVal(_nset) : 0. ;
205}
206
207
208////////////////////////////////////////////////////////////////////////////////
209/// Return lower limit on i-th variable
210
212{
213 assert(isValid());
214
215 return _vars[index]->getMin(RooNameReg::str(_rangeName));
216}
217
218
219////////////////////////////////////////////////////////////////////////////////
220/// Return upper limit on i-th variable
221
223{
224 assert(isValid());
225 return _vars[index]->getMax(RooNameReg::str(_rangeName));
226}
227
228
229////////////////////////////////////////////////////////////////////////////////
230/// Return name of function
231
232const char* RooRealBinding::getName() const
233{
234 return _func->GetName() ;
235}
236
237
238////////////////////////////////////////////////////////////////////////////////
239
240std::list<Double_t>* RooRealBinding::plotSamplingHint(RooAbsRealLValue& obs, Double_t xlo, Double_t xhi) const
241{
242 return _func->plotSamplingHint(obs,xlo,xhi) ;
243}
244
245
246////////////////////////////////////////////////////////////////////////////////
247
248std::list<Double_t>* RooRealBinding::binBoundaries(Int_t index) const
249{
250 return _func->binBoundaries(*_vars[index],getMinLimit(index),getMaxLimit(index));
251}
#define oocoutE(o, a)
Definition: RooMsgService.h:48
int Int_t
Definition: RtypesCore.h:43
unsigned int UInt_t
Definition: RtypesCore.h:44
const Bool_t kFALSE
Definition: RtypesCore.h:90
bool Bool_t
Definition: RtypesCore.h:61
double Double_t
Definition: RtypesCore.h:57
const Bool_t kTRUE
Definition: RtypesCore.h:89
#define ClassImp(name)
Definition: Rtypes.h:361
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:73
RooArgSet * getComponents() const
Definition: RooAbsArg.cxx:674
RooFIter fwdIterator() const
One-time forward iterator.
TIterator * createIterator(Bool_t dir=kIterForward) const
TIterator-style iteration over contained elements.
Abstract interface for evaluating a real-valued function of one real variable and performing numerica...
Definition: RooAbsFunc.h:23
Bool_t isValid() const
Definition: RooAbsFunc.h:33
UInt_t _dimension
Definition: RooAbsFunc.h:74
Int_t _ncall
Definition: RooAbsFunc.h:73
UInt_t getDimension() const
Definition: RooAbsFunc.h:29
Bool_t _valid
Definition: RooAbsFunc.h:75
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
virtual Double_t getMax(const char *name=0) const
Get maximum of currently defined range.
virtual void setVal(Double_t value)=0
virtual Double_t getMin(const char *name=0) const
Get miniminum of currently defined range.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:60
virtual std::list< Double_t > * plotSamplingHint(RooAbsRealLValue &, Double_t, Double_t) const
Definition: RooAbsReal.h:314
Double_t _value
Definition: RooAbsReal.h:449
virtual std::list< Double_t > * binBoundaries(RooAbsRealLValue &, Double_t, Double_t) const
Definition: RooAbsReal.h:313
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:90
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
A one-time forward iterator working on RooLinkedList or RooAbsCollection.
RooAbsArg * next()
Return next element or nullptr if at end.
static const char * str(const TNamed *ptr)
Return C++ string corresponding to given TNamed pointer.
Definition: RooNameReg.cxx:103
static RooNameReg & instance()
Return reference to singleton instance.
Definition: RooNameReg.cxx:51
const char * constStr(const TNamed *namePtr)
Return C++ string corresponding to given TNamed pointer.
Definition: RooNameReg.cxx:83
Lightweight interface adaptor that binds a RooAbsReal object to a subset of its servers and present i...
Double_t _funcSave
virtual ~RooRealBinding()
Destructor.
virtual void restoreXVec() const
Restore value of all variables to previously saved values by saveXVec()
void loadValues(const Double_t xvector[]) const
Load the vector of variable values into the RooRealVars associated as variables with the bound RooAbs...
virtual std::list< Double_t > * binBoundaries(Int_t) const
std::list< Double_t > _compSave
Double_t * _xsave
virtual void saveXVec() const
Save value of all variables.
virtual const char * getName() const
Return name of function.
RooRealBinding(const RooAbsReal &func, const RooArgSet &vars, const RooArgSet *nset=0, Bool_t clipInvalid=kFALSE, const TNamed *rangeName=0)
Construct a lightweight function binding of RooAbsReal func to variables 'vars'.
virtual Double_t getMinLimit(UInt_t dimension) const
Return lower limit on i-th variable.
RooAbsRealLValue ** _vars
virtual Double_t operator()(const Double_t xvector[]) const
Evaluate the bound RooAbsReal at the variable values provided in xvector.
std::list< RooAbsReal * > _compList
const RooArgSet * _nset
const RooAbsReal * _func
virtual std::list< Double_t > * plotSamplingHint(RooAbsRealLValue &, Double_t, Double_t) const
const TNamed * _rangeName
virtual Double_t getMaxLimit(UInt_t dimension) const
Return upper limit on i-th variable.
Iterator abstract base class.
Definition: TIterator.h:30
virtual TObject * Next()=0
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Mother of all ROOT objects.
Definition: TObject.h:37
@ InputArguments
Definition: RooGlobalFunc.h:68