Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
39
40////////////////////////////////////////////////////////////////////////////////
41
42RooFirstMoment::RooFirstMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x) :
43 RooAbsMoment(name, title,func,x,1,false),
44 _xf("!xf","xf",this,false,false),
45 _ixf("!ixf","ixf",this),
46 _if("!if","if",this)
47{
49
50 std::string pname = std::string(name) + "_product";
51
52 auto XF = std::make_unique<RooProduct>(pname.c_str(),pname.c_str(),RooArgSet(x,func));
53 XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;
54
55 if (func.isBinnedDistribution(x)) {
56 XF->specialIntegratorConfig(true)->method1D().setLabel("RooBinIntegrator");
57 }
58
59 std::unique_ptr<RooAbsReal> intXF{XF->createIntegral(x)};
60 std::unique_ptr<RooAbsReal> intF{func.createIntegral(x)};
61 static_cast<RooRealIntegral&>(*intXF).setCacheNumeric(true) ;
62 static_cast<RooRealIntegral&>(*intF).setCacheNumeric(true) ;
63
64 _xf.setArg(*XF) ;
65 _ixf.setArg(*intXF) ;
66 _if.setArg(*intF) ;
67 addOwnedComponents(std::move(XF)) ;
68 addOwnedComponents(std::move(intXF));
69 addOwnedComponents(std::move(intF));
70}
71
72////////////////////////////////////////////////////////////////////////////////
73
74RooFirstMoment::RooFirstMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset, bool intNSet) :
75 RooAbsMoment(name, title,func,x,1,false),
76 _xf("!xf","xf",this,false,false),
77 _ixf("!ixf","ixf",this),
78 _if("!if","if",this)
79{
81
82 _nset.add(nset) ;
83
84 std::string pname = std::string(name) + "_product";
85
86 auto XF = std::make_unique<RooProduct>(pname.c_str(),pname.c_str(),RooArgSet(x,func)) ;
87 XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;
88
89 if (func.isBinnedDistribution(x)) {
90 XF->specialIntegratorConfig(true)->method1D().setLabel("RooBinIntegrator");
91 }
92
93 if (intNSet && !_nset.empty() && func.isBinnedDistribution(_nset)) {
94 XF->specialIntegratorConfig(true)->method2D().setLabel("RooBinIntegrator");
95 XF->specialIntegratorConfig(true)->methodND().setLabel("RooBinIntegrator");
96 }
97
99 if (intNSet) intSet.add(_nset,true) ;
100 std::unique_ptr<RooAbsReal> intXF{XF->createIntegral(intSet, &_nset)};
101 std::unique_ptr<RooAbsReal> intF{func.createIntegral(intSet, &_nset)};
102 static_cast<RooRealIntegral&>(*intXF).setCacheNumeric(true) ;
103 static_cast<RooRealIntegral&>(*intF).setCacheNumeric(true) ;
104
105 _xf.setArg(*XF) ;
106 _ixf.setArg(*intXF) ;
107 _if.setArg(*intF) ;
108 addOwnedComponents(std::move(XF)) ;
109 addOwnedComponents(std::move(intXF));
110 addOwnedComponents(std::move(intF));
111}
112
113
114
115////////////////////////////////////////////////////////////////////////////////
116
119 _xf("xf",this,other._xf),
120 _ixf("ixf",this,other._ixf),
121 _if("if",this,other._if)
122{
123}
124
125////////////////////////////////////////////////////////////////////////////////
126/// Calculate value
127
129{
130 double ratio = _ixf / _if ;
131 //cout << "\nRooFirstMoment::eval(" << GetName() << ") val = " << ratio << std::endl ;
132 return ratio ;
133}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char name[80]
Definition TGX11.cxx:110
RooExpensiveObjectCache & expensiveObjectCache() const
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition RooAbsArg.h:444
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
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
virtual bool isBinnedDistribution(const RooArgSet &) const
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
Definition RooAbsReal.h:348
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 ...
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
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