Logo ROOT  
Reference Guide
 
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
37
38
39////////////////////////////////////////////////////////////////////////////////
40
42 : _binding(const_cast<RooAbsFunc *>(&func)), _x(func.getDimension()), _nobs(func.getDimension())
43{
44}
45
46////////////////////////////////////////////////////////////////////////////////
47/// Store list of observables
48
49RooFunctor::RooFunctor(const RooAbsReal &func, const RooArgList &observables, const RooArgList &parameters)
50 : _npar(parameters.size()), _nobs(observables.size())
51{
52 _nset.add(observables) ;
53
54 // Make list of all variables to be bound
55 RooArgList allVars(observables) ;
56 allVars.add(parameters) ;
57
58 // Create RooFit function binding
59 _ownedBinding = std::make_unique<RooRealBinding>(func,allVars,&_nset,false,nullptr) ;
60 _binding = _ownedBinding.get();
61
62 // Allocate transfer array
63 _x.resize(allVars.size());
64}
65
66
67////////////////////////////////////////////////////////////////////////////////
68/// Store normalization set
69
70RooFunctor::RooFunctor(const RooAbsReal &func, const RooArgList &observables, const RooArgList &parameters,
71 const RooArgSet &nset)
72 : _npar(parameters.size()), _nobs(observables.size())
73{
74 _nset.add(nset) ;
75
76 // Make list of all variables to be bound
77 RooArgList allVars(observables) ;
78 allVars.add(parameters) ;
79
80 // Create RooFit function binding
81 _ownedBinding = std::make_unique<RooRealBinding>(func,allVars,&_nset,false,nullptr) ;
82 _binding = _ownedBinding.get();
83
84 // Allocate transfer array
85 _x.resize(allVars.size());
86}
87
88
89
90////////////////////////////////////////////////////////////////////////////////
91
93 _nset(other._nset),
94 _binding(nullptr),
95 _npar(other._npar),
96 _nobs(other._nobs)
97{
98 if (other._ownedBinding) {
99 _ownedBinding = std::make_unique<RooRealBinding>(static_cast<RooRealBinding&>(*other._binding),&_nset);
100 _binding = _ownedBinding.get();
101 } else {
102 _binding = other._binding;
103 }
104 _x.resize(_nobs + _npar);
105}
106
107RooFunctor::~RooFunctor() = default;
108
109////////////////////////////////////////////////////////////////////////////////
110
111double RooFunctor::eval(const double *x) const
112{
113 return (*_binding)(x) ;
114}
115
116////////////////////////////////////////////////////////////////////////////////
117
118double RooFunctor::eval(double x) const
119{
120 return (*_binding)(&x) ;
121}
122
123////////////////////////////////////////////////////////////////////////////////
124
125double RooFunctor::eval(const double *x, const double *p) const
126{
127 for (int i=0 ; i<_nobs ; i++) {
128 _x[i] = x[i] ;
129 }
130 for (int i=0 ; i<_npar ; i++) {
131 _x[i+_nobs] = p[i] ;
132 }
133 return (*_binding)(_x.data());
134}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define ClassImp(name)
Definition Rtypes.h:377
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:55
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:55
RooAbsFunc * _binding
Function binding.
Definition RooFunctor.h:57
Int_t _npar
! Number of parameters ;
Definition RooFunctor.h:59
std::vector< double > _x
! Transfer array ;
Definition RooFunctor.h:58
virtual ~RooFunctor()
Int_t _nobs
! Number of observables ;
Definition RooFunctor.h:60
RooArgSet _nset
Normalization observables.
Definition RooFunctor.h:56
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