Logo ROOT  
Reference Guide
RooFirstMoment.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 RooFirstMoment.cxx
19\class RooFirstMoment
20\ingroup Roofitcore
21
22RooFirstMoment represents the first, second, or third order derivative
23of any RooAbsReal as calculated (numerically) by the MathCore Richardson
24derivator class.
25**/
26
27
28#include "Riostream.h"
29#include <math.h>
30
31#include "RooFirstMoment.h"
32#include "RooAbsReal.h"
33#include "RooAbsPdf.h"
34#include "RooErrorHandler.h"
35#include "RooArgSet.h"
36#include "RooMsgService.h"
37#include "RooRealVar.h"
38#include "RooFunctor.h"
39#include "RooGlobalFunc.h"
40#include "RooConstVar.h"
41#include "RooRealIntegral.h"
42#include "RooNumIntConfig.h"
43#include "RooProduct.h"
44#include <string>
45using namespace std;
46
47
49;
50
51
52////////////////////////////////////////////////////////////////////////////////
53/// Default constructor
54
56{
57}
58
59
60
61////////////////////////////////////////////////////////////////////////////////
62
63RooFirstMoment::RooFirstMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x) :
64 RooAbsMoment(name, title,func,x,1,kFALSE),
65 _xf("!xf","xf",this,kFALSE,kFALSE),
66 _ixf("!ixf","ixf",this),
67 _if("!if","if",this)
68{
70
71 string pname=Form("%s_product",name) ;
72
73 RooProduct* XF = new RooProduct(pname.c_str(),pname.c_str(),RooArgSet(x,func)) ;
75
76 if (func.isBinnedDistribution(x)) {
77 XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
78 }
79
82 intXF->setCacheNumeric(kTRUE) ;
83 intF->setCacheNumeric(kTRUE) ;
84
85 _xf.setArg(*XF) ;
86 _ixf.setArg(*intXF) ;
87 _if.setArg(*intF) ;
88 addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
89}
90
91////////////////////////////////////////////////////////////////////////////////
92
93RooFirstMoment::RooFirstMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset, Bool_t intNSet) :
94 RooAbsMoment(name, title,func,x,1,kFALSE),
95 _xf("!xf","xf",this,kFALSE,kFALSE),
96 _ixf("!ixf","ixf",this),
97 _if("!if","if",this)
98{
100
101 _nset.add(nset) ;
102
103 string pname=Form("%s_product",name) ;
104
105 RooProduct* XF = new RooProduct(pname.c_str(),pname.c_str(),RooArgSet(x,func)) ;
107
108 if (func.isBinnedDistribution(x)) {
109 XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
110 }
111
112 if (intNSet && _nset.getSize()>0 && func.isBinnedDistribution(_nset)) {
113 XF->specialIntegratorConfig(kTRUE)->method2D().setLabel("RooBinIntegrator");
114 XF->specialIntegratorConfig(kTRUE)->methodND().setLabel("RooBinIntegrator");
115 }
116
117 RooArgSet intSet(x) ;
118 if (intNSet) intSet.add(_nset,kTRUE) ;
119 RooRealIntegral* intXF = (RooRealIntegral*) XF->createIntegral(intSet,&_nset) ;
120 RooRealIntegral* intF = (RooRealIntegral*) func.createIntegral(intSet,&_nset) ;
121 intXF->setCacheNumeric(kTRUE) ;
122 intF->setCacheNumeric(kTRUE) ;
123
124 _xf.setArg(*XF) ;
125 _ixf.setArg(*intXF) ;
126 _if.setArg(*intF) ;
127 addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
128}
129
130
131
132////////////////////////////////////////////////////////////////////////////////
133
135 RooAbsMoment(other, name),
136 _xf("xf",this,other._xf),
137 _ixf("ixf",this,other._ixf),
138 _if("if",this,other._if)
139{
140}
141
142
143
144////////////////////////////////////////////////////////////////////////////////
145/// Destructor
146
148{
149}
150
151
152
153////////////////////////////////////////////////////////////////////////////////
154/// Calculate value
155
157{
158 Double_t ratio = _ixf / _if ;
159 //cout << "\nRooFirstMoment::eval(" << GetName() << ") val = " << ratio << endl ;
160 return ratio ;
161}
162
163
const Bool_t kFALSE
Definition: RtypesCore.h:101
const Bool_t kTRUE
Definition: RtypesCore.h:100
#define ClassImp(name)
Definition: Rtypes.h:375
char name[80]
Definition: TGX11.cxx:110
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition: TString.cxx:2447
RooExpensiveObjectCache & expensiveObjectCache() const
Definition: RooAbsArg.cxx:2354
friend class RooArgSet
Definition: RooAbsArg.h:651
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition: RooAbsArg.h:527
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
Definition: RooAbsArg.cxx:2275
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Int_t getSize() const
Return the number of elements in the collection.
RooAbsMoment represents the first, second, or third order derivative of any RooAbsReal as calculated ...
Definition: RooAbsMoment.h:27
RooSetProxy _nset
Normalization set (optional)
Definition: RooAbsMoment.h:44
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:63
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:553
RooNumIntConfig * specialIntegratorConfig() const
Returns the specialized integrator configuration for this RooAbsReal.
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:344
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:57
Bool_t setLabel(const char *label, bool printError=true) override
Set value by specifying the name of the desired state.
bool add(const RooAbsArg &var, bool valueServer, bool shapeServer, bool silent)
Overloaded RooCollection_t::add() method insert object into set and registers object as server to own...
RooFirstMoment represents the first, second, or third order derivative of any RooAbsReal as calculate...
~RooFirstMoment() override
Destructor.
RooRealProxy _xf
X*F.
RooFirstMoment()
Default constructor.
RooRealProxy _ixf
Int(X*F(X))dx ;.
RooRealProxy _if
Int(F(x))dx ;.
Double_t evaluate() const override
Calculate value.
RooCategory & method2D()
RooCategory & methodND()
RooCategory & method1D()
A RooProduct represents the product of a given set of RooAbsReal objects.
Definition: RooProduct.h:29
RooRealIntegral performs hybrid numerical/analytical integrals of RooAbsReal objects.
void setCacheNumeric(Bool_t flag)
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
bool setArg(T &newRef)
Change object held in proxy into newRef.
Double_t x[n]
Definition: legend1.C:17