Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
21 ClassImp(TGL5DDataSet);
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 
37 TGL5DDataSet::TGL5DDataSet(TTree *tree)
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 
102 Int_t TGL5DDataSet::DistancetoPrimitive(Int_t px, Int_t py)
103 {
104  return fPainter->DistancetoPrimitive(px, py);
105 }
106 
107 ////////////////////////////////////////////////////////////////////////////////
108 ///Action.
109 
110 void TGL5DDataSet::ExecuteEvent(Int_t event, Int_t px, Int_t py)
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 
135 TGL5DPainter *TGL5DDataSet::GetRealPainter()const
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 
144 void TGL5DDataSet::SelectPoints(Double_t v4Level, Double_t range)
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 
156 UInt_t TGL5DDataSet::SelectedSize()const
157 {
158  return UInt_t(fIndices.size());
159 }
160 
161 ////////////////////////////////////////////////////////////////////////////////
162 ///V1 from sub-range, converted to unit cube.
163 
164 Double_t TGL5DDataSet::V1(UInt_t ind)const
165 {
166  return V1ToUnitCube(fV1[fIndices[ind]]);
167 }
168 
169 ////////////////////////////////////////////////////////////////////////////////
170 ///V2 from sub-range, converted to unit cube.
171 
172 Double_t TGL5DDataSet::V2(UInt_t ind)const
173 {
174  return V2ToUnitCube(fV2[fIndices[ind]]);
175 }
176 
177 ////////////////////////////////////////////////////////////////////////////////
178 ///V3 from sub-range, converted to unit cube.
179 
180 Double_t TGL5DDataSet::V3(UInt_t ind)const
181 {
182  return V3ToUnitCube(fV3[fIndices[ind]]);
183 }
184 
185 ////////////////////////////////////////////////////////////////////////////////
186 ///X axis for plot.
187 
188 TAxis *TGL5DDataSet::GetXAxis()const
189 {
190  return &fXAxis;
191 }
192 
193 ////////////////////////////////////////////////////////////////////////////////
194 ///Y axis for plot.
195 
196 TAxis *TGL5DDataSet::GetYAxis()const
197 {
198  return &fYAxis;
199 }
200 
201 ////////////////////////////////////////////////////////////////////////////////
202 ///Z axis for plot.
203 
204 TAxis *TGL5DDataSet::GetZAxis()const
205 {
206  return &fZAxis;
207 }
208 
209 ////////////////////////////////////////////////////////////////////////////////
210 ///V1 range (X).
211 
212 const Rgl::Range_t &TGL5DDataSet::GetXRange()const
213 {
214  return fV1MinMax;
215 }
216 
217 ////////////////////////////////////////////////////////////////////////////////
218 ///V2 range (Y).
219 
220 const Rgl::Range_t &TGL5DDataSet::GetYRange()const
221 {
222  return fV2MinMax;
223 }
224 
225 ////////////////////////////////////////////////////////////////////////////////
226 ///V3 range (Z).
227 
228 const Rgl::Range_t &TGL5DDataSet::GetZRange()const
229 {
230  return fV3MinMax;
231 }
232 
233 ////////////////////////////////////////////////////////////////////////////////
234 ///V4 range.
235 
236 const Rgl::Range_t &TGL5DDataSet::GetV4Range()const
237 {
238  return fV4MinMax;
239 }
240 
241 ////////////////////////////////////////////////////////////////////////////////
242 ///V1 to unit cube.
243 
244 Double_t TGL5DDataSet::V1ToUnitCube(Double_t v1)const
245 {
246  return (v1 - fV1MinMax.first) / fV1Range;
247 }
248 
249 ////////////////////////////////////////////////////////////////////////////////
250 ///V2 to unit cube.
251 
252 Double_t TGL5DDataSet::V2ToUnitCube(Double_t v2)const
253 {
254  return (v2 - fV2MinMax.first) / fV2Range;
255 }
256 
257 ////////////////////////////////////////////////////////////////////////////////
258 ///V3 to unit cube.
259 
260 Double_t TGL5DDataSet::V3ToUnitCube(Double_t v3)const
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 }