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#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 std::unique_ptr<RooAbsReal> XF;
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 = std::make_unique<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 = std::make_unique<RooProduct>(pname.c_str(),pname.c_str(),RooArgList(x,x,func)) ;
87 }
88
89 XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;
90
91 if (func.isBinnedDistribution(x)) {
92 XF->specialIntegratorConfig(true)->method1D().setLabel("RooBinIntegrator");
93 }
94
95 std::unique_ptr<RooAbsReal> intXF{XF->createIntegral(x)};
96 std::unique_ptr<RooAbsReal> intF{func.createIntegral(x)};
97 static_cast<RooRealIntegral&>(*intXF).setCacheNumeric(true) ;
98 static_cast<RooRealIntegral&>(*intF).setCacheNumeric(true) ;
99
100 _xf.setArg(*XF) ;
101 _ixf.setArg(*intXF) ;
102 _if.setArg(*intF) ;
103 addOwnedComponents(std::move(XF)) ;
104 addOwnedComponents(std::move(intXF));
105 addOwnedComponents(std::move(intF));
106}
107
108////////////////////////////////////////////////////////////////////////////////
109
110RooSecondMoment::RooSecondMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset,
111 bool centr, bool takeRoot, bool intNSet) :
112 RooAbsMoment(name, title,func,x,2,takeRoot),
113 _xf("!xf","xf",this,false,false),
114 _ixf("!ixf","ixf",this),
115 _if("!if","if",this),
116 _xfOffset(0)
117{
119
120 _nset.add(nset) ;
121
122 std::unique_ptr<RooAbsReal> XF;
123 if (centr) {
124
125 string m1name=Form("%s_moment1",GetName()) ;
126 _mean.putOwnedArg(std::unique_ptr<RooAbsMoment>{func.mean(x,nset)}) ;
127
128 string pname=Form("%s_product",name) ;
129 _xfOffset = _mean->getVal() ;
130 XF = std::make_unique<RooFormulaVar>(pname.c_str(),Form("pow((@0-%f),2)*@1",_xfOffset),RooArgList(x,func)) ;
131
132
133 } else {
134
135 string pname=Form("%s_product",name) ;
136 XF = std::make_unique<RooProduct>(pname.c_str(),pname.c_str(),RooArgList(x,x,func)) ;
137
138 }
139
140 XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;
141
142 if (func.isBinnedDistribution(x)) {
143 XF->specialIntegratorConfig(true)->method1D().setLabel("RooBinIntegrator");
144 }
145 if (intNSet && _nset.getSize()>0 && func.isBinnedDistribution(_nset)) {
146 XF->specialIntegratorConfig(true)->method2D().setLabel("RooBinIntegrator");
147 XF->specialIntegratorConfig(true)->methodND().setLabel("RooBinIntegrator");
148 }
149
150 RooArgSet intSet(x) ;
151 if (intNSet) intSet.add(_nset,true) ;
152 std::unique_ptr<RooAbsReal> intXF{XF->createIntegral(intSet, &_nset)};
153 std::unique_ptr<RooAbsReal> intF{func.createIntegral(intSet, &_nset)};
154 static_cast<RooRealIntegral&>(*intXF).setCacheNumeric(true) ;
155 static_cast<RooRealIntegral&>(*intF).setCacheNumeric(true) ;
156
157 _xf.setArg(*XF) ;
158 _ixf.setArg(*intXF) ;
159 _if.setArg(*intF) ;
160 addOwnedComponents(std::move(XF)) ;
161 addOwnedComponents(std::move(intXF));
162 addOwnedComponents(std::move(intF));
163}
164
165
166
167////////////////////////////////////////////////////////////////////////////////
168
170 RooAbsMoment(other, name),
171 _xf("xf",this,other._xf),
172 _ixf("ixf",this,other._ixf),
173 _if("if",this,other._if),
174 _xfOffset(other._xfOffset)
175{
176}
177
178
179
180////////////////////////////////////////////////////////////////////////////////
181/// Destructor
182
184{
185}
186
187
188
189////////////////////////////////////////////////////////////////////////////////
190/// Calculate value
191
193{
194 double ratio = _ixf / _if ;
195
196 if (_mean.absArg()) {
197 ratio -= (_mean - _xfOffset)*(_mean-_xfOffset) ;
198 }
199
200 double ret = _takeRoot ? sqrt(ratio) : ratio ;
201 return ret ;
202}
203
204
#define ClassImp(name)
Definition Rtypes.h:377
char name[80]
Definition TGX11.cxx:110
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2467
RooExpensiveObjectCache & expensiveObjectCache() const
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition RooAbsArg.h:500
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
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 ...
RooRealProxy _mean
Mean (if calculated for central moment)
Int_t _takeRoot
Return n-order root of moment.
RooSetProxy _nset
Normalization set (optional)
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:374
RooFit::OwningPtr< 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...
virtual bool isBinnedDistribution(const RooArgSet &) const
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
Definition RooAbsReal.h:358
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:55
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...
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