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#include "Riostream.h"
28#include <math.h>
29
30#include "RooSecondMoment.h"
31#include "RooAbsReal.h"
32#include "RooAbsPdf.h"
33#include "RooErrorHandler.h"
34#include "RooArgSet.h"
35#include "RooMsgService.h"
36#include "RooRealVar.h"
37#include "RooFunctor.h"
38#include "RooGlobalFunc.h"
39#include "RooConstVar.h"
40#include "RooRealIntegral.h"
41#include "RooNumIntConfig.h"
42#include "RooFormulaVar.h"
43#include "RooLinearVar.h"
44#include "RooProduct.h"
45#include <string>
46using namespace std;
47
48
50
51
52
53////////////////////////////////////////////////////////////////////////////////
54/// Default constructor
55
57{
58}
59
60
61
62////////////////////////////////////////////////////////////////////////////////
63
64RooSecondMoment::RooSecondMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, bool centr, bool takeRoot) :
65 RooAbsMoment(name, title,func,x,2,takeRoot),
66 _xf("!xf","xf",this,false,false),
67 _ixf("!ixf","ixf",this),
68 _if("!if","if",this),
69 _xfOffset(0)
70{
72
73 RooAbsReal* XF(0) ;
74 if (centr) {
75
76 string m1name=Form("%s_moment1",GetName()) ;
77 _mean.putOwnedArg(std::unique_ptr<RooAbsMoment>{func.mean(x)}) ;
78
79 string pname=Form("%s_product",name) ;
81 XF = new RooFormulaVar(pname.c_str(),Form("pow((@0-%f),2)*@1",_xfOffset),RooArgList(x,func)) ;
82
83 } else {
84
85 string pname=Form("%s_product",name) ;
86 XF = new RooProduct(pname.c_str(),pname.c_str(),RooArgList(x,x,func)) ;
87 }
88
90
91 if (func.isBinnedDistribution(x)) {
92 XF->specialIntegratorConfig(true)->method1D().setLabel("RooBinIntegrator");
93 }
94
97 intXF->setCacheNumeric(true) ;
98 intF->setCacheNumeric(true) ;
99
100 _xf.setArg(*XF) ;
101 _ixf.setArg(*intXF) ;
102 _if.setArg(*intF) ;
103 addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
104}
105
106////////////////////////////////////////////////////////////////////////////////
107
108RooSecondMoment::RooSecondMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset,
109 bool centr, bool takeRoot, bool intNSet) :
110 RooAbsMoment(name, title,func,x,2,takeRoot),
111 _xf("!xf","xf",this,false,false),
112 _ixf("!ixf","ixf",this),
113 _if("!if","if",this),
114 _xfOffset(0)
115{
117
118 _nset.add(nset) ;
119
120 RooAbsReal* XF(0) ;
121 if (centr) {
122
123 string m1name=Form("%s_moment1",GetName()) ;
124 _mean.putOwnedArg(std::unique_ptr<RooAbsMoment>{func.mean(x,nset)}) ;
125
126 string pname=Form("%s_product",name) ;
127 _xfOffset = _mean->getVal() ;
128 XF = new RooFormulaVar(pname.c_str(),Form("pow((@0-%f),2)*@1",_xfOffset),RooArgList(x,func)) ;
129
130
131 } else {
132
133 string pname=Form("%s_product",name) ;
134 XF = new RooProduct(pname.c_str(),pname.c_str(),RooArgList(x,x,func)) ;
135
136 }
137
139
140 if (func.isBinnedDistribution(x)) {
141 XF->specialIntegratorConfig(true)->method1D().setLabel("RooBinIntegrator");
142 }
143 if (intNSet && _nset.getSize()>0 && func.isBinnedDistribution(_nset)) {
144 XF->specialIntegratorConfig(true)->method2D().setLabel("RooBinIntegrator");
145 XF->specialIntegratorConfig(true)->methodND().setLabel("RooBinIntegrator");
146 }
147
148 RooArgSet intSet(x) ;
149 if (intNSet) intSet.add(_nset,true) ;
150 RooRealIntegral* intXF = (RooRealIntegral*) XF->createIntegral(intSet,&_nset) ;
151 RooRealIntegral* intF = (RooRealIntegral*) func.createIntegral(intSet,&_nset) ;
152 intXF->setCacheNumeric(true) ;
153 intF->setCacheNumeric(true) ;
154
155 _xf.setArg(*XF) ;
156 _ixf.setArg(*intXF) ;
157 _if.setArg(*intF) ;
158 addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
159}
160
161
162
163////////////////////////////////////////////////////////////////////////////////
164
166 RooAbsMoment(other, name),
167 _xf("xf",this,other._xf),
168 _ixf("ixf",this,other._ixf),
169 _if("if",this,other._if),
170 _xfOffset(other._xfOffset)
171{
172}
173
174
175
176////////////////////////////////////////////////////////////////////////////////
177/// Destructor
178
180{
181}
182
183
184
185////////////////////////////////////////////////////////////////////////////////
186/// Calculate value
187
189{
190 double ratio = _ixf / _if ;
191
192 if (_mean.absArg()) {
193 ratio -= (_mean - _xfOffset)*(_mean-_xfOffset) ;
194 }
195
196 double ret = _takeRoot ? sqrt(ratio) : ratio ;
197 return ret ;
198}
199
200
#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:2456
RooExpensiveObjectCache & expensiveObjectCache() const
Definition: RooAbsArg.cxx:2271
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition: RooAbsArg.h:503
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
Definition: RooAbsArg.cxx:2185
Int_t getSize() const
Return the number of elements in the collection.
virtual bool add(const RooAbsArg &var, bool silent=false)
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 _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:62
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:91
RooAbsMoment * mean(RooRealVar &obs)
Definition: RooAbsReal.h:358
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 std::liste...
Definition: RooAbsReal.cxx:522
RooNumIntConfig * specialIntegratorConfig() const
Returns the specialized integrator configuration for this RooAbsReal.
virtual bool isBinnedDistribution(const RooArgSet &) const
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
Definition: RooAbsReal.h:342
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:22
RooAbsArg * absArg() const
Return pointer to contained argument.
Definition: RooArgProxy.h:47
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:56
bool 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
RooCategory & method2D()
RooCategory & methodND()
RooCategory & method1D()
A RooProduct represents the product of a given set of RooAbsReal objects.
Definition: RooProduct.h:29
RooRealIntegral performs hybrid numerical/analytical integrals of RooAbsReal objects.
void setCacheNumeric(bool flag)
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
RooSecondMoment represents the first, second, or third order derivative of any RooAbsReal as calculat...
RooRealProxy _ixf
Int((X-offset)*F(X))dx ;.
RooRealProxy _if
Int(F(x))dx ;.
double evaluate() const override
Calculate value.
RooSecondMoment()
Default constructor.
double _xfOffset
offset
RooRealProxy _xf
(X-offset)*F
~RooSecondMoment() override
Destructor.
U & putOwnedArg(std::unique_ptr< U > ownedArg)
Move a new object held and owned by proxy.
bool setArg(T &newRef)
Change object held in proxy into newRef.
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
Double_t x[n]
Definition: legend1.C:17
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)