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 "RooFit.h"
29
30#include "Riostream.h"
31#include "Riostream.h"
32#include <math.h>
33
34#include "RooMoment.h"
35#include "RooAbsReal.h"
36#include "RooAbsPdf.h"
37#include "RooErrorHandler.h"
38#include "RooArgSet.h"
39#include "RooMsgService.h"
40#include "RooRealVar.h"
41#include "RooFunctor.h"
42#include "RooFormulaVar.h"
43#include "RooGlobalFunc.h"
44#include "RooConstVar.h"
45#include "RooRealIntegral.h"
46#include "RooNumIntConfig.h"
47#include <string>
48using namespace std ;
49
50
52;
53
54
55////////////////////////////////////////////////////////////////////////////////
56/// Default constructor
57
59{
60}
61
62
63
64////////////////////////////////////////////////////////////////////////////////
65
66RooMoment::RooMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, Int_t orderIn, Bool_t centr, Bool_t takeRoot) :
67 RooAbsMoment(name, title,func,x,orderIn,takeRoot),
68 _xf("!xf","xf",this,kFALSE,kFALSE),
69 _ixf("!ixf","ixf",this),
70 _if("!if","if",this)
71{
73
74 string pname=Form("%s_product",name) ;
75
76 RooFormulaVar* XF ;
77 if (centr) {
78 string formula=Form("pow((@0-@1),%d)*@2",_order) ;
79 string m1name=Form("%s_moment1",GetName()) ;
80 RooAbsReal* mom1 = func.mean(x) ;
81 XF = new RooFormulaVar(pname.c_str(),formula.c_str(),RooArgList(x,*mom1,func)) ;
83 addOwnedComponents(*mom1) ;
84 _mean.setArg(*mom1) ;
85 } else {
86 string formula=Form("pow(@0,%d)*@1",_order) ;
87 XF = new RooFormulaVar(pname.c_str(),formula.c_str(),RooArgSet(x,func)) ;
89 }
90
91 if (func.isBinnedDistribution(x)) {
92 XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
93 }
94
97 intXF->setCacheNumeric(kTRUE) ;
98 intF->setCacheNumeric(kTRUE) ;
99
100 _xf.setArg(*XF) ;
101 _ixf.setArg(*intXF) ;
102 _if.setArg(*intF) ;
103 addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
104}
105
106////////////////////////////////////////////////////////////////////////////////
107
108RooMoment::RooMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset,
109 Int_t orderIn, Bool_t centr, Bool_t takeRoot, Bool_t intNSet) :
110 RooAbsMoment(name, title,func,x,orderIn,takeRoot),
111 _xf("!xf","xf",this,kFALSE,kFALSE),
112 _ixf("!ixf","ixf",this),
113 _if("!if","if",this)
114{
116
117 _nset.add(nset) ;
118
119 string pname=Form("%s_product",name) ;
120 RooFormulaVar* XF ;
121 if (centr) {
122 string formula=Form("pow((@0-@1),%d)*@2",_order) ;
123 string m1name=Form("%s_moment1",GetName()) ;
124 RooAbsReal* mom1 = func.mean(x,nset) ;
125 XF = new RooFormulaVar(pname.c_str(),formula.c_str(),RooArgList(x,*mom1,func)) ;
127 addOwnedComponents(*mom1) ;
128 _mean.setArg(*mom1) ;
129 } else {
130 string formula=Form("pow(@0,%d)*@1",_order) ;
131 XF = new RooFormulaVar(pname.c_str(),formula.c_str(),RooArgSet(x,func)) ;
133 }
134
135 if (func.isBinnedDistribution(x)) {
136 XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
137 }
138
139 RooArgSet intSet(x) ;
140 if (intNSet) intSet.add(_nset,kTRUE) ;
141
142 RooRealIntegral* intXF = (RooRealIntegral*) XF->createIntegral(intSet,&_nset) ;
143 RooRealIntegral* intF = (RooRealIntegral*) func.createIntegral(intSet,&_nset) ;
144 intXF->setCacheNumeric(kTRUE) ;
145 intF->setCacheNumeric(kTRUE) ;
146
147 _xf.setArg(*XF) ;
148 _ixf.setArg(*intXF) ;
149 _if.setArg(*intF) ;
150 addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
151}
152
153
154
155////////////////////////////////////////////////////////////////////////////////
156
157RooMoment::RooMoment(const RooMoment& other, const char* name) :
158 RooAbsMoment(other, name),
159 _xf("xf",this,other._xf),
160 _ixf("ixf",this,other._ixf),
161 _if("if",this,other._if)
162{
163}
164
165
166
167////////////////////////////////////////////////////////////////////////////////
168/// Destructor
169
171{
172}
173
174
175
176////////////////////////////////////////////////////////////////////////////////
177/// Calculate value
178
180{
181 Double_t ratio = _ixf / _if ;
182 Double_t ret = _takeRoot ? pow(ratio,1.0/_order) : ratio ;
183 return ret ;
184}
185
186
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:365
char name[80]
Definition: TGX11.cxx:109
double pow(double, double)
char * Form(const char *fmt,...)
RooExpensiveObjectCache & expensiveObjectCache() const
Definition: RooAbsArg.cxx:2176
friend class RooArgSet
Definition: RooAbsArg.h:551
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition: RooAbsArg.h:500
Bool_t addOwnedComponents(const RooArgSet &comps)
Take ownership of the contents of 'comps'.
Definition: RooAbsArg.cxx:2115
RooAbsMoment represents the first, second, or third order derivative of any RooAbsReal as calculated ...
Definition: RooAbsMoment.h:27
RooRealProxy _mean
Definition: RooAbsMoment.h:47
Int_t _takeRoot
Definition: RooAbsMoment.h:43
RooSetProxy _nset
Definition: RooAbsMoment.h:44
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:59
RooAbsMoment * mean(RooRealVar &obs)
Definition: RooAbsReal.h:329
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:562
RooNumIntConfig * specialIntegratorConfig() const
Returns the specialized integrator configuration for this RooAbsReal.
virtual Bool_t isBinnedDistribution(const RooArgSet &) const
Definition: RooAbsReal.h:309
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
Definition: RooArgSet.h:88
virtual Bool_t setLabel(const char *label, Bool_t printError=kTRUE)
Set value by specifying the name of the desired state If printError is set, a message will be printed...
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:29
RooMoment represents the first, second, or third order derivative of any RooAbsReal as calculated (nu...
Definition: RooMoment.h:27
RooRealProxy _xf
Definition: RooMoment.h:45
Double_t evaluate() const
Calculate value
Definition: RooMoment.cxx:179
RooRealProxy _if
Definition: RooMoment.h:47
RooMoment()
Default constructor.
Definition: RooMoment.cxx:58
RooRealProxy _ixf
Definition: RooMoment.h:46
virtual ~RooMoment()
Destructor.
Definition: RooMoment.cxx:170
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:35
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Overloaded RooArgSet::add() method inserts 'var' into set and registers 'var' as server to owner with...
Bool_t setArg(T &newRef)
Change object held in proxy into newRef.
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Double_t x[n]
Definition: legend1.C:17