00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "RooFit.h"
00028
00029 #include "RooUniformBinning.h"
00030 #include "RooUniformBinning.h"
00031 #include "RooMsgService.h"
00032
00033 #include "Riostream.h"
00034
00035
00036 ClassImp(RooUniformBinning)
00037 ;
00038
00039
00040
00041
00042 RooUniformBinning::RooUniformBinning(const char* name) :
00043 RooAbsBinning(name)
00044 {
00045
00046
00047 _array = 0 ;
00048 }
00049
00050
00051
00052 RooUniformBinning::RooUniformBinning(Double_t xlo, Double_t xhi, Int_t nBins, const char* name) :
00053 RooAbsBinning(name),
00054 _array(0),
00055 _nbins(nBins)
00056 {
00057
00058 setRange(xlo,xhi) ;
00059 }
00060
00061
00062
00063
00064 RooUniformBinning::~RooUniformBinning()
00065 {
00066
00067 if (_array) delete[] _array ;
00068 }
00069
00070
00071
00072
00073 RooUniformBinning::RooUniformBinning(const RooUniformBinning& other, const char* name) :
00074 RooAbsBinning(name)
00075 {
00076
00077 _array = 0 ;
00078 _xlo = other._xlo ;
00079 _xhi = other._xhi ;
00080 _nbins = other._nbins ;
00081 _binw = other._binw ;
00082 }
00083
00084
00085
00086
00087 void RooUniformBinning::setRange(Double_t xlo, Double_t xhi)
00088 {
00089
00090
00091
00092 if (xlo>xhi) {
00093 coutE(InputArguments) << "RooUniformBinning::setRange: ERROR low bound > high bound" << endl ;
00094 return ;
00095 }
00096
00097 _xlo = xlo ;
00098 _xhi = xhi ;
00099 _binw = (xhi-xlo)/_nbins ;
00100
00101
00102 if (_array) {
00103 delete[] _array ;
00104 _array = 0 ;
00105 }
00106 }
00107
00108
00109
00110
00111 Int_t RooUniformBinning::binNumber(Double_t x) const
00112 {
00113
00114
00115 Int_t bin = Int_t((x - _xlo)/_binw) ;
00116 if (bin<0) return 0 ;
00117 if (bin>_nbins-1) return _nbins-1 ;
00118 return bin ;
00119 }
00120
00121
00122
00123
00124 Double_t RooUniformBinning::binCenter(Int_t i) const
00125 {
00126
00127 if (i<0 || i>=_nbins) {
00128 coutE(InputArguments) << "RooUniformBinning::binCenter ERROR: bin index " << i
00129 << " is out of range (0," << _nbins-1 << ")" << endl ;
00130 return 0 ;
00131 }
00132
00133 return _xlo + (i + 0.5)*averageBinWidth() ;
00134 }
00135
00136
00137
00138
00139
00140 Double_t RooUniformBinning::binWidth(Int_t ) const
00141 {
00142
00143 return _binw ;
00144 }
00145
00146
00147
00148
00149 Double_t RooUniformBinning::binLow(Int_t i) const
00150 {
00151
00152
00153 if (i<0 || i>=_nbins) {
00154 coutE(InputArguments) << "RooUniformBinning::binLow ERROR: bin index " << i
00155 << " is out of range (0," << _nbins-1 << ")" << endl ;
00156 return 0 ;
00157 }
00158
00159 return _xlo + i*_binw ;
00160 }
00161
00162
00163
00164
00165 Double_t RooUniformBinning::binHigh(Int_t i) const
00166 {
00167
00168
00169 if (i<0 || i>=_nbins) {
00170 coutE(InputArguments) << "RooUniformBinning::fitBinHigh ERROR: bin index " << i
00171 << " is out of range (0," << _nbins-1 << ")" << endl ;
00172 return 0 ;
00173 }
00174
00175 return _xlo + (i + 1)*_binw ;
00176 }
00177
00178
00179
00180
00181 Double_t* RooUniformBinning::array() const
00182 {
00183
00184 if (_array) delete[] _array ;
00185 _array = new Double_t[_nbins+1] ;
00186
00187 Int_t i ;
00188 for (i=0 ; i<=_nbins ; i++) {
00189 _array[i] = _xlo + i*_binw ;
00190 }
00191 return _array ;
00192 }
00193
00194