Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooMomentMorphFuncND.h
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 *
4 * Copyright (c) 2023, CERN
5 *
6 * Redistribution and use in source and binary forms,
7 * with or without modification, are permitted according to the terms
8 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
9 */
10
11#ifndef ROOMOMENTMORPHFUNCND
12#define ROOMOMENTMORPHFUNCND
13
14#include "RooAbsPdf.h"
15#include "RooRealProxy.h"
16#include "RooCategoryProxy.h"
17#include "RooAbsReal.h"
18#include "RooAbsCategory.h"
19#include "RooSetProxy.h"
20#include "RooListProxy.h"
21#include "RooArgList.h"
22#include "RooBinning.h"
23
24#include "TMatrixD.h"
25#include "TMap.h"
26
27#include <vector>
28#include <map>
29
31class RooRealSumFunc;
32
34
35public:
37
38 class Grid2 {
39 public:
40 Grid2(){};
41 Grid2(const Grid2 &other);
42 Grid2(const RooAbsBinning &binning_x) { _grid.push_back(binning_x.clone()); };
43 Grid2(const RooAbsBinning &binning_x, const RooAbsBinning &binning_y)
44 {
45 _grid.push_back(binning_x.clone());
46 _grid.push_back(binning_y.clone());
47 };
48 Grid2(const RooAbsBinning &binning_x, const RooAbsBinning &binning_y, const RooAbsBinning &binning_z)
49 {
50 _grid.push_back(binning_x.clone());
51 _grid.push_back(binning_y.clone());
52 _grid.push_back(binning_z.clone());
53 };
54 Grid2(std::vector<RooAbsBinning *> const &binnings)
55 {
56 for (unsigned int i = 0; i < binnings.size(); i++) {
57 _grid.push_back(binnings[i]->clone());
58 }
59 };
60
61 virtual ~Grid2();
62
63 void addPdf(const RooAbsReal &func, int bin_x);
64 void addPdf(const RooAbsReal &func, int bin_x, int bin_y);
65 void addPdf(const RooAbsReal &func, int bin_x, int bin_y, int bin_z);
66 void addPdf(const RooAbsReal &func, std::vector<int> bins);
67 void addBinning(const RooAbsBinning &binning) { _grid.push_back(binning.clone()); };
68
69 mutable std::vector<RooAbsBinning *> _grid;
71 mutable std::map<std::vector<int>, int> _pdfMap;
72
73 mutable std::vector<std::vector<double>> _nref;
74 mutable std::vector<int> _nnuis;
75
77 };
78
79 using Grid = Grid2;
80
81protected:
83 public:
84 CacheElem(std::unique_ptr<RooAbsReal> && sumFunc, std::unique_ptr<RooChangeTracker> && tracker, const RooArgList &flist);
85 ~CacheElem() override;
87 std::unique_ptr<RooAbsReal> _sum;
88 std::unique_ptr<RooChangeTracker> _tracker;
90
91 RooRealVar *frac(int i);
92 const RooRealVar *frac(int i) const;
93 void calculateFractions(const RooMomentMorphFuncND &self, bool verbose = true) const;
94 };
95
96public:
98
100 RooMomentMorphFuncND(const char *name, const char *title, RooAbsReal &_m, const RooArgList &varList,
101 const RooArgList &pdfList, const RooArgList &mrefList, Setting setting);
102 RooMomentMorphFuncND(const char *name, const char *title, const RooArgList &parList, const RooArgList &obsList,
103 const Grid2 &referenceGrid, const Setting &setting);
104 RooMomentMorphFuncND(const RooMomentMorphFuncND &other, const char *name = nullptr);
105 RooMomentMorphFuncND(const char *name, const char *title, RooAbsReal &_m, const RooArgList &varList,
106 const RooArgList &pdfList, const TVectorD &mrefpoints, Setting setting);
107 ~RooMomentMorphFuncND() override;
108 TObject *clone(const char *newname) const override { return new RooMomentMorphFuncND(*this, newname); }
109
110 void setMode(const Setting &setting) { _setting = setting; }
111 /// Setting flag makes this RooMomentMorphFuncND instance behave like the
112 /// former RooMomentMorphND class, with the the only difference being the
113 /// base class. If you want to create a pdf object that behaves exactly like
114 /// the old RooMomentMorphND, you can do it as follows:
115 ///
116 /// ```C++
117 /// RooMomentMorphFuncND func{<c'tor args you previously passed to RooMomentMorphFunc>};
118 ///
119 /// func.setPdfMode(); // change behavior to be exactly like the former RooMomentMorphND
120 ///
121 /// // Pass the selfNormalized=true` flag to the wrapper because the
122 /// RooMomentMorphFuncND already normalizes itself in pdf mode.
123 /// RooWrapperPdf pdf{"pdf_name", "pdf_name", func, /*selfNormalized=*/true};
124 /// ```
125 void setPdfMode(bool flag=true) { _isPdfMode = flag; }
126 bool setBinIntegrator(RooArgSet &allVars);
127 void useHorizontalMorphing(bool val) { _useHorizMorph = val; }
128
129 double evaluate() const override;
130 double getValV(const RooArgSet *set = nullptr) const override;
131
132protected:
133 void initialize();
134
135 RooAbsReal *sumFunc(const RooArgSet *nset);
136 CacheElem *getCache(const RooArgSet *nset) const;
137
138 void findShape(const std::vector<double> &x) const;
139
140 friend class CacheElem;
141 friend class Grid2;
142
143 mutable RooObjCacheManager _cacheMgr; ///<! Transient cache manager
144 mutable RooArgSet *_curNormSet = nullptr; ///<! Transient cache manager
145
150
151 mutable std::unique_ptr<TMatrixD> _M;
152 mutable std::unique_ptr<TMatrixD> _MSqr;
153 mutable std::vector<std::vector<double>> _squareVec;
154 mutable std::vector<int> _squareIdx;
155
158 bool _isPdfMode = false;
159
160 inline int sij(const int &i, const int &j) const { return (i * _obsList.size() + j); }
161
163};
164
165#endif
#define ClassDef(name, id)
Definition Rtypes.h:337
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
char name[80]
Definition TGX11.cxx:110
Abstract base class for RooRealVar binning definitions.
virtual RooAbsBinning * clone(const char *name=nullptr) const =0
Abstract base class for objects to be stored in RooAbsCache cache manager objects.
Storage_t::size_type size() const
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
RooAbsReal()
coverity[UNINIT_CTOR] Default constructor
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
Meta object that tracks value changes in a given set of RooAbsArgs by registering itself as value cli...
void calculateFractions(const RooMomentMorphFuncND &self, bool verbose=true) const
std::unique_ptr< RooChangeTracker > _tracker
std::unique_ptr< RooAbsReal > _sum
RooArgList containedArgs(Action) override
Grid2(const RooAbsBinning &binning_x, const RooAbsBinning &binning_y)
void addBinning(const RooAbsBinning &binning)
std::vector< RooAbsBinning * > _grid
Grid2(std::vector< RooAbsBinning * > const &binnings)
std::map< std::vector< int >, int > _pdfMap
Grid2(const RooAbsBinning &binning_x)
Grid2(const RooAbsBinning &binning_x, const RooAbsBinning &binning_y, const RooAbsBinning &binning_z)
std::vector< std::vector< double > > _nref
void addPdf(const RooAbsReal &func, int bin_x)
RooObjCacheManager _cacheMgr
! Transient cache manager
std::unique_ptr< TMatrixD > _MSqr
void findShape(const std::vector< double > &x) const
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
RooAbsReal * sumFunc(const RooArgSet *nset)
CacheElem * getCache(const RooArgSet *nset) const
std::unique_ptr< TMatrixD > _M
void useHorizontalMorphing(bool val)
TObject * clone(const char *newname) const override
RooArgSet * _curNormSet
! Transient cache manager
void setMode(const Setting &setting)
bool setBinIntegrator(RooArgSet &allVars)
double getValV(const RooArgSet *set=nullptr) const override
Return value of object.
void setPdfMode(bool flag=true)
Setting flag makes this RooMomentMorphFuncND instance behave like the former RooMomentMorphND class,...
std::vector< std::vector< double > > _squareVec
int sij(const int &i, const int &j) const
std::vector< int > _squareIdx
Implementation of a RooCacheManager<RooAbsCacheElement> that specializes in the storage of cache elem...
Variable that can be changed from the outside.
Definition RooRealVar.h:37
Mother of all ROOT objects.
Definition TObject.h:41
Double_t x[n]
Definition legend1.C:17