Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGL5D.cxx
Go to the documentation of this file.
1// @(#)root/gl:$Id$
2// Author: Timur Pocheptsov 2009
3/*************************************************************************
4 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10#include <memory>
11#include <stdexcept>
12
13#include "TTreeFormula.h"
14#include "TTree.h"
15#include "TMath.h"
16#include "TH3.h"
17
18#include "TGLPlotCamera.h"
19#include "TGL5DPainter.h"
20#include "TGL5D.h"
21
23
24/** \class TGL5DDataSet
25\ingroup opengl
26*/
27
28namespace {
29
30void FindRange(Long64_t size, const Double_t *src, Rgl::Range_t &range);
31
32}
33
34////////////////////////////////////////////////////////////////////////////////
35///Constructor. Reads data from TTree,
36///estimates ranges, creates a painter.
37
39 : TNamed("TGL5DataSet", "TGL5DataSet"),
40 fNP(0),
41 fV1(nullptr), fV2(nullptr), fV3(nullptr), fV4(nullptr), fV5(nullptr),
42 fV1Range(1.), fV2Range(1.), fV3Range(1.),
43 fV4IsString(kFALSE)
44{
45 if (!tree) {
46 Error("TGL5Data", "Null pointer tree.");
47 throw std::runtime_error("");
48 }
49
50 fNP = tree->GetSelectedRows();
51
52 Info("TGL5DDataSet", "Number of selected rows: %d", Int_t(fNP)) ;
53 //Now, let's access the data and find ranges.
54 fV1 = tree->GetVal(0);
55 fV2 = tree->GetVal(1);
56 fV3 = tree->GetVal(2);
57 fV4 = tree->GetVal(3);
58 fV5 = tree->GetVal(4);
59 //
60 fV4IsString = tree->GetVar(3)->IsString();
61 //
62 if (!fV1 || !fV2 || !fV3 || !fV4 || !fV5) {
63 Error("TGL5DDataSet", "One or all of vN is a null pointer.");
64 throw std::runtime_error("");
65 }
66 //
67 FindRange(fNP, fV1, fV1MinMax);
68 FindRange(fNP, fV2, fV2MinMax);
69 FindRange(fNP, fV3, fV3MinMax);
70 FindRange(fNP, fV4, fV4MinMax);
71 FindRange(fNP, fV5, fV5MinMax);
72 //
73 const Double_t v1Add = 0.1 * (fV1MinMax.second - fV1MinMax.first);
74 const Double_t v2Add = 0.1 * (fV2MinMax.second - fV2MinMax.first);
75 const Double_t v3Add = 0.1 * (fV3MinMax.second - fV3MinMax.first);
76 //Adjust ranges.
77 fV1MinMax.first -= v1Add, fV1MinMax.second += v1Add;
78 fV1Range = fV1MinMax.second - fV1MinMax.first;
79 fV2MinMax.first -= v2Add, fV2MinMax.second += v2Add;
80 fV2Range = fV2MinMax.second - fV2MinMax.first;
81 fV3MinMax.first -= v3Add, fV3MinMax.second += v3Add;
82 fV3Range = fV3MinMax.second - fV3MinMax.first;
83 //Set axes.
84 TH3F hist("tmp", "tmp", 2, -1., 1., 2, -1., 1., 2, -1., 1.);
85 //TAxis has a lot of attributes, defaults, set by ctor,
86 //are not enough to be correctly painted by TGaxis object.
87 //To simplify their initialization - I use temporary histogram.
88 hist.GetXaxis()->Copy(fXAxis);
89 hist.GetYaxis()->Copy(fYAxis);
90 hist.GetZaxis()->Copy(fZAxis);
91
92 fXAxis.Set(kDefaultNB, fV1MinMax.first, fV1MinMax.second);
93 fYAxis.Set(kDefaultNB, fV2MinMax.first, fV2MinMax.second);
94 fZAxis.Set(kDefaultNB, fV3MinMax.first, fV3MinMax.second);
95
96 fPainter = std::make_unique<TGLHistPainter>(this);
97 SetBit(kCanDelete);//TPad will delete this object when closed.
98}
99
100////////////////////////////////////////////////////////////////////////////////
101///Check, if the object is under cursor.
102
104{
105 return fPainter->DistancetoPrimitive(px, py);
106}
107
108////////////////////////////////////////////////////////////////////////////////
109///Action.
110
112{
113 return fPainter->ExecuteEvent(event, px, py);
114}
115
116////////////////////////////////////////////////////////////////////////////////
117///Info for status bar.
118
119char *TGL5DDataSet::GetObjectInfo(Int_t /*px*/, Int_t /*py*/) const
120{
121 static char mess[] = {"5d data set"};
122 return mess;
123}
124
125////////////////////////////////////////////////////////////////////////////////
126///Paint.
127
129{
130 fPainter->Paint("dummyoption");
131}
132
133////////////////////////////////////////////////////////////////////////////////
134///Get access to painter (for GUI-editor).
135
137{
138 return static_cast<TGL5DPainter *>(fPainter->GetRealPainter());
139}
140
141////////////////////////////////////////////////////////////////////////////////
142///"Select" sub-range from source data
143///- remember indices of "good" points.
144
146{
147 fIndices.clear();
148
149 for (Int_t i = 0; i < fNP; ++i)
150 if (TMath::Abs(fV4[i] - v4Level) < range)
151 fIndices.push_back(i);
152}
153
154////////////////////////////////////////////////////////////////////////////////
155///Size of selected sub-range.
156
158{
159 return UInt_t(fIndices.size());
160}
161
162////////////////////////////////////////////////////////////////////////////////
163///V1 from sub-range, converted to unit cube.
164
166{
167 return V1ToUnitCube(fV1[fIndices[ind]]);
168}
169
170////////////////////////////////////////////////////////////////////////////////
171///V2 from sub-range, converted to unit cube.
172
174{
175 return V2ToUnitCube(fV2[fIndices[ind]]);
176}
177
178////////////////////////////////////////////////////////////////////////////////
179///V3 from sub-range, converted to unit cube.
180
182{
183 return V3ToUnitCube(fV3[fIndices[ind]]);
184}
185
186////////////////////////////////////////////////////////////////////////////////
187///X axis for plot.
188
190{
191 return &fXAxis;
192}
193
194////////////////////////////////////////////////////////////////////////////////
195///Y axis for plot.
196
198{
199 return &fYAxis;
200}
201
202////////////////////////////////////////////////////////////////////////////////
203///Z axis for plot.
204
206{
207 return &fZAxis;
208}
209
210////////////////////////////////////////////////////////////////////////////////
211///V1 range (X).
212
214{
215 return fV1MinMax;
216}
217
218////////////////////////////////////////////////////////////////////////////////
219///V2 range (Y).
220
222{
223 return fV2MinMax;
224}
225
226////////////////////////////////////////////////////////////////////////////////
227///V3 range (Z).
228
230{
231 return fV3MinMax;
232}
233
234////////////////////////////////////////////////////////////////////////////////
235///V4 range.
236
238{
239 return fV4MinMax;
240}
241
242////////////////////////////////////////////////////////////////////////////////
243///V1 to unit cube.
244
246{
247 return (v1 - fV1MinMax.first) / fV1Range;
248}
249
250////////////////////////////////////////////////////////////////////////////////
251///V2 to unit cube.
252
254{
255 return (v2 - fV2MinMax.first) / fV2Range;
256}
257
258////////////////////////////////////////////////////////////////////////////////
259///V3 to unit cube.
260
262{
263 return (v3 - fV3MinMax.first) / fV3Range;
264}
265
266namespace {
267
268////////////////////////////////////////////////////////////////////////////////
269///Find both min and max on a range in one pass through sequence.
270
271void FindRange(Long64_t size, const Double_t *src, Rgl::Range_t &range)
272{
273 range.first = src[0];
274 range.second = src[0];
275
276 for (Long64_t i = 1; i < size; ++i) {
277 range.first = TMath::Min(range.first, src[i]);
278 range.second = TMath::Max(range.second, src[i]);
279 }
280}
281
282}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
double Double_t
Definition RtypesCore.h:59
long long Long64_t
Definition RtypesCore.h:69
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:382
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
Class to manage histogram axis.
Definition TAxis.h:31
void Copy(TObject &axis) const override
Copy axis structure to another axis.
Definition TAxis.cxx:216
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
Definition TAxis.cxx:794
TAxis * GetZAxis() const
Z axis for plot.
Definition TGL5D.cxx:205
const Rgl::Range_t & GetZRange() const
V3 range (Z).
Definition TGL5D.cxx:229
void SelectPoints(Double_t v4Level, Double_t range)
"Select" sub-range from source data
Definition TGL5D.cxx:145
Double_t V3ToUnitCube(Double_t v3) const
V3 to unit cube.
Definition TGL5D.cxx:261
Rgl::Range_t fV4MinMax
Definition TGL5D.h:90
const Double_t * fV4
Definition TGL5D.h:79
Double_t fV3Range
Definition TGL5D.h:89
std::vector< UInt_t > fIndices
Definition TGL5D.h:103
Rgl::Range_t fV2MinMax
Definition TGL5D.h:86
char * GetObjectInfo(Int_t px, Int_t py) const override
Info for status bar.
Definition TGL5D.cxx:119
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Check, if the object is under cursor.
Definition TGL5D.cxx:103
const Double_t * fV1
Definition TGL5D.h:76
const Double_t * fV2
Definition TGL5D.h:77
const Rgl::Range_t & GetYRange() const
V2 range (Y).
Definition TGL5D.cxx:221
TGL5DPainter * GetRealPainter() const
Get access to painter (for GUI-editor).
Definition TGL5D.cxx:136
TAxis fYAxis
Definition TGL5D.h:96
TAxis * GetYAxis() const
Y axis for plot.
Definition TGL5D.cxx:197
Rgl::Range_t fV1MinMax
Definition TGL5D.h:84
Double_t V2ToUnitCube(Double_t v2) const
V2 to unit cube.
Definition TGL5D.cxx:253
TAxis * GetXAxis() const
X axis for plot.
Definition TGL5D.cxx:189
Double_t fV1Range
Definition TGL5D.h:85
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Action.
Definition TGL5D.cxx:111
TGL5DDataSet(TTree *inputData)
Constructor.
Definition TGL5D.cxx:38
Bool_t fV4IsString
Definition TGL5D.h:99
Double_t V1ToUnitCube(Double_t v1) const
V1 to unit cube.
Definition TGL5D.cxx:245
const Double_t * fV5
Definition TGL5D.h:80
Rgl::Range_t fV5MinMax
Definition TGL5D.h:91
Long64_t fNP
Definition TGL5D.h:75
std::unique_ptr< TGLHistPainter > fPainter
Definition TGL5D.h:101
@ kDefaultNB
Definition TGL5D.h:32
const Rgl::Range_t & GetXRange() const
V1 range (X).
Definition TGL5D.cxx:213
const Rgl::Range_t & GetV4Range() const
V4 range.
Definition TGL5D.cxx:237
TAxis fXAxis
Definition TGL5D.h:95
Double_t fV2Range
Definition TGL5D.h:87
TAxis fZAxis
Definition TGL5D.h:97
void Paint(Option_t *option) override
Paint.
Definition TGL5D.cxx:128
UInt_t SelectedSize() const
Size of selected sub-range.
Definition TGL5D.cxx:157
Rgl::Range_t fV3MinMax
Definition TGL5D.h:88
Double_t V1(UInt_t ind) const
V1 from sub-range, converted to unit cube.
Definition TGL5D.cxx:165
Double_t V2(UInt_t ind) const
V2 from sub-range, converted to unit cube.
Definition TGL5D.cxx:173
Double_t V3(UInt_t ind) const
V3 from sub-range, converted to unit cube.
Definition TGL5D.cxx:181
const Double_t * fV3
Definition TGL5D.h:78
TGL5DPainter implements "gl5d" option for TTree::Draw.
TAxis * GetZaxis()
Definition TH1.h:326
TAxis * GetXaxis()
Definition TH1.h:324
TAxis * GetYaxis()
Definition TH1.h:325
3-D histogram with a float per channel (see TH1 documentation)
Definition TH3.h:317
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:786
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:993
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:62
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:967
A TTree represents a columnar dataset.
Definition TTree.h:79
std::pair< Double_t, Double_t > Range_t
Definition TGLUtil.h:1202
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:250
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:198
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123