ROOT logo
/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 * @(#)root/roofitcore:$Id$
 * Authors:                                                                  *
 *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
 *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
 *                                                                           *
 * Copyright (c) 2000-2005, Regents of the University of California          *
 *                          and Stanford University. All rights reserved.    *
 *                                                                           *
 * Redistribution and use in source and binary forms,                        *
 * with or without modification, are permitted according to the terms        *
 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
 *****************************************************************************/

//////////////////////////////////////////////////////////////////////////////
//
// BEGIN_HTML
// RooFirstMoment represents the first, second, or third order derivative
// of any RooAbsReal as calculated (numerically) by the MathCore Richardson
// derivator class.
// END_HTML
//


#include "RooFit.h"

#include "Riostream.h"
#include "Riostream.h"
#include <math.h>
#include <string>

#include "RooFirstMoment.h"
#include "RooAbsReal.h"
#include "RooAbsPdf.h"
#include "RooErrorHandler.h"
#include "RooArgSet.h"
#include "RooMsgService.h"
#include "RooRealVar.h"
#include "RooFunctor.h"
#include "RooGlobalFunc.h"
#include "RooConstVar.h"
#include "RooRealIntegral.h"
#include "RooNumIntConfig.h"
#include "RooProduct.h"
#include <string>
using namespace std ;


ClassImp(RooFirstMoment)
;


//_____________________________________________________________________________
RooFirstMoment::RooFirstMoment() 
{
  // Default constructor
}



//_____________________________________________________________________________
RooFirstMoment::RooFirstMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x) :
  RooAbsMoment(name, title,func,x,1,kFALSE),
  _xf("!xf","xf",this,kFALSE,kFALSE),
  _ixf("!ixf","ixf",this),
  _if("!if","if",this)
{
  setExpensiveObjectCache(func.expensiveObjectCache()) ;
  
  string pname=Form("%s_product",name) ;

  RooProduct* XF = new RooProduct(pname.c_str(),pname.c_str(),RooArgSet(x,func)) ;
  XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;

  if (func.isBinnedDistribution(x)) {
    XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
  }

  RooRealIntegral* intXF = (RooRealIntegral*) XF->createIntegral(x) ;
  RooRealIntegral* intF =  (RooRealIntegral*) func.createIntegral(x) ;
  intXF->setCacheNumeric(kTRUE) ;
  intF->setCacheNumeric(kTRUE) ;

  _xf.setArg(*XF) ;
  _ixf.setArg(*intXF) ;
  _if.setArg(*intF) ;
  addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
}

//_____________________________________________________________________________
RooFirstMoment::RooFirstMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset, Bool_t intNSet) :
  RooAbsMoment(name, title,func,x,1,kFALSE),
  _xf("!xf","xf",this,kFALSE,kFALSE),
  _ixf("!ixf","ixf",this),
  _if("!if","if",this)
{
  setExpensiveObjectCache(func.expensiveObjectCache()) ;

  _nset.add(nset) ;

  string pname=Form("%s_product",name) ;

  RooProduct* XF = new RooProduct(pname.c_str(),pname.c_str(),RooArgSet(x,func)) ;
  XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;

  if (func.isBinnedDistribution(x)) {
    XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
  }

  if (intNSet && _nset.getSize()>0 && func.isBinnedDistribution(_nset)) {
    XF->specialIntegratorConfig(kTRUE)->method2D().setLabel("RooBinIntegrator");
    XF->specialIntegratorConfig(kTRUE)->methodND().setLabel("RooBinIntegrator");
  }

  RooArgSet intSet(x) ;
  if (intNSet) intSet.add(_nset,kTRUE) ;
  RooRealIntegral* intXF = (RooRealIntegral*) XF->createIntegral(intSet,&_nset) ;
  RooRealIntegral* intF =  (RooRealIntegral*) func.createIntegral(intSet,&_nset) ;
  intXF->setCacheNumeric(kTRUE) ;
  intF->setCacheNumeric(kTRUE) ;

  _xf.setArg(*XF) ;
  _ixf.setArg(*intXF) ;
  _if.setArg(*intF) ;
  addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
}



//_____________________________________________________________________________
RooFirstMoment::RooFirstMoment(const RooFirstMoment& other, const char* name) :
  RooAbsMoment(other, name), 
  _xf("xf",this,other._xf),
  _ixf("ixf",this,other._ixf),
  _if("if",this,other._if)
{
}



//_____________________________________________________________________________
RooFirstMoment::~RooFirstMoment() 
{
  // Destructor
}



