RooRealBinding.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooRealBinding.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 // Lightweight interface adaptor that binds a RooAbsReal object to a subset
00021 // of its servers and present it as a simple array oriented interface.
00022 // END_HTML
00023 //
00024 
00025 
00026 #include "RooFit.h"
00027 #include "Riostream.h"
00028 
00029 #include "RooRealBinding.h"
00030 #include "RooAbsReal.h"
00031 #include "RooArgSet.h"
00032 #include "RooAbsRealLValue.h"
00033 #include "RooNameReg.h"
00034 #include "RooMsgService.h"
00035 
00036 #include <assert.h>
00037 
00038 
00039 
00040 ClassImp(RooRealBinding)
00041 ;
00042 
00043 
00044 //_____________________________________________________________________________
00045 RooRealBinding::RooRealBinding(const RooAbsReal& func, const RooArgSet &vars, const RooArgSet* nset, Bool_t clipInvalid, const TNamed* rangeName) :
00046   RooAbsFunc(vars.getSize()), _func(&func), _vars(0), _nset(nset), _clipInvalid(clipInvalid), _xsave(0), _rangeName(rangeName)
00047 {
00048   // Construct a lightweight function binding of RooAbsReal func to
00049   // variables 'vars'.  Use the provided nset as normalization set to
00050   // be passed to RooAbsReal::getVal() If rangeName is not null, use
00051   // the range of with that name as range associated with the
00052   // variables of this function binding. If clipInvalid is true,
00053   // values requested to the function binding that are outside the
00054   // defined range of the variables are clipped to fit in the defined
00055   // range.
00056 
00057   // allocate memory
00058   _vars= new RooAbsRealLValue*[getDimension()];
00059   if(0 == _vars) {
00060     _valid= kFALSE;
00061     return;
00062   }
00063   // check that all of the arguments are real valued and store them
00064   RooAbsArg *var = 0;
00065   TIterator* iter = vars.createIterator() ;
00066   Int_t index(0) ;
00067   while((var=(RooAbsArg*)iter->Next())) {
00068     _vars[index]= dynamic_cast<RooAbsRealLValue*>(var);
00069     if(0 == _vars[index]) {
00070       oocoutE((TObject*)0,InputArguments) << "RooRealBinding: cannot bind to " << var->GetName() << endl ;
00071       _valid= kFALSE;
00072     }
00073     index++ ;
00074   }
00075   delete iter ;
00076   _xvecValid = kTRUE ;
00077 }
00078 
00079 
00080 //_____________________________________________________________________________
00081 RooRealBinding::RooRealBinding(const RooRealBinding& other, const RooArgSet* nset) :
00082   RooAbsFunc(other), _func(other._func), _nset(nset?nset:other._nset), _xvecValid(other._xvecValid),
00083   _clipInvalid(other._clipInvalid), _xsave(0), _rangeName(other._rangeName)
00084 {
00085   // Construct a lightweight function binding of RooAbsReal func to
00086   // variables 'vars'.  Use the provided nset as normalization set to
00087   // be passed to RooAbsReal::getVal() If rangeName is not null, use
00088   // the range of with that name as range associated with the
00089   // variables of this function binding. If clipInvalid is true,
00090   // values requested to the function binding that are outside the
00091   // defined range of the variables are clipped to fit in the defined
00092   // range.
00093 
00094   // allocate memory
00095   _vars= new RooAbsRealLValue*[getDimension()];
00096 
00097   for(unsigned int index=0 ; index<getDimension() ; index++) {
00098     _vars[index]= other._vars[index] ;
00099   }
00100 }
00101 
00102 
00103 //_____________________________________________________________________________
00104 RooRealBinding::~RooRealBinding() 
00105 {
00106   // Destructor
00107 
00108   if(0 != _vars) delete[] _vars;
00109   if (_xsave) delete[] _xsave ;
00110 }
00111 
00112 
00113 
00114 //_____________________________________________________________________________
00115 void RooRealBinding::saveXVec() const
00116 {
00117   // Save value of all variables
00118 
00119   if (!_xsave) {
00120     _xsave = new Double_t[getDimension()] ;    
00121     for (UInt_t i=0 ; i<getDimension() ; i++) {
00122       _xsave[i] = _vars[i]->getVal() ;
00123     }
00124   }
00125 }
00126 
00127 
00128 //_____________________________________________________________________________
00129 void RooRealBinding::restoreXVec() const
00130 {
00131   // Restore value of all variables to previously
00132   // saved values by saveXVec()
00133 
00134   if (!_xsave) {
00135     return ;
00136   }
00137   for (UInt_t i=0 ; i<getDimension() ; i++) {
00138    _vars[i]->setVal(_xsave[i]) ;
00139   }
00140 }
00141 
00142 
00143 
00144 //_____________________________________________________________________________
00145 void RooRealBinding::loadValues(const Double_t xvector[]) const 
00146 {
00147   // Load the vector of variable values into the RooRealVars associated
00148   // as variables with the bound RooAbsReal function
00149 
00150   _xvecValid = kTRUE ;
00151   for(UInt_t index= 0; index < _dimension; index++) {
00152     if (_clipInvalid && !_vars[index]->isValidReal(xvector[index])) {
00153       _xvecValid = kFALSE ;
00154     } else {
00155       _vars[index]->setVal(xvector[index],RooNameReg::instance().constStr(_rangeName));
00156     }
00157   }
00158 }  
00159 
00160 
00161 //_____________________________________________________________________________
00162 Double_t RooRealBinding::operator()(const Double_t xvector[]) const 
00163 {
00164   // Evaluate the bound RooAbsReal at the variable values provided in xvector
00165 
00166   assert(isValid());
00167   _ncall++ ;
00168   loadValues(xvector);
00169   //cout << getName() << "(x=" << xvector[0] << ")=" << _func->getVal(_nset) << " (nset = " << (_nset? *_nset:RooArgSet()) << ")" << endl ;
00170   return _xvecValid ? _func->getVal(_nset) : 0. ;
00171 }
00172 
00173 
00174 //_____________________________________________________________________________
00175 Double_t RooRealBinding::getMinLimit(UInt_t index) const 
00176 {
00177   // Return lower limit on i-th variable 
00178   assert(isValid());
00179 
00180   return _vars[index]->getMin(RooNameReg::str(_rangeName));
00181 }
00182 
00183 
00184 //_____________________________________________________________________________
00185 Double_t RooRealBinding::getMaxLimit(UInt_t index) const 
00186 {
00187   // Return upper limit on i-th variable 
00188 
00189   assert(isValid());
00190   return _vars[index]->getMax(RooNameReg::str(_rangeName));
00191 }
00192 
00193 
00194 //_____________________________________________________________________________
00195 const char* RooRealBinding::getName() const 
00196 { 
00197   // Return name of function
00198 
00199   return _func->GetName() ; 
00200 } 
00201 
00202 
00203 //_____________________________________________________________________________
00204 std::list<Double_t>* RooRealBinding::plotSamplingHint(RooAbsRealLValue& obs, Double_t xlo, Double_t xhi) const 
00205 {
00206   return _func->plotSamplingHint(obs,xlo,xhi) ; 
00207 }

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