Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
22Implementation 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 std::endl, std::ostream;
37
38
39
40////////////////////////////////////////////////////////////////////////////////
41/// Default constructor
42
47
48
49////////////////////////////////////////////////////////////////////////////////
50/// Construct binning with 'nBins' bins and with a range
51/// parameterized by external RooAbsReals xloIn and xhiIn.
52
55 _xlo(&xloIn),
56 _xhi(&xhiIn),
57 _nbins(nBins)
58{
59}
60
61
62
63////////////////////////////////////////////////////////////////////////////////
64/// Destructor
65
67{
68 if (_array) delete[] _array ;
69 if (_lp) delete _lp ;
70}
71
72
73
74////////////////////////////////////////////////////////////////////////////////
75/// Copy constructor
76/// std::cout << "RooParamBinning::cctor(" << this << ") orig = " << &other << std::endl ;
77
79{
80
81 if (other._lp) {
82// std::cout << "RooParamBinning::cctor(this = " << this << ") taking addresses from orig ListProxy" << std::endl ;
83 _xlo = static_cast<RooAbsReal*>(other._lp->at(0)) ;
84 _xhi = static_cast<RooAbsReal*>(other._lp->at(1)) ;
85
86 } else {
87
88// std::cout << "RooParamBinning::cctor(this = " << this << ") taking addresses from orig pointers " << other._xlo << " " << other._xhi << std::endl ;
89
90 _xlo = other._xlo ;
91 _xhi = other._xhi ;
92 }
93
94 _nbins = other._nbins ;
95 _lp = nullptr ;
96
97 //cout << "RooParamBinning::cctor(this = " << this << " xlo = " << &_xlo << " xhi = " << &_xhi << " _lp = " << _lp << " owner = " << _owner << ")" << std::endl ;
98}
99
100
101
102////////////////////////////////////////////////////////////////////////////////
103/// Hook function called by RooAbsRealLValue when this binning
104/// is inserted as binning for into given owner. Create
105/// list proxy registered with owner that will track and implement
106/// server directs to external RooAbsReals of this binning
107
109{
110 _owner = &owner ;
111
112 // If list proxy already exists update pointers from proxy
113// std::cout << "RooParamBinning::insertHook(" << this << "," << GetName() << ") _lp at beginning = " << _lp << std::endl ;
114 if (_lp) {
115// std::cout << "updating raw pointers from list proxy contents" << std::endl ;
116 _xlo = xlo() ;
117 _xhi = xhi() ;
118 delete _lp ;
119 }
120// std::cout << "_xlo = " << _xlo << " _xhi = " << _xhi << std::endl ;
121
122 // If list proxy does not exist, create it now
123 _lp = new RooListProxy(Form("range::%s",GetName()),"lp",&owner,false,true) ;
124 _lp->add(*_xlo) ;
125 _lp->add(*_xhi) ;
126 _xlo = nullptr ;
127 _xhi = nullptr ;
128
129
130}
131
132
133////////////////////////////////////////////////////////////////////////////////
134/// Hook function called by RooAbsRealLValue when this binning
135/// is removed as binning for into given owner. Delete list
136/// proxy that was inserted in owner
137
139{
140 _owner = nullptr ;
141
142 // Remove list proxy from owner
143 if (_lp) {
144 _xlo = xlo() ;
145 _xhi = xhi() ;
146 delete _lp ;
147 _lp = nullptr ;
148 }
149}
150
151
152
153////////////////////////////////////////////////////////////////////////////////
154/// Adjust range by adjusting values of external RooAbsReal values
155/// Only functional when external representations are lvalues
156
158{
159 if (newxlo>newxhi) {
160 coutE(InputArguments) << "RooParamBinning::setRange: ERROR low bound > high bound" << std::endl ;
161 return ;
162 }
163
164 RooAbsRealLValue* xlolv = dynamic_cast<RooAbsRealLValue*>(xlo()) ;
165 if (xlolv) {
166 xlolv->setVal(newxlo) ;
167 } else {
168 coutW(InputArguments) << "RooParamBinning::setRange: WARNING lower bound not represented by lvalue, cannot set lower bound value through setRange()" << std::endl ;
169 }
170
171 RooAbsRealLValue* xhilv = dynamic_cast<RooAbsRealLValue*>(xhi()) ;
172 if (xhilv) {
173 xhilv->setVal(newxhi) ;
174 } else {
175 coutW(InputArguments) << "RooParamBinning::setRange: WARNING upper bound not represented by lvalue, cannot set upper bound value through setRange()" << std::endl ;
176 }
177
178}
179
180
181
182////////////////////////////////////////////////////////////////////////////////
183/// Return the fit bin index for the current value
184
185void RooParamBinning::binNumbers(double const * x, int * bins, std::size_t n, int coef) const
186{
187 const double xloVal = xlo()->getVal();
188 const double xhiVal = xhi()->getVal();
189 const double oneOverW = 1./averageBinWidth();
190
191 for(std::size_t i = 0; i < n; ++i) {
192 bins[i] += coef * (x[i] >= xhiVal ? _nbins - 1 : std::max(0, int((x[i] - xloVal)*oneOverW)));
193 }
194}
195
196
197
198////////////////////////////////////////////////////////////////////////////////
199/// Return the central value of the 'i'-th fit bin
200
202{
203 if (i<0 || i>=_nbins) {
204 coutE(InputArguments) << "RooParamBinning::binCenter ERROR: bin index " << i
205 << " is out of range (0," << _nbins-1 << ")" << std::endl ;
206 return 0 ;
207 }
208
209 return xlo()->getVal() + (i + 0.5)*averageBinWidth() ;
210}
211
212
213
214
215////////////////////////////////////////////////////////////////////////////////
216/// Return average bin width
217
218double RooParamBinning::binWidth(Int_t /*bin*/) const
219{
220 return (xhi()->getVal()-xlo()->getVal())/_nbins ;
221}
222
223
224
225////////////////////////////////////////////////////////////////////////////////
226/// Return the low edge of the 'i'-th fit bin
227
229{
230 if (i<0 || i>=_nbins) {
231 coutE(InputArguments) << "RooParamBinning::binLow ERROR: bin index " << i
232 << " is out of range (0," << _nbins-1 << ")" << std::endl ;
233 return 0 ;
234 }
235
236 return xlo()->getVal() + i*binWidth(i) ;
237}
238
239
240
241////////////////////////////////////////////////////////////////////////////////
242/// Return the high edge of the 'i'-th fit bin
243
245{
246 if (i<0 || i>=_nbins) {
247 coutE(InputArguments) << "RooParamBinning::fitBinHigh ERROR: bin index " << i
248 << " is out of range (0," << _nbins-1 << ")" << std::endl ;
249 return 0 ;
250 }
251
252 return xlo()->getVal() + (i + 1)*binWidth(i) ;
253}
254
255
256
257////////////////////////////////////////////////////////////////////////////////
258/// Return array of bin boundaries
259
261{
262 if (_array) delete[] _array ;
263 _array = new double[_nbins+1] ;
264
265 Int_t i ;
266 for (i=0 ; i<=_nbins ; i++) {
267 _array[i] = xlo()->getVal() + i*binWidth(i) ;
268 }
269 return _array ;
270}
271
272
273
274////////////////////////////////////////////////////////////////////////////////
275/// Print details of binning
276
277void RooParamBinning::printMultiline(ostream &os, Int_t /*content*/, bool /*verbose*/, TString indent) const
278{
279 os << indent << "_xlo = " << _xlo << std::endl ;
280 os << indent << "_xhi = " << _xhi << std::endl ;
281 if (_lp) {
282 os << indent << "xlo() = " << xlo() << std::endl ;
283 os << indent << "xhi() = " << xhi() << std::endl ;
284 }
285 if (xlo()) {
286 xlo()->Print("t") ;
287 }
288 if (xhi()) {
289 xhi()->Print("t") ;
290 }
291}
RooCollectionProxy< RooArgList > RooListProxy
Definition RooAbsArg.h:53
#define coutW(a)
#define coutE(a)
static void indent(ostringstream &buf, int indent_level)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char name[80]
Definition TGX11.cxx:110
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
void Print(Option_t *options=nullptr) const override
Print the object to the defaultPrintStream().
Definition RooAbsArg.h:263
Abstract base class for RooRealVar binning definitions.
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:103
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...
Implementation of RooAbsBinning that constructs a binning with a range definition that depends on ext...
RooParamBinning(const char *name=nullptr)
Default constructor.
RooAbsReal * xhi() const
RooListProxy * _lp
RooAbsArg * _owner
~RooParamBinning() override
Destructor.
RooAbsReal * _xhi
void insertHook(RooAbsRealLValue &) const override
Hook function called by RooAbsRealLValue when this binning is inserted as binning for into given owne...
double * array() const override
Return array of bin boundaries.
double binCenter(Int_t bin) const override
Return the central value of the 'i'-th fit bin.
double binHigh(Int_t bin) const override
Return the high edge of the 'i'-th fit bin.
double binLow(Int_t bin) const override
Return the low edge of the 'i'-th fit bin.
void binNumbers(double const *x, int *bins, std::size_t n, int coef) const override
Return the fit bin index for the current value.
double binWidth(Int_t bin) const override
Return average bin width.
double averageBinWidth() const override
RooAbsReal * _xlo
do not persist
void printMultiline(std::ostream &os, Int_t content, bool verbose=false, TString indent="") const override
Print details of binning.
void removeHook(RooAbsRealLValue &) const override
Hook function called by RooAbsRealLValue when this binning is removed as binning for into given owner...
void setRange(double xlo, double 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:49
Basic string class.
Definition TString.h:139
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16