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 <string>
35
36
37////////////////////////////////////////////////////////////////////////////////
38
39RooFirstMoment::RooFirstMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x) :
40 RooAbsMoment(name, title,func,x,1,false),
41 _xf("!xf","xf",this,false,false),
42 _ixf("!ixf","ixf",this),
43 _if("!if","if",this)
44{
46
47 std::string pname = std::string(name) + "_product";
48
49 auto XF = std::make_unique<RooProduct>(pname.c_str(),pname.c_str(),RooArgSet(x,func));
50 XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;
51
52 if (func.isBinnedDistribution(x)) {
53 XF->specialIntegratorConfig(true)->method1D().setLabel("RooBinIntegrator");
54 }
55
56 std::unique_ptr<RooAbsReal> intXF{XF->createIntegral(x)};
57 std::unique_ptr<RooAbsReal> intF{func.createIntegral(x)};
58 static_cast<RooRealIntegral&>(*intXF).setCacheNumeric(true) ;
59 static_cast<RooRealIntegral&>(*intF).setCacheNumeric(true) ;
60
61 _xf.setArg(*XF) ;
62 _ixf.setArg(*intXF) ;
63 _if.setArg(*intF) ;
64 addOwnedComponents(std::move(XF)) ;
65 addOwnedComponents(std::move(intXF));
66 addOwnedComponents(std::move(intF));
67}
68
69////////////////////////////////////////////////////////////////////////////////
70
71RooFirstMoment::RooFirstMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset, bool intNSet) :
72 RooAbsMoment(name, title,func,x,1,false),
73 _xf("!xf","xf",this,false,false),
74 _ixf("!ixf","ixf",this),
75 _if("!if","if",this)
76{
78
79 _nset.add(nset) ;
80
81 std::string pname = std::string(name) + "_product";
82
83 auto XF = std::make_unique<RooProduct>(pname.c_str(),pname.c_str(),RooArgSet(x,func)) ;
84 XF->setExpensiveObjectCache(func.expensiveObjectCache()) ;
85
86 if (func.isBinnedDistribution(x)) {
87 XF->specialIntegratorConfig(true)->method1D().setLabel("RooBinIntegrator");
88 }
89
90 if (intNSet && !_nset.empty() && func.isBinnedDistribution(_nset)) {
91 XF->specialIntegratorConfig(true)->method2D().setLabel("RooBinIntegrator");
92 XF->specialIntegratorConfig(true)->methodND().setLabel("RooBinIntegrator");
93 }
94
96 if (intNSet) intSet.add(_nset,true) ;
97 std::unique_ptr<RooAbsReal> intXF{XF->createIntegral(intSet, &_nset)};
98 std::unique_ptr<RooAbsReal> intF{func.createIntegral(intSet, &_nset)};
99 static_cast<RooRealIntegral&>(*intXF).setCacheNumeric(true) ;
100 static_cast<RooRealIntegral&>(*intF).setCacheNumeric(true) ;
101
102 _xf.setArg(*XF) ;
103 _ixf.setArg(*intXF) ;
104 _if.setArg(*intF) ;
105 addOwnedComponents(std::move(XF)) ;
106 addOwnedComponents(std::move(intXF));
107 addOwnedComponents(std::move(intF));
108}
109
110
111
112////////////////////////////////////////////////////////////////////////////////
113
116 _xf("xf",this,other._xf),
117 _ixf("ixf",this,other._ixf),
118 _if("if",this,other._if)
119{
120}
121
122////////////////////////////////////////////////////////////////////////////////
123/// Calculate value
124
126{
127 double ratio = _ixf / _if ;
128 //cout << "\nRooFirstMoment::eval(" << GetName() << ") val = " << ratio << std::endl ;
129 return ratio ;
130}
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:142
RooExpensiveObjectCache & expensiveObjectCache() const
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition RooAbsArg.h:418
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:63
virtual bool isBinnedDistribution(const RooArgSet &) const
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
Definition RooAbsReal.h:343
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