Logo ROOT   6.14/05
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 }
const Rgl::Range_t & GetYRange() const
V2 range (Y).
Definition: TGL5D.cxx:220
virtual Bool_t IsString(Int_t oper) const
Return true if the expression at the index &#39;oper&#39; is to be treated as as string.
const Double_t * fV5
Definition: TGL5D.h:80
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:854
long long Long64_t
Definition: RtypesCore.h:69
3-D histogram with a float per channel (see TH1 documentation)}
Definition: TH3.h:267
std::unique_ptr< TGLHistPainter > fPainter
Definition: TGL5D.h:101
const char Option_t
Definition: RtypesCore.h:62
std::pair< Double_t, Double_t > Range_t
Definition: TGLUtil.h:1193
TAxis fYAxis
Definition: TGL5D.h:96
Double_t V3ToUnitCube(Double_t v3) const
V3 to unit cube.
Definition: TGL5D.cxx:260
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:168
int Int_t
Definition: RtypesCore.h:41
void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Action.
Definition: TGL5D.cxx:110
virtual void Copy(TObject &axis) const
Copy axis structure to another axis.
Definition: TAxis.cxx:208
Short_t Abs(Short_t d)
Definition: TMathBase.h:108
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:694
if object in a list can be deleted
Definition: TObject.h:58
virtual Long64_t GetSelectedRows()
Definition: TTree.h:434
TTreeFormula * GetVar(Int_t i)
Definition: TTree.h:444
const Rgl::Range_t & GetZRange() const
V3 range (Z).
Definition: TGL5D.cxx:228
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
Bool_t fV4IsString
Definition: TGL5D.h:99
Rgl::Range_t fV1MinMax
Definition: TGL5D.h:84
Double_t V1(UInt_t ind) const
V1 from sub-range, converted to unit cube.
Definition: TGL5D.cxx:164
TGL5DPainter * GetRealPainter() const
Get access to painter (for GUI-editor).
Definition: TGL5D.cxx:135
Double_t fV3Range
Definition: TGL5D.h:89
Rgl::Range_t fV5MinMax
Definition: TGL5D.h:91
const Double_t * fV2
Definition: TGL5D.h:77
const Double_t * fV3
Definition: TGL5D.h:78
void SelectPoints(Double_t v4Level, Double_t range)
"Select" sub-range from source data
Definition: TGL5D.cxx:144
const Rgl::Range_t & GetXRange() const
V1 range (X).
Definition: TGL5D.cxx:212
TAxis * GetYAxis() const
Y axis for plot.
Definition: TGL5D.cxx:196
Double_t V2(UInt_t ind) const
V2 from sub-range, converted to unit cube.
Definition: TGL5D.cxx:172
Class to manage histogram axis.
Definition: TAxis.h:30
Int_t DistancetoPrimitive(Int_t px, Int_t py)
Check, if the object is under cursor.
Definition: TGL5D.cxx:102
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
const Rgl::Range_t & GetV4Range() const
V4 range.
Definition: TGL5D.cxx:236
Rgl::Range_t fV3MinMax
Definition: TGL5D.h:88
TAxis * GetYaxis()
Definition: TH1.h:316
const Double_t * fV1
Definition: TGL5D.h:76
Rgl::Range_t fV2MinMax
Definition: TGL5D.h:86
Rgl::Range_t fV4MinMax
Definition: TGL5D.h:90
const Bool_t kFALSE
Definition: RtypesCore.h:88
Double_t V2ToUnitCube(Double_t v2) const
V2 to unit cube.
Definition: TGL5D.cxx:252
#define ClassImp(name)
Definition: Rtypes.h:359
double Double_t
Definition: RtypesCore.h:55
void Paint(Option_t *option)
Paint.
Definition: TGL5D.cxx:127
TGL5DPainter implements "gl5d" option for TTree::Draw.
Definition: TGL5DPainter.h:32
Long64_t fNP
Definition: TGL5D.h:75
Double_t fV2Range
Definition: TGL5D.h:87
TAxis fXAxis
Definition: TGL5D.h:95
TAxis * GetZaxis()
Definition: TH1.h:317
The histogram painter class using OpenGL.
virtual Double_t * GetVal(Int_t i)
Definition: TTree.h:454
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:200
TAxis fZAxis
Definition: TGL5D.h:97
char * GetObjectInfo(Int_t px, Int_t py) const
Info for status bar.
Definition: TGL5D.cxx:118
Definition: tree.py:1
A TTree object has a header with a name and a title.
Definition: TTree.h:70
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
Definition: TAxis.cxx:717
std::vector< UInt_t > fIndices
Definition: TGL5D.h:103
Double_t V1ToUnitCube(Double_t v1) const
V1 to unit cube.
Definition: TGL5D.cxx:244
TGL5DDataSet(TTree *inputData)
Constructor.
Definition: TGL5D.cxx:37
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:315
Double_t fV1Range
Definition: TGL5D.h:85
TAxis * GetXAxis() const
X axis for plot.
Definition: TGL5D.cxx:188
const Double_t * fV4
Definition: TGL5D.h:79
TAxis * GetZAxis() const
Z axis for plot.
Definition: TGL5D.cxx:204
Double_t V3(UInt_t ind) const
V3 from sub-range, converted to unit cube.
Definition: TGL5D.cxx:180
UInt_t SelectedSize() const
Size of selected sub-range.
Definition: TGL5D.cxx:156