File indexing completed on 2025-09-17 09:14:09
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef RooFit_RooNLLVarNew_h
0017 #define RooFit_RooNLLVarNew_h
0018
0019 #include <RooAbsPdf.h>
0020 #include <RooAbsReal.h>
0021 #include <RooGlobalFunc.h>
0022 #include <RooTemplateProxy.h>
0023
0024 #include <Math/Util.h>
0025
0026 namespace RooFit {
0027 namespace Detail {
0028
0029 class RooNLLVarNew : public RooAbsReal {
0030
0031 public:
0032
0033 static constexpr const char *weightVarName = "_weight";
0034 static constexpr const char *weightVarNameSumW2 = "_weight_sumW2";
0035
0036 RooNLLVarNew(const char *name, const char *title, RooAbsPdf &pdf, RooArgSet const &observables, bool isExtended,
0037 RooFit::OffsetMode offsetMode);
0038 RooNLLVarNew(const RooNLLVarNew &other, const char *name = nullptr);
0039 TObject *clone(const char *newname) const override { return new RooNLLVarNew(*this, newname); }
0040
0041
0042 double defaultErrorLevel() const override { return 0.5; }
0043
0044 void doEval(RooFit::EvalContext &) const override;
0045 bool canComputeBatchWithCuda() const override { return !_binnedL; }
0046 bool isReducerNode() const override { return true; }
0047
0048 void setPrefix(std::string const &prefix);
0049
0050 void applyWeightSquared(bool flag) override;
0051
0052 void enableOffsetting(bool) override;
0053
0054 void enableBinOffsetting(bool on = true) { _doBinOffset = on; }
0055
0056 void setSimCount(int simCount) { _simCount = simCount; }
0057
0058 RooAbsPdf const &pdf() const { return *_pdf; }
0059 RooAbsReal const &weightVar() const { return *_weightVar; }
0060 bool binnedL() const { return _binnedL; }
0061 int simCount() const { return _simCount; }
0062 RooAbsReal const *expectedEvents() const { return _expectedEvents ? &**_expectedEvents : nullptr; }
0063
0064 private:
0065 double evaluate() const override { return _value; }
0066 void resetWeightVarNames();
0067 void finalizeResult(RooFit::EvalContext &, ROOT::Math::KahanSum<double> result, double weightSum) const;
0068 void fillBinWidthsFromPdfBoundaries(RooAbsReal const &pdf, RooArgSet const &observables);
0069 void doEvalBinnedL(RooFit::EvalContext &, std::span<const double> preds, std::span<const double> weights) const;
0070
0071 RooTemplateProxy<RooAbsPdf> _pdf;
0072 RooTemplateProxy<RooAbsReal> _weightVar;
0073 RooTemplateProxy<RooAbsReal> _weightSquaredVar;
0074 std::unique_ptr<RooTemplateProxy<RooAbsReal>> _expectedEvents;
0075 std::unique_ptr<RooTemplateProxy<RooAbsPdf>> _offsetPdf;
0076 bool _weightSquared = false;
0077 bool _binnedL = false;
0078 bool _doOffset = false;
0079 bool _doBinOffset = false;
0080 int _simCount = 1;
0081 std::string _prefix;
0082 std::vector<double> _binw;
0083 mutable ROOT::Math::KahanSum<double> _offset{0.};
0084
0085 ClassDefOverride(RooFit::Detail::RooNLLVarNew, 0);
0086 };
0087
0088 }
0089 }
0090
0091 #endif
0092
0093