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