Logo ROOT   6.10/09
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 "Riostream.h"
32 #include <math.h>
33 #include <string>
34 
35 #include "RooSecondMoment.h"
36 #include "RooAbsReal.h"
37 #include "RooAbsPdf.h"
38 #include "RooErrorHandler.h"
39 #include "RooArgSet.h"
40 #include "RooMsgService.h"
41 #include "RooRealVar.h"
42 #include "RooFunctor.h"
43 #include "RooGlobalFunc.h"
44 #include "RooConstVar.h"
45 #include "RooRealIntegral.h"
46 #include "RooNumIntConfig.h"
47 #include "RooFormulaVar.h"
48 #include "RooLinearVar.h"
49 #include "RooProduct.h"
50 #include "RooGlobalFunc.h"
51 #include <string>
52 using namespace std ;
53 
54 
56 ;
57 
58 
59 ////////////////////////////////////////////////////////////////////////////////
60 /// Default constructor
61 
63 {
64 }
65 
66 
67 
68 ////////////////////////////////////////////////////////////////////////////////
69 
70 RooSecondMoment::RooSecondMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, Bool_t centr, Bool_t takeRoot) :
71  RooAbsMoment(name, title,func,x,2,takeRoot),
72  _xf("!xf","xf",this,kFALSE,kFALSE),
73  _ixf("!ixf","ixf",this),
74  _if("!if","if",this),
75  _xfOffset(0)
76 {
78 
79  RooAbsReal* XF(0) ;
80  if (centr) {
81 
82  string m1name=Form("%s_moment1",GetName()) ;
83  RooAbsReal* mom1 = func.mean(x) ;
84  _mean.setArg(*mom1) ;
85 
86  string pname=Form("%s_product",name) ;
87  _xfOffset = mom1->getVal() ;
88  XF = new RooFormulaVar(pname.c_str(),Form("pow((@0-%f),2)*@1",_xfOffset),RooArgList(x,func)) ;
89 
90  } else {
91 
92  string pname=Form("%s_product",name) ;
93  XF = new RooProduct(pname.c_str(),pname.c_str(),RooArgList(x,x,func)) ;
94  }
95 
97 
98  if (func.isBinnedDistribution(x)) {
99  XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
100  }
101 
102  RooRealIntegral* intXF = (RooRealIntegral*) XF->createIntegral(x) ;
103  RooRealIntegral* intF = (RooRealIntegral*) func.createIntegral(x) ;
104  intXF->setCacheNumeric(kTRUE) ;
105  intF->setCacheNumeric(kTRUE) ;
106 
107  _xf.setArg(*XF) ;
108  _ixf.setArg(*intXF) ;
109  _if.setArg(*intF) ;
110  addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
111 }
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 
115 RooSecondMoment::RooSecondMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset,
116  Bool_t centr, Bool_t takeRoot, Bool_t intNSet) :
117  RooAbsMoment(name, title,func,x,2,takeRoot),
118  _xf("!xf","xf",this,kFALSE,kFALSE),
119  _ixf("!ixf","ixf",this),
120  _if("!if","if",this),
121  _xfOffset(0)
122 {
124 
125  _nset.add(nset) ;
126 
127  RooAbsReal* XF(0) ;
128  if (centr) {
129 
130  string m1name=Form("%s_moment1",GetName()) ;
131  RooAbsReal* mom1 = func.mean(x,nset) ;
132  _mean.setArg(*mom1) ;
133 
134  string pname=Form("%s_product",name) ;
135  _xfOffset = mom1->getVal() ;
136  XF = new RooFormulaVar(pname.c_str(),Form("pow((@0-%f),2)*@1",_xfOffset),RooArgList(x,func)) ;
137 
138 
139  } else {
140 
141  string pname=Form("%s_product",name) ;
142  XF = new RooProduct(pname.c_str(),pname.c_str(),RooArgList(x,x,func)) ;
143 
144  }
145 
147 
148  if (func.isBinnedDistribution(x)) {
149  XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
150  }
151  if (intNSet && _nset.getSize()>0 && func.isBinnedDistribution(_nset)) {
152  XF->specialIntegratorConfig(kTRUE)->method2D().setLabel("RooBinIntegrator");
153  XF->specialIntegratorConfig(kTRUE)->methodND().setLabel("RooBinIntegrator");
154  }
155 
156  RooArgSet intSet(x) ;
157  if (intNSet) intSet.add(_nset,kTRUE) ;
158  RooRealIntegral* intXF = (RooRealIntegral*) XF->createIntegral(intSet,&_nset) ;
159  RooRealIntegral* intF = (RooRealIntegral*) func.createIntegral(intSet,&_nset) ;
160  intXF->setCacheNumeric(kTRUE) ;
161  intF->setCacheNumeric(kTRUE) ;
162 
163  _xf.setArg(*XF) ;
164  _ixf.setArg(*intXF) ;
165  _if.setArg(*intF) ;
166  addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
167 }
168 
169 
170 
171 ////////////////////////////////////////////////////////////////////////////////
172 
174  RooAbsMoment(other, name),
175  _xf("xf",this,other._xf),
176  _ixf("ixf",this,other._ixf),
177  _if("if",this,other._if),
178  _xfOffset(other._xfOffset)
179 {
180 }
181 
182 
183 
184 ////////////////////////////////////////////////////////////////////////////////
185 /// Destructor
186 
188 {
189 }
190 
191 
192 
193 ////////////////////////////////////////////////////////////////////////////////
194 /// Calculate value
195 
197 {
198  Double_t ratio = _ixf / _if ;
199 
200  if (_mean.absArg()) {
201  ratio -= (_mean - _xfOffset)*(_mean-_xfOffset) ;
202  }
203 
204  Double_t ret = _takeRoot ? sqrt(ratio) : ratio ;
205  return ret ;
206 }
207 
208 
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
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:86
RooCategory & methodND()
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
RooRealProxy _xf
RooCategory & method2D()
Int_t _takeRoot
Definition: RooAbsMoment.h:43
bool Bool_t
Definition: RtypesCore.h:59
Bool_t addOwnedComponents(const RooArgSet &comps)
Take ownership of the contents of &#39;comps&#39;.
Definition: RooAbsArg.cxx:2282
RooRealProxy _if
STL namespace.
RooAbsMoment represents the first, second, or third order derivative of any RooAbsReal as calculated ...
Definition: RooAbsMoment.h:27
virtual Bool_t setLabel(const char *label, Bool_t printError=kTRUE)
Set value by specifying the name of the desired state If printError is set, a message will be printed...
double sqrt(double)
RooCategory & method1D()
Double_t x[n]
Definition: legend1.C:17
RooRealIntegral performs hybrid numerical/analytical integrals of RooAbsReal objects The class perfor...
virtual ~RooSecondMoment()
Destructor.
friend class RooArgSet
Definition: RooAbsArg.h:469
RooRealProxy _ixf
RooNumIntConfig * specialIntegratorConfig() const
Returns the specialized integrator configuration for this RooAbsReal.
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
Int_t getSize() const
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:501
RooExpensiveObjectCache & expensiveObjectCache() const
Definition: RooAbsArg.cxx:2342
char * Form(const char *fmt,...)
RooAbsArg * absArg() const
Definition: RooArgProxy.h:37
Double_t evaluate() const
Calculate value.
RooRealProxy _mean
Definition: RooAbsMoment.h:47
virtual Bool_t setArg(RooAbsReal &newRef)
Change object held in proxy into newRef.
RooProduct a RooAbsReal implementation that represent the product of a given set of other RooAbsReal ...
Definition: RooProduct.h:32
const Bool_t kFALSE
Definition: RtypesCore.h:92
RooSecondMoment represents the first, second, or third order derivative of any RooAbsReal as calculat...
RooSetProxy _nset
Definition: RooAbsMoment.h:44
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition: RooAbsArg.h:497
virtual Bool_t isBinnedDistribution(const RooArgSet &) const
Definition: RooAbsReal.h:277
#define ClassImp(name)
Definition: Rtypes.h:336
double Double_t
Definition: RtypesCore.h:55
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
double func(double *x, double *p)
Definition: stressTF1.cxx:213
virtual RooAbsReal * createIntegral(const RooArgSet &iset, const RooArgSet *nset=0, const RooNumIntConfig *cfg=0, const char *rangeName=0) const
Create an object that represents the integral of the function over one or more observables listed in ...
RooSecondMoment()
Default constructor.
const Bool_t kTRUE
Definition: RtypesCore.h:91
RooAbsMoment * mean(RooRealVar &obs)
Definition: RooAbsReal.h:297
void setCacheNumeric(Bool_t flag)
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Overloaded RooArgSet::add() method inserts &#39;var&#39; into set and registers &#39;var&#39; as server to owner with...