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 : RooFunctor{func, observables, parameters, observables}
51{
52}
53
54////////////////////////////////////////////////////////////////////////////////
55/// Store normalization set
56
57RooFunctor::RooFunctor(const RooAbsReal &func, const RooArgList &observables, const RooArgList &parameters,
58 const RooArgSet &nset)
59 : _npar(parameters.size()), _nobs(observables.size())
60{
61 _nset.add(nset) ;
62
63 // Make list of all variables to be bound
64 RooArgList allVars(observables) ;
65 allVars.add(parameters) ;
66
67 // Create RooFit function binding
68 _ownedBinding = std::make_unique<RooRealBinding>(func,allVars,&_nset,false,nullptr) ;
69
70 // Allocate transfer array
71 _x.resize(allVars.size());
72}
73
74////////////////////////////////////////////////////////////////////////////////
75
77 _nset(other._nset),
78 _binding{other._binding},
79 _npar(other._npar),
80 _nobs(other._nobs)
81{
82 if (other._ownedBinding) {
83 _ownedBinding = std::make_unique<RooRealBinding>(static_cast<RooRealBinding&>(*other._ownedBinding),&_nset);
84 }
85 _x.resize(_nobs + _npar);
86}
87
88RooFunctor::~RooFunctor() = default;
89
90////////////////////////////////////////////////////////////////////////////////
91
92double RooFunctor::eval(const double *x) const
93{
94 return binding()(x) ;
95}
96
97////////////////////////////////////////////////////////////////////////////////
98
99double RooFunctor::eval(double x) const
100{
101 return binding()(&x) ;
102}
103
104////////////////////////////////////////////////////////////////////////////////
105
106double RooFunctor::eval(const double *x, const double *p) const
107{
108 for (int i=0 ; i<_nobs ; i++) {
109 _x[i] = x[i] ;
110 }
111 for (int i=0 ; i<_npar ; i++) {
112 _x[i+_nobs] = p[i] ;
113 }
114 return binding()(_x.data());
115}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define ClassImp(name)
Definition Rtypes.h:382
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