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