54 ClassImp(RooSecondMoment);
 
   61 RooSecondMoment::RooSecondMoment() 
 
   69 RooSecondMoment::RooSecondMoment(
const char* name, 
const char* title, RooAbsReal& func, RooRealVar& x, Bool_t centr, Bool_t takeRoot) :
 
   70   RooAbsMoment(name, title,func,x,2,takeRoot),
 
   71   _xf(
"!xf",
"xf",this,kFALSE,kFALSE),
 
   72   _ixf(
"!ixf",
"ixf",this),
 
   76   setExpensiveObjectCache(func.expensiveObjectCache()) ;
 
   81     string m1name=Form(
"%s_moment1",GetName()) ;
 
   82     RooAbsReal* mom1 = func.mean(x) ;
 
   85     string pname=Form(
"%s_product",name) ;
 
   86     _xfOffset = mom1->getVal() ;
 
   87     XF = 
new RooFormulaVar(pname.c_str(),Form(
"pow((@0-%f),2)*@1",_xfOffset),RooArgList(x,func)) ;  
 
   91     string pname=Form(
"%s_product",name) ;
 
   92     XF = 
new RooProduct(pname.c_str(),pname.c_str(),RooArgList(x,x,func)) ;
 
   95   XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;
 
   97   if (func.isBinnedDistribution(x)) {
 
   98     XF->specialIntegratorConfig(kTRUE)->method1D().setLabel(
"RooBinIntegrator");
 
  101   RooRealIntegral* intXF = (RooRealIntegral*) XF->createIntegral(x) ;
 
  102   RooRealIntegral* intF =  (RooRealIntegral*) func.createIntegral(x) ;
 
  103   intXF->setCacheNumeric(kTRUE) ;
 
  104   intF->setCacheNumeric(kTRUE) ;
 
  107   _ixf.setArg(*intXF) ;
 
  109   addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
 
  114 RooSecondMoment::RooSecondMoment(
const char* name, 
const char* title, RooAbsReal& func, RooRealVar& x, 
const RooArgSet& nset, 
 
  115            Bool_t centr, Bool_t takeRoot, Bool_t intNSet) :
 
  116   RooAbsMoment(name, title,func,x,2,takeRoot),
 
  117   _xf(
"!xf",
"xf",this,kFALSE,kFALSE),
 
  118   _ixf(
"!ixf",
"ixf",this),
 
  119   _if(
"!if",
"if",this),
 
  122   setExpensiveObjectCache(func.expensiveObjectCache()) ;
 
  129     string m1name=Form(
"%s_moment1",GetName()) ;
 
  130     RooAbsReal* mom1 = func.mean(x,nset) ;
 
  131     _mean.setArg(*mom1) ;
 
  133     string pname=Form(
"%s_product",name) ;
 
  134     _xfOffset = mom1->getVal() ;
 
  135     XF = 
new RooFormulaVar(pname.c_str(),Form(
"pow((@0-%f),2)*@1",_xfOffset),RooArgList(x,func)) ;  
 
  140     string pname=Form(
"%s_product",name) ;
 
  141     XF = 
new RooProduct(pname.c_str(),pname.c_str(),RooArgList(x,x,func)) ;
 
  145   XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;
 
  147   if (func.isBinnedDistribution(x)) {
 
  148     XF->specialIntegratorConfig(kTRUE)->method1D().setLabel(
"RooBinIntegrator");
 
  150   if (intNSet && _nset.getSize()>0 && func.isBinnedDistribution(_nset)) {
 
  151       XF->specialIntegratorConfig(kTRUE)->method2D().setLabel(
"RooBinIntegrator");
 
  152       XF->specialIntegratorConfig(kTRUE)->methodND().setLabel(
"RooBinIntegrator");
 
  155   RooArgSet intSet(x) ;
 
  156   if (intNSet) intSet.add(_nset,kTRUE) ;
 
  157   RooRealIntegral* intXF = (RooRealIntegral*) XF->createIntegral(intSet,&_nset) ;
 
  158   RooRealIntegral* intF =  (RooRealIntegral*) func.createIntegral(intSet,&_nset) ;
 
  159   intXF->setCacheNumeric(kTRUE) ;
 
  160   intF->setCacheNumeric(kTRUE) ;
 
  163   _ixf.setArg(*intXF) ;
 
  165   addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
 
  172 RooSecondMoment::RooSecondMoment(
const RooSecondMoment& other, 
const char* name) :
 
  173   RooAbsMoment(other, name), 
 
  174   _xf(
"xf",this,other._xf),
 
  175   _ixf(
"ixf",this,other._ixf),
 
  176   _if(
"if",this,other._if),
 
  177   _xfOffset(other._xfOffset)
 
  186 RooSecondMoment::~RooSecondMoment() 
 
  195 Double_t RooSecondMoment::evaluate()
 const  
  197   Double_t ratio = _ixf / _if ;
 
  199   if (_mean.absArg()) {
 
  200     ratio -= (_mean - _xfOffset)*(_mean-_xfOffset) ;
 
  203   Double_t ret =  _takeRoot ? sqrt(ratio) : ratio ;