RooFunctor1DBinding.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  *    File: $Id: RooFunctor1DBinding.cxx 28963 2009-06-12 15:47:45Z wouter $
00005  * Authors:                                                                  *
00006  *   WV, Wouter Verkerke, NIKHEF, verkerke@nikhef.nl                         *
00007  *                                                                           *
00008  * Copyright (c) 2000-2008, NIKHEF, Regents of the University of California  *
00009  *                          and Stanford University. All rights reserved.    *
00010  *                                                                           *
00011  *****************************************************************************/
00012 
00013 //////////////////////////////////////////////////////////////////////////////
00014 // 
00015 // BEGIN_HTML
00016 // RooCFunction1Binding is a templated implementation of class RooAbsReal that binds 
00017 // generic C(++) functions to a RooAbsReal argument thus allowing generic C++
00018 // functions to be used as RooFit functions. Instances of function binding
00019 // classes are fully functional RooFit function objects with one exception:
00020 // if the bound function is _not_ a standard TMath or MathMore function the
00021 // class cannot be persisted in a RooWorkspace without registering the function
00022 // pointer first using RooCFunction1Binding<T1,T2>::register().
00023 // END_HTML
00024 //
00025 
00026 #include "Riostream.h" 
00027 #include "RooFunctor1DBinding.h" 
00028 
00029 using namespace std ;
00030 
00031 ClassImp(RooFunctor1DBinding) 
00032 ClassImp(RooFunctor1DPdfBinding) 
00033   ;
00034 
00035 
00036 RooFunctor1DBinding::RooFunctor1DBinding(const char *name, const char *title, const ROOT::Math::IBaseFunctionOneDim& ftor, RooAbsReal& x) :
00037   RooAbsReal(name,title), 
00038   func(&ftor),
00039   var("x","x",this,x) 
00040 { 
00041 } 
00042 
00043 
00044 RooFunctor1DBinding::RooFunctor1DBinding(const RooFunctor1DBinding& other, const char* name) :  
00045   RooAbsReal(other,name), 
00046   func(other.func),
00047   var("x",this,other.var)
00048 { 
00049   // Copy constructor
00050 } 
00051 
00052 
00053 
00054 void RooFunctor1DBinding::printArgs(ostream& os) const {
00055   // Print object arguments and name/address of function pointer
00056   os << "[ function=" << func << " " ;    
00057   for (Int_t i=0 ; i<numProxies() ; i++) {
00058     RooAbsProxy* p = getProxy(i) ;
00059     if (!TString(p->name()).BeginsWith("!")) {
00060       p->print(os) ;
00061       os << " " ;
00062     }
00063   }    
00064   os << "]" ;  
00065 }
00066 
00067 Double_t RooFunctor1DBinding::evaluate() const {
00068     // Return value of embedded function using value of referenced variable x
00069     return (*func)(var.arg().getVal()) ;
00070   }
00071 
00072 
00073 
00074 RooFunctor1DPdfBinding::RooFunctor1DPdfBinding(const char *name, const char *title, const ROOT::Math::IBaseFunctionOneDim& ftor, RooAbsReal& x) :
00075   RooAbsPdf(name,title), 
00076   func(&ftor),
00077   var("x","x",this,x) 
00078 { 
00079 } 
00080 
00081 
00082 RooFunctor1DPdfBinding::RooFunctor1DPdfBinding(const RooFunctor1DPdfBinding& other, const char* name) :  
00083   RooAbsPdf(other,name), 
00084   func(other.func),
00085   var("x",this,other.var)
00086 { 
00087   // Copy constructor
00088 } 
00089 
00090 
00091 
00092 void RooFunctor1DPdfBinding::printArgs(ostream& os) const {
00093   // Print object arguments and name/address of function pointer
00094   os << "[ function=" << func << " " ;    
00095   for (Int_t i=0 ; i<numProxies() ; i++) {
00096     RooAbsProxy* p = getProxy(i) ;
00097     if (!TString(p->name()).BeginsWith("!")) {
00098       p->print(os) ;
00099       os << " " ;
00100     }
00101   }    
00102   os << "]" ;  
00103 }
00104 
00105 Double_t RooFunctor1DPdfBinding::evaluate() const {
00106     // Return value of embedded function using value of referenced variable x
00107     return (*func)(var.arg().getVal()) ;
00108   }
00109 
00110 
00111 
00112 
00113 namespace RooFit {
00114 
00115   RooAbsReal* bindFunction(const char* name, const ROOT::Math::IBaseFunctionOneDim& ftor, RooAbsReal& var) {
00116     return new RooFunctor1DBinding(name,name,ftor,var) ;
00117   }
00118 
00119   RooAbsPdf*  bindPdf(const char* name, const ROOT::Math::IBaseFunctionOneDim& ftor, RooAbsReal& var) {
00120     return new RooFunctor1DPdfBinding(name,name,ftor,var) ;
00121   }
00122 
00123 }
00124 
00125 
00126 

Generated on Tue Jul 5 14:55:11 2011 for ROOT_528-00b_version by  doxygen 1.5.1