Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 <cmath>
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,false),
65 _xf("!xf","xf",this,false,false),
66 _ixf("!ixf","ixf",this),
67 _if("!if","if",this)
68{
70
71 std::string pname = std::string(name) + "_product";
72
73 auto XF = std::make_unique<RooProduct>(pname.c_str(),pname.c_str(),RooArgSet(x,func));
74 XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;
75
76 if (func.isBinnedDistribution(x)) {
77 XF->specialIntegratorConfig(true)->method1D().setLabel("RooBinIntegrator");
78 }
79
80 std::unique_ptr<RooAbsReal> intXF{XF->createIntegral(x)};
81 std::unique_ptr<RooAbsReal> intF{func.createIntegral(x)};
82 static_cast<RooRealIntegral&>(*intXF).setCacheNumeric(true) ;
83 static_cast<RooRealIntegral&>(*intF).setCacheNumeric(true) ;
84
85 _xf.setArg(*XF) ;
86 _ixf.setArg(*intXF) ;
87 _if.setArg(*intF) ;
88 addOwnedComponents(std::move(XF)) ;
89 addOwnedComponents(std::move(intXF));
90 addOwnedComponents(std::move(intF));
91}
92
93////////////////////////////////////////////////////////////////////////////////
94
95RooFirstMoment::RooFirstMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset, bool intNSet) :
96 RooAbsMoment(name, title,func,x,1,false),
97 _xf("!xf","xf",this,false,false),
98 _ixf("!ixf","ixf",this),
99 _if("!if","if",this)
100{
102
103 _nset.add(nset) ;
104
105 std::string pname = std::string(name) + "_product";
106
107 auto XF = std::make_unique<RooProduct>(pname.c_str(),pname.c_str(),RooArgSet(x,func)) ;
108 XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;
109
110 if (func.isBinnedDistribution(x)) {
111 XF->specialIntegratorConfig(true)->method1D().setLabel("RooBinIntegrator");
112 }
113
114 if (intNSet && _nset.getSize()>0 && func.isBinnedDistribution(_nset)) {
115 XF->specialIntegratorConfig(true)->method2D().setLabel("RooBinIntegrator");
116 XF->specialIntegratorConfig(true)->methodND().setLabel("RooBinIntegrator");
117 }
118
119 RooArgSet intSet(x) ;
120 if (intNSet) intSet.add(_nset,true) ;
121 std::unique_ptr<RooAbsReal> intXF{XF->createIntegral(intSet, &_nset)};
122 std::unique_ptr<RooAbsReal> intF{func.createIntegral(intSet, &_nset)};
123 static_cast<RooRealIntegral&>(*intXF).setCacheNumeric(true) ;
124 static_cast<RooRealIntegral&>(*intF).setCacheNumeric(true) ;
125
126 _xf.setArg(*XF) ;
127 _ixf.setArg(*intXF) ;
128 _if.setArg(*intF) ;
129 addOwnedComponents(std::move(XF)) ;
130 addOwnedComponents(std::move(intXF));
131 addOwnedComponents(std::move(intF));
132}
133
134
135
136////////////////////////////////////////////////////////////////////////////////
137
139 RooAbsMoment(other, name),
140 _xf("xf",this,other._xf),
141 _ixf("ixf",this,other._ixf),
142 _if("if",this,other._if)
143{
144}
145
146
147
148////////////////////////////////////////////////////////////////////////////////
149/// Destructor
150
152{
153}
154
155
156
157////////////////////////////////////////////////////////////////////////////////
158/// Calculate value
159
161{
162 double ratio = _ixf / _if ;
163 //cout << "\nRooFirstMoment::eval(" << GetName() << ") val = " << ratio << endl ;
164 return ratio ;
165}
166
167
#define ClassImp(name)
Definition Rtypes.h:377
char name[80]
Definition TGX11.cxx:110
RooExpensiveObjectCache & expensiveObjectCache() const
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition RooAbsArg.h:503
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
Int_t getSize() const
Return the number of elements in the collection.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
RooAbsMoment represents the first, second, or third order derivative of any RooAbsReal as calculated ...
RooSetProxy _nset
Normalization set (optional)
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
RooFit::OwningPtr< RooAbsReal > createIntegral(const RooArgSet &iset, const RooCmdArg &arg1, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}) const
Create an object that represents the integral of the function over one or more observables listed in ...
virtual bool isBinnedDistribution(const RooArgSet &) const
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
Definition RooAbsReal.h:353
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
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.
double evaluate() const override
Calculate value.
RooRealProxy _ixf
Int(X*F(X))dx ;.
RooRealProxy _if
Int(F(x))dx ;.
Performs hybrid numerical/analytical integrals of RooAbsReal objects.
void setCacheNumeric(bool flag)
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:37
bool setArg(T &newRef)
Change object held in proxy into newRef.
Double_t x[n]
Definition legend1.C:17