Logo ROOT  
Reference Guide
RooSecondMoment.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 RooSecondMoment.cxx
19\class RooSecondMoment
20\ingroup Roofitcore
21
22RooSecondMoment 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 "RooSecondMoment.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 "RooGlobalFunc.h"
42#include "RooConstVar.h"
43#include "RooRealIntegral.h"
44#include "RooNumIntConfig.h"
45#include "RooFormulaVar.h"
46#include "RooLinearVar.h"
47#include "RooProduct.h"
48#include <string>
49using namespace std;
50
51
53
54
55
56////////////////////////////////////////////////////////////////////////////////
57/// Default constructor
58
60{
61}
62
63
64
65////////////////////////////////////////////////////////////////////////////////
66
67RooSecondMoment::RooSecondMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, Bool_t centr, Bool_t takeRoot) :
68 RooAbsMoment(name, title,func,x,2,takeRoot),
69 _xf("!xf","xf",this,kFALSE,kFALSE),
70 _ixf("!ixf","ixf",this),
71 _if("!if","if",this),
72 _xfOffset(0)
73{
75
76 RooAbsReal* XF(0) ;
77 if (centr) {
78
79 string m1name=Form("%s_moment1",GetName()) ;
80 RooAbsReal* mom1 = func.mean(x) ;
81 _mean.setArg(*mom1) ;
82
83 string pname=Form("%s_product",name) ;
84 _xfOffset = mom1->getVal() ;
85 XF = new RooFormulaVar(pname.c_str(),Form("pow((@0-%f),2)*@1",_xfOffset),RooArgList(x,func)) ;
86
87 } else {
88
89 string pname=Form("%s_product",name) ;
90 XF = new RooProduct(pname.c_str(),pname.c_str(),RooArgList(x,x,func)) ;
91 }
92
94
95 if (func.isBinnedDistribution(x)) {
96 XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
97 }
98
101 intXF->setCacheNumeric(kTRUE) ;
102 intF->setCacheNumeric(kTRUE) ;
103
104 _xf.setArg(*XF) ;
105 _ixf.setArg(*intXF) ;
106 _if.setArg(*intF) ;
107 addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
108}
109
110////////////////////////////////////////////////////////////////////////////////
111
112RooSecondMoment::RooSecondMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset,
113 Bool_t centr, Bool_t takeRoot, Bool_t intNSet) :
114 RooAbsMoment(name, title,func,x,2,takeRoot),
115 _xf("!xf","xf",this,kFALSE,kFALSE),
116 _ixf("!ixf","ixf",this),
117 _if("!if","if",this),
118 _xfOffset(0)
119{
121
122 _nset.add(nset) ;
123
124 RooAbsReal* XF(0) ;
125 if (centr) {
126
127 string m1name=Form("%s_moment1",GetName()) ;
128 RooAbsReal* mom1 = func.mean(x,nset) ;
129 _mean.setArg(*mom1) ;
130
131 string pname=Form("%s_product",name) ;
132 _xfOffset = mom1->getVal() ;
133 XF = new RooFormulaVar(pname.c_str(),Form("pow((@0-%f),2)*@1",_xfOffset),RooArgList(x,func)) ;
134
135
136 } else {
137
138 string pname=Form("%s_product",name) ;
139 XF = new RooProduct(pname.c_str(),pname.c_str(),RooArgList(x,x,func)) ;
140
141 }
142
144
145 if (func.isBinnedDistribution(x)) {
146 XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
147 }
148 if (intNSet && _nset.getSize()>0 && func.isBinnedDistribution(_nset)) {
149 XF->specialIntegratorConfig(kTRUE)->method2D().setLabel("RooBinIntegrator");
150 XF->specialIntegratorConfig(kTRUE)->methodND().setLabel("RooBinIntegrator");
151 }
152
153 RooArgSet intSet(x) ;
154 if (intNSet) intSet.add(_nset,kTRUE) ;
155 RooRealIntegral* intXF = (RooRealIntegral*) XF->createIntegral(intSet,&_nset) ;
156 RooRealIntegral* intF = (RooRealIntegral*) func.createIntegral(intSet,&_nset) ;
157 intXF->setCacheNumeric(kTRUE) ;
158 intF->setCacheNumeric(kTRUE) ;
159
160 _xf.setArg(*XF) ;
161 _ixf.setArg(*intXF) ;
162 _if.setArg(*intF) ;
163 addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
164}
165
166
167
168////////////////////////////////////////////////////////////////////////////////
169
171 RooAbsMoment(other, name),
172 _xf("xf",this,other._xf),
173 _ixf("ixf",this,other._ixf),
174 _if("if",this,other._if),
175 _xfOffset(other._xfOffset)
176{
177}
178
179
180
181////////////////////////////////////////////////////////////////////////////////
182/// Destructor
183
185{
186}
187
188
189
190////////////////////////////////////////////////////////////////////////////////
191/// Calculate value
192
194{
195 Double_t ratio = _ixf / _if ;
196
197 if (_mean.absArg()) {
198 ratio -= (_mean - _xfOffset)*(_mean-_xfOffset) ;
199 }
200
201 Double_t ret = _takeRoot ? sqrt(ratio) : ratio ;
202 return ret ;
203}
204
205
const Bool_t kFALSE
Definition: RtypesCore.h:90
const Bool_t kTRUE
Definition: RtypesCore.h:89
#define ClassImp(name)
Definition: Rtypes.h:361
char name[80]
Definition: TGX11.cxx:109
double sqrt(double)
char * Form(const char *fmt,...)
RooExpensiveObjectCache & expensiveObjectCache() const
Definition: RooAbsArg.cxx:2168
friend class RooArgSet
Definition: RooAbsArg.h:572
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition: RooAbsArg.h:521
Bool_t addOwnedComponents(const RooArgSet &comps)
Take ownership of the contents of 'comps'.
Definition: RooAbsArg.cxx:2107
Int_t getSize() const
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:60
RooAbsMoment * mean(RooRealVar &obs)
Definition: RooAbsReal.h:332
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:90
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:560
RooNumIntConfig * specialIntegratorConfig() const
Returns the specialized integrator configuration for this RooAbsReal.
virtual Bool_t isBinnedDistribution(const RooArgSet &) const
Definition: RooAbsReal.h:312
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooAbsArg * absArg() const
Definition: RooArgProxy.h:37
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 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...
Definition: RooFormulaVar.h:29
RooCategory & method2D()
RooCategory & methodND()
RooCategory & method1D()
A RooProduct represents the product of a given set of RooAbsReal objects.
Definition: RooProduct.h:30
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
RooSecondMoment represents the first, second, or third order derivative of any RooAbsReal as calculat...
RooRealProxy _ixf
RooRealProxy _if
Double_t evaluate() const
Calculate value
virtual ~RooSecondMoment()
Destructor.
RooSecondMoment()
Default constructor.
RooRealProxy _xf
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 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