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
22Implementation 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 std::endl;
35
37
38////////////////////////////////////////////////////////////////////////////////
39/// Construct range [xlo,xhi] with 'nBins' bins
40
41RooUniformBinning::RooUniformBinning(double xlo, double xhi, Int_t nBins, const char* name) :
43 _nbins(nBins)
44{
45 setRange(xlo,xhi) ;
46}
47
48////////////////////////////////////////////////////////////////////////////////
49/// Copy constructor
50
52 : RooAbsBinning(name), _xlo(other._xlo), _xhi(other._xhi), _nbins(other._nbins), _binw(other._binw)
53{
54}
55
56
57
58////////////////////////////////////////////////////////////////////////////////
59/// Change range to [xlo,xhi]. A changes in range automatically
60/// adjusts the binning as well to nBins bins in the new range
61
62void RooUniformBinning::setRange(double xlo, double xhi)
63{
64 if (xlo>xhi) {
65 coutE(InputArguments) << "RooUniformBinning::setRange: ERROR low bound > high bound" << endl ;
66 return ;
67 }
68
69 _xlo = xlo ;
70 _xhi = xhi ;
71 _binw = (xhi-xlo)/_nbins ;
72
73 // Delete any out-of-date boundary arrays at this point
74 _array.clear();
75}
76
77
78
79////////////////////////////////////////////////////////////////////////////////
80/// Return the index of the bin that encloses 'x'
81
82void RooUniformBinning::binNumbers(double const * x, int * bins, std::size_t n, int coef) const
83{
84 const double oneOverW = 1./_binw;
85
86 for(std::size_t i = 0; i < n; ++i) {
87 bins[i] += coef * (x[i] >= _xhi ? _nbins - 1 : std::max(0, int((x[i] - _xlo)*oneOverW)));
88 }
89}
90
91
92
93////////////////////////////////////////////////////////////////////////////////
94/// Return the central value of the 'i'-th fit bin
95
97{
98 if (i<0 || i>=_nbins) {
99 coutE(InputArguments) << "RooUniformBinning::binCenter ERROR: bin index " << i
100 << " is out of range (0," << _nbins-1 << ")" << endl ;
101 return 0 ;
102 }
103
104 return _xlo + (i + 0.5) * _binw;
105}
106
107
108
109
110////////////////////////////////////////////////////////////////////////////////
111/// Return the bin width (same for all bins)
112
114{
115 return _binw ;
116}
117
118
119
120////////////////////////////////////////////////////////////////////////////////
121/// Return the low edge of the 'i'-th fit bin
122
124{
125 if (i<0 || i>=_nbins) {
126 coutE(InputArguments) << "RooUniformBinning::binLow ERROR: bin index " << i
127 << " is out of range (0," << _nbins-1 << ")" << endl ;
128 return 0 ;
129 }
130
131 return _xlo + i*_binw ;
132}
133
134
135
136////////////////////////////////////////////////////////////////////////////////
137/// Return the high edge of the 'i'-th fit bin
138
140{
141 if (i<0 || i>=_nbins) {
142 coutE(InputArguments) << "RooUniformBinning::fitBinHigh ERROR: bin index " << i
143 << " is out of range (0," << _nbins-1 << ")" << endl ;
144 return 0 ;
145 }
146
147 return _xlo + (i + 1)*_binw ;
148}
149
150
151
152////////////////////////////////////////////////////////////////////////////////
153/// Return an array of doubles with the bin boundaries
154
156{
157 _array.resize(_nbins+1);
158
159 Int_t i ;
160 for (i=0 ; i<=_nbins ; i++) {
161 _array[i] = _xlo + i*_binw ;
162 }
163 return _array.data();
164}
165
166
#define coutE(a)
std::vector< double > _binw
!
Definition RooNLLVar.h:49
#define ClassImp(name)
Definition Rtypes.h:377
char name[80]
Definition TGX11.cxx:110
Abstract base class for RooRealVar binning definitions.
Implementation of RooAbsBinning that provides a uniform binning in 'n' bins between the range end poi...
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].
std::vector< double > _array
! do not persist
double binLow(Int_t bin) const override
Return the low edge of the 'i'-th fit bin.
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.
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)
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