Logo ROOT   6.18/05
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 "Riostream.h"
32#include <math.h>
33
34#include "RooSecondMoment.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 "RooGlobalFunc.h"
43#include "RooConstVar.h"
44#include "RooRealIntegral.h"
45#include "RooNumIntConfig.h"
46#include "RooFormulaVar.h"
47#include "RooLinearVar.h"
48#include "RooProduct.h"
49#include "RooGlobalFunc.h"
50#include <string>
51using namespace std ;
52
53
55;
56
57
58////////////////////////////////////////////////////////////////////////////////
59/// Default constructor
60
62{
63}
64
65
66
67////////////////////////////////////////////////////////////////////////////////
68
69RooSecondMoment::RooSecondMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, Bool_t centr, Bool_t takeRoot) :
70 RooAbsMoment(name, title,func,x,2,takeRoot),
71 _xf("!xf","xf",this,kFALSE,kFALSE),
72 _ixf("!ixf","ixf",this),
73 _if("!if","if",this),
74 _xfOffset(0)
75{
77
78 RooAbsReal* XF(0) ;
79 if (centr) {
80
81 string m1name=Form("%s_moment1",GetName()) ;
82 RooAbsReal* mom1 = func.mean(x) ;
83 _mean.setArg(*mom1) ;
84
85 string pname=Form("%s_product",name) ;
86 _xfOffset = mom1->getVal() ;
87 XF = new RooFormulaVar(pname.c_str(),Form("pow((@0-%f),2)*@1",_xfOffset),RooArgList(x,func)) ;
88
89 } else {
90
91 string pname=Form("%s_product",name) ;
92 XF = new RooProduct(pname.c_str(),pname.c_str(),RooArgList(x,x,func)) ;
93 }
94
96
97 if (func.isBinnedDistribution(x)) {
98 XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
99 }
100
103 intXF->setCacheNumeric(kTRUE) ;
104 intF->setCacheNumeric(kTRUE) ;
105
106 _xf.setArg(*XF) ;
107 _ixf.setArg(*intXF) ;
108 _if.setArg(*intF) ;
109 addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
110}
111
112////////////////////////////////////////////////////////////////////////////////
113
114RooSecondMoment::RooSecondMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset,
115 Bool_t centr, Bool_t takeRoot, Bool_t intNSet) :
116 RooAbsMoment(name, title,func,x,2,takeRoot),
117 _xf("!xf","xf",this,kFALSE,kFALSE),
118 _ixf("!ixf","ixf",this),
119 _if("!if","if",this),
120 _xfOffset(0)
121{
123
124 _nset.add(nset) ;
125
126 RooAbsReal* XF(0) ;
127 if (centr) {
128
129 string m1name=Form("%s_moment1",GetName()) ;
130 RooAbsReal* mom1 = func.mean(x,nset) ;
131 _mean.setArg(*mom1) ;
132
133 string pname=Form("%s_product",name) ;
134 _xfOffset = mom1->getVal() ;
135 XF = new RooFormulaVar(pname.c_str(),Form("pow((@0-%f),2)*@1",_xfOffset),RooArgList(x,func)) ;
136
137
138 } else {
139
140 string pname=Form("%s_product",name) ;
141 XF = new RooProduct(pname.c_str(),pname.c_str(),RooArgList(x,x,func)) ;
142
143 }
144
146
147 if (func.isBinnedDistribution(x)) {
148 XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
149 }
150 if (intNSet && _nset.getSize()>0 && func.isBinnedDistribution(_nset)) {
151 XF->specialIntegratorConfig(kTRUE)->method2D().setLabel("RooBinIntegrator");
152 XF->specialIntegratorConfig(kTRUE)->methodND().setLabel("RooBinIntegrator");
153 }
154
155 RooArgSet intSet(x) ;
156 if (intNSet) intSet.add(_nset,kTRUE) ;
157 RooRealIntegral* intXF = (RooRealIntegral*) XF->createIntegral(intSet,&_nset) ;
158 RooRealIntegral* intF = (RooRealIntegral*) func.createIntegral(intSet,&_nset) ;
159 intXF->setCacheNumeric(kTRUE) ;
160 intF->setCacheNumeric(kTRUE) ;
161
162 _xf.setArg(*XF) ;
163 _ixf.setArg(*intXF) ;
164 _if.setArg(*intF) ;
165 addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
166}
167
168
169
170////////////////////////////////////////////////////////////////////////////////
171
173 RooAbsMoment(other, name),
174 _xf("xf",this,other._xf),
175 _ixf("ixf",this,other._ixf),
176 _if("if",this,other._if),
177 _xfOffset(other._xfOffset)
178{
179}
180
181
182
183////////////////////////////////////////////////////////////////////////////////
184/// Destructor
185
187{
188}
189
190
191
192////////////////////////////////////////////////////////////////////////////////
193/// Calculate value
194
196{
197 Double_t ratio = _ixf / _if ;
198
199 if (_mean.absArg()) {
200 ratio -= (_mean - _xfOffset)*(_mean-_xfOffset) ;
201 }
202
203 Double_t ret = _takeRoot ? sqrt(ratio) : ratio ;
204 return ret ;
205}
206
207
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 sqrt(double)
char * Form(const char *fmt,...)
RooExpensiveObjectCache & expensiveObjectCache() const
Definition: RooAbsArg.cxx:2293
friend class RooArgSet
Definition: RooAbsArg.h:516
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition: RooAbsArg.h:543
Bool_t addOwnedComponents(const RooArgSet &comps)
Take ownership of the contents of 'comps'.
Definition: RooAbsArg.cxx:2232
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:53
RooAbsMoment * mean(RooRealVar &obs)
Definition: RooAbsReal.h:315
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:81
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:531
RooNumIntConfig * specialIntegratorConfig() const
Returns the specialized integrator configuration for this RooAbsReal.
virtual Bool_t isBinnedDistribution(const RooArgSet &) const
Definition: RooAbsReal.h:295
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_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:27
RooCategory & method2D()
RooCategory & methodND()
RooCategory & method1D()
A RooProduct represents the product of a given set of RooAbsReal objects.
Definition: RooProduct.h:32
RooRealIntegral performs hybrid numerical/analytical integrals of RooAbsReal objects.
void setCacheNumeric(Bool_t flag)
virtual Bool_t setArg(RooAbsReal &newRef)
Change object held in proxy into newRef.
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
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...
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Double_t x[n]
Definition: legend1.C:17