00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "RooFit.h"
00028
00029 #include "Riostream.h"
00030 #include "Riostream.h"
00031 #include <math.h>
00032 #include <string>
00033
00034 #include "RooMoment.h"
00035 #include "RooAbsReal.h"
00036 #include "RooAbsPdf.h"
00037 #include "RooErrorHandler.h"
00038 #include "RooArgSet.h"
00039 #include "RooMsgService.h"
00040 #include "RooRealVar.h"
00041 #include "RooFunctor.h"
00042 #include "RooFormulaVar.h"
00043 #include "RooGlobalFunc.h"
00044 #include "RooConstVar.h"
00045 #include "RooRealIntegral.h"
00046 #include <string>
00047 using namespace std ;
00048
00049
00050 ClassImp(RooMoment)
00051 ;
00052
00053
00054
00055 RooMoment::RooMoment()
00056 {
00057
00058 }
00059
00060
00061
00062
00063 RooMoment::RooMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, Int_t orderIn, Bool_t centr, Bool_t takeRoot) :
00064 RooAbsReal(name, title),
00065 _order(orderIn),
00066 _takeRoot(takeRoot),
00067 _nset("nset","nset",this,kFALSE,kFALSE),
00068 _func("function","function",this,func,kFALSE,kFALSE),
00069 _x("x","x",this,x,kFALSE,kFALSE),
00070 _mean("!mean","!mean",this,kFALSE,kFALSE),
00071 _xf("!xf","xf",this,kFALSE,kFALSE),
00072 _ixf("!ixf","ixf",this),
00073 _if("!if","if",this)
00074 {
00075
00076
00077
00078
00079 setExpensiveObjectCache(func.expensiveObjectCache()) ;
00080
00081 string pname=Form("%s_product",name) ;
00082
00083 RooFormulaVar* XF ;
00084 if (centr) {
00085 string formula=Form("pow((@0-@1),%d)*@2",_order) ;
00086 string m1name=Form("%s_moment1",GetName()) ;
00087 RooAbsReal* mom1 = func.mean(x) ;
00088 XF = new RooFormulaVar(pname.c_str(),formula.c_str(),RooArgList(x,*mom1,func)) ;
00089 XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;
00090 addOwnedComponents(*mom1) ;
00091 _mean.setArg(*mom1) ;
00092 } else {
00093 string formula=Form("pow(@0*@1,%d)",_order) ;
00094 XF = new RooFormulaVar(pname.c_str(),formula.c_str(),RooArgSet(x,func)) ;
00095 XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;
00096 }
00097 RooRealIntegral* intXF = (RooRealIntegral*) XF->createIntegral(x) ;
00098 RooRealIntegral* intF = (RooRealIntegral*) func.createIntegral(x) ;
00099 intXF->setCacheNumeric(kTRUE) ;
00100 intF->setCacheNumeric(kTRUE) ;
00101
00102 _xf.setArg(*XF) ;
00103 _ixf.setArg(*intXF) ;
00104 _if.setArg(*intF) ;
00105 addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
00106 }
00107
00108
00109 RooMoment::RooMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset,
00110 Int_t orderIn, Bool_t centr, Bool_t takeRoot, Bool_t intNSet) :
00111 RooAbsReal(name, title),
00112 _order(orderIn),
00113 _takeRoot(takeRoot),
00114 _nset("nset","nset",this,kFALSE,kFALSE),
00115 _func("function","function",this,func,kFALSE,kFALSE),
00116 _x("x","x",this,x,kFALSE,kFALSE),
00117 _mean("!mean","!mean",this,kFALSE,kFALSE),
00118 _xf("!xf","xf",this,kFALSE,kFALSE),
00119 _ixf("!ixf","ixf",this),
00120 _if("!if","if",this)
00121 {
00122
00123
00124
00125
00126
00127 setExpensiveObjectCache(func.expensiveObjectCache()) ;
00128
00129 _nset.add(nset) ;
00130
00131 string pname=Form("%s_product",name) ;
00132 RooFormulaVar* XF ;
00133 if (centr) {
00134 string formula=Form("pow((@0-@1),%d)*@2",_order) ;
00135 string m1name=Form("%s_moment1",GetName()) ;
00136 RooAbsReal* mom1 = func.mean(x,nset) ;
00137
00138 XF = new RooFormulaVar(pname.c_str(),formula.c_str(),RooArgList(x,*mom1,func)) ;
00139 XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;
00140 addOwnedComponents(*mom1) ;
00141 _mean.setArg(*mom1) ;
00142 } else {
00143 string formula=Form("pow(@0*@1,%d)",_order) ;
00144 XF = new RooFormulaVar(pname.c_str(),formula.c_str(),RooArgSet(x,func)) ;
00145 XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;
00146 }
00147
00148 RooArgSet intSet(x) ;
00149 if (intNSet) intSet.add(_nset,kTRUE) ;
00150
00151 RooRealIntegral* intXF = (RooRealIntegral*) XF->createIntegral(intSet,&_nset) ;
00152 RooRealIntegral* intF = (RooRealIntegral*) func.createIntegral(intSet,&_nset) ;
00153 intXF->setCacheNumeric(kTRUE) ;
00154 intF->setCacheNumeric(kTRUE) ;
00155
00156 _xf.setArg(*XF) ;
00157 _ixf.setArg(*intXF) ;
00158 _if.setArg(*intF) ;
00159 addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
00160 }
00161
00162
00163
00164
00165 RooMoment::RooMoment(const RooMoment& other, const char* name) :
00166 RooAbsReal(other, name),
00167 _order(other._order),
00168 _nset("nset",this,other._nset),
00169 _func("function",this,other._func),
00170 _x("x",this,other._x),
00171 _mean("!mean","!mean",this,kFALSE,kFALSE),
00172 _xf("xf",this,other._xf),
00173 _ixf("ixf",this,other._ixf),
00174 _if("if",this,other._if)
00175 {
00176 }
00177
00178
00179
00180
00181 RooMoment::~RooMoment()
00182 {
00183
00184 }
00185
00186
00187
00188
00189 Double_t RooMoment::evaluate() const
00190 {
00191
00192 Double_t ratio = _ixf / _if ;
00193 Double_t ret = _takeRoot ? pow(ratio,1.0/_order) : ratio ;
00194
00195 return ret ;
00196 }
00197
00198