Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*****************************************************************************
0002  * Project: RooFit                                                           *
0003  * Package: RooFitCore                                                       *
0004  *    File: $Id$
0005  * Authors:                                                                  *
0006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
0007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
0008  *                                                                           *
0009  * Copyright (c) 2000-2005, Regents of the University of California          *
0010  *                          and Stanford University. All rights reserved.    *
0011  *                                                                           *
0012  * Redistribution and use in source and binary forms,                        *
0013  * with or without modification, are permitted according to the terms        *
0014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
0015  *****************************************************************************/
0016 #ifndef ROO_HIST_PDF
0017 #define ROO_HIST_PDF
0018 
0019 #include "RooAbsPdf.h"
0020 #include "RooRealProxy.h"
0021 #include "RooSetProxy.h"
0022 #include "RooAICRegistry.h"
0023 #include "RooDataHist.h"
0024 
0025 #include <list>
0026 
0027 class RooRealVar;
0028 class RooAbsReal;
0029 
0030 class RooHistPdf : public RooAbsPdf {
0031 public:
0032   RooHistPdf() {}
0033   RooHistPdf(const char *name, const char *title, const RooArgSet& vars, const RooDataHist& dhist, Int_t intOrder=0);
0034   RooHistPdf(const char *name, const char *title, const RooArgList& pdfObs, const RooArgList& histObs, const RooDataHist& dhist, Int_t intOrder=0);
0035   RooHistPdf(const char *name, const char *title, const RooArgSet& vars,
0036              std::unique_ptr<RooDataHist> dhist, int intOrder=0);
0037   RooHistPdf(const char *name, const char *title, const RooArgList& pdfObs, const RooArgList& histObs,
0038              std::unique_ptr<RooDataHist> dhist, int intOrder=0);
0039   RooHistPdf(const RooHistPdf& other, const char* name=nullptr);
0040   TObject* clone(const char* newname) const override { return new RooHistPdf(*this,newname); }
0041 
0042   RooDataHist& dataHist()  {
0043     // Return RooDataHist that is represented
0044     return *_dataHist ;
0045   }
0046   const RooDataHist& dataHist() const {
0047     // Return RooDataHist that is represented
0048     return *_dataHist ;
0049   }
0050 
0051   /// Replaces underlying RooDataHist with a clone, which is now owned, and returns the clone.
0052   /// If the underlying RooDataHist is already owned, then that is returned instead of being cloned.
0053   RooDataHist* cloneAndOwnDataHist(const char* newname="");
0054 
0055   void setInterpolationOrder(Int_t order) {
0056     // Set histogram interpolation order
0057     _intOrder = order ;
0058   }
0059   Int_t getInterpolationOrder() const {
0060     // Return histogram interpolation order
0061     return _intOrder ;
0062   }
0063 
0064   Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=nullptr) const override ;
0065   double analyticalIntegral(Int_t code, const char* rangeName=nullptr) const override ;
0066 
0067   bool forceAnalyticalInt(const RooAbsArg& dep) const override;
0068 
0069   void setCdfBoundaries(bool flag) {
0070     // Set use of special boundary conditions for c.d.f.s
0071     _cdfBoundaries = flag ;
0072   }
0073   bool getCdfBoundaries() const {
0074     // If true, special boundary conditions for c.d.f.s are used
0075     return _cdfBoundaries ;
0076   }
0077 
0078   void setUnitNorm(bool flag) {
0079     // Declare contents to have unit normalization
0080     _unitNorm = flag ;
0081   }
0082   bool haveUnitNorm() const {
0083     // Return true if contents is declared to be unit normalized
0084     return _unitNorm ;
0085   }
0086 
0087   bool selfNormalized() const override { return _unitNorm ; }
0088 
0089   Int_t getMaxVal(const RooArgSet& vars) const override ;
0090   double maxVal(Int_t code) const override ;
0091 
0092   std::list<double>* plotSamplingHint(RooAbsRealLValue& obs, double xlo, double xhi) const override ;
0093   std::list<double>* binBoundaries(RooAbsRealLValue& /*obs*/, double /*xlo*/, double /*xhi*/) const override ;
0094   bool isBinnedDistribution(const RooArgSet&) const override { return _intOrder==0 ; }
0095 
0096   void doEval(RooFit::EvalContext &) const override;
0097 
0098   void translate(RooFit::Detail::CodeSquashContext &ctx) const override;
0099   std::string
0100   buildCallToAnalyticIntegral(int code, const char *rangeName, RooFit::Detail::CodeSquashContext &ctx) const override;
0101 
0102   protected:
0103   bool areIdentical(const RooDataHist& dh1, const RooDataHist& dh2) ;
0104 
0105   bool importWorkspaceHook(RooWorkspace& ws) override ;
0106 
0107   double evaluate() const override;
0108   double totalVolume() const ;
0109   friend class RooAbsCachedPdf ;
0110   double totVolume() const ;
0111 
0112   RooArgSet _histObsList;                      ///< List of observables defining dimensions of histogram
0113   RooSetProxy _pdfObsList;                     ///< List of observables mapped onto histogram observables
0114   RooDataHist* _dataHist = nullptr;            ///< Unowned pointer to underlying histogram
0115   std::unique_ptr<RooDataHist> _ownedDataHist; ///<! Owned pointer to underlying histogram
0116   mutable RooAICRegistry _codeReg ;            ///<! Auxiliary class keeping tracking of analytical integration code
0117   Int_t _intOrder = 0;                         ///< Interpolation order
0118   bool _cdfBoundaries = false;                 ///< Use boundary conditions for CDFs.
0119   mutable double _totVolume = 0.0;             ///<! Total volume of space (product of ranges of observables)
0120   bool _unitNorm  = false;                     ///< Assume contents is unit normalized (for use as pdf cache)
0121 
0122 private:
0123 
0124   friend class RooHistFunc;
0125 
0126   static bool forceAnalyticalInt(RooArgSet const& pdfObsList, RooAbsArg const& dep);
0127 
0128   static Int_t getAnalyticalIntegral(RooArgSet& allVars,
0129                                      RooArgSet& analVars,
0130                                      const char* rangeName,
0131                                      RooArgSet const& histObsList,
0132                                      RooArgSet const& pdfObsList,
0133                                      Int_t intOrder) ;
0134 
0135   static double analyticalIntegral(Int_t code,
0136                                    const char* rangeName,
0137                                    RooArgSet const& histObsList,
0138                                    RooArgSet const& pdfObsList,
0139                                    RooDataHist& dataHist,
0140                                    bool histFuncMode) ;
0141 
0142   static std::list<double>* plotSamplingHint(RooDataHist const& dataHist,
0143                                              RooArgSet const& pdfObsList,
0144                                              RooArgSet const& histObsList,
0145                                              int intOrder,
0146                                              RooAbsRealLValue& obs,
0147                                              double xlo,
0148                                              double xhi);
0149 
0150   static void rooHistTranslateImpl(RooAbsArg const *klass, RooFit::Detail::CodeSquashContext &ctx, int intOrder,
0151                                    RooDataHist const *dataHist, const RooArgSet &obs, bool correctForBinSize, bool cdfBoundaries);
0152 
0153   static std::string rooHistIntegralTranslateImpl(int code, RooAbsArg const *klass, RooDataHist const *dataHist,
0154                                                   const RooArgSet &obs, bool histFuncMode);
0155 
0156 private:
0157   inline void initializeOwnedDataHist(std::unique_ptr<RooDataHist> &&dataHist)
0158   {
0159      _ownedDataHist = std::move(dataHist);
0160   }
0161 
0162   ClassDefOverride(RooHistPdf,4) // Histogram based PDF
0163 };
0164 
0165 #endif