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 
22 RooFirstMoment 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 "RooFirstMoment.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 "RooProduct.h"
46 #include <string>
47 using namespace std;
48 
49 
51 ;
52 
53 
54 ////////////////////////////////////////////////////////////////////////////////
55 /// Default constructor
56 
58 {
59 }
60 
61 
62 
63 ////////////////////////////////////////////////////////////////////////////////
64 
65 RooFirstMoment::RooFirstMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x) :
66  RooAbsMoment(name, title,func,x,1,kFALSE),
67  _xf("!xf","xf",this,kFALSE,kFALSE),
68  _ixf("!ixf","ixf",this),
69  _if("!if","if",this)
70 {
72 
73  string pname=Form("%s_product",name) ;
74 
75  RooProduct* XF = new RooProduct(pname.c_str(),pname.c_str(),RooArgSet(x,func)) ;
77 
78  if (func.isBinnedDistribution(x)) {
79  XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
80  }
81 
84  intXF->setCacheNumeric(kTRUE) ;
85  intF->setCacheNumeric(kTRUE) ;
86 
87  _xf.setArg(*XF) ;
88  _ixf.setArg(*intXF) ;
89  _if.setArg(*intF) ;
90  addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
91 }
92 
93 ////////////////////////////////////////////////////////////////////////////////
94 
95 RooFirstMoment::RooFirstMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset, Bool_t intNSet) :
96  RooAbsMoment(name, title,func,x,1,kFALSE),
97  _xf("!xf","xf",this,kFALSE,kFALSE),
98  _ixf("!ixf","ixf",this),
99  _if("!if","if",this)
100 {
102 
103  _nset.add(nset) ;
104 
105  string pname=Form("%s_product",name) ;
106 
107  RooProduct* XF = new RooProduct(pname.c_str(),pname.c_str(),RooArgSet(x,func)) ;
109 
110  if (func.isBinnedDistribution(x)) {
111  XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
112  }
113 
114  if (intNSet && _nset.getSize()>0 && func.isBinnedDistribution(_nset)) {
115  XF->specialIntegratorConfig(kTRUE)->method2D().setLabel("RooBinIntegrator");
116  XF->specialIntegratorConfig(kTRUE)->methodND().setLabel("RooBinIntegrator");
117  }
118 
119  RooArgSet intSet(x) ;
120  if (intNSet) intSet.add(_nset,kTRUE) ;
121  RooRealIntegral* intXF = (RooRealIntegral*) XF->createIntegral(intSet,&_nset) ;
122  RooRealIntegral* intF = (RooRealIntegral*) func.createIntegral(intSet,&_nset) ;
123  intXF->setCacheNumeric(kTRUE) ;
124  intF->setCacheNumeric(kTRUE) ;
125 
126  _xf.setArg(*XF) ;
127  _ixf.setArg(*intXF) ;
128  _if.setArg(*intF) ;
129  addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
130 }
131 
132 
133 
134 ////////////////////////////////////////////////////////////////////////////////
135 
137  RooAbsMoment(other, name),
138  _xf("xf",this,other._xf),
139  _ixf("ixf",this,other._ixf),
140  _if("if",this,other._if)
141 {
142 }
143 
144 
145 
146 ////////////////////////////////////////////////////////////////////////////////
147 /// Destructor
148 
150 {
151 }
152 
153 
154 
155 ////////////////////////////////////////////////////////////////////////////////
156 /// Calculate value
157 
159 {
160  Double_t ratio = _ixf / _if ;
161  //cout << "\nRooFirstMoment::eval(" << GetName() << ") val = " << ratio << endl ;
162  return ratio ;
163 }
164 
165 
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:100
RooAbsMoment::_nset
RooSetProxy _nset
Definition: RooAbsMoment.h:44
RooAbsReal.h
RooMsgService.h
RooNumIntConfig.h
RooFit.h
RooArgSet.h
RooAbsReal::isBinnedDistribution
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:341
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:548
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
Form
char * Form(const char *fmt,...)
RooNumIntConfig::method1D
RooCategory & method1D()
Definition: RooNumIntConfig.h:34
x
Double_t x[n]
Definition: legend1.C:17
RooFirstMoment::RooFirstMoment
RooFirstMoment()
Default constructor.
Definition: RooFirstMoment.cxx:57
RooAbsReal
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:61
RooFirstMoment::_if
RooRealProxy _if
Definition: RooFirstMoment.h:46
RooAbsMoment
RooAbsMoment represents the first, second, or third order derivative of any RooAbsReal as calculated ...
Definition: RooAbsMoment.h:27
RooAbsArg::setExpensiveObjectCache
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition: RooAbsArg.h:503
RooAbsArg::expensiveObjectCache
RooExpensiveObjectCache & expensiveObjectCache() const
Definition: RooAbsArg.cxx:2277
bool
RooRealIntegral
RooRealIntegral performs hybrid numerical/analytical integrals of RooAbsReal objects.
Definition: RooRealIntegral.h:34
RooProduct
A RooProduct represents the product of a given set of RooAbsReal objects.
Definition: RooProduct.h:29
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
RooAbsPdf.h
Double_t
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:101
RooNumIntConfig::method2D
RooCategory & method2D()
Definition: RooNumIntConfig.h:35
RooAbsArg::RooArgSet
friend class RooArgSet
Definition: RooAbsArg.h:599
RooAbsCollection::add
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Definition: RooAbsCollection.cxx:455
RooFirstMoment
RooFirstMoment represents the first, second, or third order derivative of any RooAbsReal as calculate...
Definition: RooFirstMoment.h:27
RooFirstMoment::evaluate
Double_t evaluate() const
Calculate value
Definition: RooFirstMoment.cxx:158
RooTemplateProxy::setArg
bool setArg(T &newRef)
Change object held in proxy into newRef.
Definition: RooTemplateProxy.h:227
RooRealVar.h
RooProduct.h
RooConstVar.h
RooGlobalFunc.h
RooAbsReal::specialIntegratorConfig
RooNumIntConfig * specialIntegratorConfig() const
Returns the specialized integrator configuration for this RooAbsReal.
Definition: RooAbsReal.cxx:3531
RooAbsArg::addOwnedComponents
Bool_t addOwnedComponents(const RooArgSet &comps)
Take ownership of the contents of 'comps'.
Definition: RooAbsArg.cxx:2216
name
char name[80]
Definition: TGX11.cxx:110
RooFirstMoment::_ixf
RooRealProxy _ixf
Definition: RooFirstMoment.h:45
RooErrorHandler.h
RooRealIntegral::setCacheNumeric
void setCacheNumeric(Bool_t flag)
Definition: RooRealIntegral.h:60
RooRealIntegral.h
RooFunctor.h
RooRealVar
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:39
RooFirstMoment::_xf
RooRealProxy _xf
Definition: RooFirstMoment.h:44
Riostream.h
RooFirstMoment::~RooFirstMoment
virtual ~RooFirstMoment()
Destructor.
Definition: RooFirstMoment.cxx:149
RooFirstMoment.h
RooNumIntConfig::methodND
RooCategory & methodND()
Definition: RooNumIntConfig.h:36
RooAbsCollection::getSize
Int_t getSize() const
Definition: RooAbsCollection.h:231
RooSetProxy::add
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE) override
Overloaded RooArgSet::add() method inserts 'var' into set and registers 'var' as server to owner with...
Definition: RooSetProxy.cxx:165
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:33