5 #include <Reve/RGTopFrame.h>
8 #include <TTreePlayer.h>
16 //______________________________________________________________________
22 PointSet::PointSet(Int_t n_points, TreeVarType_e tv_type) :
23 RenderElement(fMarkerColor),
24 TPointSet3D(n_points),
25 TPointSelectorConsumer(tv_type),
32 PointSet::PointSet(const Text_t* name, Int_t n_points, TreeVarType_e tv_type) :
33 RenderElement(fMarkerColor),
34 TPointSet3D(n_points),
35 TPointSelectorConsumer(tv_type),
43 PointSet::PointSet(const Text_t* name, TTree* tree, TreeVarType_e tv_type) :
44 RenderElement(fMarkerColor),
45 TPointSet3D(tree->GetSelectedRows()),
46 TPointSelectorConsumer(tv_type),
50 static const Exc_t eH("PointSet::PointSet ");
55 TTreePlayer* tp = dynamic_cast<TTreePlayer*>(tree->GetPlayer());
56 TakeAction(dynamic_cast<TSelectorDraw*>(tp->GetSelector()));
59 /**************************************************************************/
61 void PointSet::Reset(Int_t n_points)
65 if(fN) fP = new Float_t [3*fN];
66 memset(fP, 0, 3*fN*sizeof(Float_t));
72 Int_t PointSet::GrowFor(Int_t n_points)
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.
79 Int_t old_size = Size();
80 Int_t new_size = old_size + n_points;
81 SetPoint(new_size - 1, 0, 0, 0);
85 /**************************************************************************/
87 void PointSet::Paint(Option_t* option)
89 if(fRnrSelf == kFALSE) return;
91 TPointSet3D::Paint(option);
94 /**************************************************************************/
96 void PointSet::TakeAction(TSelectorDraw* sel)
98 static const Exc_t eH("PointSet::TakeAction ");
101 throw(eH + "selector is <null>.");
103 Int_t n = sel->GetNfill();
104 Int_t beg = GrowFor(n);
105 Float_t *p = fP + 3*beg;
107 // printf("PointSet::TakeAction beg=%d n=%d size=%d\n", beg, n, Size());
109 Double_t *vx = sel->GetV1(), *vy = sel->GetV2(), *vz = sel->GetV3();
114 p[0] = *vx; p[1] = *vy; p[2] = *vz;
121 p[0] = *vx * TMath::Cos(*vy); p[1] = *vx * TMath::Sin(*vy); p[2] = *vz;
127 throw(eH + "unknown tree variable type.");
131 /**************************************************************************/
132 /**************************************************************************/
134 //______________________________________________________________________
138 ClassImp(PointSetArray)
140 PointSetArray::PointSetArray(const Text_t* name,
141 const Text_t* title) :
142 RenderElement(fMarkerColor),
145 fBins(0), fDefPointSetCapacity(128), fNBins(0),
146 fMin(0), fCurMin(0), fMax(0), fCurMax(0),
151 PointSetArray::~PointSetArray()
153 // Destructor: deletes the fBins array. Actual removal of
154 // elements done by RenderElement.
156 // printf("PointSetArray::~PointSetArray()\n");
157 delete [] fBins; fBins = 0;
160 void PointSetArray::Paint(Option_t* option)
163 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
164 if((*i)->GetRnrSelf())
165 (*i)->GetObject()->Paint(option);
170 void PointSetArray::RemoveElementLocal(RenderElement* el)
172 for(Int_t i=0; i<fNBins; ++i) {
178 RenderElement::RemoveElementLocal(el);
181 void PointSetArray::RemoveElements()
183 delete [] fBins; fBins = 0;
184 RenderElement::RemoveElements();
187 /**************************************************************************/
189 void PointSetArray::SetMarkerColor(Color_t tcolor)
191 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
192 TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject());
193 if(m && m->GetMarkerColor() == fMarkerColor)
194 m->SetMarkerColor(tcolor);
196 TAttMarker::SetMarkerColor(tcolor);
199 void PointSetArray::SetMarkerStyle(Style_t mstyle)
201 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
202 TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject());
203 if(m && m->GetMarkerStyle() == fMarkerStyle)
204 m->SetMarkerStyle(mstyle);
206 TAttMarker::SetMarkerStyle(mstyle);
209 void PointSetArray::SetMarkerSize(Size_t msize)
211 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
212 TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject());
213 if(m && m->GetMarkerSize() == fMarkerSize)
214 m->SetMarkerSize(msize);
216 TAttMarker::SetMarkerSize(msize);
219 /**************************************************************************/
221 void PointSetArray::TakeAction(TSelectorDraw* sel)
223 static const Exc_t eH("PointSetArray::TakeAction ");
226 throw(eH + "selector is <null>.");
228 Int_t n = sel->GetNfill();
230 // printf("PointSetArray::TakeAction n=%d\n", n);
232 Double_t *vx = sel->GetV1(), *vy = sel->GetV2(), *vz = sel->GetV3();
233 Double_t *qq = sel->GetV4();
236 throw(eH + "requires 4-d varexp.");
241 Fill(*vx, *vy, *vz, *qq);
242 ++vx; ++vy; ++vz; ++qq;
247 Fill(*vx * TMath::Cos(*vy), *vx * TMath::Sin(*vy), *vz, *qq);
248 ++vx; ++vy; ++vz; ++qq;
252 throw(eH + "unknown tree variable type.");
256 /**************************************************************************/
258 void PointSetArray::InitBins(const Text_t* quant_name,
259 Int_t nbins, Double_t min, Double_t max,
262 static const Exc_t eH("PointSetArray::InitBins ");
264 if(nbins < 1) throw(eH + "nbins < 1.");
265 if(min > max) throw(eH + "min > max.");
269 fQuantName = quant_name;
271 fMin = fCurMin = min;
272 fMax = fCurMax = max;
273 fBinWidth = (fMax - fMin)/fNBins;
275 fBins = new Reve::PointSet*[fNBins];
276 for(Int_t i=0; i<fNBins; ++i) {
277 fBins[i] = new Reve::PointSet
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);
284 gReve->AddRenderElement(this, fBins[i]);
286 AddElement(fBins[i]);
290 void PointSetArray::Fill(Double_t x, Double_t y, Double_t z, Double_t quant)
292 Int_t bin = Int_t( (quant - fMin)/fBinWidth );
293 if(bin >= 0 && bin < fNBins && fBins[bin] != 0)
294 fBins[bin]->SetNextPoint(x, y, z);
297 void PointSetArray::CloseBins()
299 for(Int_t i=0; i<fNBins; ++i) {
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;
306 fBins[i]->ComputeBBox();
311 /**************************************************************************/
313 void PointSetArray::SetRange(Double_t min, Double_t max)
315 using namespace TMath;
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) {
322 fBins[i]->SetRnrSelf(i>=low_b && i<=high_b);