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