Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 09:14:09

0001 /// \cond ROOFIT_INTERNAL
0002 
0003 /*
0004  * Project: RooFit
0005  * Authors:
0006  *   Jonas Rembser, CERN 2021
0007  *   Emmanouil Michalainas, CERN 2021
0008  *
0009  * Copyright (c) 2021, CERN
0010  *
0011  * Redistribution and use in source and binary forms,
0012  * with or without modification, are permitted according to the terms
0013  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
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    // The names for the weight variables that the RooNLLVarNew expects
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    /// Return default level for MINUIT error analysis.
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.}; ///<! Offset as KahanSum to avoid loss of precision
0084 
0085    ClassDefOverride(RooFit::Detail::RooNLLVarNew, 0);
0086 };
0087 
0088 } // namespace Detail
0089 } // namespace RooFit
0090 
0091 #endif
0092 
0093 /// \endcond