Back to home page

EIC code displayed by LXR

 
 

    


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

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    bool forceAnalyticalInt(const RooAbsArg & /*dep*/) const override { return true; }
0051    /// Forward determination of analytical integration capabilities to input p.d.f
0052    Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &analVars, const RooArgSet * /*normSet*/,
0053                                  const char *rangeName = nullptr) const override
0054    {
0055       return _pdf->getAnalyticalIntegralWN(allVars, analVars, &_normSet, rangeName);
0056    }
0057    /// Forward calculation of analytical integrals to input p.d.f
0058    double
0059    analyticalIntegralWN(Int_t code, const RooArgSet * /*normSet*/, const char *rangeName = nullptr) const override
0060    {
0061       return _pdf->analyticalIntegralWN(code, &_normSet, rangeName);
0062    }
0063 
0064    ExtendMode extendMode() const override { return static_cast<RooAbsPdf &>(*_pdf).extendMode(); }
0065    double expectedEvents(const RooArgSet * /*nset*/) const override { return _pdf->expectedEvents(&_normSet); }
0066 
0067    std::unique_ptr<RooAbsReal> createExpectedEventsFunc(const RooArgSet * /*nset*/) const override
0068    {
0069       return _pdf->createExpectedEventsFunc(&_normSet);
0070    }
0071 
0072    bool canComputeBatchWithCuda() const override { return true; }
0073 
0074    RooAbsPdf const &pdf() const { return *_pdf; }
0075    RooAbsReal const &normIntegral() const { return *_normIntegral; }
0076 
0077 protected:
0078    void doEval(RooFit::EvalContext &) const override;
0079    double evaluate() const override
0080    {
0081       // The evaluate() function should not be called in the BatchMode, but we
0082       // still need it to support printing of the object.
0083       return getValV(nullptr);
0084    }
0085    double getValV(const RooArgSet * /*normSet*/) const override
0086    {
0087       return normalizeWithNaNPacking(_pdf->getVal(), _normIntegral->getVal());
0088    };
0089 
0090 private:
0091    RooTemplateProxy<RooAbsPdf> _pdf;
0092    RooRealProxy _normIntegral;
0093    RooArgSet _normSet;
0094 
0095    ClassDefOverride(RooFit::Detail::RooNormalizedPdf, 0);
0096 };
0097 
0098 } // namespace Detail
0099 } // namespace RooFit
0100 
0101 #endif