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
31#include <RooMsgService.h>
32
33#include <Riostream.h>
34
35
36using std::endl;
37
38
39////////////////////////////////////////////////////////////////////////////////
40/// Construct range [xlo,xhi] with 'nBins' bins
41
42RooUniformBinning::RooUniformBinning(double xlo, double xhi, Int_t nBins, const char* name) :
44 _nbins(nBins)
45{
46 setRange(xlo,xhi) ;
47}
48
49////////////////////////////////////////////////////////////////////////////////
50/// Copy constructor
51
53 : RooAbsBinning(name), _xlo(other._xlo), _xhi(other._xhi), _nbins(other._nbins), _binw(other._binw)
54{
55}
56
57
58
59////////////////////////////////////////////////////////////////////////////////
60/// Change range to [xlo,xhi]. A changes in range automatically
61/// adjusts the binning as well to nBins bins in the new range
62
63void RooUniformBinning::setRange(double xlo, double xhi)
64{
65 if (xlo>xhi) {
66 coutE(InputArguments) << "RooUniformBinning::setRange: ERROR low bound > high bound" << std::endl ;
67 return ;
68 }
69
70 _xlo = xlo ;
71 _xhi = xhi ;
72 _binw = (xhi-xlo)/_nbins ;
73
74 // Delete any out-of-date boundary arrays at this point
75 _array.clear();
76}
77
78
79
80////////////////////////////////////////////////////////////////////////////////
81/// Return the index of the bin that encloses 'x'
82
83void RooUniformBinning::binNumbers(double const * x, int * bins, std::size_t n, int coef) const
84{
85 const double oneOverW = 1./_binw;
86
87 for(std::size_t i = 0; i < n; ++i) {
88 bins[i] += coef * (x[i] >= _xhi ? _nbins - 1 : std::max(0, int((x[i] - _xlo)*oneOverW)));
89 }
90}
91
92
93
94////////////////////////////////////////////////////////////////////////////////
95/// Return the central value of the 'i'-th fit bin
96
98{
99 if (i<0 || i>=_nbins) {
100 coutE(InputArguments) << "RooUniformBinning::binCenter ERROR: bin index " << i
101 << " is out of range (0," << _nbins-1 << ")" << std::endl ;
102 return 0 ;
103 }
104
105 return _xlo + (i + 0.5) * _binw;
106}
107
108
109
110
111////////////////////////////////////////////////////////////////////////////////
112/// Return the bin width (same for all bins)
113
115{
116 return _binw ;
117}
118
119
120
121////////////////////////////////////////////////////////////////////////////////
122/// Return the low edge of the 'i'-th fit bin
123
125{
126 if (i<0 || i>=_nbins) {
127 coutE(InputArguments) << "RooUniformBinning::binLow ERROR: bin index " << i
128 << " is out of range (0," << _nbins-1 << ")" << std::endl ;
129 return 0 ;
130 }
131
132 return _xlo + i*_binw ;
133}
134
135
136
137////////////////////////////////////////////////////////////////////////////////
138/// Return the high edge of the 'i'-th fit bin
139
141{
142 if (i<0 || i>=_nbins) {
143 coutE(InputArguments) << "RooUniformBinning::fitBinHigh ERROR: bin index " << i
144 << " is out of range (0," << _nbins-1 << ")" << std::endl ;
145 return 0 ;
146 }
147
148 return _xlo + (i + 1)*_binw ;
149}
150
151
152
153////////////////////////////////////////////////////////////////////////////////
154/// Return an array of doubles with the bin boundaries
155
157{
158 _array.resize(_nbins+1);
159
160 Int_t i ;
161 for (i=0 ; i<=_nbins ; i++) {
162 _array[i] = _xlo + i*_binw ;
163 }
164 return _array.data();
165}
166
167std::string
169{
170 return ctx.buildCall("RooFit::Detail::MathFuncs::uniformBinNumber", lowBound(), highBound(), var, numBins(), coef);
171}
#define coutE(a)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char name[80]
Definition TGX11.cxx:110
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
Abstract base class for RooRealVar binning definitions.
Int_t numBins() const
Return number of bins.
A class to maintain the context for squashing of RooFit models into code.
std::string buildCall(std::string const &funcname, Args_t const &...args)
Build the code to call the function with name funcname, passing some arguments.
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 highBound() const override
double binHigh(Int_t bin) const override
Return the high edge of the 'i'-th fit bin.
double lowBound() const override
std::string translateBinNumber(RooFit::Experimental::CodegenContext &ctx, RooAbsArg const &var, int coef) const override
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