Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
RooFunctor.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\file RooFunctor.cxx
20\class RooFunctor
21\ingroup Roofitcore
22
23Lightweight interface adaptor that exports a RooAbsPdf as a functor.
24**/
25
26#include "Riostream.h"
27
28#include "RooFunctor.h"
29#include "RooRealBinding.h"
30#include "RooAbsReal.h"
31#include "RooAbsPdf.h"
32#include "RooArgSet.h"
33
34#include <cassert>
35
36
37
38////////////////////////////////////////////////////////////////////////////////
39
41 : _binding(const_cast<RooAbsFunc *>(&func)), _x(func.getDimension()), _nobs(func.getDimension())
42{
43}
44
45////////////////////////////////////////////////////////////////////////////////
46/// Store list of observables
47
48RooFunctor::RooFunctor(const RooAbsReal &func, const RooArgList &observables, const RooArgList &parameters)
49 : RooFunctor{func, observables, parameters, observables}
50{
51}
52
53////////////////////////////////////////////////////////////////////////////////
54/// Store normalization set
55
56RooFunctor::RooFunctor(const RooAbsReal &func, const RooArgList &observables, const RooArgList &parameters,
57 const RooArgSet &nset)
58 : _npar(parameters.size()), _nobs(observables.size())
59{
60 _nset.add(nset) ;
61
62 // Make list of all variables to be bound
63 RooArgList allVars(observables) ;
64 allVars.add(parameters) ;
65
66 // Create RooFit function binding
67 _ownedBinding = std::make_unique<RooRealBinding>(func,allVars,&_nset,false,nullptr) ;
68
69 // Allocate transfer array
70 _x.resize(allVars.size());
71}
72
73////////////////////////////////////////////////////////////////////////////////
74
76 _nset(other._nset),
77 _binding{other._binding},
78 _npar(other._npar),
79 _nobs(other._nobs)
80{
81 if (other._ownedBinding) {
82 _ownedBinding = std::make_unique<RooRealBinding>(static_cast<RooRealBinding&>(*other._ownedBinding),&_nset);
83 }
84 _x.resize(_nobs + _npar);
85}
86
87RooFunctor::~RooFunctor() = default;
88
89////////////////////////////////////////////////////////////////////////////////
90
91double RooFunctor::eval(const double *x) const
92{
93 return binding()(x) ;
94}
95
96////////////////////////////////////////////////////////////////////////////////
97
98double RooFunctor::eval(double x) const
99{
100 return binding()(&x) ;
101}
102
103////////////////////////////////////////////////////////////////////////////////
104
105double RooFunctor::eval(const double *x, const double *p) const
106{
107 for (int i=0 ; i<_nobs ; i++) {
108 _x[i] = x[i] ;
109 }
110 for (int i=0 ; i<_npar ; i++) {
111 _x[i+_nobs] = p[i] ;
112 }
113 return binding()(_x.data());
114}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
winID h TVirtualViewer3D TVirtualGLPainter p
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
Abstract interface for evaluating a real-valued function of one real variable and performing numerica...
Definition RooAbsFunc.h:27
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Lightweight interface adaptor that exports a RooAbsPdf as a functor.
Definition RooFunctor.h:25
std::unique_ptr< RooAbsFunc > _ownedBinding
Do we own the binding function.
Definition RooFunctor.h:56
Int_t _npar
! Number of parameters ;
Definition RooFunctor.h:60
RooAbsFunc & binding()
Definition RooFunctor.h:51
std::vector< double > _x
! Transfer array ;
Definition RooFunctor.h:59
virtual ~RooFunctor()
Int_t _nobs
! Number of observables ;
Definition RooFunctor.h:61
RooArgSet _nset
Normalization observables.
Definition RooFunctor.h:57
double eval(const double *, const double *) const
RooFunctor(const RooAbsFunc &func)
Lightweight interface adaptor that binds a RooAbsReal object to a subset of its servers and present i...
Double_t x[n]
Definition legend1.C:17