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