Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooPyBind.h
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 * Authors:
4 * Robin Syring, CERN 2024
5 *
6 * Copyright (c) 2024, CERN
7 *
8 * Redistribution and use in source and binary forms,
9 * with or without modification, are permitted according to the terms
10 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
11 */
12
13/** \class RooPyBind
14 \ingroup Roofit
15 \brief A RooFit class for wrapping python functions.
16
17This clsss provides the functionality to wrap arbitrary python functions in
18RooFit.
19*/
20
21#ifndef ROOPYBINDFUNCTION_H
22#define ROOPYBINDFUNCTION_H
23
24#include "RooAbsReal.h"
25#include "RooListProxy.h"
26#include "RooArgList.h"
27
28namespace RooFit {
29namespace Detail {
30
31template <class BaseClass>
32class RooPyBind : public BaseClass {
33public:
34 RooPyBind(const char *name, const char *title, RooArgList &varlist)
35 : BaseClass(name, title), _varlist("!varlist", "All variables(list)", this)
36 {
38 }
39
40 RooPyBind(const RooPyBind &right, const char *name = nullptr)
41 : BaseClass(right, name), _varlist("!varlist", this, right._varlist)
42 {
43 }
44
45 RooPyBind *clone(const char *name) const override { return new RooPyBind(*this, name); }
46 // This function should be redefined in Python
47 double evaluate() const override { return 1.; }
48 const RooArgList &varlist() const { return _varlist; }
49
50 virtual double *doEvalPy(RooFit::EvalContext &) const
51 {
52 throw std::runtime_error("not implemented");
53 }
54
55protected:
56 void doEval(RooFit::EvalContext &ctx) const override
57 {
58 std::span<double> output = ctx.output();
59 std::span<const double> result{doEvalPy(ctx), output.size()};
60 for (std::size_t i = 0; i < result.size(); ++i) {
61 output[i] = result[i];
62 }
63 }
64
65 RooListProxy _varlist; // all variables as list of variables
66
68};
69
70} // namespace Detail
71} // namespace RooFit
72
73#endif
#define ClassDefOverride(name, id)
Definition Rtypes.h:346
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
char name[80]
Definition TGX11.cxx:110
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
bool add(const RooAbsArg &var, bool valueServer, bool shapeServer, bool silent)
Overloaded RooCollection_t::add() method insert object into set and registers object as server to own...
virtual double * doEvalPy(RooFit::EvalContext &) const
Definition RooPyBind.h:50
void doEval(RooFit::EvalContext &ctx) const override
Definition RooPyBind.h:56
RooPyBind(const RooPyBind &right, const char *name=nullptr)
Definition RooPyBind.h:40
RooPyBind * clone(const char *name) const override
Definition RooPyBind.h:45
double evaluate() const override
Definition RooPyBind.h:47
RooPyBind(const char *name, const char *title, RooArgList &varlist)
Definition RooPyBind.h:34
const RooArgList & varlist() const
Definition RooPyBind.h:48
std::span< double > output()
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26
static void output()