]>
Commit | Line | Data |
---|---|---|
5a5a1232 | 1 | // $Header$ |
2 | ||
3 | #include "PointSet.h" | |
4 | ||
5 | #include <Reve/RGTopFrame.h> | |
6 | ||
7 | #include <TTree.h> | |
db75e62a | 8 | #include <TTreePlayer.h> |
5a5a1232 | 9 | #include <TF3.h> |
10 | ||
11 | #include <TColor.h> | |
12 | #include <TCanvas.h> | |
13 | ||
14 | using namespace Reve; | |
15 | ||
16 | //______________________________________________________________________ | |
17 | // PointSet | |
18 | // | |
19 | ||
20 | ClassImp(PointSet) | |
21 | ||
db75e62a | 22 | PointSet::PointSet(Int_t n_points, TreeVarType_e tv_type) : |
db75e62a | 23 | RenderElement(fMarkerColor), |
7d42b6c2 | 24 | TPointSet3D(n_points), |
265ecb21 | 25 | TPointSelectorConsumer(tv_type), |
26 | ||
27 | fTitle() | |
5a5a1232 | 28 | { |
29 | fMarkerStyle = 20; | |
30 | } | |
31 | ||
db75e62a | 32 | PointSet::PointSet(const Text_t* name, Int_t n_points, TreeVarType_e tv_type) : |
db75e62a | 33 | RenderElement(fMarkerColor), |
7d42b6c2 | 34 | TPointSet3D(n_points), |
265ecb21 | 35 | TPointSelectorConsumer(tv_type), |
36 | ||
37 | fTitle() | |
5a5a1232 | 38 | { |
39 | fMarkerStyle = 20; | |
40 | SetName(name); | |
41 | } | |
42 | ||
db75e62a | 43 | PointSet::PointSet(const Text_t* name, TTree* tree, TreeVarType_e tv_type) : |
db75e62a | 44 | RenderElement(fMarkerColor), |
7d42b6c2 | 45 | TPointSet3D(tree->GetSelectedRows()), |
265ecb21 | 46 | TPointSelectorConsumer(tv_type), |
47 | ||
48 | fTitle() | |
5a5a1232 | 49 | { |
50 | static const Exc_t eH("PointSet::PointSet "); | |
51 | ||
52 | fMarkerStyle = 20; | |
53 | SetName(name); | |
5a5a1232 | 54 | |
db75e62a | 55 | TTreePlayer* tp = dynamic_cast<TTreePlayer*>(tree->GetPlayer()); |
56 | TakeAction(dynamic_cast<TSelectorDraw*>(tp->GetSelector())); | |
5a5a1232 | 57 | } |
58 | ||
59 | /**************************************************************************/ | |
60 | ||
61 | void PointSet::Reset(Int_t n_points) | |
62 | { | |
63 | delete [] fP; fP = 0; | |
64 | fN = n_points; | |
65 | if(fN) fP = new Float_t [3*fN]; | |
66 | memset(fP, 0, 3*fN*sizeof(Float_t)); | |
67 | fLastPoint = -1; | |
426530cc | 68 | ClearIds(); |
5a5a1232 | 69 | ResetBBox(); |
70 | } | |
71 | ||
db75e62a | 72 | Int_t PointSet::GrowFor(Int_t n_points) |
73 | { | |
74 | // Resizes internal array to allow additional n_points to be stored. | |
75 | // Returns the old size which is also the location where one can | |
76 | // start storing new data. | |
77 | // The caller is *obliged* to fill the new point slots. | |
78 | ||
79 | Int_t old_size = Size(); | |
80 | Int_t new_size = old_size + n_points; | |
81 | SetPoint(new_size - 1, 0, 0, 0); | |
82 | return old_size; | |
83 | } | |
84 | ||
5a5a1232 | 85 | /**************************************************************************/ |
86 | ||
87 | void PointSet::Paint(Option_t* option) | |
88 | { | |
5b457dfa | 89 | if(fRnrSelf == kFALSE) return; |
5a5a1232 | 90 | |
91 | TPointSet3D::Paint(option); | |
92 | } | |
93 | ||
db75e62a | 94 | /**************************************************************************/ |
95 | ||
96 | void PointSet::TakeAction(TSelectorDraw* sel) | |
97 | { | |
98 | static const Exc_t eH("PointSet::TakeAction "); | |
99 | ||
100 | if(sel == 0) | |
101 | throw(eH + "selector is <null>."); | |
102 | ||
103 | Int_t n = sel->GetNfill(); | |
104 | Int_t beg = GrowFor(n); | |
105 | Float_t *p = fP + 3*beg; | |
106 | ||
107 | // printf("PointSet::TakeAction beg=%d n=%d size=%d\n", beg, n, Size()); | |
108 | ||
109 | Double_t *vx = sel->GetV1(), *vy = sel->GetV2(), *vz = sel->GetV3(); | |
110 | ||
111 | switch(fSourceCS) { | |
112 | case TVT_XYZ: | |
113 | while(n-- > 0) { | |
114 | p[0] = *vx; p[1] = *vy; p[2] = *vz; | |
115 | p += 3; | |
116 | ++vx; ++vy; ++vz; | |
117 | } | |
118 | break; | |
119 | case TVT_RPhiZ: | |
120 | while(n-- > 0) { | |
121 | p[0] = *vx * TMath::Cos(*vy); p[1] = *vx * TMath::Sin(*vy); p[2] = *vz; | |
122 | p += 3; | |
123 | ++vx; ++vy; ++vz; | |
124 | } | |
125 | break; | |
126 | default: | |
127 | throw(eH + "unknown tree variable type."); | |
128 | } | |
129 | } | |
130 | ||
5a5a1232 | 131 | /**************************************************************************/ |
132 | /**************************************************************************/ | |
133 | ||
134 | //______________________________________________________________________ | |
135 | // PointSetArray | |
136 | // | |
137 | ||
138 | ClassImp(PointSetArray) | |
139 | ||
140 | PointSetArray::PointSetArray(const Text_t* name, | |
d15308aa | 141 | const Text_t* title) : |
5b457dfa | 142 | RenderElement(fMarkerColor), |
7d42b6c2 | 143 | TNamed(name, title), |
265ecb21 | 144 | |
145 | fBins(0), fDefPointSetCapacity(128), fNBins(0), | |
146 | fMin(0), fCurMin(0), fMax(0), fCurMax(0), | |
147 | fBinWidth(0), | |
148 | fQuantName() | |
e4f80cd8 | 149 | {} |
5a5a1232 | 150 | |
151 | PointSetArray::~PointSetArray() | |
152 | { | |
73ecdbca | 153 | // Destructor: deletes the fBins array. Actual removal of |
5b457dfa | 154 | // elements done by RenderElement. |
73ecdbca | 155 | |
156 | // printf("PointSetArray::~PointSetArray()\n"); | |
7d42b6c2 | 157 | delete [] fBins; fBins = 0; |
158 | } | |
159 | ||
5b457dfa | 160 | void PointSetArray::Paint(Option_t* option) |
161 | { | |
162 | if(fRnrSelf) { | |
163 | for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) { | |
164 | if((*i)->GetRnrSelf()) | |
165 | (*i)->GetObject()->Paint(option); | |
166 | } | |
167 | } | |
168 | } | |
169 | ||
7d42b6c2 | 170 | void PointSetArray::RemoveElementLocal(RenderElement* el) |
171 | { | |
172 | for(Int_t i=0; i<fNBins; ++i) { | |
173 | if(fBins[i] == el) { | |
174 | fBins[i] = 0; | |
175 | break; | |
176 | } | |
177 | } | |
5b457dfa | 178 | RenderElement::RemoveElementLocal(el); |
7d42b6c2 | 179 | } |
180 | ||
181 | void PointSetArray::RemoveElements() | |
182 | { | |
183 | delete [] fBins; fBins = 0; | |
5b457dfa | 184 | RenderElement::RemoveElements(); |
5a5a1232 | 185 | } |
186 | ||
187 | /**************************************************************************/ | |
d15308aa | 188 | |
189 | void PointSetArray::SetMarkerColor(Color_t tcolor) | |
190 | { | |
e6ac3950 | 191 | for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) { |
d15308aa | 192 | TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject()); |
193 | if(m && m->GetMarkerColor() == fMarkerColor) | |
194 | m->SetMarkerColor(tcolor); | |
195 | } | |
196 | TAttMarker::SetMarkerColor(tcolor); | |
197 | } | |
198 | ||
199 | void PointSetArray::SetMarkerStyle(Style_t mstyle) | |
200 | { | |
e6ac3950 | 201 | for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) { |
d15308aa | 202 | TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject()); |
203 | if(m && m->GetMarkerStyle() == fMarkerStyle) | |
204 | m->SetMarkerStyle(mstyle); | |
205 | } | |
206 | TAttMarker::SetMarkerStyle(mstyle); | |
207 | } | |
208 | ||
209 | void PointSetArray::SetMarkerSize(Size_t msize) | |
210 | { | |
e6ac3950 | 211 | for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) { |
d15308aa | 212 | TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject()); |
213 | if(m && m->GetMarkerSize() == fMarkerSize) | |
214 | m->SetMarkerSize(msize); | |
215 | } | |
216 | TAttMarker::SetMarkerSize(msize); | |
217 | } | |
218 | ||
5a5a1232 | 219 | /**************************************************************************/ |
220 | ||
db75e62a | 221 | void PointSetArray::TakeAction(TSelectorDraw* sel) |
222 | { | |
223 | static const Exc_t eH("PointSetArray::TakeAction "); | |
224 | ||
225 | if(sel == 0) | |
226 | throw(eH + "selector is <null>."); | |
227 | ||
228 | Int_t n = sel->GetNfill(); | |
229 | ||
230 | // printf("PointSetArray::TakeAction n=%d\n", n); | |
231 | ||
232 | Double_t *vx = sel->GetV1(), *vy = sel->GetV2(), *vz = sel->GetV3(); | |
233 | Double_t *qq = sel->GetV4(); | |
234 | ||
235 | if(qq == 0) | |
236 | throw(eH + "requires 4-d varexp."); | |
237 | ||
238 | switch(fSourceCS) { | |
239 | case TVT_XYZ: | |
240 | while(n-- > 0) { | |
241 | Fill(*vx, *vy, *vz, *qq); | |
242 | ++vx; ++vy; ++vz; ++qq; | |
243 | } | |
244 | break; | |
245 | case TVT_RPhiZ: | |
246 | while(n-- > 0) { | |
247 | Fill(*vx * TMath::Cos(*vy), *vx * TMath::Sin(*vy), *vz, *qq); | |
248 | ++vx; ++vy; ++vz; ++qq; | |
249 | } | |
250 | break; | |
251 | default: | |
252 | throw(eH + "unknown tree variable type."); | |
253 | } | |
254 | } | |
255 | ||
256 | /**************************************************************************/ | |
257 | ||
7d42b6c2 | 258 | void PointSetArray::InitBins(const Text_t* quant_name, |
259 | Int_t nbins, Double_t min, Double_t max, | |
260 | Bool_t addRe) | |
5a5a1232 | 261 | { |
e4f80cd8 | 262 | static const Exc_t eH("PointSetArray::InitBins "); |
263 | ||
264 | if(nbins < 1) throw(eH + "nbins < 1."); | |
265 | if(min > max) throw(eH + "min > max."); | |
266 | ||
7d42b6c2 | 267 | RemoveElements(); |
e4f80cd8 | 268 | |
5a5a1232 | 269 | fQuantName = quant_name; |
270 | fNBins = nbins; | |
271 | fMin = fCurMin = min; | |
272 | fMax = fCurMax = max; | |
273 | fBinWidth = (fMax - fMin)/fNBins; | |
274 | ||
275 | fBins = new Reve::PointSet*[fNBins]; | |
276 | for(Int_t i=0; i<fNBins; ++i) { | |
277 | fBins[i] = new Reve::PointSet | |
e4f80cd8 | 278 | (Form("Slice %d [%4.3lf, %4.3lf]", i, fMin + i*fBinWidth, fMin + (i+1)*fBinWidth), |
279 | fDefPointSetCapacity); | |
280 | fBins[i]->SetMarkerColor(fMarkerColor); | |
281 | fBins[i]->SetMarkerStyle(fMarkerStyle); | |
282 | fBins[i]->SetMarkerSize(fMarkerSize); | |
7d42b6c2 | 283 | if(addRe) |
284 | gReve->AddRenderElement(this, fBins[i]); | |
285 | else | |
286 | AddElement(fBins[i]); | |
5a5a1232 | 287 | } |
288 | } | |
289 | ||
db75e62a | 290 | void PointSetArray::Fill(Double_t x, Double_t y, Double_t z, Double_t quant) |
5a5a1232 | 291 | { |
292 | Int_t bin = Int_t( (quant - fMin)/fBinWidth ); | |
7d42b6c2 | 293 | if(bin >= 0 && bin < fNBins && fBins[bin] != 0) |
5a5a1232 | 294 | fBins[bin]->SetNextPoint(x, y, z); |
295 | } | |
296 | ||
d15308aa | 297 | void PointSetArray::CloseBins() |
5a5a1232 | 298 | { |
299 | for(Int_t i=0; i<fNBins; ++i) { | |
7d42b6c2 | 300 | if(fBins[i] != 0) { |
301 | // HACK! PolyMarker3D does half-management of array size. | |
302 | // In fact, the error is mine, in pointset3d(gl) i use fN instead of Size(). | |
303 | // Fixed in my root, but not elsewhere. | |
304 | fBins[i]->fN = fBins[i]->fLastPoint; | |
305 | ||
306 | fBins[i]->ComputeBBox(); | |
307 | } | |
5a5a1232 | 308 | } |
309 | } | |
310 | ||
311 | /**************************************************************************/ | |
312 | ||
313 | void PointSetArray::SetRange(Double_t min, Double_t max) | |
314 | { | |
315 | using namespace TMath; | |
316 | ||
317 | fCurMin = min; fCurMax = max; | |
318 | Int_t low_b = (Int_t) Max(Double_t(0), Floor((min-fMin)/fBinWidth)); | |
319 | Int_t high_b = (Int_t) Min(Double_t(fNBins-1), Ceil((max-fMin)/fBinWidth)); | |
320 | for(Int_t i=0; i<fNBins; ++i) { | |
7d42b6c2 | 321 | if(fBins[i] != 0) |
5b457dfa | 322 | fBins[i]->SetRnrSelf(i>=low_b && i<=high_b); |
5a5a1232 | 323 | } |
324 | } |