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**/
22
23#include <RooFirstMoment.h>
24#include <RooAbsReal.h>
25#include <RooAbsPdf.h>
26#include <RooArgSet.h>
27#include <RooMsgService.h>
28#include <RooRealVar.h>
29#include <RooGlobalFunc.h>
30#include <RooRealIntegral.h>
31#include <RooNumIntConfig.h>
32#include <RooProduct.h>
33
34#include <Riostream.h>
35
36#include <cmath>
37#include <string>
38
40
41////////////////////////////////////////////////////////////////////////////////
42
43RooFirstMoment::RooFirstMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x) :
44 RooAbsMoment(name, title,func,x,1,false),
45 _xf("!xf","xf",this,false,false),
46 _ixf("!ixf","ixf",this),
47 _if("!if","if",this)
48{
50
51 std::string pname = std::string(name) + "_product";
52
53 auto XF = std::make_unique<RooProduct>(pname.c_str(),pname.c_str(),RooArgSet(x,func));
54 XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;
55
56 if (func.isBinnedDistribution(x)) {
57 XF->specialIntegratorConfig(true)->method1D().setLabel("RooBinIntegrator");
58 }
59
60 std::unique_ptr<RooAbsReal> intXF{XF->createIntegral(x)};
61 std::unique_ptr<RooAbsReal> intF{func.createIntegral(x)};
62 static_cast<RooRealIntegral&>(*intXF).setCacheNumeric(true) ;
63 static_cast<RooRealIntegral&>(*intF).setCacheNumeric(true) ;
64
65 _xf.setArg(*XF) ;
66 _ixf.setArg(*intXF) ;
67 _if.setArg(*intF) ;
68 addOwnedComponents(std::move(XF)) ;
69 addOwnedComponents(std::move(intXF));
70 addOwnedComponents(std::move(intF));
71}
72
73////////////////////////////////////////////////////////////////////////////////
74
75RooFirstMoment::RooFirstMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset, bool intNSet) :
76 RooAbsMoment(name, title,func,x,1,false),
77 _xf("!xf","xf",this,false,false),
78 _ixf("!ixf","ixf",this),
79 _if("!if","if",this)
80{
82
83 _nset.add(nset) ;
84
85 std::string pname = std::string(name) + "_product";
86
87 auto XF = std::make_unique<RooProduct>(pname.c_str(),pname.c_str(),RooArgSet(x,func)) ;
88 XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;
89
90 if (func.isBinnedDistribution(x)) {
91 XF->specialIntegratorConfig(true)->method1D().setLabel("RooBinIntegrator");
92 }
93
94 if (intNSet && !_nset.empty() && func.isBinnedDistribution(_nset)) {
95 XF->specialIntegratorConfig(true)->method2D().setLabel("RooBinIntegrator");
96 XF->specialIntegratorConfig(true)->methodND().setLabel("RooBinIntegrator");
97 }
98
99 RooArgSet intSet(x) ;
100 if (intNSet) intSet.add(_nset,true) ;
101 std::unique_ptr<RooAbsReal> intXF{XF->createIntegral(intSet, &_nset)};
102 std::unique_ptr<RooAbsReal> intF{func.createIntegral(intSet, &_nset)};
103 static_cast<RooRealIntegral&>(*intXF).setCacheNumeric(true) ;
104 static_cast<RooRealIntegral&>(*intF).setCacheNumeric(true) ;
105
106 _xf.setArg(*XF) ;
107 _ixf.setArg(*intXF) ;
108 _if.setArg(*intF) ;
109 addOwnedComponents(std::move(XF)) ;
110 addOwnedComponents(std::move(intXF));
111 addOwnedComponents(std::move(intF));
112}
113
114
115
116////////////////////////////////////////////////////////////////////////////////
117
119 RooAbsMoment(other, name),
120 _xf("xf",this,other._xf),
121 _ixf("ixf",this,other._ixf),
122 _if("if",this,other._if)
123{
124}
125
126////////////////////////////////////////////////////////////////////////////////
127/// Calculate value
128
130{
131 double ratio = _ixf / _if ;
132 //cout << "\nRooFirstMoment::eval(" << GetName() << ") val = " << ratio << endl ;
133 return ratio ;
134}
#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:501
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
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()=default
RooRealProxy _xf
X*F.
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)
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