Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/RooBinSamplingPdf.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Authors: Stephan Hageboeck, CERN; Andrea Sciandra, SCIPP-UCSC/Atlas; Nov 2020
0002 
0003 /*****************************************************************************
0004  * Project: RooFit                                                           *
0005  * Package: RooFitCore                                                       *
0006  * Authors:                                                                  *
0007  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
0008  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
0009  *                                                                           *
0010  * Copyright (c) 2000-2018, Regents of the University of California          *
0011  *                          and Stanford University. All rights reserved.    *
0012  *                                                                           *
0013  * Redistribution and use in source and binary forms,                        *
0014  * with or without modification, are permitted according to the terms        *
0015  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
0016  *****************************************************************************/
0017 #ifndef ROO_BIN_SAMPLING__PDF
0018 #define ROO_BIN_SAMPLING__PDF
0019 
0020 #include "RooAbsReal.h"
0021 #include "RooTemplateProxy.h"
0022 #include "RooAbsPdf.h"
0023 
0024 #include "Math/Integrator.h"
0025 
0026 #include <memory>
0027 
0028 class RooBinSamplingPdf : public RooAbsPdf {
0029 public:
0030 
0031   RooBinSamplingPdf() { };
0032   RooBinSamplingPdf(const char *name, const char *title, RooAbsRealLValue& observable, RooAbsPdf& inputPdf,
0033       double epsilon = 1.E-4);
0034 
0035   RooBinSamplingPdf(const RooBinSamplingPdf& other, const char* name = nullptr);
0036 
0037   TObject* clone(const char* newname) const override {
0038     return new RooBinSamplingPdf(*this, newname);
0039   }
0040 
0041   // Analytical Integration handling
0042   bool forceAnalyticalInt(const RooAbsArg& dep) const override {
0043     return _pdf->forceAnalyticalInt(dep);
0044   }
0045   /// Forwards to the PDF's implementation.
0046   Int_t getAnalyticalIntegralWN(RooArgSet& allVars, RooArgSet& analVars, const RooArgSet* normSet,
0047       const char* rangeName=nullptr) const override {
0048     return _pdf->getAnalyticalIntegralWN(allVars, analVars, normSet, rangeName);
0049   }
0050   /// Forwards to the PDF's implementation.
0051   Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& numVars,
0052       const char* rangeName=nullptr) const override {
0053     return _pdf->getAnalyticalIntegral(allVars, numVars, rangeName);
0054   }
0055   /// Forwards to the PDF's implementation.
0056   double analyticalIntegralWN(Int_t code, const RooArgSet* normSet, const char* rangeName) const override {
0057     return _pdf->analyticalIntegralWN(code, normSet, rangeName);
0058   }
0059   /// Forwards to the PDF's implementation.
0060   double analyticalIntegral(Int_t code, const char* rangeName=nullptr) const override {
0061     return _pdf->analyticalIntegral(code, rangeName);
0062   }
0063 
0064   /// Forwards to the PDF's implementation.
0065   bool selfNormalized() const override { return true; }
0066 
0067   /// Forwards to the PDF's implementation.
0068   RooFit::OwningPtr<RooAbsReal> createIntegral(const RooArgSet& iset,
0069                              const RooArgSet* nset=nullptr,
0070                              const RooNumIntConfig* cfg=nullptr,
0071                              const char* rangeName=nullptr) const override {
0072     return _pdf->createIntegral(iset, nset, cfg, rangeName);
0073   }
0074 
0075   ExtendMode extendMode() const override { return _pdf->extendMode(); }
0076   double expectedEvents(const RooArgSet* nset) const override { return _pdf->expectedEvents(nset); }
0077 
0078   /// Forwards to the PDF's implementation.
0079   Int_t getGenerator(const RooArgSet& directVars, RooArgSet& generateVars, bool staticInitOK = true) const override {
0080     return _pdf->getGenerator(directVars, generateVars, staticInitOK);
0081   }
0082   /// Forwards to the PDF's implementation.
0083   void initGenerator(Int_t code) override { _pdf->initGenerator(code); }
0084   /// Forwards to the PDF's implementation.
0085   void generateEvent(Int_t code) override { _pdf->generateEvent(code); }
0086   /// Forwards to the PDF's implementation.
0087   bool isDirectGenSafe(const RooAbsArg& arg) const override { return _pdf->isDirectGenSafe(arg); }
0088 
0089 
0090   // Hints for optimized brute-force sampling
0091   Int_t getMaxVal(const RooArgSet& vars) const override { return _pdf->getMaxVal(vars); }
0092   double maxVal(Int_t code) const override { return _pdf->maxVal(code); }
0093   Int_t minTrialSamples(const RooArgSet& arGenObs) const override { return _pdf->minTrialSamples(arGenObs); }
0094 
0095   // Plotting and binning hints
0096   /// Returns true, since this PDF is meant to be binned.
0097   bool isBinnedDistribution(const RooArgSet& /*obs*/) const override { return true; }
0098   std::list<double>* binBoundaries(RooAbsRealLValue& obs, double xlo, double xhi) const override;
0099   std::list<double>* plotSamplingHint(RooAbsRealLValue& obs, double xlo, double xhi) const override;
0100 
0101   std::unique_ptr<ROOT::Math::IntegratorOneDim>& integrator() const;
0102 
0103   static std::unique_ptr<RooAbsPdf> create(RooAbsPdf& pdf, RooAbsData const &data, double precision);
0104 
0105   double epsilon() const { return _relEpsilon; }
0106   const RooAbsPdf& pdf() const { return _pdf.arg(); }
0107   const RooAbsReal& observable() const { return _observable.arg(); }
0108 
0109   void doEval(RooFit::EvalContext &) const override;
0110 
0111 protected:
0112   double evaluate() const override;
0113   std::span<const double> binBoundaries() const;
0114 
0115 private:
0116   template<typename Func>
0117   friend class ROOT::Math::WrappedFunction;
0118   // Call operator for our internal integrator.
0119   double operator()(double x) const;
0120   double integrate(const RooArgSet* normSet, double low, double high) const;
0121 
0122 
0123   RooTemplateProxy<RooAbsPdf> _pdf;
0124   RooTemplateProxy<RooAbsRealLValue> _observable;
0125   double _relEpsilon{1.E-4}; ///< Default integrator precision.
0126 
0127   mutable std::unique_ptr<ROOT::Math::IntegratorOneDim> _integrator{nullptr}; ///<! Integrator used to sample bins.
0128   mutable std::vector<double> _binBoundaries; ///<! Workspace to store data for bin sampling
0129 
0130   ClassDefOverride(RooBinSamplingPdf,1)
0131 };
0132 
0133 #endif