Logo ROOT  
Reference Guide
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 RooSecondMoment represents the first, second, or third order derivative
23 of any RooAbsReal as calculated (numerically) by the MathCore Richardson
24 derivator 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>
49 using namespace std;
50 
51 
53 
54 
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 /// Default constructor
58 
60 {
61 }
62 
63 
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 
67 RooSecondMoment::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) ;
83  _xfOffset = _mean->getVal() ;
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 
111 RooSecondMoment::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 
RooFormulaVar.h
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:100
RooAbsMoment::_nset
RooSetProxy _nset
Definition: RooAbsMoment.h:44
RooAbsReal.h
RooMsgService.h
RooNumIntConfig.h
RooSecondMoment::_ixf
RooRealProxy _ixf
Definition: RooSecondMoment.h:45
RooFit.h
RooSecondMoment::_if
RooRealProxy _if
Definition: RooSecondMoment.h:46
RooArgSet.h
RooAbsReal::isBinnedDistribution
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
RooAbsReal::createIntegral
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 ...
Definition: RooAbsReal.cxx:548
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
Form
char * Form(const char *fmt,...)
RooAbsMoment::_mean
RooRealProxy _mean
Definition: RooAbsMoment.h:47
RooNumIntConfig::method1D
RooCategory & method1D()
Definition: RooNumIntConfig.h:34
RooArgList
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooAbsReal::getVal
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:91
RooSecondMoment::_xf
RooRealProxy _xf
Definition: RooSecondMoment.h:44
x
Double_t x[n]
Definition: legend1.C:17
RooAbsReal
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:61
RooAbsMoment
RooAbsMoment represents the first, second, or third order derivative of any RooAbsReal as calculated ...
Definition: RooAbsMoment.h:27
RooAbsArg::setExpensiveObjectCache
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition: RooAbsArg.h:503
RooAbsReal::mean
RooAbsMoment * mean(RooRealVar &obs)
Definition: RooAbsReal.h:357
RooAbsArg::expensiveObjectCache
RooExpensiveObjectCache & expensiveObjectCache() const
Definition: RooAbsArg.cxx:2277
bool
RooRealIntegral
RooRealIntegral performs hybrid numerical/analytical integrals of RooAbsReal objects.
Definition: RooRealIntegral.h:34
RooProduct
A RooProduct represents the product of a given set of RooAbsReal objects.
Definition: RooProduct.h:29
RooLinearVar.h
RooCategory::setLabel
virtual Bool_t setLabel(const char *label, bool printError=true) override
Set value by specifying the name of the desired state.
Definition: RooCategory.cxx:185
RooFormulaVar
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:30
RooAbsMoment::_takeRoot
Int_t _takeRoot
Definition: RooAbsMoment.h:43
RooAbsPdf.h
Double_t
RooArgProxy::absArg
RooAbsArg * absArg() const
Definition: RooArgProxy.h:37
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:101
RooNumIntConfig::method2D
RooCategory & method2D()
Definition: RooNumIntConfig.h:35
RooAbsArg::RooArgSet
friend class RooArgSet
Definition: RooAbsArg.h:599
RooAbsCollection::add
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Definition: RooAbsCollection.cxx:455
sqrt
double sqrt(double)
RooTemplateProxy::setArg
bool setArg(T &newRef)
Change object held in proxy into newRef.
Definition: RooTemplateProxy.h:227
RooRealVar.h
RooProduct.h
RooSecondMoment.h
RooConstVar.h
RooGlobalFunc.h
RooAbsReal::specialIntegratorConfig
RooNumIntConfig * specialIntegratorConfig() const
Returns the specialized integrator configuration for this RooAbsReal.
Definition: RooAbsReal.cxx:3531
RooAbsArg::addOwnedComponents
Bool_t addOwnedComponents(const RooArgSet &comps)
Take ownership of the contents of 'comps'.
Definition: RooAbsArg.cxx:2216
name
char name[80]
Definition: TGX11.cxx:110
RooSecondMoment
RooSecondMoment represents the first, second, or third order derivative of any RooAbsReal as calculat...
Definition: RooSecondMoment.h:27
RooErrorHandler.h
RooSecondMoment::_xfOffset
Double_t _xfOffset
Definition: RooSecondMoment.h:47
RooRealIntegral::setCacheNumeric
void setCacheNumeric(Bool_t flag)
Definition: RooRealIntegral.h:60
RooRealIntegral.h
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
RooSecondMoment::evaluate
Double_t evaluate() const
Calculate value
Definition: RooSecondMoment.cxx:191
RooFunctor.h
RooRealVar
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:39
RooSecondMoment::~RooSecondMoment
virtual ~RooSecondMoment()
Destructor.
Definition: RooSecondMoment.cxx:182
Riostream.h
RooSecondMoment::RooSecondMoment
RooSecondMoment()
Default constructor.
Definition: RooSecondMoment.cxx:59
RooNumIntConfig::methodND
RooCategory & methodND()
Definition: RooNumIntConfig.h:36
RooAbsCollection::getSize
Int_t getSize() const
Definition: RooAbsCollection.h:231
RooTemplateProxy::putOwnedArg
U & putOwnedArg(std::unique_ptr< U > ownedArg)
Move a new object held and owned by proxy.
Definition: RooTemplateProxy.h:259
RooSetProxy::add
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...
Definition: RooSetProxy.cxx:165
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:33