Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-05 09:56:04

0001 /*****************************************************************************
0002  * Project: RooFit                                                           *
0003  * Package: RooFitCore                                                       *
0004  *    File: $Id: RooRealSumPdf.h,v 1.10 2007/05/11 09:11:30 verkerke Exp $
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_REAL_SUM_PDF
0017 #define ROO_REAL_SUM_PDF
0018 
0019 #include "RooAbsPdf.h"
0020 #include "RooListProxy.h"
0021 #include "RooAICRegistry.h"
0022 #include "RooObjCacheManager.h"
0023 
0024 class RooRealSumPdf : public RooAbsPdf {
0025 public:
0026 
0027   RooRealSumPdf() ;
0028   RooRealSumPdf(const char *name, const char *title);
0029   RooRealSumPdf(const char *name, const char *title, const RooArgList& funcList, const RooArgList& coefList, bool extended=false) ;
0030   RooRealSumPdf(const char *name, const char *title,
0031          RooAbsReal& func1, RooAbsReal& func2, RooAbsReal& coef1) ;
0032   RooRealSumPdf(const RooRealSumPdf& other, const char* name=nullptr) ;
0033   TObject* clone(const char* newname=nullptr) const override { return new RooRealSumPdf(*this,newname) ; }
0034 
0035   double evaluate() const override ;
0036   bool checkObservables(const RooArgSet* nset) const override ;
0037 
0038   void doEval(RooFit::EvalContext &) const override;
0039 
0040   bool forceAnalyticalInt(const RooAbsArg& arg) const override { return arg.isFundamental() ; }
0041   Int_t getAnalyticalIntegralWN(RooArgSet& allVars, RooArgSet& numVars, const RooArgSet* normSet, const char* rangeName=nullptr) const override ;
0042   double analyticalIntegralWN(Int_t code, const RooArgSet* normSet, const char* rangeName=nullptr) const override ;
0043 
0044   const RooArgList& funcList() const { return _funcList ; }
0045   const RooArgList& coefList() const { return _coefList ; }
0046   const RooArgList &funcIntListFromCache(Int_t code, const char *rangeName = nullptr) const;
0047 
0048   ExtendMode extendMode() const override ;
0049 
0050   /// Return expected number of events for extended likelihood calculation, which
0051   /// is the sum of all coefficients.
0052   double expectedEvents(const RooArgSet* nset) const override ;
0053 
0054   bool selfNormalized() const override { return getAttribute("BinnedLikelihoodActive") ; }
0055 
0056   void printMetaArgs(std::ostream& os) const override ;
0057 
0058 
0059   std::list<double>* binBoundaries(RooAbsRealLValue& /*obs*/, double /*xlo*/, double /*xhi*/) const override ;
0060   std::list<double>* plotSamplingHint(RooAbsRealLValue& /*obs*/, double /*xlo*/, double /*xhi*/) const override ;
0061   bool isBinnedDistribution(const RooArgSet& obs) const override  ;
0062 
0063   void setFloor(bool flag) { _doFloor = flag ; }
0064   bool getFloor() const { return _doFloor ; }
0065   static void setFloorGlobal(bool flag) { _doFloorGlobal = flag ; }
0066   static bool getFloorGlobal() { return _doFloorGlobal ; }
0067 
0068   CacheMode canNodeBeCached() const override { return RooAbsArg::NotAdvised ; } ;
0069   void setCacheAndTrackHints(RooArgSet&) override ;
0070 
0071   std::unique_ptr<RooAbsArg> compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileContext & ctx) const override;
0072 
0073   std::unique_ptr<RooAbsReal> createExpectedEventsFunc(const RooArgSet* nset) const override;
0074 
0075 protected:
0076 
0077   class CacheElem : public RooAbsCacheElement {
0078   public:
0079     CacheElem()  {} ;
0080     RooArgList containedArgs(Action) override { RooArgList ret(_funcIntList) ; ret.add(_funcNormList) ; return ret ; }
0081     RooArgList _funcIntList ;
0082     RooArgList _funcNormList ;
0083   } ;
0084   mutable RooObjCacheManager _normIntMgr ; ///<! The integration cache manager
0085 
0086 
0087   RooListProxy _funcList ;  ///<  List of component FUNCs
0088   RooListProxy _coefList ;  ///<  List of coefficients
0089   bool _extended ;        ///< Allow use as extended p.d.f.
0090 
0091   bool _doFloor = false; ///< Introduce floor at zero in pdf
0092   mutable bool _haveWarned{false}; ///<!
0093   static bool _doFloorGlobal ; ///< Global flag for introducing floor at zero in pdf
0094 
0095 private:
0096 
0097   friend class RooAddPdf;
0098   friend class RooAddition;
0099   friend class RooRealSumFunc;
0100 
0101   static void initializeFuncsAndCoefs(RooAbsReal const& caller,
0102                                       const RooArgList& inFuncList, const RooArgList& inCoefList,
0103                                       RooArgList& funcList, RooArgList& coefList);
0104 
0105   static double evaluate(RooAbsReal const& caller,
0106                          RooArgList const& funcList,
0107                          RooArgList const& coefList,
0108                          bool doFloor,
0109                          bool & hasWarnedBefore);
0110 
0111   static bool checkObservables(RooAbsReal const &caller, RooArgSet const *nset, RooArgList const &funcList,
0112                                RooArgList const &coefList);
0113 
0114   static const RooArgList &
0115   funcIntListFromCache(RooAbsReal const &caller, RooObjCacheManager &normIntMgr, Int_t code, const char *rangeName);
0116 
0117   static Int_t getAnalyticalIntegralWN(RooAbsReal const& caller, RooObjCacheManager & normIntMgr,
0118                                        RooArgList const& funcList, RooArgList const& coefList,
0119                                        RooArgSet& allVars, RooArgSet& numVars, const RooArgSet* normSet, const char* rangeName);
0120   static double analyticalIntegralWN(RooAbsReal const& caller, RooObjCacheManager & normIntMgr,
0121                                      RooArgList const& funcList, RooArgList const& coefList,
0122                                      Int_t code, const RooArgSet* normSet, const char* rangeName,
0123                                      bool hasWarnedBefore);
0124 
0125   static const CacheElem *
0126   getCacheElem(RooAbsReal const &caller, RooObjCacheManager &normIntMgr, Int_t code, const char *rangeName);
0127 
0128   static std::list<double>* binBoundaries(
0129           RooArgList const& funcList, RooAbsRealLValue& /*obs*/, double /*xlo*/, double /*xhi*/);
0130   static std::list<double>* plotSamplingHint(
0131           RooArgList const& funcList, RooAbsRealLValue& /*obs*/, double /*xlo*/, double /*xhi*/);
0132   static bool isBinnedDistribution(RooArgList const& funcList, const RooArgSet& obs);
0133 
0134   static void printMetaArgs(RooArgList const& funcList, RooArgList const& coefList, std::ostream& os);
0135 
0136   static void setCacheAndTrackHints(RooArgList const& funcList, RooArgSet& trackNodes);
0137 
0138   inline void setExtended(bool extended) { _extended = extended; }
0139 
0140   ClassDefOverride(RooRealSumPdf, 5) // PDF constructed from a sum of (non-pdf) functions
0141 };
0142 
0143 #endif