Logo ROOT   6.10/09
Reference Guide
RooUniformBinning.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 RooUniformBinning.cxx
19 \class RooUniformBinning
20 \ingroup Roofitcore
21 
22 RooUniformBinning is an implementation of RooAbsBinning that provides
23 a uniform binning in 'n' bins between the range end points. A RooUniformBinning
24 is 'elastic': if the range changes the binning will change accordingly, unlike
25 e.g. the binning of class RooBinning.
26 **/
27 
28 #include "RooFit.h"
29 
30 #include "RooUniformBinning.h"
31 #include "RooUniformBinning.h"
32 #include "RooMsgService.h"
33 
34 #include "Riostream.h"
35 
36 
37 using namespace std;
38 
40 ;
41 
42 
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// Default Constructor
46 /// coverity[UNINIT_CTOR]
47 
49  RooAbsBinning(name)
50 {
51  _array = 0 ;
52 }
53 
54 
55 ////////////////////////////////////////////////////////////////////////////////
56 /// Construct range [xlo,xhi] with 'nBins' bins
57 
59  RooAbsBinning(name),
60  _array(0),
61  _nbins(nBins)
62 {
63  setRange(xlo,xhi) ;
64 }
65 
66 
67 
68 ////////////////////////////////////////////////////////////////////////////////
69 /// Destructor
70 
72 {
73  if (_array) delete[] _array ;
74 }
75 
76 
77 
78 ////////////////////////////////////////////////////////////////////////////////
79 /// Copy constructor
80 
82  RooAbsBinning(name)
83 {
84  _array = 0 ;
85  _xlo = other._xlo ;
86  _xhi = other._xhi ;
87  _nbins = other._nbins ;
88  _binw = other._binw ;
89 }
90 
91 
92 
93 ////////////////////////////////////////////////////////////////////////////////
94 /// Change range to [xlo,xhi]. A changes in range automatically
95 /// adjusts the binning as well to nBins bins in the new range
96 
98 {
99  if (xlo>xhi) {
100  coutE(InputArguments) << "RooUniformBinning::setRange: ERROR low bound > high bound" << endl ;
101  return ;
102  }
103 
104  _xlo = xlo ;
105  _xhi = xhi ;
106  _binw = (xhi-xlo)/_nbins ;
107 
108  // Delete any out-of-date boundary arrays at this point
109  if (_array) {
110  delete[] _array ;
111  _array = 0 ;
112  }
113 }
114 
115 
116 
117 ////////////////////////////////////////////////////////////////////////////////
118 /// Return the index of the bin that encloses 'x'
119 
121 {
122  Int_t bin = Int_t((x - _xlo)/_binw) ;
123  if (bin<0) return 0 ;
124  if (bin>_nbins-1) return _nbins-1 ;
125  return bin ;
126 }
127 
128 
129 
130 ////////////////////////////////////////////////////////////////////////////////
131 /// Return the central value of the 'i'-th fit bin
132 
134 {
135  if (i<0 || i>=_nbins) {
136  coutE(InputArguments) << "RooUniformBinning::binCenter ERROR: bin index " << i
137  << " is out of range (0," << _nbins-1 << ")" << endl ;
138  return 0 ;
139  }
140 
141  return _xlo + (i + 0.5)*averageBinWidth() ;
142 }
143 
144 
145 
146 
147 ////////////////////////////////////////////////////////////////////////////////
148 /// Return the bin width (same for all bins)
149 
151 {
152  return _binw ;
153 }
154 
155 
156 
157 ////////////////////////////////////////////////////////////////////////////////
158 /// Return the low edge of the 'i'-th fit bin
159 
161 {
162  if (i<0 || i>=_nbins) {
163  coutE(InputArguments) << "RooUniformBinning::binLow ERROR: bin index " << i
164  << " is out of range (0," << _nbins-1 << ")" << endl ;
165  return 0 ;
166  }
167 
168  return _xlo + i*_binw ;
169 }
170 
171 
172 
173 ////////////////////////////////////////////////////////////////////////////////
174 /// Return the high edge of the 'i'-th fit bin
175 
177 {
178  if (i<0 || i>=_nbins) {
179  coutE(InputArguments) << "RooUniformBinning::fitBinHigh ERROR: bin index " << i
180  << " is out of range (0," << _nbins-1 << ")" << endl ;
181  return 0 ;
182  }
183 
184  return _xlo + (i + 1)*_binw ;
185 }
186 
187 
188 
189 ////////////////////////////////////////////////////////////////////////////////
190 /// Return an array of doubles with the bin boundaries
191 
193 {
194  if (_array) delete[] _array ;
195  _array = new Double_t[_nbins+1] ;
196 
197  Int_t i ;
198  for (i=0 ; i<=_nbins ; i++) {
199  _array[i] = _xlo + i*_binw ;
200  }
201  return _array ;
202 }
203 
204 
#define coutE(a)
Definition: RooMsgService.h:34
int Int_t
Definition: RtypesCore.h:41
STL namespace.
virtual Double_t binCenter(Int_t bin) const
Return the central value of the &#39;i&#39;-th fit bin.
virtual Double_t * array() const
Return an array of doubles with the bin boundaries.
Double_t x[n]
Definition: legend1.C:17
RooUniformBinning(const char *name=0)
Default Constructor coverity[UNINIT_CTOR].
virtual ~RooUniformBinning()
Destructor.
virtual void setRange(Double_t xlo, Double_t xhi)
Change range to [xlo,xhi].
RooAbsBinning is the abstract base class for RooRealVar binning definitions This class defines the in...
Definition: RooAbsBinning.h:26
virtual Double_t binHigh(Int_t bin) const
Return the high edge of the &#39;i&#39;-th fit bin.
RooUniformBinning is an implementation of RooAbsBinning that provides a uniform binning in &#39;n&#39; bins b...
#define ClassImp(name)
Definition: Rtypes.h:336
double Double_t
Definition: RtypesCore.h:55
virtual Int_t binNumber(Double_t x) const
Return the index of the bin that encloses &#39;x&#39;.
virtual Double_t binWidth(Int_t bin) const
Return the bin width (same for all bins)
Double_t _xlo
do not persist
virtual Double_t binLow(Int_t bin) const
Return the low edge of the &#39;i&#39;-th fit bin.
virtual Double_t averageBinWidth() const