Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
EvalContext.cxx
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 * Authors:
4 * Garima Singh, CERN 2023
5 * Jonas Rembser, CERN 2023
6 *
7 * Copyright (c) 2023, CERN
8 *
9 * Redistribution and use in source and binary forms,
10 * with or without modification, are permitted according to the terms
11 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
12 */
13
14#include <RooFit/EvalContext.h>
15
16#include <RooBatchCompute.h>
17#include <RooRealVar.h>
18
19#include <algorithm>
20#include <stdexcept>
21
22namespace {
23
24// To avoid deleted move assignment.
25template <class T>
26void assignSpan(std::span<T> &to, std::span<T> const &from)
27{
28 to = from;
29}
30
31} // namespace
32
33namespace RooFit {
34
35std::span<const double> EvalContext::at(RooAbsArg const *arg, RooAbsArg const * /*caller*/)
36{
37 std::span<const double> out;
38
39 if (!arg->hasDataToken()) {
40 auto var = static_cast<RooRealVar const *>(arg);
41 assignSpan(out, {&var->_value, 1});
42 } else {
43 std::size_t idx = arg->dataToken();
44 out = _ctx[idx];
45 }
46
47 if (!_enableVectorBuffers || out.size() != 1) {
48 return out;
49 }
50
51 if (_bufferIdx == _buffers.size()) {
53 }
54
55 double *buffer = _buffers[_bufferIdx].data();
56
57 std::fill_n(buffer, RooBatchCompute::bufferSize, out[0]);
58 assignSpan(out, {buffer, 1});
59
60 ++_bufferIdx;
61
62 return out;
63}
64
66{
67 if (!arg->hasDataToken())
68 return;
69 std::size_t idx = arg->dataToken();
70 _cfgs[idx] = config;
71}
72
74{
75 if (!arg->hasDataToken()) {
76 return {};
77 }
78 std::size_t idx = arg->dataToken();
79 return _cfgs[idx];
80}
81
82void EvalContext::resize(std::size_t n)
83{
84 _cfgs.resize(n);
85 _ctx.resize(n);
86}
87
88/// \brief Sets the output value with an offset.
89///
90/// This function sets the output value with an offset for the given argument.
91/// It should only be used in reducer nodes. Depending on the current
92/// OffsetMode, the result will either be just the value, the value minus the
93/// offset, of just the offset.
94///
95/// \param arg Pointer to the RooAbsArg object.
96/// \param val The value to be set.
97/// \param offset The offset value.
98///
99/// \throws std::runtime_error if the argument is not a reducer node.
102{
103 if (!arg->isReducerNode()) {
104 throw std::runtime_error("You can only use setOutputWithOffset() in reducer nodes!");
105 }
107 val -= offset;
108 } else if (_offsetMode == OffsetMode::OnlyOffset) {
109 val = offset;
110 }
111 const_cast<double *>(_ctx[arg->dataToken()].data())[0] = val.Sum();
112}
113
114} // namespace RooFit
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 Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
The Kahan summation is a compensated summation algorithm, which significantly reduces numerical error...
Definition Util.h:122
T Sum() const
Definition Util.h:240
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
virtual bool isReducerNode() const
Definition RooAbsArg.h:575
bool hasDataToken() const
Definition RooAbsArg.h:705
std::size_t dataToken() const
Returns the token for retrieving results in the BatchMode. For internal use only.
Definition RooAbsArg.h:704
Minimal configuration struct to steer the evaluation of a single node with the RooBatchCompute librar...
std::vector< RooBatchCompute::Config > _cfgs
std::span< const double > at(RooAbsArg const *arg, RooAbsArg const *caller=nullptr)
std::size_t _bufferIdx
OffsetMode _offsetMode
RooBatchCompute::Config config(RooAbsArg const *arg) const
void setConfig(RooAbsArg const *arg, RooBatchCompute::Config const &config)
std::vector< std::span< const double > > _ctx
void setOutputWithOffset(RooAbsArg const *arg, ROOT::Math::KahanSum< double > val, ROOT::Math::KahanSum< double > const &offset)
Sets the output value with an offset.
std::vector< std::vector< double > > _buffers
void resize(std::size_t n)
Variable that can be changed from the outside.
Definition RooRealVar.h:37
const Int_t n
Definition legend1.C:16
constexpr std::size_t bufferSize
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26