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