File indexing completed on 2025-01-18 10:11:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef ROOMOMENTMORPHFUNCND
0012 #define ROOMOMENTMORPHFUNCND
0013
0014 #include "RooAbsPdf.h"
0015 #include "RooRealProxy.h"
0016 #include "RooCategoryProxy.h"
0017 #include "RooAbsReal.h"
0018 #include "RooAbsCategory.h"
0019 #include "RooSetProxy.h"
0020 #include "RooListProxy.h"
0021 #include "RooArgList.h"
0022 #include "RooBinning.h"
0023
0024 #include "TMatrixD.h"
0025 #include "TMap.h"
0026
0027 #include <vector>
0028 #include <map>
0029
0030 class RooChangeTracker;
0031 class RooRealSumFunc;
0032
0033 class RooMomentMorphFuncND : public RooAbsReal {
0034
0035 public:
0036 using Base_t = RooAbsReal;
0037
0038 class Grid2 {
0039 public:
0040 Grid2(){};
0041 Grid2(const Grid2 &other);
0042 Grid2(const RooAbsBinning &binning_x) { _grid.push_back(binning_x.clone()); };
0043 Grid2(const RooAbsBinning &binning_x, const RooAbsBinning &binning_y)
0044 {
0045 _grid.push_back(binning_x.clone());
0046 _grid.push_back(binning_y.clone());
0047 };
0048 Grid2(const RooAbsBinning &binning_x, const RooAbsBinning &binning_y, const RooAbsBinning &binning_z)
0049 {
0050 _grid.push_back(binning_x.clone());
0051 _grid.push_back(binning_y.clone());
0052 _grid.push_back(binning_z.clone());
0053 };
0054 Grid2(std::vector<RooAbsBinning *> const &binnings)
0055 {
0056 for (unsigned int i = 0; i < binnings.size(); i++) {
0057 _grid.push_back(binnings[i]->clone());
0058 }
0059 };
0060
0061 virtual ~Grid2();
0062
0063 void addPdf(const RooAbsReal &func, int bin_x);
0064 void addPdf(const RooAbsReal &func, int bin_x, int bin_y);
0065 void addPdf(const RooAbsReal &func, int bin_x, int bin_y, int bin_z);
0066 void addPdf(const RooAbsReal &func, std::vector<int> bins);
0067 void addBinning(const RooAbsBinning &binning) { _grid.push_back(binning.clone()); };
0068
0069 mutable std::vector<RooAbsBinning *> _grid;
0070 mutable RooArgList _pdfList;
0071 mutable std::map<std::vector<int>, int> _pdfMap;
0072
0073 mutable std::vector<std::vector<double>> _nref;
0074 mutable std::vector<int> _nnuis;
0075
0076 ClassDef(RooMomentMorphFuncND::Grid2, 1);
0077 };
0078
0079 using Grid = Grid2;
0080
0081 protected:
0082 class CacheElem : public RooAbsCacheElement {
0083 public:
0084 CacheElem(std::unique_ptr<RooAbsReal> && sumFunc, std::unique_ptr<RooChangeTracker> && tracker, const RooArgList &flist);
0085 ~CacheElem() override;
0086 RooArgList containedArgs(Action) override;
0087 std::unique_ptr<RooAbsReal> _sum;
0088 std::unique_ptr<RooChangeTracker> _tracker;
0089 RooArgList _frac;
0090
0091 RooRealVar *frac(int i);
0092 const RooRealVar *frac(int i) const;
0093 void calculateFractions(const RooMomentMorphFuncND &self, bool verbose = true) const;
0094 };
0095
0096 public:
0097 enum Setting { Linear, SineLinear, NonLinear, NonLinearPosFractions, NonLinearLinFractions };
0098
0099 RooMomentMorphFuncND();
0100 RooMomentMorphFuncND(const char *name, const char *title, RooAbsReal &_m, const RooArgList &varList,
0101 const RooArgList &pdfList, const RooArgList &mrefList, Setting setting);
0102 RooMomentMorphFuncND(const char *name, const char *title, const RooArgList &parList, const RooArgList &obsList,
0103 const Grid2 &referenceGrid, const Setting &setting);
0104 RooMomentMorphFuncND(const RooMomentMorphFuncND &other, const char *name = nullptr);
0105 RooMomentMorphFuncND(const char *name, const char *title, RooAbsReal &_m, const RooArgList &varList,
0106 const RooArgList &pdfList, const TVectorD &mrefpoints, Setting setting);
0107 ~RooMomentMorphFuncND() override;
0108 TObject *clone(const char *newname) const override { return new RooMomentMorphFuncND(*this, newname); }
0109
0110 void setMode(const Setting &setting) { _setting = setting; }
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125 void setPdfMode(bool flag=true) { _isPdfMode = flag; }
0126 bool setBinIntegrator(RooArgSet &allVars);
0127 void useHorizontalMorphing(bool val) { _useHorizMorph = val; }
0128
0129 double evaluate() const override;
0130 double getValV(const RooArgSet *set = nullptr) const override;
0131
0132 protected:
0133 void initialize();
0134
0135 RooAbsReal *sumFunc(const RooArgSet *nset);
0136 CacheElem *getCache(const RooArgSet *nset) const;
0137
0138 void findShape(const std::vector<double> &x) const;
0139
0140 friend class CacheElem;
0141 friend class Grid2;
0142
0143 mutable RooObjCacheManager _cacheMgr;
0144 mutable RooArgSet *_curNormSet = nullptr;
0145
0146 RooListProxy _parList;
0147 RooSetProxy _obsList;
0148 mutable Grid2 _referenceGrid;
0149 RooListProxy _pdfList;
0150
0151 mutable std::unique_ptr<TMatrixD> _M;
0152 mutable std::unique_ptr<TMatrixD> _MSqr;
0153 mutable std::vector<std::vector<double>> _squareVec;
0154 mutable std::vector<int> _squareIdx;
0155
0156 Setting _setting;
0157 bool _useHorizMorph;
0158 bool _isPdfMode = false;
0159
0160 inline int sij(const int &i, const int &j) const { return (i * _obsList.size() + j); }
0161
0162 ClassDefOverride(RooMomentMorphFuncND, 4);
0163 };
0164
0165 #endif