Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
39
40////////////////////////////////////////////////////////////////////////////////
41/// Construct range [xlo,xhi] with 'nBins' bins
42
43RooUniformBinning::RooUniformBinning(double xlo, double xhi, Int_t nBins, const char* name) :
45 _nbins(nBins)
46{
47 setRange(xlo,xhi) ;
48}
49
50////////////////////////////////////////////////////////////////////////////////
51/// Copy constructor
52
54 : RooAbsBinning(name), _xlo(other._xlo), _xhi(other._xhi), _nbins(other._nbins), _binw(other._binw)
55{
56}
57
58
59
60////////////////////////////////////////////////////////////////////////////////
61/// Change range to [xlo,xhi]. A changes in range automatically
62/// adjusts the binning as well to nBins bins in the new range
63
64void RooUniformBinning::setRange(double xlo, double xhi)
65{
66 if (xlo>xhi) {
67 coutE(InputArguments) << "RooUniformBinning::setRange: ERROR low bound > high bound" << endl ;
68 return ;
69 }
70
71 _xlo = xlo ;
72 _xhi = xhi ;
73 _binw = (xhi-xlo)/_nbins ;
74
75 // Delete any out-of-date boundary arrays at this point
76 _array.clear();
77}
78
79
80
81////////////////////////////////////////////////////////////////////////////////
82/// Return the index of the bin that encloses 'x'
83
84void RooUniformBinning::binNumbers(double const * x, int * bins, std::size_t n, int coef) const
85{
86 const double oneOverW = 1./_binw;
87
88 for(std::size_t i = 0; i < n; ++i) {
89 bins[i] += coef * (x[i] >= _xhi ? _nbins - 1 : std::max(0, int((x[i] - _xlo)*oneOverW)));
90 }
91}
92
93
94
95////////////////////////////////////////////////////////////////////////////////
96/// Return the central value of the 'i'-th fit bin
97
99{
100 if (i<0 || i>=_nbins) {
101 coutE(InputArguments) << "RooUniformBinning::binCenter ERROR: bin index " << i
102 << " is out of range (0," << _nbins-1 << ")" << endl ;
103 return 0 ;
104 }
105
106 return _xlo + (i + 0.5) * _binw;
107}
108
109
110
111
112////////////////////////////////////////////////////////////////////////////////
113/// Return the bin width (same for all bins)
114
116{
117 return _binw ;
118}
119
120
121
122////////////////////////////////////////////////////////////////////////////////
123/// Return the low edge of the 'i'-th fit bin
124
126{
127 if (i<0 || i>=_nbins) {
128 coutE(InputArguments) << "RooUniformBinning::binLow ERROR: bin index " << i
129 << " is out of range (0," << _nbins-1 << ")" << endl ;
130 return 0 ;
131 }
132
133 return _xlo + i*_binw ;
134}
135
136
137
138////////////////////////////////////////////////////////////////////////////////
139/// Return the high edge of the 'i'-th fit bin
140
142{
143 if (i<0 || i>=_nbins) {
144 coutE(InputArguments) << "RooUniformBinning::fitBinHigh ERROR: bin index " << i
145 << " is out of range (0," << _nbins-1 << ")" << endl ;
146 return 0 ;
147 }
148
149 return _xlo + (i + 1)*_binw ;
150}
151
152
153
154////////////////////////////////////////////////////////////////////////////////
155/// Return an array of doubles with the bin boundaries
156
158{
159 _array.resize(_nbins+1);
160
161 Int_t i ;
162 for (i=0 ; i<=_nbins ; i++) {
163 _array[i] = _xlo + i*_binw ;
164 }
165 return _array.data();
166}
167
168std::string
170{
171 return ctx.buildCall("RooFit::Detail::MathFuncs::uniformBinNumber", lowBound(), highBound(), var, numBins(), coef);
172}
#define coutE(a)
#define ClassImp(name)
Definition Rtypes.h:382
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:79
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::string translateBinNumber(RooFit::Detail::CodeSquashContext &ctx, RooAbsArg const &var, int coef) const override
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
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