00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "Riostream.h"
00010
00011 #include "RooTFnBinding.h"
00012 #include "RooAbsReal.h"
00013 #include "RooAbsCategory.h"
00014 #include "TF3.h"
00015
00016 ClassImp(RooTFnBinding)
00017
00018 RooTFnBinding::RooTFnBinding(const char *name, const char *title, TF1* _func, const RooArgList& _list) :
00019 RooAbsReal(name,title),
00020 olist("obs","obs",this),
00021 func(_func)
00022 {
00023 olist.add(_list) ;
00024 }
00025
00026
00027 RooTFnBinding::RooTFnBinding(const char *name, const char *title, TF1* _func, const RooArgList& _obsList, const RooArgList& paramList) :
00028 RooAbsReal(name,title),
00029 olist("obs","obs",this),
00030 plist("params","params",this),
00031 func(_func)
00032 {
00033 olist.add(_obsList) ;
00034 plist.add(paramList) ;
00035 }
00036
00037
00038 RooTFnBinding::RooTFnBinding(const RooTFnBinding& other, const char* name) :
00039 RooAbsReal(other,name),
00040 olist("obs",this,other.olist),
00041 plist("params",this,other.plist),
00042 func(other.func)
00043 {
00044 }
00045
00046
00047
00048 Double_t RooTFnBinding::evaluate() const
00049 {
00050 Double_t x = olist.at(0) ? ((RooAbsReal*)olist.at(0))->getVal() : 0 ;
00051 Double_t y = olist.at(1) ? ((RooAbsReal*)olist.at(1))->getVal() : 0 ;
00052 Double_t z = olist.at(2) ? ((RooAbsReal*)olist.at(2))->getVal() : 0 ;
00053 for (Int_t i=0 ; i<func->GetNpar() ; i++) {
00054 func->SetParameter(i,plist.at(i)?((RooAbsReal*)plist.at(i))->getVal() : 0) ;
00055 }
00056 return func->Eval(x,y,z) ;
00057 }
00058
00059
00060
00061 void RooTFnBinding::printArgs(ostream& os) const
00062 {
00063
00064 os << "[ TFn={" << func->GetName() << "=" << func->GetTitle() << "} " ;
00065 for (Int_t i=0 ; i<numProxies() ; i++) {
00066 RooAbsProxy* p = getProxy(i) ;
00067 if (!TString(p->name()).BeginsWith("!")) {
00068 p->print(os) ;
00069 os << " " ;
00070 }
00071 }
00072 os << "]" ;
00073 }
00074
00075
00076 namespace RooFit {
00077
00078 RooAbsReal* bindFunction(TF1* func,RooAbsReal& x) {
00079 return new RooTFnBinding(func->GetName(),func->GetTitle(),func,x) ;
00080 }
00081
00082 RooAbsReal* bindFunction(TF2* func,RooAbsReal& x, RooAbsReal& y) {
00083 return new RooTFnBinding(func->GetName(),func->GetTitle(),func,RooArgList(x,y)) ;
00084 }
00085
00086 RooAbsReal* bindFunction(TF3* func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) {
00087 return new RooTFnBinding(func->GetName(),func->GetTitle(),func,RooArgList(x,y,z)) ;
00088 }
00089
00090 RooAbsReal* bindFunction(TF1* func,RooAbsReal& x, const RooArgList& params) {
00091 return new RooTFnBinding(func->GetName(),func->GetTitle(),func,x,params) ;
00092 }
00093
00094 RooAbsReal* bindFunction(TF2* func,RooAbsReal& x, RooAbsReal& y, const RooArgList& params) {
00095 return new RooTFnBinding(func->GetName(),func->GetTitle(),func,RooArgList(x,y),params) ;
00096 }
00097
00098 RooAbsReal* bindFunction(TF3* func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z, const RooArgList& params) {
00099 return new RooTFnBinding(func->GetName(),func->GetTitle(),func,RooArgList(x,y,z),params) ;
00100 }
00101
00102 }