Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooMoment.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 RooMoment.cxx
19\class RooMoment
20\ingroup Roofitcore
21**/
22
23
24#include "Riostream.h"
25#include <cmath>
26
27#include "RooMoment.h"
28#include "RooAbsReal.h"
29#include "RooAbsPdf.h"
30#include "RooErrorHandler.h"
31#include "RooArgSet.h"
32#include "RooMsgService.h"
33#include "RooRealVar.h"
34#include "RooFunctor.h"
35#include "RooFormulaVar.h"
36#include "RooGlobalFunc.h"
37#include "RooConstVar.h"
38#include "RooRealIntegral.h"
39#include "RooNumIntConfig.h"
40#include <string>
41
42
43////////////////////////////////////////////////////////////////////////////////
44
45RooMoment::RooMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, Int_t orderIn, bool centr, bool takeRoot) :
46 RooAbsMoment(name, title,func,x,orderIn,takeRoot),
47 _xf("!xf","xf",this,false,false),
48 _ixf("!ixf","ixf",this),
49 _if("!if","if",this)
50{
52
53 std::string pname=Form("%s_product",name) ;
54
55 std::unique_ptr<RooFormulaVar> XF;
56 if (centr) {
57 std::string formula=Form("pow((@0-@1),%d)*@2",_order) ;
58 std::string m1name=Form("%s_moment1",GetName()) ;
59 RooAbsReal* mom1 = func.mean(x) ;
60 XF = std::make_unique<RooFormulaVar>(pname.c_str(),formula.c_str(),RooArgList(x,*mom1,func)) ;
61 XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;
63 _mean.setArg(*mom1) ;
64 } else {
65 std::string formula=Form("pow(@0,%d)*@1",_order) ;
66 XF = std::make_unique<RooFormulaVar>(pname.c_str(),formula.c_str(),RooArgSet(x,func)) ;
67 XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;
68 }
69
70 if (func.isBinnedDistribution(x)) {
71 XF->specialIntegratorConfig(true)->method1D().setLabel("RooBinIntegrator");
72 }
73
74 std::unique_ptr<RooAbsReal> intXF{XF->createIntegral(x)};
75 std::unique_ptr<RooAbsReal> intF{func.createIntegral(x)};
76 static_cast<RooRealIntegral&>(*intXF).setCacheNumeric(true) ;
77 static_cast<RooRealIntegral&>(*intF).setCacheNumeric(true) ;
78
79 _xf.setArg(*XF) ;
80 _ixf.setArg(*intXF) ;
81 _if.setArg(*intF) ;
82 addOwnedComponents(std::move(XF)) ;
83 addOwnedComponents(std::move(intXF));
84 addOwnedComponents(std::move(intF));
85}
86
87////////////////////////////////////////////////////////////////////////////////
88
89RooMoment::RooMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset,
90 Int_t orderIn, bool centr, bool takeRoot, bool intNSet) :
91 RooAbsMoment(name, title,func,x,orderIn,takeRoot),
92 _xf("!xf","xf",this,false,false),
93 _ixf("!ixf","ixf",this),
94 _if("!if","if",this)
95{
97
98 _nset.add(nset) ;
99
100 std::string pname=Form("%s_product",name) ;
101 std::unique_ptr<RooFormulaVar> XF;
102 if (centr) {
103 std::string formula=Form("pow((@0-@1),%d)*@2",_order) ;
104 std::string m1name=Form("%s_moment1",GetName()) ;
105 RooAbsReal* mom1 = func.mean(x,nset) ;
106 XF = std::make_unique<RooFormulaVar>(pname.c_str(),formula.c_str(),RooArgList(x,*mom1,func)) ;
107 XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;
109 _mean.setArg(*mom1) ;
110 } else {
111 std::string formula=Form("pow(@0,%d)*@1",_order) ;
112 XF = std::make_unique<RooFormulaVar>(pname.c_str(),formula.c_str(),RooArgSet(x,func)) ;
113 XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;
114 }
115
116 if (func.isBinnedDistribution(x)) {
117 XF->specialIntegratorConfig(true)->method1D().setLabel("RooBinIntegrator");
118 }
119
121 if (intNSet) intSet.add(_nset,true) ;
122
123 std::unique_ptr<RooAbsReal> intXF{XF->createIntegral(intSet, &_nset)};
124 std::unique_ptr<RooAbsReal> intF{func.createIntegral(intSet, &_nset)};
125 static_cast<RooRealIntegral&>(*intXF).setCacheNumeric(true) ;
126 static_cast<RooRealIntegral&>(*intF).setCacheNumeric(true) ;
127
128 _xf.setArg(*XF) ;
129 _ixf.setArg(*intXF) ;
130 _if.setArg(*intF) ;
131 addOwnedComponents(std::move(XF)) ;
132 addOwnedComponents(std::move(intXF));
133 addOwnedComponents(std::move(intF));
134}
135
136
137
138////////////////////////////////////////////////////////////////////////////////
139
142 _xf("xf",this,other._xf),
143 _ixf("ixf",this,other._ixf),
144 _if("if",this,other._if)
145{
146}
147
148////////////////////////////////////////////////////////////////////////////////
149/// Calculate value
150
152{
153 double ratio = _ixf / _if ;
154 double ret = _takeRoot ? pow(ratio,1.0/_order) : ratio ;
155 return ret ;
156}
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
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
RooExpensiveObjectCache & expensiveObjectCache() const
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition RooAbsArg.h:444
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
RooRealProxy _mean
Mean (if calculated for central moment)
Int_t _order
Moment order.
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:59
RooAbsMoment * mean(RooRealVar &obs)
Definition RooAbsReal.h:361
virtual bool isBinnedDistribution(const RooArgSet &) const
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
Definition RooAbsReal.h:348
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
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...
RooRealProxy _xf
X*F.
Definition RooMoment.h:43
RooMoment()=default
double evaluate() const override
Calculate value.
RooRealProxy _if
Int(F(x))dx ;.
Definition RooMoment.h:45
RooRealProxy _ixf
Int(X*F(X))dx ;.
Definition RooMoment.h:44
Performs hybrid numerical/analytical integrals of RooAbsReal objects.
void setCacheNumeric(bool flag)
Variable that can be changed from the outside.
Definition RooRealVar.h:37
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