RooFunctor.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooFunctor.cxx 28259 2009-04-16 16:21:16Z 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 //
00020 // BEGIN_HTML
00021 // Lightweight interface adaptor that exports a RooAbsPdf as a functor
00022 // END_HTML
00023 //
00024 
00025 
00026 #include "RooFit.h"
00027 #include "Riostream.h"
00028 
00029 #include "RooFunctor.h"
00030 #include "RooRealBinding.h"
00031 #include "RooAbsReal.h"
00032 #include "RooAbsPdf.h"
00033 #include "RooArgSet.h"
00034 
00035 #include <assert.h>
00036 
00037 
00038 
00039 ClassImp(RooFunctor)
00040 ;
00041 
00042 
00043 //_____________________________________________________________________________
00044 RooFunctor::RooFunctor(const RooAbsFunc& func)
00045 {
00046   _ownBinding = kFALSE ;
00047 
00048   _x = new Double_t[func.getDimension()] ; 
00049 
00050   _nobs = func.getDimension() ;
00051   _npar = 0 ;
00052   _binding = (RooAbsFunc*) &func ;
00053 }
00054 
00055 
00056 
00057 //_____________________________________________________________________________
00058 RooFunctor::RooFunctor(const RooAbsReal& func, const RooArgList& observables, const RooArgList& parameters) 
00059 {
00060   // Store list of observables
00061   _nset.add(observables) ;
00062 
00063   // Make list of all variables to be bound
00064   RooArgList allVars(observables) ;
00065   allVars.add(parameters) ;
00066 
00067   // Create RooFit function binding
00068   _binding = new RooRealBinding(func,allVars,&_nset,kFALSE,0) ;
00069   _ownBinding = kTRUE ;
00070 
00071   // Allocate transfer array
00072   _x = new Double_t[allVars.getSize()] ; 
00073   _nobs = observables.getSize() ;
00074   _npar = parameters.getSize() ;
00075 }
00076 
00077 
00078 //_____________________________________________________________________________
00079 RooFunctor::RooFunctor(const RooAbsReal& func, const RooArgList& observables, const RooArgList& parameters, const RooArgSet& nset) 
00080 {
00081   // Store normalization set
00082   _nset.add(nset) ;
00083 
00084   // Make list of all variables to be bound
00085   RooArgList allVars(observables) ;
00086   allVars.add(parameters) ;
00087 
00088   // Create RooFit function binding
00089   _binding = new RooRealBinding(func,allVars,&_nset,kFALSE,0) ;
00090   _ownBinding = kTRUE ;
00091 
00092   // Allocate transfer array
00093   _x = new Double_t[allVars.getSize()] ; 
00094   _nobs = observables.getSize() ;
00095   _npar = parameters.getSize() ;
00096 }
00097 
00098 
00099 
00100 //_____________________________________________________________________________
00101 RooFunctor::RooFunctor(const RooFunctor& other) :
00102   _ownBinding(other._ownBinding),
00103   _nset(other._nset),
00104   _binding(0),
00105   _npar(other._npar),
00106   _nobs(other._nobs)
00107 {
00108   if (other._ownBinding) {
00109     _binding = new RooRealBinding((RooRealBinding&)*other._binding,&_nset) ;
00110   } else {
00111     _binding = other._binding ;
00112   }
00113   _x = new Double_t[_nobs+_npar] ;
00114 }
00115 
00116 
00117 
00118 
00119 //_____________________________________________________________________________
00120 RooFunctor::~RooFunctor() 
00121 {
00122   // Destructor
00123   if (_ownBinding) delete _binding ; 
00124   delete[] _x ;
00125 }
00126 
00127 
00128 
00129 //_____________________________________________________________________________
00130 Double_t RooFunctor::eval(const Double_t *x) const
00131 {
00132   return (*_binding)(x) ;
00133 }
00134 
00135 //_____________________________________________________________________________
00136 Double_t RooFunctor::eval(Double_t x) const
00137 {
00138   return (*_binding)(&x) ;
00139 }
00140 
00141 //_____________________________________________________________________________
00142 Double_t RooFunctor::eval(const Double_t *x, const Double_t *p) const
00143 {
00144   for (int i=0 ; i<_nobs ; i++) { 
00145     _x[i] = x[i] ; 
00146   }
00147   for (int i=0 ; i<_npar ; i++) { 
00148     _x[i+_nobs] = p[i] ; 
00149   }
00150   return (*_binding)(_x) ;
00151 }

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