Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:11:23

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_FUNC
0017 #define ROO_HIST_FUNC
0018 
0019 #include "RooAbsReal.h"
0020 #include "RooRealProxy.h"
0021 #include "RooSetProxy.h"
0022 #include "RooAICRegistry.h"
0023 #include "RooTrace.h"
0024 #include "RooDataHist.h"
0025 
0026 #include <list>
0027 
0028 class RooRealVar;
0029 class RooAbsReal;
0030 
0031 class RooHistFunc : public RooAbsReal {
0032 public:
0033   RooHistFunc() {}
0034   RooHistFunc(const char *name, const char *title, const RooArgSet& vars, const RooDataHist& dhist, Int_t intOrder=0);
0035   RooHistFunc(const char *name, const char *title, const RooArgList& funcObs, const RooArgList& histObs, const RooDataHist& dhist, Int_t intOrder=0);
0036   RooHistFunc(const char *name, const char *title, const RooArgSet& vars,
0037              std::unique_ptr<RooDataHist> dhist, int intOrder=0);
0038   RooHistFunc(const char *name, const char *title, const RooArgList& pdfObs, const RooArgList& histObs,
0039              std::unique_ptr<RooDataHist> dhist, int intOrder=0);
0040   RooHistFunc(const RooHistFunc& other, const char* name=nullptr);
0041   TObject* clone(const char* newname) const override { return new RooHistFunc(*this,newname); }
0042   ~RooHistFunc() override ;
0043 
0044   /// Return RooDataHist that is represented.
0045   RooDataHist& dataHist()  {
0046     return *_dataHist ;
0047   }
0048 
0049   /// Return RooDataHist that is represented.
0050   const RooDataHist& dataHist() const {
0051     return *_dataHist ;
0052   }
0053 
0054   /// Replaces underlying RooDataHist with a clone, which is now owned, and returns the clone.
0055   /// If the underlying RooDataHist is already owned, then that is returned instead of being cloned.
0056   RooDataHist* cloneAndOwnDataHist(const char* newname="");
0057 
0058   /// Get total bin volume spanned by this hist function.
0059   /// In 1-d, this is e.g. the range spanned on the x-axis.
0060   double totVolume() const;
0061 
0062   /// Set histogram interpolation order.
0063   void setInterpolationOrder(Int_t order) {
0064 
0065     _intOrder = order ;
0066   }
0067 
0068   /// Return histogram interpolation order.
0069   Int_t getInterpolationOrder() const {
0070 
0071     return _intOrder ;
0072   }
0073 
0074   Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=nullptr) const override ;
0075   double analyticalIntegral(Int_t code, const char* rangeName=nullptr) const override ;
0076 
0077   bool forceAnalyticalInt(const RooAbsArg& dep) const override;
0078 
0079   /// Set use of special boundary conditions for c.d.f.s
0080   void setCdfBoundaries(bool flag) {
0081     _cdfBoundaries = flag ;
0082   }
0083 
0084   /// If true, special boundary conditions for c.d.f.s are used
0085   bool getCdfBoundaries() const {
0086 
0087     return _cdfBoundaries ;
0088   }
0089 
0090   Int_t getMaxVal(const RooArgSet& vars) const override;
0091   double maxVal(Int_t code) const override;
0092 
0093   std::list<double>* binBoundaries(RooAbsRealLValue& /*obs*/, double /*xlo*/, double /*xhi*/) const override ;
0094   std::list<double>* plotSamplingHint(RooAbsRealLValue& obs, double xlo, double xhi) const override ;
0095   bool isBinnedDistribution(const RooArgSet&) const override { return _intOrder==0 ; }
0096   RooArgSet const& getHistObsList() const { return _histObsList; }
0097 
0098 
0099   Int_t getBin() const;
0100   std::vector<Int_t> getBins(RooFit::EvalContext & ctx) const;
0101 
0102   void translate(RooFit::Detail::CodeSquashContext &ctx) const override;
0103   std::string
0104   buildCallToAnalyticIntegral(int code, const char *rangeName, RooFit::Detail::CodeSquashContext &ctx) const override;
0105 
0106   RooArgSet const &variables() const { return _depList; }
0107 
0108 protected:
0109 
0110   bool importWorkspaceHook(RooWorkspace& ws) override ;
0111   bool areIdentical(const RooDataHist& dh1, const RooDataHist& dh2) ;
0112 
0113   double evaluate() const override;
0114   void doEval(RooFit::EvalContext &) const override;
0115   friend class RooAbsCachedReal ;
0116 
0117   void ioStreamerPass2() override ;
0118 
0119   RooArgSet _histObsList;                      ///< List of observables defining dimensions of histogram
0120   RooSetProxy _depList;                        ///< List of observables mapped onto histogram observables
0121   RooDataHist* _dataHist = nullptr;            ///< Unowned pointer to underlying histogram
0122   std::unique_ptr<RooDataHist> _ownedDataHist; ///<! Owned pointer to underlying histogram
0123   mutable RooAICRegistry _codeReg;             ///<! Auxiliary class keeping tracking of analytical integration code
0124   Int_t _intOrder = 0;                         ///< Interpolation order
0125   bool _cdfBoundaries = false;                 ///< Use boundary conditions for CDFs.
0126   mutable double _totVolume = 0.0;             ///<! Total volume of space (product of ranges of observables)
0127   bool _unitNorm = false;                      ///<! Assume contents is unit normalized (for use as pdf cache)
0128 
0129 private:
0130   inline void initializeOwnedDataHist(std::unique_ptr<RooDataHist> &&dataHist)
0131   {
0132      _ownedDataHist = std::move(dataHist);
0133   }
0134 
0135   ClassDefOverride(RooHistFunc,2) // Histogram based function
0136 };
0137 
0138 #endif