RooMoment.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooMoment.cxx 36230 2010-10-09 20:21:02Z 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 // RooMoment represents the first, second, or third order derivative
00021 // of any RooAbsReal as calculated (numerically) by the MathCore Richardson
00022 // derivator class.
00023 // END_HTML
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   // Default constructor
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 //   cout << "RooMoment::ctor(" << GetName() << ") func = " << func.GetName() << " x = " << x.GetName() 
00076 //        << " order = " << _order << " centr = " << (centr?"T":"F") << " takeRoot = " << (takeRoot?"T":"F") << endl ; 
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 //   cout << "RooMoment::ctor(" << GetName() << ") func = " << func.GetName() << " x = " << x.GetName() << " nset = " << nset 
00124 //        << " order = " << _order << " centr = " << (centr?"T":"F") << " takeRoot = " << (takeRoot?"T":"F") 
00125 //        << " intNSet= " << (intNSet?"T":"F") << endl ;
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     //mom1->Print("v") ;
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   // Destructor
00184 }
00185 
00186 
00187 
00188 //_____________________________________________________________________________
00189 Double_t RooMoment::evaluate() const 
00190 {
00191   // Calculate value  
00192   Double_t ratio = _ixf / _if ;
00193   Double_t ret =  _takeRoot ? pow(ratio,1.0/_order) : ratio ;
00194   //cout << "RooMoment(" << GetName() << ")::evaluate() ret = " << ret << endl ;
00195   return ret ;
00196 }
00197 
00198 

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