Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:29:42

0001 /*
0002  * Project: RooFit
0003  * Authors:
0004  *   Jonas Rembser, CERN 2022
0005  *
0006  * Copyright (c) 2022, 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 #ifndef RooFit_RooNormalizedPdf_h
0014 #define RooFit_RooNormalizedPdf_h
0015 
0016 #include <RooAbsPdf.h>
0017 #include <RooRealProxy.h>
0018 
0019 namespace RooFit {
0020 namespace Detail {
0021 
0022 class RooNormalizedPdf : public RooAbsPdf {
0023 public:
0024    RooNormalizedPdf(RooAbsPdf &pdf, RooArgSet const &normSet)
0025       : _pdf("numerator", "numerator", this, pdf),
0026         _normIntegral(
0027            "denominator", "denominator", this,
0028            std::unique_ptr<RooAbsReal>{pdf.createIntegral(normSet, *pdf.getIntegratorConfig(), pdf.normRange())}, true,
0029            false),
0030         _normSet{normSet}
0031    {
0032       auto name = std::string(pdf.GetName()) + "_over_" + _normIntegral->GetName();
0033       SetName(name.c_str());
0034       SetTitle(name.c_str());
0035       _normRange = pdf.normRange(); // so that e.g. RooAddPdf can query over what we are normalized
0036    }
0037 
0038    RooNormalizedPdf(const RooNormalizedPdf &other, const char *name)
0039       : RooAbsPdf(other, name),
0040         _pdf("numerator", this, other._pdf),
0041         _normIntegral("denominator", this, other._normIntegral),
0042         _normSet{other._normSet}
0043    {
0044    }
0045 
0046    TObject *clone(const char *newname) const override { return new RooNormalizedPdf(*this, newname); }
0047 
0048    bool selfNormalized() const override { return true; }
0049 
0050    inline double getCorrection() const override { return _pdf->getCorrection(); }
0051 
0052    bool forceAnalyticalInt(const RooAbsArg & /*dep*/) const override { return true; }
0053    /// Forward determination of analytical integration capabilities to input p.d.f
0054    Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &analVars, const RooArgSet * /*normSet*/,
0055                                  const char *rangeName = nullptr) const override
0056    {
0057       return _pdf->getAnalyticalIntegralWN(allVars, analVars, &_normSet, rangeName);
0058    }
0059    /// Forward calculation of analytical integrals to input p.d.f
0060    double
0061    analyticalIntegralWN(Int_t code, const RooArgSet * /*normSet*/, const char *rangeName = nullptr) const override
0062    {
0063       return _pdf->analyticalIntegralWN(code, &_normSet, rangeName);
0064    }
0065 
0066    ExtendMode extendMode() const override { return static_cast<RooAbsPdf &>(*_pdf).extendMode(); }
0067    double expectedEvents(const RooArgSet * /*nset*/) const override { return _pdf->expectedEvents(&_normSet); }
0068 
0069    std::unique_ptr<RooAbsReal> createExpectedEventsFunc(const RooArgSet * /*nset*/) const override
0070    {
0071       return _pdf->createExpectedEventsFunc(&_normSet);
0072    }
0073 
0074    bool canComputeBatchWithCuda() const override { return true; }
0075 
0076    RooAbsPdf const &pdf() const { return *_pdf; }
0077    RooAbsReal const &normIntegral() const { return *_normIntegral; }
0078 
0079 protected:
0080    void doEval(RooFit::EvalContext &) const override;
0081    double evaluate() const override
0082    {
0083       // The evaluate() function should not be called in the BatchMode, but we
0084       // still need it to support printing of the object.
0085       return getValV(nullptr);
0086    }
0087    double getValV(const RooArgSet * /*normSet*/) const override
0088    {
0089       return normalizeWithNaNPacking(_pdf->getVal(), _normIntegral->getVal());
0090    };
0091 
0092 private:
0093    RooTemplateProxy<RooAbsPdf> _pdf;
0094    RooRealProxy _normIntegral;
0095    RooArgSet _normSet;
0096 
0097    ClassDefOverride(RooFit::Detail::RooNormalizedPdf, 0);
0098 };
0099 
0100 } // namespace Detail
0101 } // namespace RooFit
0102 
0103 #endif