Logo ROOT  
Reference Guide
RooMoment.cxx
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * @(#)root/roofitcore:$Id$
5  * Authors: *
6  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8  * *
9  * Copyright (c) 2000-2005, Regents of the University of California *
10  * and Stanford University. All rights reserved. *
11  * *
12  * Redistribution and use in source and binary forms, *
13  * with or without modification, are permitted according to the terms *
14  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15  *****************************************************************************/
16 
17 /**
18 \file RooMoment.cxx
19 \class RooMoment
20 \ingroup Roofitcore
21 
22 RooMoment represents the first, second, or third order derivative
23 of any RooAbsReal as calculated (numerically) by the MathCore Richardson
24 derivator class.
25 **/
26 
27 
28 #include "RooFit.h"
29 
30 #include "Riostream.h"
31 #include <math.h>
32 
33 #include "RooMoment.h"
34 #include "RooAbsReal.h"
35 #include "RooAbsPdf.h"
36 #include "RooErrorHandler.h"
37 #include "RooArgSet.h"
38 #include "RooMsgService.h"
39 #include "RooRealVar.h"
40 #include "RooFunctor.h"
41 #include "RooFormulaVar.h"
42 #include "RooGlobalFunc.h"
43 #include "RooConstVar.h"
44 #include "RooRealIntegral.h"
45 #include "RooNumIntConfig.h"
46 #include <string>
47 using namespace std;
48 
49 
51 
52 
53 
54 ////////////////////////////////////////////////////////////////////////////////
55 /// Default constructor
56 
58 {
59 }
60 
61 
62 
63 ////////////////////////////////////////////////////////////////////////////////
64 
65 RooMoment::RooMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, Int_t orderIn, Bool_t centr, Bool_t takeRoot) :
66  RooAbsMoment(name, title,func,x,orderIn,takeRoot),
67  _xf("!xf","xf",this,kFALSE,kFALSE),
68  _ixf("!ixf","ixf",this),
69  _if("!if","if",this)
70 {
72 
73  string pname=Form("%s_product",name) ;
74 
75  RooFormulaVar* XF ;
76  if (centr) {
77  string formula=Form("pow((@0-@1),%d)*@2",_order) ;
78  string m1name=Form("%s_moment1",GetName()) ;
79  RooAbsReal* mom1 = func.mean(x) ;
80  XF = new RooFormulaVar(pname.c_str(),formula.c_str(),RooArgList(x,*mom1,func)) ;
82  addOwnedComponents(*mom1) ;
83  _mean.setArg(*mom1) ;
84  } else {
85  string formula=Form("pow(@0,%d)*@1",_order) ;
86  XF = new RooFormulaVar(pname.c_str(),formula.c_str(),RooArgSet(x,func)) ;
88  }
89 
90  if (func.isBinnedDistribution(x)) {
91  XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
92  }
93 
96  intXF->setCacheNumeric(kTRUE) ;
97  intF->setCacheNumeric(kTRUE) ;
98 
99  _xf.setArg(*XF) ;
100  _ixf.setArg(*intXF) ;
101  _if.setArg(*intF) ;
102  addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
103 }
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 
107 RooMoment::RooMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset,
108  Int_t orderIn, Bool_t centr, Bool_t takeRoot, Bool_t intNSet) :
109  RooAbsMoment(name, title,func,x,orderIn,takeRoot),
110  _xf("!xf","xf",this,kFALSE,kFALSE),
111  _ixf("!ixf","ixf",this),
112  _if("!if","if",this)
113 {
115 
116  _nset.add(nset) ;
117 
118  string pname=Form("%s_product",name) ;
119  RooFormulaVar* XF ;
120  if (centr) {
121  string formula=Form("pow((@0-@1),%d)*@2",_order) ;
122  string m1name=Form("%s_moment1",GetName()) ;
123  RooAbsReal* mom1 = func.mean(x,nset) ;
124  XF = new RooFormulaVar(pname.c_str(),formula.c_str(),RooArgList(x,*mom1,func)) ;
126  addOwnedComponents(*mom1) ;
127  _mean.setArg(*mom1) ;
128  } else {
129  string formula=Form("pow(@0,%d)*@1",_order) ;
130  XF = new RooFormulaVar(pname.c_str(),formula.c_str(),RooArgSet(x,func)) ;
132  }
133 
134  if (func.isBinnedDistribution(x)) {
135  XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
136  }
137 
138  RooArgSet intSet(x) ;
139  if (intNSet) intSet.add(_nset,kTRUE) ;
140 
141  RooRealIntegral* intXF = (RooRealIntegral*) XF->createIntegral(intSet,&_nset) ;
142  RooRealIntegral* intF = (RooRealIntegral*) func.createIntegral(intSet,&_nset) ;
143  intXF->setCacheNumeric(kTRUE) ;
144  intF->setCacheNumeric(kTRUE) ;
145 
146  _xf.setArg(*XF) ;
147  _ixf.setArg(*intXF) ;
148  _if.setArg(*intF) ;
149  addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
150 }
151 
152 
153 
154 ////////////////////////////////////////////////////////////////////////////////
155 
156 RooMoment::RooMoment(const RooMoment& other, const char* name) :
157  RooAbsMoment(other, name),
158  _xf("xf",this,other._xf),
159  _ixf("ixf",this,other._ixf),
160  _if("if",this,other._if)
161 {
162 }
163 
164 
165 
166 ////////////////////////////////////////////////////////////////////////////////
167 /// Destructor
168 
170 {
171 }
172 
173 
174 
175 ////////////////////////////////////////////////////////////////////////////////
176 /// Calculate value
177 
179 {
180  Double_t ratio = _ixf / _if ;
181  Double_t ret = _takeRoot ? pow(ratio,1.0/_order) : ratio ;
182  return ret ;
183 }
184 
185 
RooFormulaVar.h
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:100
RooAbsMoment::_nset
RooSetProxy _nset
Definition: RooAbsMoment.h:44
RooAbsReal.h
RooMsgService.h
RooNumIntConfig.h
RooFit.h
RooArgSet.h
RooAbsReal::isBinnedDistribution
virtual Bool_t isBinnedDistribution(const RooArgSet &) const
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
Definition: RooAbsReal.h:341
RooAbsReal::createIntegral
RooAbsReal * createIntegral(const RooArgSet &iset, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Create an object that represents the integral of the function over one or more observables listed in ...
Definition: RooAbsReal.cxx:548
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
Form
char * Form(const char *fmt,...)
RooAbsMoment::_mean
RooRealProxy _mean
Definition: RooAbsMoment.h:47
RooNumIntConfig::method1D
RooCategory & method1D()
Definition: RooNumIntConfig.h:34
RooArgList
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooMoment::_if
RooRealProxy _if
Definition: RooMoment.h:47
RooMoment::RooMoment
RooMoment()
Default constructor.
Definition: RooMoment.cxx:57
x
Double_t x[n]
Definition: legend1.C:17
RooAbsReal
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:61
RooAbsMoment
RooAbsMoment represents the first, second, or third order derivative of any RooAbsReal as calculated ...
Definition: RooAbsMoment.h:27
RooAbsArg::setExpensiveObjectCache
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition: RooAbsArg.h:503
RooAbsReal::mean
RooAbsMoment * mean(RooRealVar &obs)
Definition: RooAbsReal.h:357
RooAbsArg::expensiveObjectCache
RooExpensiveObjectCache & expensiveObjectCache() const
Definition: RooAbsArg.cxx:2277
bool
RooRealIntegral
RooRealIntegral performs hybrid numerical/analytical integrals of RooAbsReal objects.
Definition: RooRealIntegral.h:34
RooMoment::evaluate
Double_t evaluate() const
Calculate value
Definition: RooMoment.cxx:178
RooMoment::_ixf
RooRealProxy _ixf
Definition: RooMoment.h:46
RooAbsMoment::_order
Int_t _order
Definition: RooAbsMoment.h:42
RooCategory::setLabel
virtual Bool_t setLabel(const char *label, bool printError=true) override
Set value by specifying the name of the desired state.
Definition: RooCategory.cxx:185
RooFormulaVar
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:30
RooAbsMoment::_takeRoot
Int_t _takeRoot
Definition: RooAbsMoment.h:43
RooAbsPdf.h
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:101
RooAbsArg::RooArgSet
friend class RooArgSet
Definition: RooAbsArg.h:599
RooAbsCollection::add
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Definition: RooAbsCollection.cxx:455
RooTemplateProxy::setArg
bool setArg(T &newRef)
Change object held in proxy into newRef.
Definition: RooTemplateProxy.h:227
RooRealVar.h
RooConstVar.h
RooGlobalFunc.h
Double_t
double Double_t
Definition: RtypesCore.h:59
RooAbsReal::specialIntegratorConfig
RooNumIntConfig * specialIntegratorConfig() const
Returns the specialized integrator configuration for this RooAbsReal.
Definition: RooAbsReal.cxx:3523
RooAbsArg::addOwnedComponents
Bool_t addOwnedComponents(const RooArgSet &comps)
Take ownership of the contents of 'comps'.
Definition: RooAbsArg.cxx:2216
name
char name[80]
Definition: TGX11.cxx:110
RooErrorHandler.h
RooRealIntegral::setCacheNumeric
void setCacheNumeric(Bool_t flag)
Definition: RooRealIntegral.h:60
RooRealIntegral.h
RooMoment
RooMoment represents the first, second, or third order derivative of any RooAbsReal as calculated (nu...
Definition: RooMoment.h:27
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
RooMoment.h
RooMoment::~RooMoment
virtual ~RooMoment()
Destructor.
Definition: RooMoment.cxx:169
RooFunctor.h
RooRealVar
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:39
Riostream.h
RooMoment::_xf
RooRealProxy _xf
Definition: RooMoment.h:45
pow
double pow(double, double)
RooSetProxy::add
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE) override
Overloaded RooArgSet::add() method inserts 'var' into set and registers 'var' as server to owner with...
Definition: RooSetProxy.cxx:165
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:33
int