Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooNLLVarNew.h
Go to the documentation of this file.
1/// \cond ROOFIT_INTERNAL
2
3/*
4 * Project: RooFit
5 * Authors:
6 * Jonas Rembser, CERN 2021
7 * Emmanouil Michalainas, CERN 2021
8 *
9 * Copyright (c) 2021, CERN
10 *
11 * Redistribution and use in source and binary forms,
12 * with or without modification, are permitted according to the terms
13 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
14 */
15
16#ifndef RooFit_RooNLLVarNew_h
17#define RooFit_RooNLLVarNew_h
18
19#include <RooAbsPdf.h>
20#include <RooAbsReal.h>
21#include <RooDataHist.h>
22#include <RooGlobalFunc.h>
23#include <RooTemplateProxy.h>
24
25#include <Math/Util.h>
26
27namespace RooFit {
28namespace Detail {
29
30class RooNLLVarNew : public RooAbsReal {
31
32public:
33 // The names for the special variables that the RooNLLVarNew expects
34 static constexpr const char *weightVarName = "_weight";
35 static constexpr const char *weightVarNameSumW2 = "_weight_sumW2";
36 static constexpr const char *binVolumeVarName = "_bin_volume";
37 static constexpr const char *weightErrorLoVarName = "_weight_err_lo";
38 static constexpr const char *weightErrorHiVarName = "_weight_err_hi";
39
40 enum class Statistic {
41 NLL,
42 Chi2
43 };
44
45 /// Configuration struct for the unified constructor. Note that `offsetMode`
46 /// only applies to `Statistic::NLL`, and `chi2ErrorType` only applies to
47 /// `Statistic::Chi2`.
48 struct Config {
49 Statistic statistic = Statistic::NLL;
50 bool extended = false;
53 };
54
55 RooNLLVarNew(const char *name, const char *title, RooAbsReal &func, RooArgSet const &observables, Config const &cfg);
56 RooNLLVarNew(const RooNLLVarNew &other, const char *name = nullptr);
57 TObject *clone(const char *newname) const override { return new RooNLLVarNew(*this, newname); }
58
59 /// Return default level for MINUIT error analysis.
60 double defaultErrorLevel() const override { return _statistic == Statistic::Chi2 ? 1.0 : 0.5; }
61
62 void doEval(RooFit::EvalContext &) const override;
63 bool canComputeBatchWithCuda() const override { return _statistic == Statistic::NLL && !_binnedL; }
64 bool isReducerNode() const override { return true; }
65
66 void setPrefix(std::string const &prefix);
67
68 void applyWeightSquared(bool flag) override;
69
70 void enableOffsetting(bool) override;
71
72 void enableBinOffsetting(bool on = true) { _doBinOffset = on; }
73
74 void setSimCount(int simCount) { _simCount = simCount; }
75
76 enum class FuncMode {
77 Pdf,
80 };
81
82 RooAbsReal const &func() const { return *_func; }
83 RooAbsReal const &weightVar() const { return *_weightVar; }
84 RooAbsReal const &weightSquaredVar() const { return *_weightSquaredVar; }
85 bool binnedL() const { return _binnedL; }
86 int simCount() const { return _simCount; }
87 Statistic statistic() const { return _statistic; }
88 FuncMode funcMode() const { return _funcMode; }
90 RooAbsReal const *expectedEvents() const { return _expectedEvents ? &**_expectedEvents : nullptr; }
91 RooAbsReal const *binVolumes() const { return _binVolumes ? &**_binVolumes : nullptr; }
92 RooAbsReal const *weightErrLo() const { return _weightErrLo ? &**_weightErrLo : nullptr; }
93 RooAbsReal const *weightErrHi() const { return _weightErrHi ? &**_weightErrHi : nullptr; }
94
95private:
96 double evaluate() const override { return _value; }
99 void fillBinWidthsFromPdfBoundaries(RooAbsReal const &pdf, RooArgSet const &observables);
100 void doEvalBinnedL(RooFit::EvalContext &, std::span<const double> preds, std::span<const double> weights) const;
101 void doEvalChi2(RooFit::EvalContext &, std::span<const double> preds, std::span<const double> weights,
102 std::span<const double> weightsSumW2) const;
103
107 std::unique_ptr<RooTemplateProxy<RooAbsReal>> _expectedEvents;
108 std::unique_ptr<RooTemplateProxy<RooAbsPdf>> _offsetPdf;
109 std::unique_ptr<RooTemplateProxy<RooAbsReal>> _binVolumes;
110 std::unique_ptr<RooTemplateProxy<RooAbsReal>> _weightErrLo;
111 std::unique_ptr<RooTemplateProxy<RooAbsReal>> _weightErrHi;
112 bool _weightSquared = false;
113 bool _binnedL = false;
114 bool _doOffset = false;
115 bool _doBinOffset = false;
116 Statistic _statistic = Statistic::NLL;
117 FuncMode _funcMode = FuncMode::Pdf;
119 int _simCount = 1;
120 std::string _prefix;
121 std::vector<double> _binw;
122 mutable ROOT::Math::KahanSum<double> _offset{0.}; ///<! Offset as KahanSum to avoid loss of precision
123
124 ClassDefOverride(RooFit::Detail::RooNLLVarNew, 0);
125};
126
127} // namespace Detail
128} // namespace RooFit
129
130#endif
131
132/// \endcond
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
char name[80]
Definition TGX11.cxx:145
Double_t(* Function)(Double_t)
Definition Functor.C:4
The Kahan summation is a compensated summation algorithm, which significantly reduces numerical error...
Definition Util.h:141
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:63
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Mother of all ROOT objects.
Definition TObject.h:42
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition CodegenImpl.h:72
OffsetMode
For setting the offset mode with the Offset() command argument to RooAbsPdf::fitTo()
void evaluate(typename Architecture_t::Tensor_t &A, EActivationFunction f)
Apply the given activation function to each value in the given tensor A.
Definition Functions.h:98