ROOT  6.06/09
Reference Guide
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 //
19 // BEGIN_HTML
20 // Implementation of RooAbsFunc that represent the the integrand
21 // of a generic (numeric) convolution A (x) B so that it can be
22 // passed to a numeric integrator. This is a utility class for
23 // RooNumConvPdf
24 // END_HTML
25 //
26 
27 #include "RooFit.h"
28 
30 #include "RooAbsReal.h"
31 #include "RooArgSet.h"
32 #include "RooAbsRealLValue.h"
33 #include "RooMsgService.h"
34 
35 #include <assert.h>
36 
37 using namespace std;
38 
40 ;
41 
42 
43 ////////////////////////////////////////////////////////////////////////////////
44 
46  RooAbsReal& xprime, RooAbsReal& x,
47  const RooArgSet* nset, Bool_t clipInvalid) :
48 
49  RooAbsFunc(2), _func(&func), _model(&model), _vars(0), _nset(nset), _clipInvalid(clipInvalid)
50 {
51  // Constructor where func and model
52  //
53  // 'func' = func(xprime)
54  // 'model' = model(xprime)
55  //
56  // and
57 
58  // 'xprime' is the RRV that should be connected to func and model
59  // (i.e. the variable that will be integrated over)
60  // 'x' is RRV that represents the value at which the convolution is calculated
61  // (this variable should _not_ be connected to func and model)
62  //
63  // this function returns RCBB[x',x] = f[x']*g[x-x'], i.e. the substiturion g[x'] --> g[x-x']
64  // is taken care internally
65  //
66  // The integral of this binding over its 1st arg yields the convolution (f (x) g)[x]
67  //
68 
69  // allocate memory
70  _vars= new RooAbsRealLValue*[2];
71  if(0 == _vars) {
72  _valid= kFALSE;
73  return;
74  }
75 
76  // check that all of the arguments are real valued and store them
77  _vars[0]= dynamic_cast<RooAbsRealLValue*>(&xprime);
78  if(0 == _vars[0]) {
79  oocoutE(&func,InputArguments) << "RooConvIntegrandBinding: cannot bind to ";
80  xprime.Print("1");
81  _valid= kFALSE;
82  }
83 
84  _vars[1]= dynamic_cast<RooAbsRealLValue*>(&x);
85  if(0 == _vars[1]) {
86  oocoutE(&func,InputArguments) << "RooConvIntegrandBinding: cannot bind to ";
87  x.Print("1");
88  _valid= kFALSE;
89  }
90 
91  _xvecValid = kTRUE ;
92 }
93 
94 
95 
96 ////////////////////////////////////////////////////////////////////////////////
97 /// Destructor
98 
100 {
101  if(0 != _vars) delete[] _vars;
102 }
103 
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 /// Load external input values
107 
108 void RooConvIntegrandBinding::loadValues(const Double_t xvector[], Bool_t clipInvalid) const
109 {
110  _xvecValid = kTRUE ;
111  for(UInt_t index= 0; index < _dimension; index++) {
112  if (clipInvalid && !_vars[index]->isValidReal(xvector[index])) {
113  _xvecValid = kFALSE ;
114  } else {
115  //cout << "RooConvBasBinding::loadValues[" << index << "] loading value " << xvector[index] << endl ;
116  _vars[index]->setVal(xvector[index]);
117  }
118  }
119 }
120 
121 
122 ////////////////////////////////////////////////////////////////////////////////
123 /// Evaluate self at given parameter values
124 
126 {
127  assert(isValid());
128  _ncall++ ;
129 
130  // First evaluate function at x'
131  loadValues(xvector);
132  if (!_xvecValid) return 0 ;
133  //cout << "RooConvIntegrandBinding::operator(): evaluating f(x') at x' = " << xvector[0] << endl ;
134  Double_t f_xp = _func->getVal(_nset) ;
135 
136  // Next evaluate model at x-x'
137  const Double_t xvec_tmp[2] = { xvector[1]-xvector[0] , xvector[1] } ;
138  loadValues(xvec_tmp,kTRUE);
139  if (!_xvecValid) return 0 ;
140  Double_t g_xmxp = _model->getVal(_nset) ;
141 
142  //cout << "RooConvIntegrandBinding::operator(): evaluating g(x-x') at x-x' = " << _vars[0]->getVal() << " = " << g_xmxp << endl ;
143  //cout << "RooConvIntegrandBinding::operator(): return value = " << f_xp << " * " << g_xmxp << " = " << f_xp*g_xmxp << endl ;
144 
145  //cout << "_vars[0] = " << _vars[0]->getVal() << " _vars[1] = " << _vars[1]->getVal() << endl ;
146  //cout << "_xvec[0] = " << xvector[0] << " _xvec[1] = " << xvector[1] << endl ;
147 
148  return f_xp*g_xmxp ;
149 }
150 
151 
152 ////////////////////////////////////////////////////////////////////////////////
153 /// Retrieve lower limit of i-th observable
154 
156 {
157  assert(isValid());
158  return _vars[index]->getMin();
159 }
160 
161 
162 ////////////////////////////////////////////////////////////////////////////////
163 /// Retrieve upper limit of i-th observable
164 
166 {
167  assert(isValid());
168  return _vars[index]->getMax();
169 }
ClassImp(RooConvIntegrandBinding)
#define assert(cond)
Definition: unittest.h:542
void loadValues(const Double_t xvector[], Bool_t clipInvalid=kFALSE) const
Load external input values.
virtual Double_t getMin(const char *name=0) const
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
STL namespace.
virtual Double_t getMaxLimit(UInt_t dimension) const
Retrieve upper limit of i-th observable.
Double_t x[n]
Definition: legend1.C:17
virtual void Print(Option_t *options=0) const
Print TNamed name and title.
Definition: RooAbsArg.h:227
#define oocoutE(o, a)
Definition: RooMsgService.h:48
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
Int_t _ncall
Definition: RooAbsFunc.h:73
unsigned int UInt_t
Definition: RtypesCore.h:42
Bool_t isValid() const
Definition: RooAbsFunc.h:33
virtual Double_t getMinLimit(UInt_t dimension) const
Retrieve lower limit of i-th observable.
virtual void setVal(Double_t value)=0
double Double_t
Definition: RtypesCore.h:55
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
double func(double *x, double *p)
Definition: stressTF1.cxx:213
virtual ~RooConvIntegrandBinding()
Destructor.
virtual Double_t getMax(const char *name=0) const
RooConvIntegrandBinding(const RooAbsReal &func, const RooAbsReal &model, RooAbsReal &x, RooAbsReal &xprime, const RooArgSet *nset=0, Bool_t clipInvalid=kFALSE)
Bool_t _valid
Definition: RooAbsFunc.h:75
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual Double_t operator()(const Double_t xvector[]) const
Evaluate self at given parameter values.
UInt_t _dimension
Definition: RooAbsFunc.h:74