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#include "RooFunctor.h"
26#include "RooRealBinding.h"
27#include "RooAbsReal.h"
28#include "RooAbsPdf.h"
29#include "RooArgSet.h"
30
31#include <cassert>
32
33
34////////////////////////////////////////////////////////////////////////////////
35
37 : _binding(const_cast<RooAbsFunc *>(&func)), _x(func.getDimension()), _nobs(func.getDimension())
38{
39}
40
41////////////////////////////////////////////////////////////////////////////////
42/// Store list of observables
43
44RooFunctor::RooFunctor(const RooAbsReal &func, const RooArgList &observables, const RooArgList &parameters)
45 : RooFunctor{func, observables, parameters, observables}
46{
47}
48
49////////////////////////////////////////////////////////////////////////////////
50/// Store normalization set
51
52RooFunctor::RooFunctor(const RooAbsReal &func, const RooArgList &observables, const RooArgList &parameters,
53 const RooArgSet &nset)
54 : _npar(parameters.size()), _nobs(observables.size())
55{
56 _nset.add(nset) ;
57
58 // Make list of all variables to be bound
59 RooArgList allVars(observables) ;
60 allVars.add(parameters) ;
61
62 // Create RooFit function binding
63 _ownedBinding = std::make_unique<RooRealBinding>(func,allVars,&_nset,false,nullptr) ;
64
65 // Allocate transfer array
66 _x.resize(allVars.size());
67}
68
69////////////////////////////////////////////////////////////////////////////////
70
72 _nset(other._nset),
73 _binding{other._binding},
74 _npar(other._npar),
75 _nobs(other._nobs)
76{
77 if (other._ownedBinding) {
78 _ownedBinding = std::make_unique<RooRealBinding>(static_cast<RooRealBinding&>(*other._ownedBinding),&_nset);
79 }
80 _x.resize(_nobs + _npar);
81}
82
83RooFunctor::~RooFunctor() = default;
84
85////////////////////////////////////////////////////////////////////////////////
86
87double RooFunctor::eval(const double *x) const
88{
89 return binding()(x) ;
90}
91
92////////////////////////////////////////////////////////////////////////////////
93
94double RooFunctor::eval(double x) const
95{
96 return binding()(&x) ;
97}
98
99////////////////////////////////////////////////////////////////////////////////
100
101double RooFunctor::eval(const double *x, const double *p) const
102{
103 for (int i=0 ; i<_nobs ; i++) {
104 _x[i] = x[i] ;
105 }
106 for (int i=0 ; i<_npar ; i++) {
107 _x[i+_nobs] = p[i] ;
108 }
109 return binding()(_x.data());
110}
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:63
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