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  RooAbsReal* mom1 = func.mean(x) ;
81  _mean.setArg(*mom1) ;
82 
83  string pname=Form("%s_product",name) ;
84  _xfOffset = mom1->getVal() ;
85  XF = new RooFormulaVar(pname.c_str(),Form("pow((@0-%f),2)*@1",_xfOffset),RooArgList(x,func)) ;
86 
87  } else {
88 
89  string pname=Form("%s_product",name) ;
90  XF = new RooProduct(pname.c_str(),pname.c_str(),RooArgList(x,x,func)) ;
91  }
92 
94 
95  if (func.isBinnedDistribution(x)) {
96  XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
97  }
98 
101  intXF->setCacheNumeric(kTRUE) ;
102  intF->setCacheNumeric(kTRUE) ;
103 
104  _xf.setArg(*XF) ;
105  _ixf.setArg(*intXF) ;
106  _if.setArg(*intF) ;
107  addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
108 }
109 
110 ////////////////////////////////////////////////////////////////////////////////
111 
112 RooSecondMoment::RooSecondMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset,
113  Bool_t centr, Bool_t takeRoot, Bool_t intNSet) :
114  RooAbsMoment(name, title,func,x,2,takeRoot),
115  _xf("!xf","xf",this,kFALSE,kFALSE),
116  _ixf("!ixf","ixf",this),
117  _if("!if","if",this),
118  _xfOffset(0)
119 {
121 
122  _nset.add(nset) ;
123 
124  RooAbsReal* XF(0) ;
125  if (centr) {
126 
127  string m1name=Form("%s_moment1",GetName()) ;
128  RooAbsReal* mom1 = func.mean(x,nset) ;
129  _mean.setArg(*mom1) ;
130 
131  string pname=Form("%s_product",name) ;
132  _xfOffset = mom1->getVal() ;
133  XF = new RooFormulaVar(pname.c_str(),Form("pow((@0-%f),2)*@1",_xfOffset),RooArgList(x,func)) ;
134 
135 
136  } else {
137 
138  string pname=Form("%s_product",name) ;
139  XF = new RooProduct(pname.c_str(),pname.c_str(),RooArgList(x,x,func)) ;
140 
141  }
142 
144 
145  if (func.isBinnedDistribution(x)) {
146  XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
147  }
148  if (intNSet && _nset.getSize()>0 && func.isBinnedDistribution(_nset)) {
149  XF->specialIntegratorConfig(kTRUE)->method2D().setLabel("RooBinIntegrator");
150  XF->specialIntegratorConfig(kTRUE)->methodND().setLabel("RooBinIntegrator");
151  }
152 
153  RooArgSet intSet(x) ;
154  if (intNSet) intSet.add(_nset,kTRUE) ;
155  RooRealIntegral* intXF = (RooRealIntegral*) XF->createIntegral(intSet,&_nset) ;
156  RooRealIntegral* intF = (RooRealIntegral*) func.createIntegral(intSet,&_nset) ;
157  intXF->setCacheNumeric(kTRUE) ;
158  intF->setCacheNumeric(kTRUE) ;
159 
160  _xf.setArg(*XF) ;
161  _ixf.setArg(*intXF) ;
162  _if.setArg(*intF) ;
163  addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
164 }
165 
166 
167 
168 ////////////////////////////////////////////////////////////////////////////////
169 
171  RooAbsMoment(other, name),
172  _xf("xf",this,other._xf),
173  _ixf("ixf",this,other._ixf),
174  _if("if",this,other._if),
175  _xfOffset(other._xfOffset)
176 {
177 }
178 
179 
180 
181 ////////////////////////////////////////////////////////////////////////////////
182 /// Destructor
183 
185 {
186 }
187 
188 
189 
190 ////////////////////////////////////////////////////////////////////////////////
191 /// Calculate value
192 
194 {
195  Double_t ratio = _ixf / _if ;
196 
197  if (_mean.absArg()) {
198  ratio -= (_mean - _xfOffset)*(_mean-_xfOffset) ;
199  }
200 
201  Double_t ret = _takeRoot ? sqrt(ratio) : ratio ;
202  return ret ;
203 }
204 
205 
RooFormulaVar.h
RooSetProxy::add
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Overloaded RooArgSet::add() method inserts 'var' into set and registers 'var' as server to owner with...
Definition: RooSetProxy.cxx:165
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
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
Definition: RooAbsReal.h:313
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:561
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
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
RooArgSet::add
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
Definition: RooArgSet.h:88
RooAbsReal
Definition: RooAbsReal.h:61
RooAbsMoment
Definition: RooAbsMoment.h:27
RooAbsArg::setExpensiveObjectCache
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition: RooAbsArg.h:528
RooAbsReal::mean
RooAbsMoment * mean(RooRealVar &obs)
Definition: RooAbsReal.h:333
RooAbsArg::expensiveObjectCache
RooExpensiveObjectCache & expensiveObjectCache() const
Definition: RooAbsArg.cxx:2170
bool
RooRealIntegral
Definition: RooRealIntegral.h:34
RooProduct
Definition: RooProduct.h:30
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
Definition: RooFormulaVar.h:30
RooAbsMoment::_takeRoot
Int_t _takeRoot
Definition: RooAbsMoment.h:43
RooAbsPdf.h
RooArgProxy::absArg
RooAbsArg * absArg() const
Definition: RooArgProxy.h:51
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
RooNumIntConfig::method2D
RooCategory & method2D()
Definition: RooNumIntConfig.h:35
RooAbsArg::RooArgSet
friend class RooArgSet
Definition: RooAbsArg.h:579
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
Double_t
double Double_t
Definition: RtypesCore.h:59
RooAbsReal::specialIntegratorConfig
RooNumIntConfig * specialIntegratorConfig() const
Returns the specialized integrator configuration for this RooAbsReal.
Definition: RooAbsReal.cxx:3541
RooAbsArg::addOwnedComponents
Bool_t addOwnedComponents(const RooArgSet &comps)
Take ownership of the contents of 'comps'.
Definition: RooAbsArg.cxx:2109
name
char name[80]
Definition: TGX11.cxx:110
RooSecondMoment
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:53
RooSecondMoment::evaluate
Double_t evaluate() const
Calculate value
Definition: RooSecondMoment.cxx:193
RooFunctor.h
RooRealVar
Definition: RooRealVar.h:35
RooSecondMoment::~RooSecondMoment
virtual ~RooSecondMoment()
Destructor.
Definition: RooSecondMoment.cxx:184
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:171
RooArgSet
Definition: RooArgSet.h:28