Logo ROOT   6.16/01
Reference Guide
TKDEAdapter.cxx
Go to the documentation of this file.
1// @(#)root/gl:$Id$
2// Author: Timur Pocheptsov 28/07/2009
3
4/*************************************************************************
5 * Copyright (C) 1995-2009, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include <stdexcept>
13
14#include "TKDEAdapter.h"
15#include "TKDEFGT.h"
16#include "TError.h"
17#include "TGL5D.h"
18#include "TAxis.h"
19
20namespace Rgl {
21namespace Fgt {
22
23////////////////////////////////////////////////////////////////////////////////
24///Constructor. "Half-baked" object.
25
27 : fW(0), fH(0), fD(0),
28 fSliceSize(0),
29 fXMin(0.), fXStep(0.),
30 fYMin(0.), fYStep(0.),
31 fZMin(0.), fZStep(0.),
32 fDE(0),
33 fE(10.)
34{
35}
36
37////////////////////////////////////////////////////////////////////////////////
38///Set grid's dimensions.
39
41{
42 const TAxis *xA = dataSet->GetXAxis();
43 const Rgl::Range_t &xMinMax = dataSet->GetXRange();
44 const Double_t xRange = xMinMax.second - xMinMax.first;
45
46 const TAxis *yA = dataSet->GetYAxis();
47 const Rgl::Range_t &yMinMax = dataSet->GetYRange();
48 const Double_t yRange = yMinMax.second - yMinMax.first;
49
50 const TAxis *zA = dataSet->GetZAxis();
51 const Rgl::Range_t &zMinMax = dataSet->GetZRange();
52 const Double_t zRange = zMinMax.second - zMinMax.first;
53
54 fW = xA->GetNbins();
55 fH = yA->GetNbins();
56 fD = zA->GetNbins();
57
58 fSliceSize = fW * fH;
59
60 fXMin = (xA->GetBinLowEdge(1) - xMinMax.first) / xRange;
61 fXStep = (xA->GetBinUpEdge(xA->GetLast()) - xA->GetBinLowEdge(xA->GetFirst())) / (fW - 1) / xRange;
62
63 fYMin = (yA->GetBinLowEdge(1) - yMinMax.first) / yRange;
64 fYStep = (yA->GetBinUpEdge(yA->GetLast()) - yA->GetBinLowEdge(yA->GetFirst())) / (fH - 1) / yRange;
65
66 fZMin = (zA->GetBinLowEdge(1) - zMinMax.first) / zRange;
67 fZStep = (zA->GetBinCenter(zA->GetLast()) - zA->GetBinLowEdge(zA->GetFirst())) / (fD - 1) / zRange;
68}
69
70////////////////////////////////////////////////////////////////////////////////
71///e for kdefgt.
72
74{
75 fE = e;
76}
77
78////////////////////////////////////////////////////////////////////////////////
79///e for kdefgt.
80
82{
83 return fE;
84}
85
86////////////////////////////////////////////////////////////////////////////////
87///Number of cells along X.
88
90{
91 return fW;
92}
93
94////////////////////////////////////////////////////////////////////////////////
95///Number of cells along Y.
96
98{
99 return fH;
100}
101
102////////////////////////////////////////////////////////////////////////////////
103///Number of cells along Z.
104
106{
107 return fD;
108}
109
110////////////////////////////////////////////////////////////////////////////////
111///Set density estimator as a data source.
112
114{
115 fDE = de;
116}
117
118////////////////////////////////////////////////////////////////////////////////
119///Do some initialization and calculate densities.
120
122{
123 if (!fDE) {
124 Error("TKDEAdapter::FetchFirstSlices", "Density estimator is a null pointer."
125 " Set it correctly first.");
126 throw std::runtime_error("No density estimator.");
127 }
128
129 fGrid.resize(fD * fSliceSize * 3);//3 is the number of coordinates: xyz
130
131 //1D index into fGrid array.
132 UInt_t ind = 0;
133 //The first slice.
134 for(UInt_t k = 0; k < fD; ++k) {
135 for (UInt_t i = 0; i < fH; ++i) {
136 for (UInt_t j = 0; j < fW; ++j, ind += 3) {
137 fGrid[ind] = fXMin + j * fXStep;
138 fGrid[ind + 1] = fYMin + i * fYStep;
139 fGrid[ind + 2] = fZMin + k * fZStep;
140 }
141 }
142 }
143
144 fDensities.resize(fSliceSize * fD);
145 //Ok, now, we can estimate densities.
147}
148
149////////////////////////////////////////////////////////////////////////////////
150/// Get data at given position.
151
153{
154 const UInt_t ind = k * fSliceSize + j * fW + i;
155 return fDensities[ind];
156}
157
158////////////////////////////////////////////////////////////////////////////////
159/// Free grid and density vectors.
160
162{
163 vector_t().swap(fGrid);
164 vector_t().swap(fDensities);
165}
166
167}
168}
#define e(i)
Definition: RSha256.hxx:103
unsigned int UInt_t
Definition: RtypesCore.h:42
double Double_t
Definition: RtypesCore.h:55
float Float_t
Definition: RtypesCore.h:53
void Error(const char *location, const char *msgfmt,...)
TKDEAdapter()
Constructor. "Half-baked" object.
Definition: TKDEAdapter.cxx:26
void SetGeometry(const TGL5DDataSet *dataSet)
Set grid's dimensions.
Definition: TKDEAdapter.cxx:40
Float_t GetData(UInt_t i, UInt_t j, UInt_t k) const
Get data at given position.
UInt_t GetH() const
Number of cells along Y.
Definition: TKDEAdapter.cxx:97
void SetDataSource(const TKDEFGT *dataSource)
Set density estimator as a data source.
void SetE(Double_t e)
e for kdefgt.
Definition: TKDEAdapter.cxx:73
void FetchDensities() const
Do some initialization and calculate densities.
UInt_t GetD() const
Number of cells along Z.
std::vector< Double_t > vector_t
Definition: TKDEAdapter.h:62
const TKDEFGT * fDE
Definition: TKDEAdapter.h:77
void FreeVectors()
Free grid and density vectors.
UInt_t GetW() const
Number of cells along X.
Definition: TKDEAdapter.cxx:89
Double_t GetE() const
e for kdefgt.
Definition: TKDEAdapter.cxx:81
Class to manage histogram axis.
Definition: TAxis.h:30
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition: TAxis.cxx:464
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
Definition: TAxis.cxx:504
Int_t GetLast() const
Return last bin on the axis i.e.
Definition: TAxis.cxx:455
Int_t GetNbins() const
Definition: TAxis.h:121
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
Definition: TAxis.cxx:514
Int_t GetFirst() const
Return first bin on the axis i.e.
Definition: TAxis.cxx:444
TAxis * GetZAxis() const
Z axis for plot.
Definition: TGL5D.cxx:204
const Rgl::Range_t & GetZRange() const
V3 range (Z).
Definition: TGL5D.cxx:228
const Rgl::Range_t & GetYRange() const
V2 range (Y).
Definition: TGL5D.cxx:220
TAxis * GetYAxis() const
Y axis for plot.
Definition: TGL5D.cxx:196
TAxis * GetXAxis() const
X axis for plot.
Definition: TGL5D.cxx:188
const Rgl::Range_t & GetXRange() const
V1 range (X).
Definition: TGL5D.cxx:212
void Predict(const std::vector< Double_t > &targets, std::vector< Double_t > &densities, Double_t e) const
Calculate densities.
Definition: TKDEFGT.cxx:388
std::pair< Double_t, Double_t > Range_t
Definition: TGLUtil.h:1193