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
22RooMoment represents the first, second, or third order derivative
23of any RooAbsReal as calculated (numerically) by the MathCore Richardson
24derivator class.
25**/
26
27
28#include "Riostream.h"
29#include <math.h>
30
31#include "RooMoment.h"
32#include "RooAbsReal.h"
33#include "RooAbsPdf.h"
34#include "RooErrorHandler.h"
35#include "RooArgSet.h"
36#include "RooMsgService.h"
37#include "RooRealVar.h"
38#include "RooFunctor.h"
39#include "RooFormulaVar.h"
40#include "RooGlobalFunc.h"
41#include "RooConstVar.h"
42#include "RooRealIntegral.h"
43#include "RooNumIntConfig.h"
44#include <string>
45using namespace std;
46
47
49
50
51
52////////////////////////////////////////////////////////////////////////////////
53/// Default constructor
54
56{
57}
58
59
60
61////////////////////////////////////////////////////////////////////////////////
62
63RooMoment::RooMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, Int_t orderIn, Bool_t centr, Bool_t takeRoot) :
64 RooAbsMoment(name, title,func,x,orderIn,takeRoot),
65 _xf("!xf","xf",this,kFALSE,kFALSE),
66 _ixf("!ixf","ixf",this),
67 _if("!if","if",this)
68{
70
71 string pname=Form("%s_product",name) ;
72
73 RooFormulaVar* XF ;
74 if (centr) {
75 string formula=Form("pow((@0-@1),%d)*@2",_order) ;
76 string m1name=Form("%s_moment1",GetName()) ;
77 RooAbsReal* mom1 = func.mean(x) ;
78 XF = new RooFormulaVar(pname.c_str(),formula.c_str(),RooArgList(x,*mom1,func)) ;
80 addOwnedComponents(*mom1) ;
81 _mean.setArg(*mom1) ;
82 } else {
83 string formula=Form("pow(@0,%d)*@1",_order) ;
84 XF = new RooFormulaVar(pname.c_str(),formula.c_str(),RooArgSet(x,func)) ;
86 }
87
88 if (func.isBinnedDistribution(x)) {
89 XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
90 }
91
94 intXF->setCacheNumeric(kTRUE) ;
95 intF->setCacheNumeric(kTRUE) ;
96
97 _xf.setArg(*XF) ;
98 _ixf.setArg(*intXF) ;
99 _if.setArg(*intF) ;
100 addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
101}
102
103////////////////////////////////////////////////////////////////////////////////
104
105RooMoment::RooMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset,
106 Int_t orderIn, Bool_t centr, Bool_t takeRoot, Bool_t intNSet) :
107 RooAbsMoment(name, title,func,x,orderIn,takeRoot),
108 _xf("!xf","xf",this,kFALSE,kFALSE),
109 _ixf("!ixf","ixf",this),
110 _if("!if","if",this)
111{
113
114 _nset.add(nset) ;
115
116 string pname=Form("%s_product",name) ;
117 RooFormulaVar* XF ;
118 if (centr) {
119 string formula=Form("pow((@0-@1),%d)*@2",_order) ;
120 string m1name=Form("%s_moment1",GetName()) ;
121 RooAbsReal* mom1 = func.mean(x,nset) ;
122 XF = new RooFormulaVar(pname.c_str(),formula.c_str(),RooArgList(x,*mom1,func)) ;
124 addOwnedComponents(*mom1) ;
125 _mean.setArg(*mom1) ;
126 } else {
127 string formula=Form("pow(@0,%d)*@1",_order) ;
128 XF = new RooFormulaVar(pname.c_str(),formula.c_str(),RooArgSet(x,func)) ;
130 }
131
132 if (func.isBinnedDistribution(x)) {
133 XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
134 }
135
136 RooArgSet intSet(x) ;
137 if (intNSet) intSet.add(_nset,kTRUE) ;
138
139 RooRealIntegral* intXF = (RooRealIntegral*) XF->createIntegral(intSet,&_nset) ;
140 RooRealIntegral* intF = (RooRealIntegral*) func.createIntegral(intSet,&_nset) ;
141 intXF->setCacheNumeric(kTRUE) ;
142 intF->setCacheNumeric(kTRUE) ;
143
144 _xf.setArg(*XF) ;
145 _ixf.setArg(*intXF) ;
146 _if.setArg(*intF) ;
147 addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
148}
149
150
151
152////////////////////////////////////////////////////////////////////////////////
153
154RooMoment::RooMoment(const RooMoment& other, const char* name) :
155 RooAbsMoment(other, name),
156 _xf("xf",this,other._xf),
157 _ixf("ixf",this,other._ixf),
158 _if("if",this,other._if)
159{
160}
161
162
163
164////////////////////////////////////////////////////////////////////////////////
165/// Destructor
166
168{
169}
170
171
172
173////////////////////////////////////////////////////////////////////////////////
174/// Calculate value
175
177{
178 Double_t ratio = _ixf / _if ;
179 Double_t ret = _takeRoot ? pow(ratio,1.0/_order) : ratio ;
180 return ret ;
181}
182
183
const Bool_t kFALSE
Definition: RtypesCore.h:101
const Bool_t kTRUE
Definition: RtypesCore.h:100
#define ClassImp(name)
Definition: Rtypes.h:375
char name[80]
Definition: TGX11.cxx:110
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition: TString.cxx:2447
RooExpensiveObjectCache & expensiveObjectCache() const
Definition: RooAbsArg.cxx:2354
friend class RooArgSet
Definition: RooAbsArg.h:651
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition: RooAbsArg.h:527
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
Definition: RooAbsArg.cxx:2275
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
RooAbsMoment represents the first, second, or third order derivative of any RooAbsReal as calculated ...
Definition: RooAbsMoment.h:27
RooRealProxy _mean
Mean (if calculated for central moment)
Definition: RooAbsMoment.h:47
Int_t _order
Moment order.
Definition: RooAbsMoment.h:42
Int_t _takeRoot
Return n-order root of moment.
Definition: RooAbsMoment.h:43
RooSetProxy _nset
Normalization set (optional)
Definition: RooAbsMoment.h:44
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:63
RooAbsMoment * mean(RooRealVar &obs)
Definition: RooAbsReal.h:360
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:553
RooNumIntConfig * specialIntegratorConfig() const
Returns the specialized integrator configuration for this RooAbsReal.
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:344
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:57
Bool_t setLabel(const char *label, bool printError=true) override
Set value by specifying the name of the desired state.
bool add(const RooAbsArg &var, bool valueServer, bool shapeServer, bool silent)
Overloaded RooCollection_t::add() method insert object into set and registers object as server to own...
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:30
RooMoment represents the first, second, or third order derivative of any RooAbsReal as calculated (nu...
Definition: RooMoment.h:27
RooRealProxy _xf
X*F.
Definition: RooMoment.h:45
~RooMoment() override
Destructor.
Definition: RooMoment.cxx:167
RooRealProxy _if
Int(F(x))dx ;.
Definition: RooMoment.h:47
RooMoment()
Default constructor.
Definition: RooMoment.cxx:55
RooRealProxy _ixf
Int(X*F(X))dx ;.
Definition: RooMoment.h:46
Double_t evaluate() const override
Calculate value.
Definition: RooMoment.cxx:176
RooCategory & method1D()
RooRealIntegral performs hybrid numerical/analytical integrals of RooAbsReal objects.
void setCacheNumeric(Bool_t flag)
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
bool setArg(T &newRef)
Change object held in proxy into newRef.
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
RVec< PromoteTypes< T0, T1 > > pow(const T0 &x, const RVec< T1 > &v)
Definition: RVec.hxx:1753
Double_t x[n]
Definition: legend1.C:17