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**/
22
23#include "Riostream.h"
24#include <cmath>
25
26#include "RooSecondMoment.h"
27#include "RooAbsReal.h"
28#include "RooAbsPdf.h"
29#include "RooErrorHandler.h"
30#include "RooArgSet.h"
31#include "RooMsgService.h"
32#include "RooRealVar.h"
33#include "RooFunctor.h"
34#include "RooGlobalFunc.h"
35#include "RooConstVar.h"
36#include "RooRealIntegral.h"
37#include "RooNumIntConfig.h"
38#include "RooFormulaVar.h"
39#include "RooLinearVar.h"
40#include "RooProduct.h"
41#include <string>
42using std::string;
43
44
45
46////////////////////////////////////////////////////////////////////////////////
47
48RooSecondMoment::RooSecondMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, bool centr, bool takeRoot) :
49 RooAbsMoment(name, title,func,x,2,takeRoot),
50 _xf("!xf","xf",this,false,false),
51 _ixf("!ixf","ixf",this),
52 _if("!if","if",this),
53 _xfOffset(0)
54{
56
57 std::unique_ptr<RooAbsReal> XF;
58 if (centr) {
59
60 std::string m1name = std::string{GetName()} + "_moment1";
61 _mean.putOwnedArg(std::unique_ptr<RooAbsMoment>{func.mean(x)});
62
63 std::string pname = std::string{name} + "_product";
65 std::stringstream formula;
66 formula << "std::pow((@0-" << _xfOffset << "),2) * @1";
67 XF = std::make_unique<RooFormulaVar>(pname.c_str(), formula.str().c_str(), RooArgList(x, func));
68
69 } else {
70
71 std::string pname = std::string{name} + "_product";
72 XF = std::make_unique<RooProduct>(pname.c_str(), pname.c_str(), RooArgList(x, x, func));
73 }
74
75 XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;
76
77 if (func.isBinnedDistribution(x)) {
78 XF->specialIntegratorConfig(true)->method1D().setLabel("RooBinIntegrator");
79 }
80
81 std::unique_ptr<RooAbsReal> intXF{XF->createIntegral(x)};
82 std::unique_ptr<RooAbsReal> intF{func.createIntegral(x)};
83 static_cast<RooRealIntegral&>(*intXF).setCacheNumeric(true) ;
84 static_cast<RooRealIntegral&>(*intF).setCacheNumeric(true) ;
85
86 _xf.setArg(*XF) ;
87 _ixf.setArg(*intXF) ;
88 _if.setArg(*intF) ;
89 addOwnedComponents(std::move(XF)) ;
90 addOwnedComponents(std::move(intXF));
91 addOwnedComponents(std::move(intF));
92}
93
94////////////////////////////////////////////////////////////////////////////////
95
96RooSecondMoment::RooSecondMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset,
97 bool centr, bool takeRoot, bool intNSet) :
98 RooAbsMoment(name, title,func,x,2,takeRoot),
99 _xf("!xf","xf",this,false,false),
100 _ixf("!ixf","ixf",this),
101 _if("!if","if",this),
102 _xfOffset(0)
103{
105
106 _nset.add(nset) ;
107
108 std::unique_ptr<RooAbsReal> XF;
109 if (centr) {
110
111 std::string m1name = std::string{GetName()} + "_moment1";
112 _mean.putOwnedArg(std::unique_ptr<RooAbsMoment>{func.mean(x, nset)});
113
114 std::string pname = std::string{name} + "_product";
116 std::stringstream formula;
117 formula << "std::pow((@0-" << _xfOffset << "),2) * @1";
118 XF = std::make_unique<RooFormulaVar>(pname.c_str(), formula.str().c_str(), RooArgList(x, func));
119
120 } else {
121
122 std::string pname = std::string{name} + "_product";
123 XF = std::make_unique<RooProduct>(pname.c_str(), pname.c_str(), RooArgList(x, x, func));
124 }
125
126 XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;
127
128 if (func.isBinnedDistribution(x)) {
129 XF->specialIntegratorConfig(true)->method1D().setLabel("RooBinIntegrator");
130 }
131 if (intNSet && !_nset.empty() && func.isBinnedDistribution(_nset)) {
132 XF->specialIntegratorConfig(true)->method2D().setLabel("RooBinIntegrator");
133 XF->specialIntegratorConfig(true)->methodND().setLabel("RooBinIntegrator");
134 }
135
137 if (intNSet) intSet.add(_nset,true) ;
138 std::unique_ptr<RooAbsReal> intXF{XF->createIntegral(intSet, &_nset)};
139 std::unique_ptr<RooAbsReal> intF{func.createIntegral(intSet, &_nset)};
140 static_cast<RooRealIntegral&>(*intXF).setCacheNumeric(true) ;
141 static_cast<RooRealIntegral&>(*intF).setCacheNumeric(true) ;
142
143 _xf.setArg(*XF) ;
144 _ixf.setArg(*intXF) ;
145 _if.setArg(*intF) ;
146 addOwnedComponents(std::move(XF)) ;
147 addOwnedComponents(std::move(intXF));
148 addOwnedComponents(std::move(intF));
149}
150
151
152
153////////////////////////////////////////////////////////////////////////////////
154
157 _xf("xf",this,other._xf),
158 _ixf("ixf",this,other._ixf),
159 _if("if",this,other._if),
160 _xfOffset(other._xfOffset)
161{
162}
163
164////////////////////////////////////////////////////////////////////////////////
165/// Calculate value
166
168{
169 double ratio = _ixf / _if ;
170
171 if (_mean.absArg()) {
172 ratio -= (_mean - _xfOffset)*(_mean-_xfOffset) ;
173 }
174
175 double ret = _takeRoot ? sqrt(ratio) : ratio ;
176 return ret ;
177}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char name[80]
Definition TGX11.cxx:110
RooExpensiveObjectCache & expensiveObjectCache() const
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition RooAbsArg.h:439
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
RooRealProxy _mean
Mean (if calculated for central moment)
Int_t _takeRoot
Return n-order root of moment.
RooSetProxy _nset
Normalization set (optional)
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:63
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:107
RooAbsMoment * mean(RooRealVar &obs)
Definition RooAbsReal.h:365
virtual bool isBinnedDistribution(const RooArgSet &) const
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
Definition RooAbsReal.h:352
RooFit::OwningPtr< RooAbsReal > createIntegral(const RooArgSet &iset, const RooCmdArg &arg1, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}) const
Create an object that represents the integral of the function over one or more observables listed in ...
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:46
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
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...
Performs hybrid numerical/analytical integrals of RooAbsReal objects.
void setCacheNumeric(bool flag)
Variable that can be changed from the outside.
Definition RooRealVar.h:37
RooRealProxy _ixf
Int((X-offset)*F(X))dx ;.
RooSecondMoment()=default
RooRealProxy _if
Int(F(x))dx ;.
double evaluate() const override
Calculate value.
double _xfOffset
offset
RooRealProxy _xf
(X-offset)*F
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:49
Double_t x[n]
Definition legend1.C:17