Logo ROOT  
Reference Guide
RooNDKeysPdf.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitModels *
4 * File: $Id: RooNDKeysPdf.h 44368 2012-05-30 15:38:44Z axel $
5 * Authors: *
6 * Max Baak, CERN, mbaak@cern.ch *
7 * *
8 * Copyright (c) 2000-2005, Regents of the University of California *
9 * and Stanford University. All rights reserved. *
10 * *
11 * Redistribution and use in source and binary forms, *
12 * with or without modification, are permitted according to the terms *
13 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
14 *****************************************************************************/
15#ifndef ROO_NDKEYS_PDF
16#define ROO_NDKEYS_PDF
17
18#include "RooAbsPdf.h"
19#include "RooRealProxy.h"
20#include "RooSetProxy.h"
21#include "RooDataSet.h"
22#include "RooListProxy.h"
23#include "TH1.h"
24#include "TAxis.h"
25#include "TVectorD.h"
26#include "TMatrixD.h"
27#include "TMatrixDSym.h"
28#include <map>
29#include <vector>
30#include <string>
31
32class RooRealVar;
33class RooArgList;
34class RooArgSet;
36
37#ifndef __CINT__
38class VecVecDouble : public std::vector<std::vector<double> > { } ;
39class VecTVecDouble : public std::vector<TVectorD> { } ;
40typedef std::pair<Int_t, VecVecDouble::iterator > iiPair;
41typedef std::vector< iiPair > iiVec;
42typedef std::pair<Int_t, VecTVecDouble::iterator > itPair;
43typedef std::vector< itPair > itVec;
44#else
45class itPair ;
46#endif
47
48class RooNDKeysPdf : public RooAbsPdf {
49
50public:
51
56
57 RooNDKeysPdf() = default;
58
59 RooNDKeysPdf(const char *name, const char *title, const RooArgList &varList, const RooDataSet &data,
60 TString options = "ma", double rho = 1, double nSigma = 3, bool rotate = true,
61 bool sortInput = true);
62
63 RooNDKeysPdf(const char *name, const char *title, const RooArgList &varList, const TH1 &hist, TString options = "ma",
64 double rho = 1, double nSigma = 3, bool rotate = true, bool sortInput = true);
65
66 RooNDKeysPdf(const char *name, const char *title, const RooArgList &varList, const RooDataSet &data,
67 const TVectorD &rho, TString options = "ma", double nSigma = 3, bool rotate = true,
68 bool sortInput = true);
69
70 RooNDKeysPdf(const char *name, const char *title, const RooArgList &varList, const RooDataSet &data,
71 const RooArgList &rhoList, TString options = "ma", double nSigma = 3, bool rotate = true,
72 bool sortInput = true);
73
74 RooNDKeysPdf(const char *name, const char *title, const RooArgList &varList, const TH1 &hist,
75 const RooArgList &rhoList, TString options = "ma", double nSigma = 3, bool rotate = true,
76 bool sortInput = true);
77
78 RooNDKeysPdf(const char *name, const char *title, RooAbsReal &x, const RooDataSet &data, Mirror mirror = NoMirror,
79 double rho = 1, double nSigma = 3, bool rotate = true, bool sortInput = true);
80
81 RooNDKeysPdf(const char *name, const char *title, RooAbsReal &x, RooAbsReal &y, const RooDataSet &data,
82 TString options = "ma", double rho = 1.0, double nSigma = 3, bool rotate = true,
83 bool sortInput = true);
84
85 RooNDKeysPdf(const RooNDKeysPdf& other, const char* name=nullptr);
86 ~RooNDKeysPdf() override;
87
88 TObject* clone(const char* newname) const override { return new RooNDKeysPdf(*this,newname); }
89
90 Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=nullptr) const override ;
91 double analyticalIntegral(Int_t code, const char* rangeName=nullptr) const override ;
92
93 inline void fixShape(bool fix) {
94 createPdf(false);
95 _fixedShape=fix;
96 }
97
98 TMatrixD getWeights(const int &k) const;
99
100 struct BoxInfo {
101 bool filled;
103 double nEventsBW;
105 std::vector<double> xVarLo, xVarHi;
106 std::vector<double> xVarLoM3s, xVarLoP3s, xVarHiM3s, xVarHiP3s;
107 std::map<Int_t,bool> bpsIdcs;
108 std::vector<Int_t> sIdcs;
109 std::vector<Int_t> bIdcs;
110 std::vector<Int_t> bmsIdcs;
111 } ;
112
113protected:
114
117
118 double evaluate() const override;
119
120 void createPdf(bool firstCall = true);
121 void setOptions();
122 void initialize();
123 void loadDataSet(bool firstCall);
124 void mirrorDataSet();
125 void loadWeightSet();
126 void calculateShell(BoxInfo *bi) const;
127 void calculatePreNorm(BoxInfo *bi) const;
128 void sortDataIndices(BoxInfo *bi = 0);
129 void calculateBandWidth();
130 double gauss(std::vector<double> &x, std::vector<std::vector<double>> &weights) const;
131 void loopRange(std::vector<double> &x, std::vector<Int_t> &indices) const;
132 void boxInfoInit(BoxInfo *bi, const char *rangeName, Int_t code) const;
133 RooDataSet *createDatasetFromHist(const RooArgList &varList, const TH1 &hist) const;
134 void updateRho() const;
135 void checkInitWeights() const {
136 if (_weights == &_weights0 || _weights == &_weights1)
137 return;
138 const_cast<RooNDKeysPdf*>(this)->calculateBandWidth();
139 }
140
141 std::unique_ptr<RooDataSet> _ownedData{nullptr};
142 const RooDataSet* _data; //! do not persist
145 double _nSigma;
146
147 bool _fixedShape{false};
148 bool _mirror{false};
149 bool _debug{false}; //!
150 bool _verbose{false}; //!
151
155 double _nEventsW{0.};
156 double _d{0.};
157 double _n{0.};
158
159 // cached info on variable
160 std::vector<std::vector<double> > _dataPts;
161 std::vector<TVectorD> _dataPtsR;
162 std::vector<std::vector<double> > _weights0; // Plain weights
163 std::vector<std::vector<double> > _weights1; // Weights for adaptive kernels
164 std::vector<std::vector<double> >* _weights{nullptr}; //! Weights to be used. Points either to _weights0 or _weights1
165
166 std::vector<itVec> _sortTVIdcs; //!
167
168 std::vector<std::string> _varName;
169 mutable std::vector<double> _rho;
171 mutable std::vector<double> _x; // Cache for x values
172 std::vector<double> _x0, _x1, _x2;
173 std::vector<double> _mean, _sigma;
174 std::vector<double> _xDatLo, _xDatHi;
175 std::vector<double> _xDatLo3s, _xDatHi3s;
176
177 bool _netFluxZ{false};
178 double _nEventsBW{0.};
179 double _nEventsBMSW{0.};
180 std::vector<double> _xVarLo, _xVarHi;
182 std::map<Int_t,bool> _bpsIdcs;
183 std::map<Int_t, bool> _ibNoSort;
184 std::vector<Int_t> _sIdcs;
185 std::vector<Int_t> _bIdcs;
186 std::vector<Int_t> _bmsIdcs;
187
188 // Data for analytical integrals:
189 mutable std::map<std::pair<std::string,int>,BoxInfo*> _rangeBoxInfo ;
191
192 std::vector<Int_t> _idx;
193 double _minWeight{0.};
194 double _maxWeight{0.};
195 std::map<Int_t,double> _wMap;
196
199 TMatrixD* _rotMat{nullptr};
200 TVectorD* _sigmaR{nullptr};
201 TVectorD* _dx{nullptr};
202 double _sigmaAvgR{0.};
203
207
209
210 ClassDefOverride(RooNDKeysPdf, 1) // General N-dimensional non-parametric kernel estimation p.d.f
211};
212
213#endif
std::pair< Int_t, VecVecDouble::iterator > iiPair
Definition: RooNDKeysPdf.h:40
std::vector< itPair > itVec
Definition: RooNDKeysPdf.h:43
std::vector< iiPair > iiVec
Definition: RooNDKeysPdf.h:41
std::pair< Int_t, VecTVecDouble::iterator > itPair
Definition: RooNDKeysPdf.h:42
#define ClassDefOverride(name, id)
Definition: Rtypes.h:339
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
char name[80]
Definition: TGX11.cxx:110
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:62
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:56
RooChangeTracker is a meta object that tracks value changes in a given set of RooAbsArgs by registeri...
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:55
Generic N-dimensional implementation of a kernel estimation p.d.f.
Definition: RooNDKeysPdf.h:48
BoxInfo _fullBoxInfo
Definition: RooNDKeysPdf.h:190
RooListProxy _rhoList
Definition: RooNDKeysPdf.h:116
std::vector< double > _xVarLoM3s
Definition: RooNDKeysPdf.h:181
TVectorD * _dx
Definition: RooNDKeysPdf.h:201
std::unique_ptr< RooDataSet > _ownedData
Definition: RooNDKeysPdf.h:141
void loadWeightSet()
std::map< Int_t, bool > _ibNoSort
Definition: RooNDKeysPdf.h:183
std::vector< Int_t > _sIdcs
Definition: RooNDKeysPdf.h:184
std::vector< std::vector< double > > _weights0
Definition: RooNDKeysPdf.h:162
void initialize()
initialization
double analyticalIntegral(Int_t code, const char *rangeName=nullptr) const override
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral.
~RooNDKeysPdf() override
void calculatePreNorm(BoxInfo *bi) const
bi->nEventsBMSW=0.; bi->nEventsBW=0.;
std::vector< double > _xDatHi
Definition: RooNDKeysPdf.h:174
void loadDataSet(bool firstCall)
copy the dataset and calculate some useful variables
std::vector< std::vector< double > > * _weights
Definition: RooNDKeysPdf.h:164
TVectorD * _sigmaR
Definition: RooNDKeysPdf.h:200
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
void loopRange(std::vector< double > &x, std::vector< Int_t > &indices) const
determine closest points to x, to loop over in evaluate()
std::vector< double > _xDatLo
Definition: RooNDKeysPdf.h:174
std::vector< double > _x
Definition: RooNDKeysPdf.h:171
std::map< Int_t, double > _wMap
Definition: RooNDKeysPdf.h:195
double _maxWeight
Definition: RooNDKeysPdf.h:194
double _nEventsBMSW
Definition: RooNDKeysPdf.h:179
std::vector< double > _xVarHi
Definition: RooNDKeysPdf.h:180
const RooDataSet * _data
Definition: RooNDKeysPdf.h:142
std::vector< Int_t > _bIdcs
Definition: RooNDKeysPdf.h:185
std::vector< TVectorD > _dataPtsR
Definition: RooNDKeysPdf.h:161
void updateRho() const
std::vector< double > _mean
Definition: RooNDKeysPdf.h:173
std::vector< double > _xVarLo
Definition: RooNDKeysPdf.h:180
void calculateShell(BoxInfo *bi) const
determine points in +/- nSigma shell around the box determined by the variable ranges.
void calculateBandWidth()
std::vector< double > _xDatLo3s
Definition: RooNDKeysPdf.h:175
std::vector< double > _x1
Definition: RooNDKeysPdf.h:172
double _widthFactor
Definition: RooNDKeysPdf.h:144
std::vector< std::vector< double > > _dataPts
Definition: RooNDKeysPdf.h:160
double _sigmaAvgR
Definition: RooNDKeysPdf.h:202
std::vector< double > _xVarHiM3s
Definition: RooNDKeysPdf.h:181
std::vector< double > _x0
Definition: RooNDKeysPdf.h:172
std::vector< double > _x2
Definition: RooNDKeysPdf.h:172
double gauss(std::vector< double > &x, std::vector< std::vector< double > > &weights) const
loop over all closest point to x, as determined by loopRange()
std::vector< double > _rho
Definition: RooNDKeysPdf.h:169
RooArgSet _dataVars
Definition: RooNDKeysPdf.h:170
RooListProxy _varList
Definition: RooNDKeysPdf.h:115
TMatrixDSym * _corrMat
Definition: RooNDKeysPdf.h:198
std::vector< Int_t > _bmsIdcs
Definition: RooNDKeysPdf.h:186
std::vector< itVec > _sortTVIdcs
Weights to be used. Points either to _weights0 or _weights1.
Definition: RooNDKeysPdf.h:166
void boxInfoInit(BoxInfo *bi, const char *rangeName, Int_t code) const
std::map< std::pair< std::string, int >, BoxInfo * > _rangeBoxInfo
Definition: RooNDKeysPdf.h:189
std::vector< Int_t > _idx
Definition: RooNDKeysPdf.h:192
TObject * clone(const char *newname) const override
Definition: RooNDKeysPdf.h:88
void sortDataIndices(BoxInfo *bi=0)
sort entries, as needed for loopRange()
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=nullptr) const override
Interface function getAnalyticalIntergral advertises the analytical integrals that are supported.
std::vector< double > _xVarLoP3s
Definition: RooNDKeysPdf.h:181
std::vector< std::vector< double > > _weights1
Definition: RooNDKeysPdf.h:163
std::vector< double > _xDatHi3s
Definition: RooNDKeysPdf.h:175
TString _options
do not persist
Definition: RooNDKeysPdf.h:143
std::vector< double > _xVarHiP3s
Definition: RooNDKeysPdf.h:181
TMatrixD getWeights(const int &k) const
Return evaluated weights.
std::vector< double > _sigma
Definition: RooNDKeysPdf.h:173
void mirrorDataSet()
determine mirror dataset.
void setOptions()
set the configuration
RooDataSet * createDatasetFromHist(const RooArgList &varList, const TH1 &hist) const
double _nSigma
Definition: RooNDKeysPdf.h:145
RooNDKeysPdf()=default
std::vector< std::string > _varName
Definition: RooNDKeysPdf.h:168
void checkInitWeights() const
Definition: RooNDKeysPdf.h:135
double _nEventsBW
Definition: RooNDKeysPdf.h:178
TMatrixD * _rotMat
Definition: RooNDKeysPdf.h:199
void fixShape(bool fix)
Definition: RooNDKeysPdf.h:93
void createPdf(bool firstCall=true)
evaluation order of constructor.
std::map< Int_t, bool > _bpsIdcs
Definition: RooNDKeysPdf.h:182
TMatrixDSym * _covMat
Definition: RooNDKeysPdf.h:197
double _nEventsW
Definition: RooNDKeysPdf.h:155
double _minWeight
Definition: RooNDKeysPdf.h:193
RooChangeTracker * _tracker
Definition: RooNDKeysPdf.h:208
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
TH1 is the base class of all histogram classes in ROOT.
Definition: TH1.h:58
Mother of all ROOT objects.
Definition: TObject.h:37
Basic string class.
Definition: TString.h:136
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
std::vector< double > xVarHiM3s
Definition: RooNDKeysPdf.h:106
std::vector< Int_t > bIdcs
Definition: RooNDKeysPdf.h:109
std::vector< double > xVarHiP3s
Definition: RooNDKeysPdf.h:106
std::vector< double > xVarLo
Definition: RooNDKeysPdf.h:105
std::vector< double > xVarHi
Definition: RooNDKeysPdf.h:105
std::map< Int_t, bool > bpsIdcs
Definition: RooNDKeysPdf.h:107
std::vector< Int_t > sIdcs
Definition: RooNDKeysPdf.h:108
std::vector< double > xVarLoM3s
Definition: RooNDKeysPdf.h:106
std::vector< double > xVarLoP3s
Definition: RooNDKeysPdf.h:106
std::vector< Int_t > bmsIdcs
Definition: RooNDKeysPdf.h:110