Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 _mean.putOwnedArg(std::unique_ptr<RooAbsMoment>{func.mean(x)}) ;
81
82 string pname=Form("%s_product",name) ;
84 XF = new RooFormulaVar(pname.c_str(),Form("pow((@0-%f),2)*@1",_xfOffset),RooArgList(x,func)) ;
85
86 } else {
87
88 string pname=Form("%s_product",name) ;
89 XF = new RooProduct(pname.c_str(),pname.c_str(),RooArgList(x,x,func)) ;
90 }
91
93
94 if (func.isBinnedDistribution(x)) {
95 XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
96 }
97
100 intXF->setCacheNumeric(kTRUE) ;
101 intF->setCacheNumeric(kTRUE) ;
102
103 _xf.setArg(*XF) ;
104 _ixf.setArg(*intXF) ;
105 _if.setArg(*intF) ;
106 addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
107}
108
109////////////////////////////////////////////////////////////////////////////////
110
111RooSecondMoment::RooSecondMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset,
112 Bool_t centr, Bool_t takeRoot, Bool_t intNSet) :
113 RooAbsMoment(name, title,func,x,2,takeRoot),
114 _xf("!xf","xf",this,kFALSE,kFALSE),
115 _ixf("!ixf","ixf",this),
116 _if("!if","if",this),
117 _xfOffset(0)
118{
120
121 _nset.add(nset) ;
122
123 RooAbsReal* XF(0) ;
124 if (centr) {
125
126 string m1name=Form("%s_moment1",GetName()) ;
127 _mean.putOwnedArg(std::unique_ptr<RooAbsMoment>{func.mean(x,nset)}) ;
128
129 string pname=Form("%s_product",name) ;
130 _xfOffset = _mean->getVal() ;
131 XF = new RooFormulaVar(pname.c_str(),Form("pow((@0-%f),2)*@1",_xfOffset),RooArgList(x,func)) ;
132
133
134 } else {
135
136 string pname=Form("%s_product",name) ;
137 XF = new RooProduct(pname.c_str(),pname.c_str(),RooArgList(x,x,func)) ;
138
139 }
140
142
143 if (func.isBinnedDistribution(x)) {
144 XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
145 }
146 if (intNSet && _nset.getSize()>0 && func.isBinnedDistribution(_nset)) {
147 XF->specialIntegratorConfig(kTRUE)->method2D().setLabel("RooBinIntegrator");
148 XF->specialIntegratorConfig(kTRUE)->methodND().setLabel("RooBinIntegrator");
149 }
150
151 RooArgSet intSet(x) ;
152 if (intNSet) intSet.add(_nset,kTRUE) ;
153 RooRealIntegral* intXF = (RooRealIntegral*) XF->createIntegral(intSet,&_nset) ;
154 RooRealIntegral* intF = (RooRealIntegral*) func.createIntegral(intSet,&_nset) ;
155 intXF->setCacheNumeric(kTRUE) ;
156 intF->setCacheNumeric(kTRUE) ;
157
158 _xf.setArg(*XF) ;
159 _ixf.setArg(*intXF) ;
160 _if.setArg(*intF) ;
161 addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
162}
163
164
165
166////////////////////////////////////////////////////////////////////////////////
167
169 RooAbsMoment(other, name),
170 _xf("xf",this,other._xf),
171 _ixf("ixf",this,other._ixf),
172 _if("if",this,other._if),
173 _xfOffset(other._xfOffset)
174{
175}
176
177
178
179////////////////////////////////////////////////////////////////////////////////
180/// Destructor
181
183{
184}
185
186
187
188////////////////////////////////////////////////////////////////////////////////
189/// Calculate value
190
192{
193 Double_t ratio = _ixf / _if ;
194
195 if (_mean.absArg()) {
196 ratio -= (_mean - _xfOffset)*(_mean-_xfOffset) ;
197 }
198
199 Double_t ret = _takeRoot ? sqrt(ratio) : ratio ;
200 return ret ;
201}
202
203
const Bool_t kFALSE
Definition RtypesCore.h:92
const Bool_t kTRUE
Definition RtypesCore.h:91
#define ClassImp(name)
Definition Rtypes.h:364
char name[80]
Definition TGX11.cxx:110
double sqrt(double)
char * Form(const char *fmt,...)
RooExpensiveObjectCache & expensiveObjectCache() const
friend class RooArgSet
Definition RooAbsArg.h:606
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition RooAbsArg.h:521
Bool_t addOwnedComponents(const RooArgSet &comps)
Take ownership of the contents of 'comps'.
Int_t getSize() const
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:61
RooAbsMoment * mean(RooRealVar &obs)
Definition RooAbsReal.h:357
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:91
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:341
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:29
Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE) override
Add element to non-owning set.
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...
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_t flag)
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:39
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) override
Overloaded RooArgSet::add() method inserts 'var' into set and registers 'var' as server to owner with...
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.
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
Double_t x[n]
Definition legend1.C:17