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 "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
55RooUniformBinning::RooUniformBinning(double xlo, double xhi, Int_t nBins, const char* name) :
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
94void RooUniformBinning::setRange(double xlo, double xhi)
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
117void RooUniformBinning::binNumbers(double const * x, int * bins, std::size_t n, int coef) const
118{
119 const double oneOverW = 1./_binw;
120
121 for(std::size_t i = 0; i < n; ++i) {
122 bins[i] += coef * (x[i] >= _xhi ? _nbins - 1 : std::max(0, int((x[i] - _xlo)*oneOverW)));
123 }
124}
125
126
127
128////////////////////////////////////////////////////////////////////////////////
129/// Return the central value of the 'i'-th fit bin
130
132{
133 if (i<0 || i>=_nbins) {
134 coutE(InputArguments) << "RooUniformBinning::binCenter ERROR: bin index " << i
135 << " is out of range (0," << _nbins-1 << ")" << endl ;
136 return 0 ;
137 }
138
139 return _xlo + (i + 0.5) * _binw;
140}
141
142
143
144
145////////////////////////////////////////////////////////////////////////////////
146/// Return the bin width (same for all bins)
147
149{
150 return _binw ;
151}
152
153
154
155////////////////////////////////////////////////////////////////////////////////
156/// Return the low edge of the 'i'-th fit bin
157
159{
160 if (i<0 || i>=_nbins) {
161 coutE(InputArguments) << "RooUniformBinning::binLow ERROR: bin index " << i
162 << " is out of range (0," << _nbins-1 << ")" << endl ;
163 return 0 ;
164 }
165
166 return _xlo + i*_binw ;
167}
168
169
170
171////////////////////////////////////////////////////////////////////////////////
172/// Return the high edge of the 'i'-th fit bin
173
175{
176 if (i<0 || i>=_nbins) {
177 coutE(InputArguments) << "RooUniformBinning::fitBinHigh ERROR: bin index " << i
178 << " is out of range (0," << _nbins-1 << ")" << endl ;
179 return 0 ;
180 }
181
182 return _xlo + (i + 1)*_binw ;
183}
184
185
186
187////////////////////////////////////////////////////////////////////////////////
188/// Return an array of doubles with the bin boundaries
189
191{
192 if (_array) delete[] _array ;
193 _array = new double[_nbins+1] ;
194
195 Int_t i ;
196 for (i=0 ; i<=_nbins ; i++) {
197 _array[i] = _xlo + i*_binw ;
198 }
199 return _array ;
200}
201
202
#define coutE(a)
#define ClassImp(name)
Definition Rtypes.h:377
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...
double * array() const override
Return an array of doubles with the bin boundaries.
void setRange(double xlo, double xhi) override
Change range to [xlo,xhi].
double binLow(Int_t bin) const override
Return the low edge of the 'i'-th fit bin.
~RooUniformBinning() override
Destructor.
double binHigh(Int_t bin) const override
Return the high edge of the 'i'-th fit bin.
double binCenter(Int_t bin) const override
Return the central value of the 'i'-th fit bin.
double * _array
! do not persist
void binNumbers(double const *x, int *bins, std::size_t n, int coef) const override
Return the index of the bin that encloses 'x'.
RooUniformBinning(const char *name=nullptr)
Default Constructor coverity[UNINIT_CTOR].
double binWidth(Int_t bin) const override
Return the bin width (same for all bins)
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16