ROOT
git-r3/HEAD
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
22
Implementation of RooAbsBinning that provides
23
a uniform binning in 'n' bins between the range end points. A RooUniformBinning
24
is 'elastic': if the range changes the binning will change accordingly, unlike
25
e.g. the binning of class RooBinning.
26
**/
27
28
#include <
RooUniformBinning.h
>
29
30
#include <
RooFit/CodegenContext.h
>
31
#include <
RooMsgService.h
>
32
33
#include <
Riostream.h
>
34
35
36
using
std::endl;
37
38
39
////////////////////////////////////////////////////////////////////////////////
40
/// Construct range [xlo,xhi] with 'nBins' bins
41
42
RooUniformBinning::RooUniformBinning
(
double
xlo,
double
xhi,
Int_t
nBins,
const
char
*
name
) :
43
RooAbsBinning
(
name
),
44
_nbins
(nBins)
45
{
46
setRange
(xlo,xhi) ;
47
}
48
49
////////////////////////////////////////////////////////////////////////////////
50
/// Copy constructor
51
52
RooUniformBinning::RooUniformBinning
(
const
RooUniformBinning
&other,
const
char
*
name
)
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
63
void
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
83
void
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
97
double
RooUniformBinning::binCenter
(
Int_t
i)
const
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
114
double
RooUniformBinning::binWidth
(
Int_t
/*bin*/
)
const
115
{
116
return
_binw
;
117
}
118
119
120
121
////////////////////////////////////////////////////////////////////////////////
122
/// Return the low edge of the 'i'-th fit bin
123
124
double
RooUniformBinning::binLow
(
Int_t
i)
const
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
140
double
RooUniformBinning::binHigh
(
Int_t
i)
const
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
156
double
*
RooUniformBinning::array
()
const
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
167
std::string
168
RooUniformBinning::translateBinNumber
(
RooFit::Experimental::CodegenContext
&ctx,
RooAbsArg
const
&var,
int
coef)
const
169
{
170
return
ctx.
buildCall
(
"RooFit::Detail::MathFuncs::uniformBinNumber"
,
lowBound
(),
highBound
(), var,
numBins
(), coef);
171
}
CodegenContext.h
Riostream.h
RooMsgService.h
coutE
#define coutE(a)
Definition
RooMsgService.h:37
RooUniformBinning.h
Int_t
int Int_t
Signed integer 4 bytes (int).
Definition
RtypesCore.h:59
return
return
Definition
TDirectory.cxx:1438
name
char name[80]
Definition
TGX11.cxx:148
RooAbsArg
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition
RooAbsArg.h:76
RooAbsBinning::numBins
Int_t numBins() const
Return number of bins.
Definition
RooAbsBinning.h:44
RooAbsBinning::RooAbsBinning
RooAbsBinning(const char *name=nullptr)
Definition
RooAbsBinning.h:36
RooFit::Experimental::CodegenContext
A class to maintain the context for squashing of RooFit models into code.
Definition
CodegenContext.h:46
RooFit::Experimental::CodegenContext::buildCall
std::string buildCall(std::string const &funcname, Args_t const &...args)
Build the code to call the function with name funcname, passing some arguments.
Definition
CodegenContext.h:71
RooUniformBinning::array
double * array() const override
Return an array of doubles with the bin boundaries.
Definition
RooUniformBinning.cxx:156
RooUniformBinning::setRange
void setRange(double xlo, double xhi) override
Change range to [xlo,xhi].
Definition
RooUniformBinning.cxx:63
RooUniformBinning::_array
std::vector< double > _array
! do not persist
Definition
RooUniformBinning.h:50
RooUniformBinning::binLow
double binLow(Int_t bin) const override
Return the low edge of the 'i'-th fit bin.
Definition
RooUniformBinning.cxx:124
RooUniformBinning::highBound
double highBound() const override
Definition
RooUniformBinning.h:37
RooUniformBinning::binHigh
double binHigh(Int_t bin) const override
Return the high edge of the 'i'-th fit bin.
Definition
RooUniformBinning.cxx:140
RooUniformBinning::lowBound
double lowBound() const override
Definition
RooUniformBinning.h:36
RooUniformBinning::translateBinNumber
std::string translateBinNumber(RooFit::Experimental::CodegenContext &ctx, RooAbsArg const &var, int coef) const override
Definition
RooUniformBinning.cxx:168
RooUniformBinning::_xlo
double _xlo
Definition
RooUniformBinning.h:51
RooUniformBinning::binCenter
double binCenter(Int_t bin) const override
Return the central value of the 'i'-th fit bin.
Definition
RooUniformBinning.cxx:97
RooUniformBinning::_xhi
double _xhi
Definition
RooUniformBinning.h:52
RooUniformBinning::_binw
double _binw
Definition
RooUniformBinning.h:54
RooUniformBinning::_nbins
Int_t _nbins
Definition
RooUniformBinning.h:53
RooUniformBinning::binNumbers
void binNumbers(double const *x, int *bins, std::size_t n, int coef) const override
Return the index of the bin that encloses 'x'.
Definition
RooUniformBinning.cxx:83
RooUniformBinning::RooUniformBinning
RooUniformBinning(const char *name=nullptr)
Definition
RooUniformBinning.h:25
RooUniformBinning::binWidth
double binWidth(Int_t bin) const override
Return the bin width (same for all bins).
Definition
RooUniformBinning.cxx:114
x
Double_t x[n]
Definition
legend1.C:17
n
const Int_t n
Definition
legend1.C:16
roofit
roofitcore
src
RooUniformBinning.cxx
ROOTgit-r3/HEAD - Reference Guide Generated on
(GVA Time) using Doxygen 1.16.1