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