Logo ROOT   6.12/07
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 "RooRealConstant.h"
22 #include "RooDataSet.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 
32 class RooRealVar;
33 class RooArgList;
34 class RooArgSet;
35 class RooChangeTracker;
36 
37 #ifndef __CINT__
38 class VecVecDouble : public std::vector<std::vector<Double_t> > { } ;
39 class VecTVecDouble : public std::vector<TVectorD> { } ;
40 typedef std::pair<Int_t, VecVecDouble::iterator > iiPair;
41 typedef std::vector< iiPair > iiVec;
42 typedef std::pair<Int_t, VecTVecDouble::iterator > itPair;
43 typedef std::vector< itPair > itVec;
44 #else
45 class itPair ;
46 #endif
47 
48 class RooNDKeysPdf : public RooAbsPdf {
49 
50 public:
51 
52  enum Mirror {NoMirror, MirrorLeft, MirrorRight, MirrorBoth,
53  MirrorAsymLeft, MirrorAsymLeftRight,
54  MirrorAsymRight, MirrorLeftAsymRight,
55  MirrorAsymBoth };
56 
57  RooNDKeysPdf(const char *name, const char *title, const RooArgList &varList, const RooAbsData &data,
58  TString options = "ma", Double_t rho = 1, Double_t nSigma = 3, Bool_t rotate = kTRUE,
59  Bool_t sortInput = kTRUE);
60 
61  RooNDKeysPdf(const char *name, const char *title, const RooArgList &varList, const TH1 &hist, TString options = "ma",
62  Double_t rho = 1, Double_t nSigma = 3, Bool_t rotate = kTRUE, Bool_t sortInput = kTRUE);
63 
64  RooNDKeysPdf(const char *name, const char *title, const RooArgList &varList, const RooAbsData &data,
65  const TVectorD &rho, TString options = "ma", Double_t nSigma = 3, Bool_t rotate = kTRUE,
66  Bool_t sortInput = kTRUE);
67 
68  RooNDKeysPdf(const char *name, const char *title, const RooArgList &varList, const RooAbsData &data,
69  const RooArgList &rhoList, TString options = "ma", Double_t nSigma = 3, Bool_t rotate = kTRUE,
70  Bool_t sortInput = kTRUE);
71 
72  RooNDKeysPdf(const char *name, const char *title, const RooArgList &varList, const TH1 &hist,
73  const RooArgList &rhoList, TString options = "ma", Double_t nSigma = 3, Bool_t rotate = kTRUE,
74  Bool_t sortInput = kTRUE);
75 
76  RooNDKeysPdf(const char *name, const char *title, RooAbsReal &x, const RooAbsData &data, Mirror mirror = NoMirror,
77  Double_t rho = 1, Double_t nSigma = 3, Bool_t rotate = kTRUE, Bool_t sortInput = kTRUE);
78 
79  RooNDKeysPdf(const char *name, const char *title, RooAbsReal &x, RooAbsReal &y, const RooAbsData &data,
80  TString options = "ma", Double_t rho = 1.0, Double_t nSigma = 3, Bool_t rotate = kTRUE,
81  Bool_t sortInput = kTRUE);
82 
83  RooNDKeysPdf(const RooNDKeysPdf& other, const char* name=0);
84  virtual ~RooNDKeysPdf();
85 
86  virtual TObject* clone(const char* newname) const { return new RooNDKeysPdf(*this,newname); }
87 
88  Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=0) const ;
89  Double_t analyticalIntegral(Int_t code, const char* rangeName=0) const ;
90 
91  inline void fixShape(Bool_t fix) {
92  createPdf(kFALSE);
93  _fixedShape=fix;
94  }
95 
96  TMatrixD getWeights(const int &k) const;
97 
98  struct BoxInfo {
103  std::vector<Double_t> xVarLo, xVarHi;
104  std::vector<Double_t> xVarLoM3s, xVarLoP3s, xVarHiM3s, xVarHiP3s;
105  std::map<Int_t,Bool_t> bpsIdcs;
106  std::vector<Int_t> sIdcs;
107  std::vector<Int_t> bIdcs;
108  std::vector<Int_t> bmsIdcs;
109  } ;
110 
111 protected:
112 
114  TIterator* _varItr ; //! do not persist
115 
117  TIterator *_rhoItr; //! do not persist
118 
119  Double_t evaluate() const;
120 
121  void createPdf(Bool_t firstCall = kTRUE) const;
122  void setOptions() const;
123  void initialize() const;
124  void loadDataSet(Bool_t firstCall) const;
125  void mirrorDataSet() const;
126  void loadWeightSet() const;
127  void calculateShell(BoxInfo *bi) const;
128  void calculatePreNorm(BoxInfo *bi) const;
129  void sortDataIndices(BoxInfo *bi = 0) const;
130  void calculateBandWidth() const;
131  Double_t gauss(std::vector<Double_t> &x, std::vector<std::vector<Double_t>> &weights) const;
132  void loopRange(std::vector<Double_t> &x, std::map<Int_t, Bool_t> &ibMap) const;
133  void boxInfoInit(BoxInfo *bi, const char *rangeName, Int_t code) const;
134  RooDataSet *createDatasetFromHist(const RooArgList &varList, const TH1 &hist) const;
135  void updateRho() const;
136 
137  mutable RooDataSet *_dataP; //! do not persist
138  const RooAbsData &_data; //!
139  mutable TString _options;
141  mutable Double_t _nSigma;
142 
144  mutable Bool_t _mirror;
145  mutable Bool_t _debug;
146  mutable Bool_t _verbose;
147 
149  mutable Int_t _nDim;
150  mutable Int_t _nEvents;
151  mutable Int_t _nEventsM;
153  mutable Double_t _d;
154  mutable Double_t _n;
155 
156  // cached info on variable
157 
158  mutable std::vector<std::vector<Double_t> > _dataPts;
159  mutable std::vector<TVectorD> _dataPtsR;
160  mutable std::vector<std::vector<Double_t> > _weights0;
161  mutable std::vector<std::vector<Double_t> > _weights1;
162  mutable std::vector<std::vector<Double_t> >* _weights; //!
163 
164 #ifndef __CINT__
165  mutable std::vector<iiVec> _sortIdcs; //!
166  mutable std::vector<itVec> _sortTVIdcs; //!
167 #endif
168 
169  mutable std::vector<std::string> _varName;
170  mutable std::vector<Double_t> _rho;
172  mutable std::vector<Double_t> _x;
173  mutable std::vector<Double_t> _x0, _x1, _x2;
174  mutable std::vector<Double_t> _mean, _sigma;
175  mutable std::vector<Double_t> _xDatLo, _xDatHi;
176  mutable std::vector<Double_t> _xDatLo3s, _xDatHi3s;
177 
178  mutable Bool_t _netFluxZ;
181  mutable std::vector<Double_t> _xVarLo, _xVarHi;
182  mutable std::vector<Double_t> _xVarLoM3s, _xVarLoP3s, _xVarHiM3s, _xVarHiP3s;
183  mutable std::map<Int_t,Bool_t> _bpsIdcs;
184  mutable std::map<Int_t, Bool_t> _ibNoSort;
185  mutable std::vector<Int_t> _sIdcs;
186  mutable std::vector<Int_t> _bIdcs;
187  mutable std::vector<Int_t> _bmsIdcs;
188 
189  mutable std::map<std::pair<std::string,int>,BoxInfo*> _rangeBoxInfo ;
191 
192  mutable std::vector<Int_t> _idx;
195  mutable std::map<Int_t,Double_t> _wMap;
196 
199  mutable TMatrixD* _rotMat;
200  mutable TVectorD* _sigmaR;
201  mutable TVectorD* _dx;
203 
204  mutable Bool_t _rotate;
206  mutable Int_t _nAdpt;
207 
208  mutable RooChangeTracker *_tracker; //! do not persist
209 
210  /// sorter function
211  struct SorterTV_L2H {
213 
214  SorterTV_L2H (Int_t index) : idx(index) {}
215  bool operator() (const itPair& a, const itPair& b) {
216  const TVectorD& aVec = *(a.second);
217  const TVectorD& bVec = *(b.second);
218  return (aVec[idx]<bVec[idx]);
219  }
220  };
221 
222  ClassDef(RooNDKeysPdf, 2) // General N-dimensional non-parametric kernel estimation p.d.f
223 };
224 
225 #endif
Double_t _n
Definition: RooNDKeysPdf.h:154
Bool_t _rotate
Definition: RooNDKeysPdf.h:204
std::vector< itPair > itVec
Definition: RooNDKeysPdf.h:43
std::vector< iiPair > iiVec
Definition: RooNDKeysPdf.h:41
RooListProxy _varList
Definition: RooNDKeysPdf.h:113
std::vector< Double_t > _xVarLo
Definition: RooNDKeysPdf.h:181
Double_t _nEventsW
Definition: RooNDKeysPdf.h:152
TMatrixDSym * _corrMat
Definition: RooNDKeysPdf.h:198
Double_t _nSigma
Definition: RooNDKeysPdf.h:141
std::vector< std::string > _varName
Definition: RooNDKeysPdf.h:169
std::vector< Int_t > bIdcs
Definition: RooNDKeysPdf.h:107
TVectorD * _dx
Definition: RooNDKeysPdf.h:201
TVectorT.
Definition: TMatrixTBase.h:77
Bool_t _netFluxZ
Definition: RooNDKeysPdf.h:178
std::vector< Int_t > _bIdcs
Definition: RooNDKeysPdf.h:186
Basic string class.
Definition: TString.h:125
std::vector< Double_t > _xDatLo
Definition: RooNDKeysPdf.h:175
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TMatrixD * _rotMat
Definition: RooNDKeysPdf.h:199
TRObject operator()(const T1 &t1) const
Double_t _widthFactor
Definition: RooNDKeysPdf.h:140
Iterator abstract base class.
Definition: TIterator.h:30
void evaluate(typename Architecture_t::Matrix_t &A, EActivationFunction f)
Apply the given activation function to each value in the given matrix A.
Definition: Functions.h:85
TMatrixT.
Definition: TMatrixDfwd.h:22
Bool_t _verbose
Definition: RooNDKeysPdf.h:146
std::vector< std::vector< Double_t > > _weights1
Definition: RooNDKeysPdf.h:161
Double_t x[n]
Definition: legend1.C:17
std::pair< Int_t, VecVecDouble::iterator > iiPair
Definition: RooNDKeysPdf.h:40
#define ClassDef(name, id)
Definition: Rtypes.h:320
std::map< Int_t, Double_t > _wMap
Definition: RooNDKeysPdf.h:195
std::map< Int_t, Bool_t > _ibNoSort
Definition: RooNDKeysPdf.h:184
std::map< std::pair< std::string, int >, BoxInfo * > _rangeBoxInfo
Definition: RooNDKeysPdf.h:189
void fixShape(Bool_t fix)
Definition: RooNDKeysPdf.h:91
TVectorD * _sigmaR
Definition: RooNDKeysPdf.h:200
std::vector< Double_t > _xDatLo3s
Definition: RooNDKeysPdf.h:176
TMatrixTSym.
std::vector< std::vector< Double_t > > * _weights
Definition: RooNDKeysPdf.h:162
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
RooListProxy _rhoList
do not persist
Definition: RooNDKeysPdf.h:116
Bool_t _sortInput
Definition: RooNDKeysPdf.h:205
std::vector< Double_t > _x
Definition: RooNDKeysPdf.h:172
std::vector< itVec > _sortTVIdcs
Definition: RooNDKeysPdf.h:166
auto * a
Definition: textangle.C:12
Double_t _maxWeight
Definition: RooNDKeysPdf.h:194
Double_t _minWeight
Definition: RooNDKeysPdf.h:193
Double_t _sigmaAvgR
Definition: RooNDKeysPdf.h:202
TMatrixDSym * _covMat
Definition: RooNDKeysPdf.h:197
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:37
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
Generic N-dimensional implementation of a kernel estimation p.d.f.
Definition: RooNDKeysPdf.h:48
Double_t _nEventsBW
Definition: RooNDKeysPdf.h:179
RooListProxy is the concrete proxy for RooArgList objects.
Definition: RooListProxy.h:25
const Bool_t kFALSE
Definition: RtypesCore.h:88
TString _options
Definition: RooNDKeysPdf.h:139
BoxInfo _fullBoxInfo
Definition: RooNDKeysPdf.h:190
Double_t _nEventsBMSW
Definition: RooNDKeysPdf.h:180
RooArgSet _dataVars
Definition: RooNDKeysPdf.h:171
static constexpr double gauss
double Double_t
Definition: RtypesCore.h:55
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
std::map< Int_t, Bool_t > _bpsIdcs
Definition: RooNDKeysPdf.h:183
std::vector< Int_t > sIdcs
Definition: RooNDKeysPdf.h:106
std::vector< Double_t > xVarLoP3s
Definition: RooNDKeysPdf.h:104
Double_t y[n]
Definition: legend1.C:17
The TH1 histogram class.
Definition: TH1.h:56
std::vector< Int_t > _idx
Definition: RooNDKeysPdf.h:192
std::pair< Int_t, VecTVecDouble::iterator > itPair
Definition: RooNDKeysPdf.h:42
TIterator * _rhoItr
Definition: RooNDKeysPdf.h:117
RooChangeTracker is a meta object that tracks value changes in a given set of RooAbsArgs by registeri...
std::vector< Int_t > _sIdcs
Definition: RooNDKeysPdf.h:185
RooChangeTracker * _tracker
Definition: RooNDKeysPdf.h:208
Mother of all ROOT objects.
Definition: TObject.h:37
std::map< Int_t, Bool_t > bpsIdcs
Definition: RooNDKeysPdf.h:105
std::vector< Int_t > bmsIdcs
Definition: RooNDKeysPdf.h:108
const RooAbsData & _data
do not persist
Definition: RooNDKeysPdf.h:138
std::vector< Double_t > _rho
Definition: RooNDKeysPdf.h:170
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
RooDataSet * _dataP
Definition: RooNDKeysPdf.h:137
Bool_t _fixedShape
Definition: RooNDKeysPdf.h:143
Double_t _sqrt2pi
Definition: RooNDKeysPdf.h:148
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
std::vector< TVectorD > _dataPtsR
Definition: RooNDKeysPdf.h:159
std::vector< std::vector< Double_t > > _dataPts
Definition: RooNDKeysPdf.h:158
std::vector< std::vector< Double_t > > _weights0
Definition: RooNDKeysPdf.h:160
TIterator * _varItr
Definition: RooNDKeysPdf.h:114
std::vector< Double_t > _xVarLoP3s
Definition: RooNDKeysPdf.h:182
Bool_t _mirror
Definition: RooNDKeysPdf.h:144
const Bool_t kTRUE
Definition: RtypesCore.h:87
void initialize(typename Architecture_t::Matrix_t &A, EInitialization m)
Definition: Functions.h:249
std::vector< Double_t > _sigma
Definition: RooNDKeysPdf.h:174
std::vector< Double_t > xVarLo
Definition: RooNDKeysPdf.h:103
std::vector< Int_t > _bmsIdcs
Definition: RooNDKeysPdf.h:187
char name[80]
Definition: TGX11.cxx:109
virtual TObject * clone(const char *newname) const
Definition: RooNDKeysPdf.h:86
std::vector< iiVec > _sortIdcs
Definition: RooNDKeysPdf.h:165
Double_t _d
Definition: RooNDKeysPdf.h:153
std::vector< Double_t > _x2
Definition: RooNDKeysPdf.h:173