RooConvIntegrandBinding.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooConvIntegrandBinding.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 // Implementation of RooAbsFunc that represent the the integrand
00021 // of a generic (numeric) convolution A (x) B so that it can be
00022 // passed to a numeric integrator. This is a utility class for
00023 // RooNumConvPdf
00024 // END_HTML
00025 //
00026 
00027 #include "RooFit.h"
00028 
00029 #include "RooConvIntegrandBinding.h"
00030 #include "RooAbsReal.h"
00031 #include "RooArgSet.h"
00032 #include "RooAbsRealLValue.h"
00033 #include "RooMsgService.h"
00034 
00035 #include <assert.h>
00036 
00037 ClassImp(RooConvIntegrandBinding)
00038 ;
00039 
00040 
00041 //_____________________________________________________________________________
00042 RooConvIntegrandBinding::RooConvIntegrandBinding(const RooAbsReal& func, const RooAbsReal& model, 
00043                                        RooAbsReal& xprime, RooAbsReal& x, 
00044                                        const RooArgSet* nset, Bool_t clipInvalid) :
00045 
00046   RooAbsFunc(2), _func(&func), _model(&model), _vars(0), _nset(nset), _clipInvalid(clipInvalid)
00047 {
00048   // Constructor where func and model 
00049   //
00050   // 'func'  = func(xprime)
00051   // 'model' = model(xprime)
00052   // 
00053   // and 
00054 
00055   // 'xprime' is the RRV that should be connected to func and model 
00056   //          (i.e. the variable that will be integrated over)
00057   // 'x'      is RRV that represents the value at which the convolution is calculated
00058   //          (this variable should _not_ be connected to func and model)
00059   //
00060   // this function returns RCBB[x',x] = f[x']*g[x-x'], i.e. the substiturion g[x'] --> g[x-x'] 
00061   // is taken care internally
00062   // 
00063   // The integral of this binding over its 1st arg yields the convolution (f (x) g)[x]
00064   //
00065         
00066   // allocate memory
00067   _vars= new RooAbsRealLValue*[2];
00068   if(0 == _vars) {
00069     _valid= kFALSE;
00070     return;
00071   }
00072 
00073   // check that all of the arguments are real valued and store them
00074   _vars[0]= dynamic_cast<RooAbsRealLValue*>(&xprime);
00075   if(0 == _vars[0]) {
00076     oocoutE(&func,InputArguments) << "RooConvIntegrandBinding: cannot bind to ";
00077     xprime.Print("1");
00078     _valid= kFALSE;
00079   }
00080 
00081   _vars[1]= dynamic_cast<RooAbsRealLValue*>(&x);
00082   if(0 == _vars[1]) {
00083     oocoutE(&func,InputArguments) << "RooConvIntegrandBinding: cannot bind to ";
00084     x.Print("1");
00085     _valid= kFALSE;
00086   }
00087 
00088   _xvecValid = kTRUE ;
00089 }
00090 
00091 
00092 
00093 //_____________________________________________________________________________
00094 RooConvIntegrandBinding::~RooConvIntegrandBinding() 
00095 {
00096   // Destructor
00097   if(0 != _vars) delete[] _vars;
00098 }
00099 
00100 
00101 //_____________________________________________________________________________
00102 void RooConvIntegrandBinding::loadValues(const Double_t xvector[], Bool_t clipInvalid) const 
00103 {
00104   // Load external input values
00105 
00106   _xvecValid = kTRUE ;
00107   for(UInt_t index= 0; index < _dimension; index++) {
00108     if (clipInvalid && !_vars[index]->isValidReal(xvector[index])) {
00109       _xvecValid = kFALSE ;
00110     } else {
00111       //cout << "RooConvBasBinding::loadValues[" << index << "] loading value " << xvector[index] << endl ;
00112       _vars[index]->setVal(xvector[index]);
00113     }
00114   }
00115 }  
00116 
00117 
00118 //_____________________________________________________________________________
00119 Double_t RooConvIntegrandBinding::operator()(const Double_t xvector[]) const 
00120 {
00121   // Evaluate self at given parameter values
00122 
00123   assert(isValid());
00124   _ncall++ ;
00125 
00126   // First evaluate function at x'
00127   loadValues(xvector);
00128   if (!_xvecValid) return 0 ;
00129   //cout << "RooConvIntegrandBinding::operator(): evaluating f(x') at x' = " << xvector[0] << endl ;
00130   Double_t f_xp = _func->getVal(_nset) ;
00131 
00132   // Next evaluate model at x-x'
00133   const Double_t xvec_tmp[2] = { xvector[1]-xvector[0] , xvector[1] } ;
00134   loadValues(xvec_tmp,kTRUE);
00135   if (!_xvecValid) return 0 ;
00136   Double_t g_xmxp = _model->getVal(_nset) ;
00137 
00138   //cout << "RooConvIntegrandBinding::operator(): evaluating g(x-x') at x-x' = " << _vars[0]->getVal() << " = " << g_xmxp << endl ; 
00139   //cout << "RooConvIntegrandBinding::operator(): return value = " << f_xp << " * " << g_xmxp << " = " << f_xp*g_xmxp << endl ;
00140 
00141   //cout << "_vars[0] = " << _vars[0]->getVal() << " _vars[1] = " << _vars[1]->getVal() << endl ;
00142   //cout << "_xvec[0] = " <<  xvector[0]        << " _xvec[1] = " <<  xvector[1] << endl ;
00143 
00144   return f_xp*g_xmxp ;
00145 }
00146 
00147 
00148 //_____________________________________________________________________________
00149 Double_t RooConvIntegrandBinding::getMinLimit(UInt_t index) const 
00150 {
00151   // Retrieve lower limit of i-th observable 
00152   assert(isValid());
00153   return _vars[index]->getMin();
00154 }
00155 
00156 
00157 //_____________________________________________________________________________
00158 Double_t RooConvIntegrandBinding::getMaxLimit(UInt_t index) const 
00159 {
00160   // Retrieve upper limit of i-th observable 
00161 
00162   assert(isValid());
00163   return _vars[index]->getMax();
00164 }

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