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 "RooSecondMoment.h"
24#include "RooAbsReal.h"
25#include "RooAbsPdf.h"
26#include "RooArgSet.h"
27#include "RooRealVar.h"
28#include "RooGlobalFunc.h"
29#include "RooConstVar.h"
30#include "RooRealIntegral.h"
31#include "RooNumIntConfig.h"
32#include "RooFormulaVar.h"
33#include "RooLinearVar.h"
34#include "RooProduct.h"
35
36#include <string>
37#include <cmath>
38#include <ostream>
39
40using std::string;
41
42////////////////////////////////////////////////////////////////////////////////
43
44RooSecondMoment::RooSecondMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, bool centr, bool takeRoot) :
45 RooAbsMoment(name, title,func,x,2,takeRoot),
46 _xf("!xf","xf",this,false,false),
47 _ixf("!ixf","ixf",this),
48 _if("!if","if",this),
49 _xfOffset(0)
50{
52
53 std::unique_ptr<RooAbsReal> XF;
54 if (centr) {
55
56 std::string m1name = std::string{GetName()} + "_moment1";
57 _mean.putOwnedArg(std::unique_ptr<RooAbsMoment>{func.mean(x)});
58
59 std::string pname = std::string{name} + "_product";
61 std::stringstream formula;
62 formula << "std::pow((@0-" << _xfOffset << "),2) * @1";
63 XF = std::make_unique<RooFormulaVar>(pname.c_str(), formula.str().c_str(), RooArgList(x, func));
64
65 } else {
66
67 std::string pname = std::string{name} + "_product";
68 XF = std::make_unique<RooProduct>(pname.c_str(), pname.c_str(), RooArgList(x, x, func));
69 }
70
71 XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;
72
73 if (func.isBinnedDistribution(x)) {
74 XF->specialIntegratorConfig(true)->method1D().setLabel("RooBinIntegrator");
75 }
76
77 std::unique_ptr<RooAbsReal> intXF{XF->createIntegral(x)};
78 std::unique_ptr<RooAbsReal> intF{func.createIntegral(x)};
79 static_cast<RooRealIntegral&>(*intXF).setCacheNumeric(true) ;
80 static_cast<RooRealIntegral&>(*intF).setCacheNumeric(true) ;
81
82 _xf.setArg(*XF) ;
83 _ixf.setArg(*intXF) ;
84 _if.setArg(*intF) ;
85 addOwnedComponents(std::move(XF)) ;
86 addOwnedComponents(std::move(intXF));
87 addOwnedComponents(std::move(intF));
88}
89
90////////////////////////////////////////////////////////////////////////////////
91
92RooSecondMoment::RooSecondMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset,
93 bool centr, bool takeRoot, bool intNSet) :
94 RooAbsMoment(name, title,func,x,2,takeRoot),
95 _xf("!xf","xf",this,false,false),
96 _ixf("!ixf","ixf",this),
97 _if("!if","if",this),
98 _xfOffset(0)
99{
101
102 _nset.add(nset) ;
103
104 std::unique_ptr<RooAbsReal> XF;
105 if (centr) {
106
107 std::string m1name = std::string{GetName()} + "_moment1";
108 _mean.putOwnedArg(std::unique_ptr<RooAbsMoment>{func.mean(x, nset)});
109
110 std::string pname = std::string{name} + "_product";
112 std::stringstream formula;
113 formula << "std::pow((@0-" << _xfOffset << "),2) * @1";
114 XF = std::make_unique<RooFormulaVar>(pname.c_str(), formula.str().c_str(), RooArgList(x, func));
115
116 } else {
117
118 std::string pname = std::string{name} + "_product";
119 XF = std::make_unique<RooProduct>(pname.c_str(), pname.c_str(), RooArgList(x, x, func));
120 }
121
122 XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;
123
124 if (func.isBinnedDistribution(x)) {
125 XF->specialIntegratorConfig(true)->method1D().setLabel("RooBinIntegrator");
126 }
127 if (intNSet && !_nset.empty() && func.isBinnedDistribution(_nset)) {
128 XF->specialIntegratorConfig(true)->method2D().setLabel("RooBinIntegrator");
129 XF->specialIntegratorConfig(true)->methodND().setLabel("RooBinIntegrator");
130 }
131
133 if (intNSet) intSet.add(_nset,true) ;
134 std::unique_ptr<RooAbsReal> intXF{XF->createIntegral(intSet, &_nset)};
135 std::unique_ptr<RooAbsReal> intF{func.createIntegral(intSet, &_nset)};
136 static_cast<RooRealIntegral&>(*intXF).setCacheNumeric(true) ;
137 static_cast<RooRealIntegral&>(*intF).setCacheNumeric(true) ;
138
139 _xf.setArg(*XF) ;
140 _ixf.setArg(*intXF) ;
141 _if.setArg(*intF) ;
142 addOwnedComponents(std::move(XF)) ;
143 addOwnedComponents(std::move(intXF));
144 addOwnedComponents(std::move(intF));
145}
146
147
148
149////////////////////////////////////////////////////////////////////////////////
150
153 _xf("xf",this,other._xf),
154 _ixf("ixf",this,other._ixf),
155 _if("if",this,other._if),
156 _xfOffset(other._xfOffset)
157{
158}
159
160////////////////////////////////////////////////////////////////////////////////
161/// Calculate value
162
164{
165 double ratio = _ixf / _if ;
166
167 if (_mean.absArg()) {
168 ratio -= (_mean - _xfOffset)*(_mean-_xfOffset) ;
169 }
170
171 double ret = _takeRoot ? sqrt(ratio) : ratio ;
172 return ret ;
173}
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:142
RooExpensiveObjectCache & expensiveObjectCache() const
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition RooAbsArg.h:418
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:356
virtual bool isBinnedDistribution(const RooArgSet &) const
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
Definition RooAbsReal.h:343
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