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"
24
25#include "TMatrixD.h"
26#include "TMap.h"
27
28#include <vector>
29#include <map>
30
32class RooRealSumFunc;
33
34namespace RooFit {
35namespace Detail {
36class RooMomentMorphFraction;
37}
38} // namespace RooFit
39
41
42public:
44
45 class Grid2 {
46 public:
47 Grid2(){};
48 Grid2(const Grid2 &other);
49 Grid2(const RooAbsBinning &binning_x) { _grid.push_back(binning_x.clone()); };
51 {
52 _grid.push_back(binning_x.clone());
53 _grid.push_back(binning_y.clone());
54 };
56 {
57 _grid.push_back(binning_x.clone());
58 _grid.push_back(binning_y.clone());
59 _grid.push_back(binning_z.clone());
60 };
61 Grid2(std::vector<RooAbsBinning *> const &binnings)
62 {
63 for (unsigned int i = 0; i < binnings.size(); i++) {
64 _grid.push_back(binnings[i]->clone());
65 }
66 };
67
68 virtual ~Grid2();
69
70 void addPdf(const RooAbsReal &func, int bin_x);
71 void addPdf(const RooAbsReal &func, int bin_x, int bin_y);
72 void addPdf(const RooAbsReal &func, int bin_x, int bin_y, int bin_z);
73 void addPdf(const RooAbsReal &func, std::vector<int> bins);
74 void addBinning(const RooAbsBinning &binning) { _grid.push_back(binning.clone()); };
75
76 mutable std::vector<RooAbsBinning *> _grid;
78 mutable std::map<std::vector<int>, int> _pdfMap;
79
80 mutable std::vector<std::vector<double>> _nref;
81 mutable std::vector<int> _nnuis;
82
84 };
85
86 using Grid = Grid2;
87
88protected:
90 public:
91 CacheElem(std::unique_ptr<RooAbsReal> && sumFunc, std::unique_ptr<RooChangeTracker> && tracker, const RooArgList &flist);
92 ~CacheElem() override;
94 std::unique_ptr<RooAbsReal> _sum;
95 std::unique_ptr<RooChangeTracker> _tracker;
97
98 RooRealVar *frac(int i);
99 const RooRealVar *frac(int i) const;
100 void calculateFractions(const RooMomentMorphFuncND &self, bool verbose = true) const;
101 };
102
103public:
105
107 RooMomentMorphFuncND(const char *name, const char *title, RooAbsReal &_m, const RooArgList &varList,
108 const RooArgList &pdfList, const RooArgList &mrefList, Setting setting);
109 RooMomentMorphFuncND(const char *name, const char *title, const RooArgList &parList, const RooArgList &obsList,
110 const Grid2 &referenceGrid, Setting setting);
111 RooMomentMorphFuncND(const RooMomentMorphFuncND &other, const char *name = nullptr);
112 RooMomentMorphFuncND(const char *name, const char *title, RooAbsReal &_m, const RooArgList &varList,
113 const RooArgList &pdfList, const TVectorD &mrefpoints, Setting setting);
114 ~RooMomentMorphFuncND() override;
115 TObject *clone(const char *newname) const override { return new RooMomentMorphFuncND(*this, newname); }
116
118 /// Setting flag makes this RooMomentMorphFuncND instance behave like the
119 /// former RooMomentMorphND class, with the the only difference being the
120 /// base class. If you want to create a pdf object that behaves exactly like
121 /// the old RooMomentMorphND, you can do it as follows:
122 ///
123 /// ```C++
124 /// RooMomentMorphFuncND func{<c'tor args you previously passed to RooMomentMorphFunc>};
125 ///
126 /// func.setPdfMode(); // change behavior to be exactly like the former RooMomentMorphND
127 ///
128 /// // Pass the selfNormalized=true` flag to the wrapper because the
129 /// RooMomentMorphFuncND already normalizes itself in pdf mode.
130 /// RooWrapperPdf pdf{"pdf_name", "pdf_name", func, /*selfNormalized=*/true};
131 /// ```
132 void setPdfMode(bool flag=true) { _isPdfMode = flag; }
133 bool setBinIntegrator(RooArgSet &allVars);
134 void useHorizontalMorphing(bool val) { _useHorizMorph = val; }
135
136 double evaluate() const override;
137 double getValV(const RooArgSet *set = nullptr) const override;
138
139 std::unique_ptr<RooAbsArg>
141
142protected:
143 void initialize();
144
145 RooAbsReal *sumFunc(const RooArgSet *nset);
146 CacheElem *getCache(const RooArgSet *nset) const;
147
148 void findShape(const std::vector<double> &x) const;
149
150 friend class CacheElem;
151 friend class Grid2;
153
154 mutable RooObjCacheManager _cacheMgr; ///<! Transient cache manager
155 mutable RooArgSet *_curNormSet = nullptr; ///<! Transient cache manager
156
161
162 mutable std::unique_ptr<TMatrixD> _M;
163 mutable std::unique_ptr<TMatrixD> _MSqr;
164 mutable std::vector<std::vector<double>> _squareVec;
165 mutable std::vector<int> _squareIdx;
166
169 bool _isPdfMode = false;
170
171 inline int sij(const int &i, const int &j) const { return (i * _obsList.size() + j); }
172
174};
175
176namespace RooFit {
177namespace Detail {
178
179/// Helper compute-graph node that exposes one of the morph mixing fractions to
180/// the RooFit::Evaluator. It re-runs RooMomentMorphFuncND::CacheElem::calculateFractions
181/// only when the morph parameters change, then returns the cached fraction value
182/// for this index.
184public:
186 RooMomentMorphFraction(const char *name, const char *title, RooMomentMorphFuncND const &parent, int index);
187 RooMomentMorphFraction(RooMomentMorphFraction const &other, const char *name = nullptr);
188 TObject *clone(const char *newname) const override { return new RooMomentMorphFraction(*this, newname); }
189
190protected:
191 double evaluate() const override;
192
193private:
195 const RooMomentMorphFuncND *_parent = nullptr; ///<! morph that owns the cache (not owned)
196 int _index = 0;
197
199};
200
201} // namespace Detail
202} // namespace RooFit
203
204#endif
#define ClassDef(name, id)
Definition Rtypes.h:344
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
char name[80]
Definition TGX11.cxx:148
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:63
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:24
Meta object that tracks value changes in a given set of RooAbsArgs by registering itself as value cli...
Helper compute-graph node that exposes one of the morph mixing fractions to the RooFit::Evaluator.
TObject * clone(const char *newname) const override
const RooMomentMorphFuncND * _parent
! morph that owns the cache (not owned)
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
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::unique_ptr< RooAbsArg > compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileContext &ctx) const override
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:42
Double_t x[n]
Definition legend1.C:17
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition CodegenImpl.h:72