RooUniformBinning.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooUniformBinning.cxx 36209 2010-10-08 21:37:36Z wouter $
00005  * Authors:                                                                  *
00006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
00007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
00008  *                                                                           *
00009  * Copyright (c) 2000-2005, Regents of the University of California          *
00010  *                          and Stanford University. All rights reserved.    *
00011  *                                                                           *
00012  * Redistribution and use in source and binary forms,                        *
00013  * with or without modification, are permitted according to the terms        *
00014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
00015  *****************************************************************************/
00016 
00017 //////////////////////////////////////////////////////////////////////////////
00018 //
00019 // BEGIN_HTML
00020 // RooUniformBinning is an implementation of RooAbsBinning that provides
00021 // a uniform binning in 'n' bins between the range end points. A RooUniformBinning
00022 // is 'elastic': if the range changes the binning will change accordingly, unlike
00023 // e.g. the binning of class RooBinning.
00024 // END_HTML
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   // Default Constructor
00046   // coverity[UNINIT_CTOR]
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   // Construct range [xlo,xhi] with 'nBins' bins
00058   setRange(xlo,xhi) ;
00059 }
00060 
00061 
00062 
00063 //_____________________________________________________________________________
00064 RooUniformBinning::~RooUniformBinning() 
00065 {
00066   // Destructor
00067   if (_array) delete[] _array ;
00068 }
00069 
00070 
00071 
00072 //_____________________________________________________________________________
00073 RooUniformBinning::RooUniformBinning(const RooUniformBinning& other, const char* name) :
00074   RooAbsBinning(name)
00075 {
00076   // Copy constructor
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   // Change range to [xlo,xhi]. A changes in range automatically
00090   // adjusts the binning as well to nBins bins in the new range
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   // Delete any out-of-date boundary arrays at this point
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   // Return the index of the bin that encloses 'x'
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   // Return the central value of the 'i'-th fit bin
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 /*bin*/) const 
00141 {
00142   // Return the bin width (same for all bins)
00143   return _binw ;
00144 }
00145 
00146 
00147 
00148 //_____________________________________________________________________________
00149 Double_t RooUniformBinning::binLow(Int_t i) const 
00150 {
00151   // Return the low edge of the 'i'-th fit bin
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   // Return the high edge of the 'i'-th fit bin
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   // Return an array of doubles with the bin boundaries
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 

Generated on Tue Jul 5 15:07:36 2011 for ROOT_528-00b_version by  doxygen 1.5.1