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> > { } ;
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 TMatrixD getWeights(const int &k) const;
94
95 struct BoxInfo {
96 bool filled;
98 double nEventsBW;
100 std::vector<double> xVarLo, xVarHi;
101 std::vector<double> xVarLoM3s, xVarLoP3s, xVarHiM3s, xVarHiP3s;
102 std::map<Int_t,bool> bpsIdcs;
103 std::vector<Int_t> sIdcs;
104 std::vector<Int_t> bIdcs;
105 std::vector<Int_t> bmsIdcs;
106 } ;
107
108protected:
109
112
113 double evaluate() const override;
114
115 void createPdf(bool firstCall, RooDataSet const& data);
116 void setOptions();
117 void initialize(RooDataSet const& data);
118 void loadDataSet(bool firstCall, RooDataSet const& data);
119 void mirrorDataSet();
120 void loadWeightSet(RooDataSet const& data);
121 void calculateShell(BoxInfo *bi) const;
122 void calculatePreNorm(BoxInfo *bi) const;
123 void sortDataIndices(BoxInfo *bi = nullptr);
124 void calculateBandWidth();
125 double gauss(std::vector<double> &x, std::vector<std::vector<double>> &weights) const;
126 void loopRange(std::vector<double> &x, std::vector<Int_t> &indices) const;
127 void boxInfoInit(BoxInfo *bi, const char *rangeName, Int_t code) const;
128 RooDataSet *createDatasetFromHist(const RooArgList &varList, const TH1 &hist) const;
129 void updateRho() const;
130 void checkInitWeights() const {
131 if (_weights == &_weights0 || _weights == &_weights1)
132 return;
133 const_cast<RooNDKeysPdf*>(this)->calculateBandWidth();
134 }
135
138 double _nSigma;
139
140 bool _fixedShape{false};
141 bool _mirror{false};
142 bool _debug{false}; //!
143 bool _verbose{false}; //!
144
148 double _nEventsW{0.};
149 double _d{0.};
150 double _n{0.};
151
152 // cached info on variable
153 std::vector<std::vector<double> > _dataPts;
154 std::vector<TVectorD> _dataPtsR;
155 std::vector<std::vector<double> > _weights0; // Plain weights
156 std::vector<std::vector<double> > _weights1; // Weights for adaptive kernels
157 std::vector<std::vector<double> >* _weights{nullptr}; //! Weights to be used. Points either to _weights0 or _weights1
158
159 std::vector<itVec> _sortTVIdcs; //!
160
161 std::vector<std::string> _varName;
162 mutable std::vector<double> _rho;
164 mutable std::vector<double> _x; // Cache for x values
165 std::vector<double> _x0, _x1, _x2;
166 std::vector<double> _mean, _sigma;
167 std::vector<double> _xDatLo, _xDatHi;
168 std::vector<double> _xDatLo3s, _xDatHi3s;
169
170 bool _netFluxZ{false};
171 double _nEventsBW{0.};
172 double _nEventsBMSW{0.};
173 std::vector<double> _xVarLo, _xVarHi;
175 std::map<Int_t,bool> _bpsIdcs;
176 std::map<Int_t, bool> _ibNoSort;
177 std::vector<Int_t> _sIdcs;
178 std::vector<Int_t> _bIdcs;
179 std::vector<Int_t> _bmsIdcs;
180
181 // Data for analytical integrals:
182 mutable std::map<std::pair<std::string,int>,BoxInfo*> _rangeBoxInfo ;
184
185 std::vector<Int_t> _idx;
186 double _minWeight{0.};
187 double _maxWeight{0.};
188 std::map<Int_t,double> _wMap;
189
192 TMatrixD* _rotMat{nullptr};
193 TVectorD* _sigmaR{nullptr};
194 TVectorD* _dx{nullptr};
195 double _sigmaAvgR{0.};
196
200
202
203 ClassDefOverride(RooNDKeysPdf, 2) // General N-dimensional non-parametric kernel estimation p.d.f
204};
205
206#endif
std::pair< Int_t, VecVecDouble::iterator > iiPair
std::vector< itPair > itVec
std::vector< iiPair > iiVec
std::pair< Int_t, VecTVecDouble::iterator > itPair
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
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
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:40
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
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...
RooDataSet is a container class to hold unbinned data.
Definition RooDataSet.h:57
Generic N-dimensional implementation of a kernel estimation p.d.f.
BoxInfo _fullBoxInfo
RooListProxy _rhoList
std::vector< double > _xVarLoM3s
TVectorD * _dx
std::map< Int_t, bool > _ibNoSort
std::vector< Int_t > _sIdcs
std::vector< std::vector< double > > _weights0
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
std::vector< std::vector< double > > * _weights
TVectorD * _sigmaR
void createPdf(bool firstCall, RooDataSet const &data)
evaluation order of constructor.
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
std::vector< double > _x
void initialize(RooDataSet const &data)
initialization
std::map< Int_t, double > _wMap
double _maxWeight
void sortDataIndices(BoxInfo *bi=nullptr)
sort entries, as needed for loopRange()
double _nEventsBMSW
std::vector< double > _xVarHi
void loadDataSet(bool firstCall, RooDataSet const &data)
copy the dataset and calculate some useful variables
std::vector< Int_t > _bIdcs
std::vector< TVectorD > _dataPtsR
void updateRho() const
std::vector< double > _mean
std::vector< double > _xVarLo
void calculateShell(BoxInfo *bi) const
determine points in +/- nSigma shell around the box determined by the variable ranges.
void calculateBandWidth()
std::vector< double > _xDatLo3s
std::vector< double > _x1
double _widthFactor
std::vector< std::vector< double > > _dataPts
double _sigmaAvgR
std::vector< double > _xVarHiM3s
std::vector< double > _x0
std::vector< double > _x2
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
RooArgSet _dataVars
RooListProxy _varList
TMatrixDSym * _corrMat
std::vector< Int_t > _bmsIdcs
void loadWeightSet(RooDataSet const &data)
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< Int_t > _idx
TObject * clone(const char *newname) const override
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
std::vector< std::vector< double > > _weights1
std::vector< double > _xDatHi3s
TString _options
std::vector< double > _xVarHiP3s
TMatrixD getWeights(const int &k) const
Return evaluated weights.
std::vector< double > _sigma
void mirrorDataSet()
determine mirror dataset.
void setOptions()
set the configuration
RooDataSet * createDatasetFromHist(const RooArgList &varList, const TH1 &hist) const
RooNDKeysPdf()=default
std::vector< std::string > _varName
void checkInitWeights() const
double _nEventsBW
TMatrixD * _rotMat
std::map< Int_t, bool > _bpsIdcs
TMatrixDSym * _covMat
double _minWeight
RooChangeTracker * _tracker
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:37
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:58
Mother of all ROOT objects.
Definition TObject.h:41
Basic string class.
Definition TString.h:139
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
std::vector< double > xVarHiM3s
std::vector< Int_t > bIdcs
std::vector< double > xVarHiP3s
std::vector< double > xVarLo
std::vector< double > xVarHi
std::map< Int_t, bool > bpsIdcs
std::vector< Int_t > sIdcs
std::vector< double > xVarLoM3s
std::vector< double > xVarLoP3s
std::vector< Int_t > bmsIdcs