RooParamBinning.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooParamBinning.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 // Class RooParamBinning is an implementation of RooAbsBinning that constructs
00021 // a binning with a range definition that depends on external RooAbsReal objects.
00022 // The external RooAbsReal definitions are explicitly allowed to depend on other
00023 // observables and parameters, and make it possible to define non-rectangular
00024 // range definitions in RooFit. Objects of class RooParamBinning are made
00025 // by the RooRealVar::setRange() that takes RooAbsReal references as arguments
00026 // END_HTML
00027 //
00028 
00029 #include "RooFit.h"
00030 
00031 #include "RooParamBinning.h"
00032 #include "RooParamBinning.h"
00033 #include "RooMsgService.h"
00034 
00035 #include "Riostream.h"
00036 
00037 
00038 ClassImp(RooParamBinning)
00039 ;
00040 
00041 
00042 //_____________________________________________________________________________
00043 RooParamBinning::RooParamBinning(const char* name) : 
00044   RooAbsBinning(name), _xlo(0), _xhi(0), _nbins(100), _binw(0), _lp(0), _owner(0)
00045 {  
00046   // Default constructor
00047 //   cout << "RooParamBinning(" << this << ") default ctor" << endl ;
00048   _array = 0 ;
00049 }
00050 
00051 
00052 //_____________________________________________________________________________
00053 RooParamBinning::RooParamBinning(RooAbsReal& xloIn, RooAbsReal& xhiIn, Int_t nBins, const char* name) :
00054   RooAbsBinning(name),
00055   _array(0), 
00056   _xlo(&xloIn),
00057   _xhi(&xhiIn),
00058   _nbins(nBins),
00059   _binw(0),
00060   _lp(0),
00061   _owner(0)
00062 {
00063   // Construct binning with 'nBins' bins and with a range
00064   // parameterized by external RooAbsReals xloIn and xhiIn.
00065 }
00066 
00067 
00068 
00069 //_____________________________________________________________________________
00070 RooParamBinning::~RooParamBinning() 
00071 {
00072   // Destructor
00073 
00074   if (_array) delete[] _array ;
00075   if (_lp) delete _lp ;
00076 }
00077 
00078 
00079 
00080 //_____________________________________________________________________________
00081 RooParamBinning::RooParamBinning(const RooParamBinning& other, const char* name) :
00082   RooAbsBinning(name), _binw(0), _owner(0)
00083 {
00084   // Copy constructor
00085 //   cout << "RooParamBinning::cctor(" << this << ") orig = " << &other << endl ;
00086 
00087   _array = 0 ;
00088 
00089   if (other._lp) {
00090 //     cout << "RooParamBinning::cctor(this = " << this << ") taking addresses from orig  ListProxy" << endl ;
00091     _xlo = (RooAbsReal*) other._lp->at(0) ;
00092     _xhi = (RooAbsReal*) other._lp->at(1) ;
00093 
00094   } else {
00095 
00096 //     cout << "RooParamBinning::cctor(this = " << this << ") taking addresses from orig pointers " << other._xlo << " " << other._xhi << endl ;
00097 
00098     _xlo   = other._xlo ;
00099     _xhi   = other._xhi ;
00100   }
00101 
00102   _nbins = other._nbins ;
00103   _lp = 0 ;
00104 
00105   //cout << "RooParamBinning::cctor(this = " << this << " xlo = " << &_xlo << " xhi = " << &_xhi << " _lp = " << _lp << " owner = " << _owner << ")" << endl ;
00106 }
00107 
00108 
00109 
00110 //_____________________________________________________________________________
00111 void RooParamBinning::insertHook(RooAbsRealLValue& owner) const  
00112 {
00113   // Hook function called by RooAbsRealLValue when this binning
00114   // is inserted as binning for into given owner. Create
00115   // list proxy registered with owner that will track and implement
00116   // server directs to external RooAbsReals of this binning
00117 
00118   _owner = &owner ;
00119 
00120   // If list proxy already exists update pointers from proxy
00121 //   cout << "RooParamBinning::insertHook(" << this << "," << GetName() << ") _lp at beginning = " << _lp << endl ;
00122   if (_lp) {
00123 //     cout << "updating raw pointers from list proxy contents" << endl ;
00124     _xlo = xlo() ;
00125     _xhi = xhi() ;
00126     delete _lp ;
00127   }
00128 //   cout << "_xlo = " << _xlo << " _xhi = " << _xhi << endl ;
00129 
00130   // If list proxy does not exist, create it now
00131   _lp = new RooListProxy(Form("range::%s",GetName()),"lp",&owner,kFALSE,kTRUE) ;
00132   _lp->add(*_xlo) ;
00133   _lp->add(*_xhi) ;
00134   _xlo = 0 ;
00135   _xhi = 0 ;
00136 
00137 
00138 }
00139 
00140 
00141 //_____________________________________________________________________________
00142 void RooParamBinning::removeHook(RooAbsRealLValue& /*owner*/) const  
00143 {
00144   // Hook function called by RooAbsRealLValue when this binning
00145   // is removed as binning for into given owner. Delete list
00146   // proxy that was inserted in owner
00147 
00148   _owner = 0 ;
00149   
00150   // Remove list proxy from owner
00151   if (_lp) {
00152     _xlo = xlo() ;
00153     _xhi = xhi() ;
00154     delete _lp ;
00155     _lp = 0 ;
00156   }
00157 }
00158 
00159 
00160 
00161 //_____________________________________________________________________________
00162 void RooParamBinning::setRange(Double_t newxlo, Double_t newxhi) 
00163 {
00164   // Adjust range by adjusting values of external RooAbsReal values
00165   // Only functional when external representations are lvalues
00166 
00167   if (newxlo>newxhi) {
00168     coutE(InputArguments) << "RooParamBinning::setRange: ERROR low bound > high bound" << endl ;
00169     return ;
00170   }
00171 
00172   RooAbsRealLValue* xlolv = dynamic_cast<RooAbsRealLValue*>(xlo()) ;
00173   if (xlolv) {
00174     xlolv->setVal(newxlo) ;
00175   } else {
00176     coutW(InputArguments) << "RooParamBinning::setRange: WARNING lower bound not represented by lvalue, cannot set lower bound value through setRange()" << endl ;
00177   }
00178 
00179   RooAbsRealLValue* xhilv = dynamic_cast<RooAbsRealLValue*>(xhi()) ;
00180   if (xhilv) {
00181     xhilv->setVal(newxhi) ;
00182   } else {
00183     coutW(InputArguments) << "RooParamBinning::setRange: WARNING upper bound not represented by lvalue, cannot set upper bound value through setRange()" << endl ;
00184   }
00185 
00186 }
00187 
00188 
00189 
00190 //_____________________________________________________________________________
00191 Int_t RooParamBinning::binNumber(Double_t x) const  
00192 {
00193   // Return the fit bin index for the current value
00194 
00195   if (x >= xhi()->getVal()) return _nbins-1 ;
00196   if (x < xlo()->getVal()) return 0 ;
00197 
00198   return Int_t((x - xlo()->getVal())/averageBinWidth()) ;
00199 }
00200 
00201 
00202 
00203 //_____________________________________________________________________________
00204 Double_t RooParamBinning::binCenter(Int_t i) const 
00205 {
00206   // Return the central value of the 'i'-th fit bin
00207 
00208   if (i<0 || i>=_nbins) {
00209     coutE(InputArguments) << "RooParamBinning::binCenter ERROR: bin index " << i 
00210                           << " is out of range (0," << _nbins-1 << ")" << endl ;
00211     return 0 ;
00212   }
00213 
00214   return xlo()->getVal() + (i + 0.5)*averageBinWidth() ;  
00215 }
00216 
00217 
00218 
00219 
00220 //_____________________________________________________________________________
00221 Double_t RooParamBinning::binWidth(Int_t /*bin*/) const 
00222 {
00223   // Return average bin width
00224 
00225   return (xhi()->getVal()-xlo()->getVal())/_nbins ;
00226 }
00227 
00228 
00229 
00230 //_____________________________________________________________________________
00231 Double_t RooParamBinning::binLow(Int_t i) const 
00232 {
00233   // Return the low edge of the 'i'-th fit bin
00234 
00235   if (i<0 || i>=_nbins) {
00236     coutE(InputArguments) << "RooParamBinning::binLow ERROR: bin index " << i 
00237                           << " is out of range (0," << _nbins-1 << ")" << endl ;
00238     return 0 ;
00239   }
00240 
00241   return xlo()->getVal() + i*binWidth(i) ;
00242 }
00243 
00244 
00245 
00246 //_____________________________________________________________________________
00247 Double_t RooParamBinning::binHigh(Int_t i) const 
00248 {
00249   // Return the high edge of the 'i'-th fit bin
00250 
00251   if (i<0 || i>=_nbins) {
00252     coutE(InputArguments) << "RooParamBinning::fitBinHigh ERROR: bin index " << i 
00253                           << " is out of range (0," << _nbins-1 << ")" << endl ;
00254     return 0 ;
00255   }
00256 
00257   return xlo()->getVal() + (i + 1)*binWidth(i) ;
00258 }
00259 
00260 
00261 
00262 //_____________________________________________________________________________
00263 Double_t* RooParamBinning::array() const 
00264 {
00265   // Return array of bin boundaries
00266 
00267   if (_array) delete[] _array ;
00268   _array = new Double_t[_nbins+1] ;
00269 
00270   Int_t i ;
00271   for (i=0 ; i<=_nbins ; i++) {
00272     _array[i] = xlo()->getVal() + i*binWidth(i) ;
00273   }
00274   return _array ;
00275 }
00276 
00277 
00278 
00279 //_____________________________________________________________________________
00280 void RooParamBinning::printMultiline(ostream &os, Int_t /*content*/, Bool_t /*verbose*/, TString indent) const
00281 {
00282   // Print details of binning
00283   os << indent << "_xlo = " << _xlo << endl ;
00284   os << indent << "_xhi = " << _xhi << endl ;
00285   if (_lp) {
00286     os << indent << "xlo() = " << xlo() << endl ;
00287     os << indent << "xhi() = " << xhi() << endl ;
00288   }  
00289   if (xlo()) {
00290     xlo()->Print("t") ;
00291   }
00292   if (xhi()) {
00293     xhi()->Print("t") ;
00294   }
00295 }
00296 
00297 

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