Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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_t> > { } ;
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_t rho = 1, Double_t nSigma = 3, Bool_t rotate = kTRUE,
61 Bool_t sortInput = kTRUE);
62
63 RooNDKeysPdf(const char *name, const char *title, const RooArgList &varList, const TH1 &hist, TString options = "ma",
64 Double_t rho = 1, Double_t nSigma = 3, Bool_t rotate = kTRUE, Bool_t sortInput = kTRUE);
65
66 RooNDKeysPdf(const char *name, const char *title, const RooArgList &varList, const RooDataSet &data,
67 const TVectorD &rho, TString options = "ma", Double_t nSigma = 3, Bool_t rotate = kTRUE,
68 Bool_t sortInput = kTRUE);
69
70 RooNDKeysPdf(const char *name, const char *title, const RooArgList &varList, const RooDataSet &data,
71 const RooArgList &rhoList, TString options = "ma", Double_t nSigma = 3, Bool_t rotate = kTRUE,
72 Bool_t sortInput = kTRUE);
73
74 RooNDKeysPdf(const char *name, const char *title, const RooArgList &varList, const TH1 &hist,
75 const RooArgList &rhoList, TString options = "ma", Double_t nSigma = 3, Bool_t rotate = kTRUE,
76 Bool_t sortInput = kTRUE);
77
78 RooNDKeysPdf(const char *name, const char *title, RooAbsReal &x, const RooDataSet &data, Mirror mirror = NoMirror,
79 Double_t rho = 1, Double_t nSigma = 3, Bool_t rotate = kTRUE, Bool_t sortInput = kTRUE);
80
81 RooNDKeysPdf(const char *name, const char *title, RooAbsReal &x, RooAbsReal &y, const RooDataSet &data,
82 TString options = "ma", Double_t rho = 1.0, Double_t nSigma = 3, Bool_t rotate = kTRUE,
83 Bool_t sortInput = kTRUE);
84
85 RooNDKeysPdf(const RooNDKeysPdf& other, const char* name=0);
86 virtual ~RooNDKeysPdf();
87
88 virtual TObject* clone(const char* newname) const { return new RooNDKeysPdf(*this,newname); }
89
90 Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=0) const ;
91 Double_t analyticalIntegral(Int_t code, const char* rangeName=0) const ;
92
93 inline void fixShape(Bool_t fix) {
95 _fixedShape=fix;
96 }
97
98 TMatrixD getWeights(const int &k) const;
99
100 struct BoxInfo {
105 std::vector<Double_t> xVarLo, xVarHi;
106 std::vector<Double_t> xVarLoM3s, xVarLoP3s, xVarHiM3s, xVarHiP3s;
107 std::map<Int_t,Bool_t> 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_t evaluate() const;
119
120 void createPdf(Bool_t firstCall = kTRUE);
121 void setOptions();
122 void initialize();
123 void loadDataSet(Bool_t 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_t gauss(std::vector<Double_t> &x, std::vector<std::vector<Double_t>> &weights) const;
131 void loopRange(std::vector<Double_t> &x, std::map<Int_t, Bool_t> &ibMap) 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
146
149 Bool_t _debug{false}; //!
150 Bool_t _verbose{false}; //!
151
158
159 // cached info on variable
160 std::vector<std::vector<Double_t> > _dataPts;
161 std::vector<TVectorD> _dataPtsR;
162 std::vector<std::vector<Double_t> > _weights0; // Plain weights
163 std::vector<std::vector<Double_t> > _weights1; // Weights for adaptive kernels
164 std::vector<std::vector<Double_t> >* _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_t> _rho;
171 mutable std::vector<Double_t> _x; // Cache for x values
172 std::vector<Double_t> _x0, _x1, _x2;
173 std::vector<Double_t> _mean, _sigma;
174 std::vector<Double_t> _xDatLo, _xDatHi;
175 std::vector<Double_t> _xDatLo3s, _xDatHi3s;
176
180 std::vector<Double_t> _xVarLo, _xVarHi;
181 std::vector<Double_t> _xVarLoM3s, _xVarLoP3s, _xVarHiM3s, _xVarHiP3s;
182 std::map<Int_t,Bool_t> _bpsIdcs;
183 std::map<Int_t, Bool_t> _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;
195 std::map<Int_t,Double_t> _wMap;
196
199 TMatrixD* _rotMat{nullptr};
200 TVectorD* _sigmaR{nullptr};
201 TVectorD* _dx{nullptr};
203
207
209
210 ClassDef(RooNDKeysPdf, 1) // General N-dimensional non-parametric kernel estimation p.d.f
211};
212
213#endif
std::pair< Int_t, VecVecDouble::iterator > iiPair
std::vector< itPair > itVec
std::vector< iiPair > iiVec
std::pair< Int_t, VecTVecDouble::iterator > itPair
const Bool_t kFALSE
Definition RtypesCore.h:92
double Double_t
Definition RtypesCore.h:59
const Bool_t kTRUE
Definition RtypesCore.h:91
#define ClassDef(name, id)
Definition Rtypes.h:325
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:61
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:21
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:29
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:33
RooListProxy is the concrete proxy for RooArgList objects.
Generic N-dimensional implementation of a kernel estimation p.d.f.
BoxInfo _fullBoxInfo
RooListProxy _rhoList
Double_t _nSigma
TVectorD * _dx
std::unique_ptr< RooDataSet > _ownedData
Double_t _minWeight
std::vector< Int_t > _sIdcs
void initialize()
initialization
std::vector< Double_t > _xVarLo
void calculatePreNorm(BoxInfo *bi) const
bi->nEventsBMSW=0.; bi->nEventsBW=0.;
Double_t analyticalIntegral(Int_t code, const char *rangeName=0) const
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral.
TVectorD * _sigmaR
std::vector< Double_t > _xDatLo3s
Double_t _nEventsBW
std::vector< Double_t > _x0
virtual ~RooNDKeysPdf()
std::vector< Double_t > _xVarLoP3s
Bool_t _fixedShape
Bool_t _sortInput
std::vector< Double_t > _xDatHi3s
const RooDataSet * _data
std::vector< Int_t > _bIdcs
std::vector< TVectorD > _dataPtsR
void loopRange(std::vector< Double_t > &x, std::map< Int_t, Bool_t > &ibMap) const
determine closest points to x, to loop over in evaluate()
void fixShape(Bool_t fix)
std::vector< Double_t > _xVarHi
void createPdf(Bool_t firstCall=kTRUE)
evaluation order of constructor.
Double_t _nEventsBMSW
void updateRho() const
Double_t _nEventsW
void calculateShell(BoxInfo *bi) const
determine points in +/- nSigma shell around the box determined by the variable ranges.
void calculateBandWidth()
std::vector< Double_t > _x1
Double_t _maxWeight
RooArgSet _dataVars
std::vector< Double_t > _mean
RooListProxy _varList
TMatrixDSym * _corrMat
std::vector< Int_t > _bmsIdcs
std::vector< Double_t > _rho
std::vector< Double_t > _xDatHi
std::vector< Double_t > _x
std::vector< itVec > _sortTVIdcs
Weights to be used. Points either to _weights0 or _weights1.
void boxInfoInit(BoxInfo *bi, const char *rangeName, Int_t code) const
std::map< std::pair< std::string, int >, BoxInfo * > _rangeBoxInfo
std::vector< Double_t > _xVarLoM3s
Double_t _sigmaAvgR
Double_t _widthFactor
std::vector< Int_t > _idx
std::vector< Double_t > _xDatLo
void sortDataIndices(BoxInfo *bi=0)
sort entries, as needed for loopRange()
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=0) const
Interface function getAnalyticalIntergral advertises the analytical integrals that are supported.
void loadDataSet(Bool_t firstCall)
copy the dataset and calculate some useful variables
TString _options
do not persist
std::vector< std::vector< Double_t > > * _weights
TMatrixD getWeights(const int &k) const
Return evaluated weights.
std::vector< Double_t > _xVarHiM3s
Double_t evaluate() const
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
std::map< Int_t, Bool_t > _ibNoSort
std::vector< std::vector< Double_t > > _weights0
void mirrorDataSet()
determine mirror dataset.
virtual TObject * clone(const char *newname) const
void setOptions()
set the configuration
std::vector< std::vector< Double_t > > _dataPts
RooDataSet * createDatasetFromHist(const RooArgList &varList, const TH1 &hist) const
RooNDKeysPdf()=default
std::vector< Double_t > _sigma
std::vector< std::string > _varName
Double_t gauss(std::vector< Double_t > &x, std::vector< std::vector< Double_t > > &weights) const
loop over all closest point to x, as determined by loopRange()
void checkInitWeights() const
std::map< Int_t, Double_t > _wMap
std::vector< std::vector< Double_t > > _weights1
TMatrixD * _rotMat
std::vector< Double_t > _x2
TMatrixDSym * _covMat
std::vector< Double_t > _xVarHiP3s
std::map< Int_t, Bool_t > _bpsIdcs
RooChangeTracker * _tracker
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:39
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_t > xVarHiP3s
std::vector< Double_t > xVarHi
std::map< Int_t, Bool_t > bpsIdcs
std::vector< Int_t > bIdcs
std::vector< Double_t > xVarLoM3s
std::vector< Double_t > xVarHiM3s
std::vector< Double_t > xVarLoP3s
std::vector< Double_t > xVarLo
std::vector< Int_t > sIdcs
std::vector< Int_t > bmsIdcs