Logo ROOT   6.14/05
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 
34 #include "RooSecondMoment.h"
35 #include "RooAbsReal.h"
36 #include "RooAbsPdf.h"
37 #include "RooErrorHandler.h"
38 #include "RooArgSet.h"
39 #include "RooMsgService.h"
40 #include "RooRealVar.h"
41 #include "RooFunctor.h"
42 #include "RooGlobalFunc.h"
43 #include "RooConstVar.h"
44 #include "RooRealIntegral.h"
45 #include "RooNumIntConfig.h"
46 #include "RooFormulaVar.h"
47 #include "RooLinearVar.h"
48 #include "RooProduct.h"
49 #include "RooGlobalFunc.h"
50 #include <string>
51 using namespace std ;
52 
53 
55 ;
56 
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// Default constructor
60 
62 {
63 }
64 
65 
66 
67 ////////////////////////////////////////////////////////////////////////////////
68 
69 RooSecondMoment::RooSecondMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, Bool_t centr, Bool_t takeRoot) :
70  RooAbsMoment(name, title,func,x,2,takeRoot),
71  _xf("!xf","xf",this,kFALSE,kFALSE),
72  _ixf("!ixf","ixf",this),
73  _if("!if","if",this),
74  _xfOffset(0)
75 {
77 
78  RooAbsReal* XF(0) ;
79  if (centr) {
80 
81  string m1name=Form("%s_moment1",GetName()) ;
82  RooAbsReal* mom1 = func.mean(x) ;
83  _mean.setArg(*mom1) ;
84 
85  string pname=Form("%s_product",name) ;
86  _xfOffset = mom1->getVal() ;
87  XF = new RooFormulaVar(pname.c_str(),Form("pow((@0-%f),2)*@1",_xfOffset),RooArgList(x,func)) ;
88 
89  } else {
90 
91  string pname=Form("%s_product",name) ;
92  XF = new RooProduct(pname.c_str(),pname.c_str(),RooArgList(x,x,func)) ;
93  }
94 
96 
97  if (func.isBinnedDistribution(x)) {
98  XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
99  }
100 
101  RooRealIntegral* intXF = (RooRealIntegral*) XF->createIntegral(x) ;
102  RooRealIntegral* intF = (RooRealIntegral*) func.createIntegral(x) ;
103  intXF->setCacheNumeric(kTRUE) ;
104  intF->setCacheNumeric(kTRUE) ;
105 
106  _xf.setArg(*XF) ;
107  _ixf.setArg(*intXF) ;
108  _if.setArg(*intF) ;
109  addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
110 }
111 
112 ////////////////////////////////////////////////////////////////////////////////
113 
114 RooSecondMoment::RooSecondMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset,
115  Bool_t centr, Bool_t takeRoot, Bool_t intNSet) :
116  RooAbsMoment(name, title,func,x,2,takeRoot),
117  _xf("!xf","xf",this,kFALSE,kFALSE),
118  _ixf("!ixf","ixf",this),
119  _if("!if","if",this),
120  _xfOffset(0)
121 {
123 
124  _nset.add(nset) ;
125 
126  RooAbsReal* XF(0) ;
127  if (centr) {
128 
129  string m1name=Form("%s_moment1",GetName()) ;
130  RooAbsReal* mom1 = func.mean(x,nset) ;
131  _mean.setArg(*mom1) ;
132 
133  string pname=Form("%s_product",name) ;
134  _xfOffset = mom1->getVal() ;
135  XF = new RooFormulaVar(pname.c_str(),Form("pow((@0-%f),2)*@1",_xfOffset),RooArgList(x,func)) ;
136 
137 
138  } else {
139 
140  string pname=Form("%s_product",name) ;
141  XF = new RooProduct(pname.c_str(),pname.c_str(),RooArgList(x,x,func)) ;
142 
143  }
144 
146 
147  if (func.isBinnedDistribution(x)) {
148  XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
149  }
150  if (intNSet && _nset.getSize()>0 && func.isBinnedDistribution(_nset)) {
151  XF->specialIntegratorConfig(kTRUE)->method2D().setLabel("RooBinIntegrator");
152  XF->specialIntegratorConfig(kTRUE)->methodND().setLabel("RooBinIntegrator");
153  }
154 
155  RooArgSet intSet(x) ;
156  if (intNSet) intSet.add(_nset,kTRUE) ;
157  RooRealIntegral* intXF = (RooRealIntegral*) XF->createIntegral(intSet,&_nset) ;
158  RooRealIntegral* intF = (RooRealIntegral*) func.createIntegral(intSet,&_nset) ;
159  intXF->setCacheNumeric(kTRUE) ;
160  intF->setCacheNumeric(kTRUE) ;
161 
162  _xf.setArg(*XF) ;
163  _ixf.setArg(*intXF) ;
164  _if.setArg(*intF) ;
165  addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
166 }
167 
168 
169 
170 ////////////////////////////////////////////////////////////////////////////////
171 
173  RooAbsMoment(other, name),
174  _xf("xf",this,other._xf),
175  _ixf("ixf",this,other._ixf),
176  _if("if",this,other._if),
177  _xfOffset(other._xfOffset)
178 {
179 }
180 
181 
182 
183 ////////////////////////////////////////////////////////////////////////////////
184 /// Destructor
185 
187 {
188 }
189 
190 
191 
192 ////////////////////////////////////////////////////////////////////////////////
193 /// Calculate value
194 
196 {
197  Double_t ratio = _ixf / _if ;
198 
199  if (_mean.absArg()) {
200  ratio -= (_mean - _xfOffset)*(_mean-_xfOffset) ;
201  }
202 
203  Double_t ret = _takeRoot ? sqrt(ratio) : ratio ;
204  return ret ;
205 }
206 
207 
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:2273
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:471
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:2333
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:88
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:499
virtual Bool_t isBinnedDistribution(const RooArgSet &) const
Definition: RooAbsReal.h:277
#define ClassImp(name)
Definition: Rtypes.h:359
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
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:87
RooAbsMoment * mean(RooRealVar &obs)
Definition: RooAbsReal.h:297
char name[80]
Definition: TGX11.cxx:109
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...