//_____________________________________________________________________________
Double_t RooFirstMoment::evaluate() const 
{
  // Calculate value  
  Double_t ratio = _ixf / _if ;
  //cout << "\nRooFirstMoment::eval(" << GetName() << ") val = " << ratio << endl ;
  return ratio ;
}


 RooFirstMoment.cxx:1
 RooFirstMoment.cxx:2
 RooFirstMoment.cxx:3
 RooFirstMoment.cxx:4
 RooFirstMoment.cxx:5
 RooFirstMoment.cxx:6
 RooFirstMoment.cxx:7
 RooFirstMoment.cxx:8
 RooFirstMoment.cxx:9
 RooFirstMoment.cxx:10
 RooFirstMoment.cxx:11
 RooFirstMoment.cxx:12
 RooFirstMoment.cxx:13
 RooFirstMoment.cxx:14
 RooFirstMoment.cxx:15
 RooFirstMoment.cxx:16
 RooFirstMoment.cxx:17
 RooFirstMoment.cxx:18
 RooFirstMoment.cxx:19
 RooFirstMoment.cxx:20
 RooFirstMoment.cxx:21
 RooFirstMoment.cxx:22
 RooFirstMoment.cxx:23
 RooFirstMoment.cxx:24
 RooFirstMoment.cxx:25
 RooFirstMoment.cxx:26
 RooFirstMoment.cxx:27
 RooFirstMoment.cxx:28
 RooFirstMoment.cxx:29
 RooFirstMoment.cxx:30
 RooFirstMoment.cxx:31
 RooFirstMoment.cxx:32
 RooFirstMoment.cxx:33
 RooFirstMoment.cxx:34
 RooFirstMoment.cxx:35
 RooFirstMoment.cxx:36
 RooFirstMoment.cxx:37
 RooFirstMoment.cxx:38
 RooFirstMoment.cxx:39
 RooFirstMoment.cxx:40
 RooFirstMoment.cxx:41
 RooFirstMoment.cxx:42
 RooFirstMoment.cxx:43
 RooFirstMoment.cxx:44
 RooFirstMoment.cxx:45
 RooFirstMoment.cxx:46
 RooFirstMoment.cxx:47
 RooFirstMoment.cxx:48
 RooFirstMoment.cxx:49
 RooFirstMoment.cxx:50
 RooFirstMoment.cxx:51
 RooFirstMoment.cxx:52
 RooFirstMoment.cxx:53
 RooFirstMoment.cxx:54
 RooFirstMoment.cxx:55
 RooFirstMoment.cxx:56
 RooFirstMoment.cxx:57
 RooFirstMoment.cxx:58
 RooFirstMoment.cxx:59
 RooFirstMoment.cxx:60
 RooFirstMoment.cxx:61
 RooFirstMoment.cxx:62
 RooFirstMoment.cxx:63
 RooFirstMoment.cxx:64
 RooFirstMoment.cxx:65
 RooFirstMoment.cxx:66
 RooFirstMoment.cxx:67
 RooFirstMoment.cxx:68
 RooFirstMoment.cxx:69
 RooFirstMoment.cxx:70
 RooFirstMoment.cxx:71
 RooFirstMoment.cxx:72
 RooFirstMoment.cxx:73
 RooFirstMoment.cxx:74
 RooFirstMoment.cxx:75
 RooFirstMoment.cxx:76
 RooFirstMoment.cxx:77
 RooFirstMoment.cxx:78
 RooFirstMoment.cxx:79
 RooFirstMoment.cxx:80
 RooFirstMoment.cxx:81
 RooFirstMoment.cxx:82
 RooFirstMoment.cxx:83
 RooFirstMoment.cxx:84
 RooFirstMoment.cxx:85
 RooFirstMoment.cxx:86
 RooFirstMoment.cxx:87
 RooFirstMoment.cxx:88
 RooFirstMoment.cxx:89
 RooFirstMoment.cxx:90
 RooFirstMoment.cxx:91
 RooFirstMoment.cxx:92
 RooFirstMoment.cxx:93
 RooFirstMoment.cxx:94
 RooFirstMoment.cxx:95
 RooFirstMoment.cxx:96
 RooFirstMoment.cxx:97
 RooFirstMoment.cxx:98
 RooFirstMoment.cxx:99
 RooFirstMoment.cxx:100
 RooFirstMoment.cxx:101
 RooFirstMoment.cxx:102
 RooFirstMoment.cxx:103
 RooFirstMoment.cxx:104
 RooFirstMoment.cxx:105
 RooFirstMoment.cxx:106
 RooFirstMoment.cxx:107
 RooFirstMoment.cxx:108
 RooFirstMoment.cxx:109
 RooFirstMoment.cxx:110
 RooFirstMoment.cxx:111
 RooFirstMoment.cxx:112
 RooFirstMoment.cxx:113
 RooFirstMoment.cxx:114
 RooFirstMoment.cxx:115
 RooFirstMoment.cxx:116
 RooFirstMoment.cxx:117
 RooFirstMoment.cxx:118
 RooFirstMoment.cxx:119
 RooFirstMoment.cxx:120
 RooFirstMoment.cxx:121
 RooFirstMoment.cxx:122
 RooFirstMoment.cxx:123
 RooFirstMoment.cxx:124
 RooFirstMoment.cxx:125
 RooFirstMoment.cxx:126
 RooFirstMoment.cxx:127
 RooFirstMoment.cxx:128
 RooFirstMoment.cxx:129
 RooFirstMoment.cxx:130
 RooFirstMoment.cxx:131
 RooFirstMoment.cxx:132
 RooFirstMoment.cxx:133
 RooFirstMoment.cxx:134
 RooFirstMoment.cxx:135
 RooFirstMoment.cxx:136
 RooFirstMoment.cxx:137
 RooFirstMoment.cxx:138
 RooFirstMoment.cxx:139
 RooFirstMoment.cxx:140
 RooFirstMoment.cxx:141
 RooFirstMoment.cxx:142
 RooFirstMoment.cxx:143
 RooFirstMoment.cxx:144
 RooFirstMoment.cxx:145
 RooFirstMoment.cxx:146
 RooFirstMoment.cxx:147
 RooFirstMoment.cxx:148
 RooFirstMoment.cxx:149
 RooFirstMoment.cxx:150
 RooFirstMoment.cxx:151
 RooFirstMoment.cxx:152
 RooFirstMoment.cxx:153
 RooFirstMoment.cxx:154
 RooFirstMoment.cxx:155
 RooFirstMoment.cxx:156
 RooFirstMoment.cxx:157
 RooFirstMoment.cxx:158
 RooFirstMoment.cxx:159
 RooFirstMoment.cxx:160