Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooParamBinning.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 RooParamBinning.cxx
19\class RooParamBinning
20\ingroup Roofitcore
21
22Class RooParamBinning is an implementation of RooAbsBinning that constructs
23a binning with a range definition that depends on external RooAbsReal objects.
24The external RooAbsReal definitions are explicitly allowed to depend on other
25observables and parameters, and make it possible to define non-rectangular
26range definitions in RooFit. Objects of class RooParamBinning are made
27by the RooRealVar::setRange() that takes RooAbsReal references as arguments
28**/
29
30#include "RooFit.h"
31
32#include "RooParamBinning.h"
33#include "RooMsgService.h"
34
35#include "Riostream.h"
36
37
38using namespace std;
39
41;
42
43
44////////////////////////////////////////////////////////////////////////////////
45/// Default constructor
46/// cout << "RooParamBinning(" << this << ") default ctor" << endl ;
47
49 RooAbsBinning(name), _xlo(0), _xhi(0), _nbins(100), _binw(0), _lp(0), _owner(0)
50{
51 _array = 0 ;
52}
53
54
55////////////////////////////////////////////////////////////////////////////////
56/// Construct binning with 'nBins' bins and with a range
57/// parameterized by external RooAbsReals xloIn and xhiIn.
58
61 _array(0),
62 _xlo(&xloIn),
63 _xhi(&xhiIn),
64 _nbins(nBins),
65 _binw(0),
66 _lp(0),
67 _owner(0)
68{
69}
70
71
72
73////////////////////////////////////////////////////////////////////////////////
74/// Destructor
75
77{
78 if (_array) delete[] _array ;
79 if (_lp) delete _lp ;
80}
81
82
83
84////////////////////////////////////////////////////////////////////////////////
85/// Copy constructor
86/// cout << "RooParamBinning::cctor(" << this << ") orig = " << &other << endl ;
87
89 RooAbsBinning(name), _binw(0), _owner(0)
90{
91 _array = 0 ;
92
93 if (other._lp) {
94// cout << "RooParamBinning::cctor(this = " << this << ") taking addresses from orig ListProxy" << endl ;
95 _xlo = (RooAbsReal*) other._lp->at(0) ;
96 _xhi = (RooAbsReal*) other._lp->at(1) ;
97
98 } else {
99
100// cout << "RooParamBinning::cctor(this = " << this << ") taking addresses from orig pointers " << other._xlo << " " << other._xhi << endl ;
101
102 _xlo = other._xlo ;
103 _xhi = other._xhi ;
104 }
105
106 _nbins = other._nbins ;
107 _lp = 0 ;
108
109 //cout << "RooParamBinning::cctor(this = " << this << " xlo = " << &_xlo << " xhi = " << &_xhi << " _lp = " << _lp << " owner = " << _owner << ")" << endl ;
110}
111
112
113
114////////////////////////////////////////////////////////////////////////////////
115/// Hook function called by RooAbsRealLValue when this binning
116/// is inserted as binning for into given owner. Create
117/// list proxy registered with owner that will track and implement
118/// server directs to external RooAbsReals of this binning
119
121{
122 _owner = &owner ;
123
124 // If list proxy already exists update pointers from proxy
125// cout << "RooParamBinning::insertHook(" << this << "," << GetName() << ") _lp at beginning = " << _lp << endl ;
126 if (_lp) {
127// cout << "updating raw pointers from list proxy contents" << endl ;
128 _xlo = xlo() ;
129 _xhi = xhi() ;
130 delete _lp ;
131 }
132// cout << "_xlo = " << _xlo << " _xhi = " << _xhi << endl ;
133
134 // If list proxy does not exist, create it now
135 _lp = new RooListProxy(Form("range::%s",GetName()),"lp",&owner,kFALSE,kTRUE) ;
136 _lp->add(*_xlo) ;
137 _lp->add(*_xhi) ;
138 _xlo = 0 ;
139 _xhi = 0 ;
140
141
142}
143
144
145////////////////////////////////////////////////////////////////////////////////
146/// Hook function called by RooAbsRealLValue when this binning
147/// is removed as binning for into given owner. Delete list
148/// proxy that was inserted in owner
149
151{
152 _owner = 0 ;
153
154 // Remove list proxy from owner
155 if (_lp) {
156 _xlo = xlo() ;
157 _xhi = xhi() ;
158 delete _lp ;
159 _lp = 0 ;
160 }
161}
162
163
164
165////////////////////////////////////////////////////////////////////////////////
166/// Adjust range by adjusting values of external RooAbsReal values
167/// Only functional when external representations are lvalues
168
170{
171 if (newxlo>newxhi) {
172 coutE(InputArguments) << "RooParamBinning::setRange: ERROR low bound > high bound" << endl ;
173 return ;
174 }
175
176 RooAbsRealLValue* xlolv = dynamic_cast<RooAbsRealLValue*>(xlo()) ;
177 if (xlolv) {
178 xlolv->setVal(newxlo) ;
179 } else {
180 coutW(InputArguments) << "RooParamBinning::setRange: WARNING lower bound not represented by lvalue, cannot set lower bound value through setRange()" << endl ;
181 }
182
183 RooAbsRealLValue* xhilv = dynamic_cast<RooAbsRealLValue*>(xhi()) ;
184 if (xhilv) {
185 xhilv->setVal(newxhi) ;
186 } else {
187 coutW(InputArguments) << "RooParamBinning::setRange: WARNING upper bound not represented by lvalue, cannot set upper bound value through setRange()" << endl ;
188 }
189
190}
191
192
193
194////////////////////////////////////////////////////////////////////////////////
195/// Return the fit bin index for the current value
196
198{
199 if (x >= xhi()->getVal()) return _nbins-1 ;
200 if (x < xlo()->getVal()) return 0 ;
201
202 return Int_t((x - xlo()->getVal())/averageBinWidth()) ;
203}
204
205
206
207////////////////////////////////////////////////////////////////////////////////
208/// Return the central value of the 'i'-th fit bin
209
211{
212 if (i<0 || i>=_nbins) {
213 coutE(InputArguments) << "RooParamBinning::binCenter ERROR: bin index " << i
214 << " is out of range (0," << _nbins-1 << ")" << endl ;
215 return 0 ;
216 }
217
218 return xlo()->getVal() + (i + 0.5)*averageBinWidth() ;
219}
220
221
222
223
224////////////////////////////////////////////////////////////////////////////////
225/// Return average bin width
226
228{
229 return (xhi()->getVal()-xlo()->getVal())/_nbins ;
230}
231
232
233
234////////////////////////////////////////////////////////////////////////////////
235/// Return the low edge of the 'i'-th fit bin
236
238{
239 if (i<0 || i>=_nbins) {
240 coutE(InputArguments) << "RooParamBinning::binLow ERROR: bin index " << i
241 << " is out of range (0," << _nbins-1 << ")" << endl ;
242 return 0 ;
243 }
244
245 return xlo()->getVal() + i*binWidth(i) ;
246}
247
248
249
250////////////////////////////////////////////////////////////////////////////////
251/// Return the high edge of the 'i'-th fit bin
252
254{
255 if (i<0 || i>=_nbins) {
256 coutE(InputArguments) << "RooParamBinning::fitBinHigh ERROR: bin index " << i
257 << " is out of range (0," << _nbins-1 << ")" << endl ;
258 return 0 ;
259 }
260
261 return xlo()->getVal() + (i + 1)*binWidth(i) ;
262}
263
264
265
266////////////////////////////////////////////////////////////////////////////////
267/// Return array of bin boundaries
268
270{
271 if (_array) delete[] _array ;
272 _array = new Double_t[_nbins+1] ;
273
274 Int_t i ;
275 for (i=0 ; i<=_nbins ; i++) {
276 _array[i] = xlo()->getVal() + i*binWidth(i) ;
277 }
278 return _array ;
279}
280
281
282
283////////////////////////////////////////////////////////////////////////////////
284/// Print details of binning
285
286void RooParamBinning::printMultiline(ostream &os, Int_t /*content*/, Bool_t /*verbose*/, TString indent) const
287{
288 os << indent << "_xlo = " << _xlo << endl ;
289 os << indent << "_xhi = " << _xhi << endl ;
290 if (_lp) {
291 os << indent << "xlo() = " << xlo() << endl ;
292 os << indent << "xhi() = " << xhi() << endl ;
293 }
294 if (xlo()) {
295 xlo()->Print("t") ;
296 }
297 if (xhi()) {
298 xhi()->Print("t") ;
299 }
300}
301
302
#define coutW(a)
#define coutE(a)
int Int_t
Definition RtypesCore.h:45
const Bool_t kFALSE
Definition RtypesCore.h:92
const Bool_t kTRUE
Definition RtypesCore.h:91
#define ClassImp(name)
Definition Rtypes.h:364
static void indent(ostringstream &buf, int indent_level)
char name[80]
Definition TGX11.cxx:110
char * Form(const char *fmt,...)
virtual void Print(Option_t *options=0) const
Print the object to the defaultPrintStream().
Definition RooAbsArg.h:340
RooAbsBinning is the abstract base class for RooRealVar binning definitions.
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
virtual void setVal(Double_t value)=0
Set the current value of the object. Needs to be overridden by implementations.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:61
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:91
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Definition RooArgList.h:70
RooListProxy is the concrete proxy for RooArgList objects.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE) override
Reimplementation of standard RooArgList::add()
Class RooParamBinning is an implementation of RooAbsBinning that constructs a binning with a range de...
RooAbsReal * xhi() const
virtual Double_t binWidth(Int_t bin) const
Return average bin width.
RooListProxy * _lp
RooAbsArg * _owner
virtual ~RooParamBinning()
Destructor.
virtual Int_t binNumber(Double_t x) const
Return the fit bin index for the current value.
RooAbsReal * _xhi
RooParamBinning(const char *name=0)
Default constructor cout << "RooParamBinning(" << this << ") default ctor" << endl ;.
void printMultiline(std::ostream &os, Int_t content, Bool_t verbose=kFALSE, TString indent="") const
Print details of binning.
virtual Double_t binCenter(Int_t bin) const
Return the central value of the 'i'-th fit bin.
virtual Double_t binLow(Int_t bin) const
Return the low edge of the 'i'-th fit bin.
virtual void removeHook(RooAbsRealLValue &) const
Hook function called by RooAbsRealLValue when this binning is removed as binning for into given owner...
RooAbsReal * _xlo
do not persist
virtual void setRange(Double_t xlo, Double_t xhi)
Adjust range by adjusting values of external RooAbsReal values Only functional when external represen...
virtual Double_t averageBinWidth() const
virtual Double_t * array() const
Return array of bin boundaries.
RooAbsReal * xlo() const
virtual Double_t binHigh(Int_t bin) const
Return the high edge of the 'i'-th fit bin.
virtual void insertHook(RooAbsRealLValue &) const
Hook function called by RooAbsRealLValue when this binning is inserted as binning for into given owne...
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
Basic string class.
Definition TString.h:136
Double_t x[n]
Definition legend1.C:17