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