Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooConvIntegrandBinding.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 RooConvIntegrandBinding.cxx
19\class RooConvIntegrandBinding
20\ingroup Roofitcore
21
22Implementation of RooAbsFunc that represent the integrand
23of a generic (numeric) convolution A (x) B so that it can be
24passed to a numeric integrator. This is a utility class for
25RooNumConvPdf
26**/
27
29#include "RooAbsReal.h"
30#include "RooArgSet.h"
31#include "RooAbsRealLValue.h"
32#include "RooMsgService.h"
33
34#include <cassert>
35
36using namespace std;
37
38
39////////////////////////////////////////////////////////////////////////////////
40
42 RooAbsReal& xprime, RooAbsReal& x,
43 const RooArgSet* nset, bool clipInvalid) :
44
45 RooAbsFunc(2), _func(&func), _model(&model), _vars(nullptr), _nset(nset), _clipInvalid(clipInvalid)
46{
47 // Constructor where func and model
48 //
49 // 'func' = func(xprime)
50 // 'model' = model(xprime)
51 //
52 // and
53
54 // 'xprime' is the RRV that should be connected to func and model
55 // (i.e. the variable that will be integrated over)
56 // 'x' is RRV that represents the value at which the convolution is calculated
57 // (this variable should _not_ be connected to func and model)
58 //
59 // this function returns RCBB[x',x] = f[x']*g[x-x'], i.e. the substiturion g[x'] --> g[x-x']
60 // is taken care internally
61 //
62 // The integral of this binding over its 1st arg yields the convolution (f (x) g)[x]
63 //
64
65 // allocate memory
66 _vars= new RooAbsRealLValue*[2];
67 if(nullptr == _vars) {
68 _valid= false;
69 return;
70 }
71
72 // check that all of the arguments are real valued and store them
73 _vars[0]= dynamic_cast<RooAbsRealLValue*>(&xprime);
74 if(nullptr == _vars[0]) {
75 oocoutE(&func,InputArguments) << "RooConvIntegrandBinding: cannot bind to ";
76 xprime.Print("1");
77 _valid= false;
78 }
79
80 _vars[1]= dynamic_cast<RooAbsRealLValue*>(&x);
81 if(nullptr == _vars[1]) {
82 oocoutE(&func,InputArguments) << "RooConvIntegrandBinding: cannot bind to ";
83 x.Print("1");
84 _valid= false;
85 }
86
87 _xvecValid = true ;
88}
89
90
91
92////////////////////////////////////////////////////////////////////////////////
93/// Destructor
94
96{
97 if(nullptr != _vars) delete[] _vars;
98}
99
100
101////////////////////////////////////////////////////////////////////////////////
102/// Load external input values
103
104void RooConvIntegrandBinding::loadValues(const double xvector[], bool clipInvalid) const
105{
106 _xvecValid = true ;
107 for(UInt_t index= 0; index < _dimension; index++) {
108 if (clipInvalid && !_vars[index]->isValidReal(xvector[index])) {
109 _xvecValid = false ;
110 } else {
111 //cout << "RooConvBasBinding::loadValues[" << index << "] loading value " << xvector[index] << endl ;
112 _vars[index]->setVal(xvector[index]);
113 }
114 }
115}
116
117
118////////////////////////////////////////////////////////////////////////////////
119/// Evaluate self at given parameter values
120
121double RooConvIntegrandBinding::operator()(const double xvector[]) const
122{
123 assert(isValid());
124 _ncall++ ;
125
126 // First evaluate function at x'
127 loadValues(xvector);
128 if (!_xvecValid) return 0 ;
129 //cout << "RooConvIntegrandBinding::operator(): evaluating f(x') at x' = " << xvector[0] << endl ;
130 double f_xp = _func->getVal(_nset) ;
131
132 // Next evaluate model at x-x'
133 const double xvec_tmp[2] = { xvector[1]-xvector[0] , xvector[1] } ;
134 loadValues(xvec_tmp,true);
135 if (!_xvecValid) return 0 ;
136 double g_xmxp = _model->getVal(_nset) ;
137
138 //cout << "RooConvIntegrandBinding::operator(): evaluating g(x-x') at x-x' = " << _vars[0]->getVal() << " = " << g_xmxp << endl ;
139 //cout << "RooConvIntegrandBinding::operator(): return value = " << f_xp << " * " << g_xmxp << " = " << f_xp*g_xmxp << endl ;
140
141 //cout << "_vars[0] = " << _vars[0]->getVal() << " _vars[1] = " << _vars[1]->getVal() << endl ;
142 //cout << "_xvec[0] = " << xvector[0] << " _xvec[1] = " << xvector[1] << endl ;
143
144 return f_xp*g_xmxp ;
145}
146
147
148////////////////////////////////////////////////////////////////////////////////
149/// Retrieve lower limit of i-th observable
150
152{
153 assert(isValid());
154 return _vars[index]->getMin();
155}
156
157
158////////////////////////////////////////////////////////////////////////////////
159/// Retrieve upper limit of i-th observable
160
162{
163 assert(isValid());
164 return _vars[index]->getMax();
165}
#define oocoutE(o, a)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
void Print(Option_t *options=nullptr) const override
Print the object to the defaultPrintStream().
Definition RooAbsArg.h:322
Abstract interface for evaluating a real-valued function of one real variable and performing numerica...
Definition RooAbsFunc.h:27
UInt_t _dimension
Number of observables.
Definition RooAbsFunc.h:79
bool isValid() const
Definition RooAbsFunc.h:37
Int_t _ncall
Function call counter.
Definition RooAbsFunc.h:78
bool _valid
Is binding in valid state?
Definition RooAbsFunc.h:80
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
virtual double getMax(const char *name=nullptr) const
Get maximum of currently defined range.
virtual void setVal(double value)=0
Set the current value of the object. Needs to be overridden by implementations.
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:103
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
bool _xvecValid
If true _xvec defines a valid point.
double getMaxLimit(UInt_t dimension) const override
Retrieve upper limit of i-th observable.
double operator()(const double xvector[]) const override
Evaluate self at given parameter values.
const RooAbsReal * _func
Pointer to input function.
const RooAbsReal * _model
Pointer to input resolution model.
double getMinLimit(UInt_t dimension) const override
Retrieve lower limit of i-th observable.
RooConvIntegrandBinding(const RooAbsReal &func, const RooAbsReal &model, RooAbsReal &x, RooAbsReal &xprime, const RooArgSet *nset=nullptr, bool clipInvalid=false)
void loadValues(const double xvector[], bool clipInvalid=false) const
Load external input values.
RooAbsRealLValue ** _vars
Array of pointers to variables.
const RooArgSet * _nset
Normalization set to be used for function evaluations.
~RooConvIntegrandBinding() override
Destructor.
Double_t x[n]
Definition legend1.C:17