Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/RooPyBind.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  * Project: RooFit
0003  * Authors:
0004  *   Robin Syring, CERN 2024
0005  *
0006  * Copyright (c) 2024, CERN
0007  *
0008  * Redistribution and use in source and binary forms,
0009  * with or without modification, are permitted according to the terms
0010  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
0011  */
0012 
0013 /** \class RooPyBind
0014     \ingroup Roofit
0015     \brief A RooFit class for wrapping python functions.
0016 
0017 This clsss provides the functionality to wrap arbitrary python functions in
0018 RooFit.
0019 */
0020 
0021 #ifndef ROOPYBINDFUNCTION_H
0022 #define ROOPYBINDFUNCTION_H
0023 
0024 #include "RooAbsReal.h"
0025 #include "RooListProxy.h"
0026 #include "RooArgList.h"
0027 
0028 namespace RooFit {
0029 namespace Detail {
0030 
0031 template <class BaseClass>
0032 class RooPyBind : public BaseClass {
0033 public:
0034    RooPyBind(const char *name, const char *title, RooArgList &varlist)
0035       : BaseClass(name, title), _varlist("!varlist", "All variables(list)", this)
0036    {
0037       _varlist.add(varlist);
0038    }
0039 
0040    RooPyBind(const RooPyBind &right, const char *name = nullptr)
0041       : BaseClass(right, name), _varlist("!varlist", this, right._varlist)
0042    {
0043    }
0044 
0045    RooPyBind *clone(const char *name) const override { return new RooPyBind(*this, name); }
0046    // This function should be redefined in Python
0047    double evaluate() const override { return 1.; }
0048    const RooArgList &varlist() const { return _varlist; }
0049 
0050    virtual double *doEvalPy(RooFit::EvalContext &) const
0051    {
0052       throw std::runtime_error("not implemented");
0053    }
0054 
0055 protected:
0056    void doEval(RooFit::EvalContext &ctx) const override
0057    {
0058       std::span<double> output = ctx.output();
0059       std::span<const double> result{doEvalPy(ctx), output.size()};
0060       for (std::size_t i = 0; i < result.size(); ++i) {
0061          output[i] = result[i];
0062       }
0063    }
0064 
0065    RooListProxy _varlist; // all variables as list of variables
0066 
0067    ClassDefOverride(RooPyBind, 0);
0068 };
0069 
0070 } // namespace Detail
0071 } // namespace RooFit
0072 
0073 #endif