Logo ROOT   6.08/07
Reference Guide
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 RooMoment 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 "RooMoment.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 "RooFormulaVar.h"
44 #include "RooGlobalFunc.h"
45 #include "RooConstVar.h"
46 #include "RooRealIntegral.h"
47 #include "RooNumIntConfig.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 RooMoment::RooMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, Int_t orderIn, Bool_t centr, Bool_t takeRoot) :
68  RooAbsMoment(name, title,func,x,orderIn,takeRoot),
69  _xf("!xf","xf",this,kFALSE,kFALSE),
70  _ixf("!ixf","ixf",this),
71  _if("!if","if",this)
72 {
74 
75  string pname=Form("%s_product",name) ;
76 
77  RooFormulaVar* XF ;
78  if (centr) {
79  string formula=Form("pow((@0-@1),%d)*@2",_order) ;
80  string m1name=Form("%s_moment1",GetName()) ;
81  RooAbsReal* mom1 = func.mean(x) ;
82  XF = new RooFormulaVar(pname.c_str(),formula.c_str(),RooArgList(x,*mom1,func)) ;
84  addOwnedComponents(*mom1) ;
85  _mean.setArg(*mom1) ;
86  } else {
87  string formula=Form("pow(@0,%d)*@1",_order) ;
88  XF = new RooFormulaVar(pname.c_str(),formula.c_str(),RooArgSet(x,func)) ;
90  }
91 
92  if (func.isBinnedDistribution(x)) {
93  XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
94  }
95 
98  intXF->setCacheNumeric(kTRUE) ;
99  intF->setCacheNumeric(kTRUE) ;
100 
101  _xf.setArg(*XF) ;
102  _ixf.setArg(*intXF) ;
103  _if.setArg(*intF) ;
104  addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
105 }
106 
107 ////////////////////////////////////////////////////////////////////////////////
108 
109 RooMoment::RooMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset,
110  Int_t orderIn, Bool_t centr, Bool_t takeRoot, Bool_t intNSet) :
111  RooAbsMoment(name, title,func,x,orderIn,takeRoot),
112  _xf("!xf","xf",this,kFALSE,kFALSE),
113  _ixf("!ixf","ixf",this),
114  _if("!if","if",this)
115 {
117 
118  _nset.add(nset) ;
119 
120  string pname=Form("%s_product",name) ;
121  RooFormulaVar* XF ;
122  if (centr) {
123  string formula=Form("pow((@0-@1),%d)*@2",_order) ;
124  string m1name=Form("%s_moment1",GetName()) ;
125  RooAbsReal* mom1 = func.mean(x,nset) ;
126  XF = new RooFormulaVar(pname.c_str(),formula.c_str(),RooArgList(x,*mom1,func)) ;
128  addOwnedComponents(*mom1) ;
129  _mean.setArg(*mom1) ;
130  } else {
131  string formula=Form("pow(@0,%d)*@1",_order) ;
132  XF = new RooFormulaVar(pname.c_str(),formula.c_str(),RooArgSet(x,func)) ;
134  }
135 
136  if (func.isBinnedDistribution(x)) {
137  XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
138  }
139 
140  RooArgSet intSet(x) ;
141  if (intNSet) intSet.add(_nset,kTRUE) ;
142 
143  RooRealIntegral* intXF = (RooRealIntegral*) XF->createIntegral(intSet,&_nset) ;
144  RooRealIntegral* intF = (RooRealIntegral*) func.createIntegral(intSet,&_nset) ;
145  intXF->setCacheNumeric(kTRUE) ;
146  intF->setCacheNumeric(kTRUE) ;
147 
148  _xf.setArg(*XF) ;
149  _ixf.setArg(*intXF) ;
150  _if.setArg(*intF) ;
151  addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
152 }
153 
154 
155 
156 ////////////////////////////////////////////////////////////////////////////////
157 
158 RooMoment::RooMoment(const RooMoment& other, const char* name) :
159  RooAbsMoment(other, name),
160  _xf("xf",this,other._xf),
161  _ixf("ixf",this,other._ixf),
162  _if("if",this,other._if)
163 {
164 }
165 
166 
167 
168 ////////////////////////////////////////////////////////////////////////////////
169 /// Destructor
170 
172 {
173 }
174 
175 
176 
177 ////////////////////////////////////////////////////////////////////////////////
178 /// Calculate value
179 
181 {
182  Double_t ratio = _ixf / _if ;
183  Double_t ret = _takeRoot ? pow(ratio,1.0/_order) : ratio ;
184  return ret ;
185 }
186 
187 
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
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
RooRealProxy _ixf
Definition: RooMoment.h:46
Int_t _takeRoot
Definition: RooAbsMoment.h:43
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
Bool_t addOwnedComponents(const RooArgSet &comps)
Take ownership of the contents of &#39;comps&#39;.
Definition: RooAbsArg.cxx:2282
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...
RooCategory & method1D()
Double_t x[n]
Definition: legend1.C:17
RooRealIntegral performs hybrid numerical/analytical integrals of RooAbsReal objects The class perfor...
RooRealProxy _if
Definition: RooMoment.h:47
double pow(double, double)
friend class RooArgSet
Definition: RooAbsArg.h:469
RooMoment()
Default constructor.
Definition: RooMoment.cxx:59
RooNumIntConfig * specialIntegratorConfig() const
Returns the specialized integrator configuration for this RooAbsReal.
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
RooRealProxy _xf
Definition: RooMoment.h:45
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:503
RooExpensiveObjectCache & expensiveObjectCache() const
Definition: RooAbsArg.cxx:2342
char * Form(const char *fmt,...)
RooRealProxy _mean
Definition: RooAbsMoment.h:47
virtual Bool_t setArg(RooAbsReal &newRef)
Change object held in proxy into newRef.
virtual ~RooMoment()
Destructor.
Definition: RooMoment.cxx:171
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
Double_t evaluate() const
Calculate value.
Definition: RooMoment.cxx:180
#define ClassImp(name)
Definition: Rtypes.h:279
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
RooMoment represents the first, second, or third order derivative of any RooAbsReal as calculated (nu...
Definition: RooMoment.h:27
double func(double *x, double *p)
Definition: stressTF1.cxx:213
const Bool_t kTRUE
Definition: Rtypes.h:91
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...