Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 <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>
47using namespace std;
48
49
51
52
53
54////////////////////////////////////////////////////////////////////////////////
55/// Default constructor
56
58{
59}
60
61
62
63////////////////////////////////////////////////////////////////////////////////
64
65RooMoment::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
107RooMoment::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
156RooMoment::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
const Bool_t kFALSE
Definition RtypesCore.h:101
const Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:364
char name[80]
Definition TGX11.cxx:110
char * Form(const char *fmt,...)
RooExpensiveObjectCache & expensiveObjectCache() const
friend class RooArgSet
Definition RooAbsArg.h:642
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition RooAbsArg.h:518
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
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 ...
RooRealProxy _mean
RooSetProxy _nset
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:64
RooAbsMoment * mean(RooRealVar &obs)
Definition RooAbsReal.h:361
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 ...
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:345
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:35
virtual Bool_t setLabel(const char *label, bool printError=true) override
Set value by specifying the name of the desired state.
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
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
RooRealProxy _if
Definition RooMoment.h:47
RooMoment()
Default constructor.
Definition RooMoment.cxx:57
RooRealProxy _ixf
Definition RooMoment.h:46
virtual ~RooMoment()
Destructor.
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:39
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...
bool 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