5 #include <Reve/ReveManager.h>
6 #include <Reve/NLTProjector.h>
9 #include <TTreePlayer.h>
17 //______________________________________________________________________
20 // PointSet is a render-element holding a collection of 3D points with
21 // optional per-point TRef and an arbitrary number of integer ids (to
22 // be used for signal, volume id, track-id, etc).
24 // 3D point representation is implemented in base-class TPolyMarker3D.
25 // Per-point TRef is implemented in base-class TPointSet3D.
27 // By using the TPointSelector the points and integer ids can be
28 // filled directly from a TTree holding the source data.
29 // Setting of per-point TRef's is not supported.
31 // PointSet is a NLTProjectable: it can be projected by using the
32 // NLTProjector class.
36 PointSet::PointSet(Int_t n_points, TreeVarType_e tv_type) :
37 RenderElement(fMarkerColor),
38 TPointSet3D(n_points),
39 TPointSelectorConsumer(tv_type),
50 PointSet::PointSet(const Text_t* name, Int_t n_points, TreeVarType_e tv_type) :
51 RenderElement(fMarkerColor),
52 TPointSet3D(n_points),
53 TPointSelectorConsumer(tv_type),
72 /**************************************************************************/
74 void PointSet::ComputeBBox()
76 // Override of virtual method from TAttBBox.
78 TPointSet3D::ComputeBBox();
79 AssertBBoxExtents(0.1);
82 void PointSet::Reset(Int_t n_points, Int_t n_int_ids)
84 // Drop all data and set-up the data structures to recive new data.
85 // n_points specifies the initial size of the arrays.
86 // n_int_ids specifies the number of integer ids per point.
90 if(fN) fP = new Float_t [3*fN];
91 memset(fP, 0, 3*fN*sizeof(Float_t));
94 delete fIntIds; fIntIds = 0;
95 fIntIdsPerPoint = n_int_ids;
96 if (fIntIdsPerPoint > 0) fIntIds = new TArrayI(fIntIdsPerPoint*fN);
100 Int_t PointSet::GrowFor(Int_t n_points)
102 // Resizes internal array to allow additional n_points to be stored.
103 // Returns the old size which is also the location where one can
104 // start storing new data.
105 // The caller is *obliged* to fill the new point slots.
107 Int_t old_size = Size();
108 Int_t new_size = old_size + n_points;
109 SetPoint(new_size - 1, 0, 0, 0);
111 fIntIds->Set(fIntIdsPerPoint * new_size);
115 /**************************************************************************/
117 inline void PointSet::AssertIntIdsSize()
119 // Assert that size of IntId array is compatible with the size of
122 Int_t exp_size = GetN()*fIntIdsPerPoint;
123 if (fIntIds->GetSize() < exp_size)
124 fIntIds->Set(exp_size);
127 Int_t* PointSet::GetPointIntIds(Int_t p) const
129 // Return a pointer to integer ids of point with index p.
130 // Existence of integer id array is checked, 0 is returned if it
132 // Validity of p is *not* checked.
135 return fIntIds->GetArray() + p*fIntIdsPerPoint;
139 Int_t PointSet::GetPointIntId(Int_t p, Int_t i) const
141 // Return i-th integer id of point with index p.
142 // Existence of integer id array is checked, kMinInt is returned if
143 // it does not exist.
144 // Validity of p and i is *not* checked.
147 return * (fIntIds->GetArray() + p*fIntIdsPerPoint + i);
151 void PointSet::SetPointIntIds(Int_t* ids)
153 // Set integer ids for the last point that was registerd (most
154 // probably via TPolyMarker3D::SetNextPoint(x,y,z)).
156 SetPointIntIds(fLastPoint, ids);
159 void PointSet::SetPointIntIds(Int_t n, Int_t* ids)
161 if (!fIntIds) return;
163 Int_t* x = fIntIds->GetArray() + n*fIntIdsPerPoint;
164 for (Int_t i=0; i<fIntIdsPerPoint; ++i)
168 /**************************************************************************/
170 void PointSet::SetRnrElNameTitle(const Text_t* name, const Text_t* title)
176 /**************************************************************************/
178 void PointSet::Paint(Option_t* option)
180 if(fRnrSelf == kFALSE) return;
182 TPointSet3D::Paint(option);
185 /**************************************************************************/
187 void PointSet::InitFill(Int_t subIdNum)
190 fIntIdsPerPoint = subIdNum;
192 fIntIds = new TArrayI(fIntIdsPerPoint*GetN());
194 fIntIds->Set(fIntIdsPerPoint*GetN());
196 delete fIntIds; fIntIds = 0;
201 void PointSet::TakeAction(TPointSelector* sel)
203 static const Exc_t eH("PointSet::TakeAction ");
206 throw(eH + "selector is <null>.");
208 Int_t n = sel->GetNfill();
209 Int_t beg = GrowFor(n);
211 // printf("PointSet::TakeAction beg=%d n=%d size=%d nsubid=%d dim=%d\n",
212 // beg, n, Size(), sel->GetSubIdNum(), sel->GetDimension());
214 Double_t *vx = sel->GetV1(), *vy = sel->GetV2(), *vz = sel->GetV3();
215 Float_t *p = fP + 3*beg;
220 p[0] = *vx; p[1] = *vy; p[2] = *vz;
227 p[0] = *vx * TMath::Cos(*vy); p[1] = *vx * TMath::Sin(*vy); p[2] = *vz;
233 throw(eH + "unknown tree variable type.");
237 Double_t** subarr = new Double_t* [fIntIdsPerPoint];
238 for (Int_t i=0; i<fIntIdsPerPoint; ++i) {
239 subarr[i] = sel->GetVal(sel->GetDimension() - fIntIdsPerPoint + i);
241 throw(eH + "sub-id array not available.");
243 Int_t* ids = fIntIds->GetArray() + fIntIdsPerPoint*beg;
246 for (Int_t i=0; i<fIntIdsPerPoint; ++i) {
247 ids[i] = TMath::Nint(*subarr[i]);
250 ids += fIntIdsPerPoint;
256 /**************************************************************************/
258 TClass* PointSet::ProjectedClass() const
260 return NLTPointSet::Class();
264 /**************************************************************************/
265 /**************************************************************************/
267 //______________________________________________________________________
271 ClassImp(PointSetArray)
273 PointSetArray::PointSetArray(const Text_t* name,
274 const Text_t* title) :
275 RenderElement(fMarkerColor),
278 fBins(0), fDefPointSetCapacity(128), fNBins(0), fLastBin(-1),
279 fMin(0), fCurMin(0), fMax(0), fCurMax(0),
284 PointSetArray::~PointSetArray()
286 // Destructor: deletes the fBins array. Actual removal of
287 // elements done by RenderElement.
289 // printf("PointSetArray::~PointSetArray()\n");
290 delete [] fBins; fBins = 0;
293 void PointSetArray::Paint(Option_t* option)
296 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
297 if((*i)->GetRnrSelf())
298 (*i)->GetObject()->Paint(option);
303 void PointSetArray::RemoveElementLocal(RenderElement* el)
305 for(Int_t i=0; i<fNBins; ++i) {
313 void PointSetArray::RemoveElementsLocal()
315 delete [] fBins; fBins = 0; fLastBin = -1;
318 /**************************************************************************/
320 void PointSetArray::SetMarkerColor(Color_t tcolor)
322 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
323 TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject());
324 if(m && m->GetMarkerColor() == fMarkerColor)
325 m->SetMarkerColor(tcolor);
327 TAttMarker::SetMarkerColor(tcolor);
330 void PointSetArray::SetMarkerStyle(Style_t mstyle)
332 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
333 TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject());
334 if(m && m->GetMarkerStyle() == fMarkerStyle)
335 m->SetMarkerStyle(mstyle);
337 TAttMarker::SetMarkerStyle(mstyle);
340 void PointSetArray::SetMarkerSize(Size_t msize)
342 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
343 TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject());
344 if(m && m->GetMarkerSize() == fMarkerSize)
345 m->SetMarkerSize(msize);
347 TAttMarker::SetMarkerSize(msize);
350 /**************************************************************************/
352 void PointSetArray::TakeAction(TPointSelector* sel)
354 static const Exc_t eH("PointSetArray::TakeAction ");
357 throw(eH + "selector is <null>.");
359 Int_t n = sel->GetNfill();
361 // printf("PointSetArray::TakeAction n=%d\n", n);
363 Double_t *vx = sel->GetV1(), *vy = sel->GetV2(), *vz = sel->GetV3();
364 Double_t *qq = sel->GetV4();
367 throw(eH + "requires 4-d varexp.");
372 Fill(*vx, *vy, *vz, *qq);
373 ++vx; ++vy; ++vz; ++qq;
378 Fill(*vx * TMath::Cos(*vy), *vx * TMath::Sin(*vy), *vz, *qq);
379 ++vx; ++vy; ++vz; ++qq;
383 throw(eH + "unknown tree variable type.");
387 /**************************************************************************/
389 void PointSetArray::InitBins(const Text_t* quant_name,
390 Int_t nbins, Double_t min, Double_t max,
393 static const Exc_t eH("PointSetArray::InitBins ");
395 if(nbins < 1) throw(eH + "nbins < 1.");
396 if(min > max) throw(eH + "min > max.");
400 fQuantName = quant_name;
403 fMin = fCurMin = min;
404 fMax = fCurMax = max;
405 fBinWidth = (fMax - fMin)/fNBins;
407 fBins = new Reve::PointSet*[fNBins];
408 for(Int_t i=0; i<fNBins; ++i) {
409 fBins[i] = new Reve::PointSet
410 (Form("Slice %d [%4.3lf, %4.3lf]", i, fMin + i*fBinWidth, fMin + (i+1)*fBinWidth),
411 fDefPointSetCapacity);
412 fBins[i]->SetMarkerColor(fMarkerColor);
413 fBins[i]->SetMarkerStyle(fMarkerStyle);
414 fBins[i]->SetMarkerSize(fMarkerSize);
416 gReve->AddRenderElement(fBins[i], this);
418 AddElement(fBins[i]);
422 void PointSetArray::Fill(Double_t x, Double_t y, Double_t z, Double_t quant)
424 fLastBin = Int_t( (quant - fMin)/fBinWidth );
425 if(fLastBin >= 0 && fLastBin < fNBins && fBins[fLastBin] != 0)
426 fBins[fLastBin]->SetNextPoint(x, y, z);
431 void PointSetArray::SetPointId(TObject* id)
434 fBins[fLastBin]->SetPointId(id);
437 void PointSetArray::CloseBins()
439 for(Int_t i=0; i<fNBins; ++i) {
441 // HACK! PolyMarker3D does half-management of array size.
442 // In fact, the error is mine, in pointset3d(gl) i use fN instead of Size().
443 // Fixed in my root, but not elsewhere.
444 fBins[i]->fN = fBins[i]->fLastPoint;
446 fBins[i]->ComputeBBox();
452 /**************************************************************************/
454 void PointSetArray::SetOwnIds(Bool_t o)
456 for(Int_t i=0; i<fNBins; ++i)
459 fBins[i]->SetOwnIds(o);
463 /**************************************************************************/
465 void PointSetArray::SetRange(Double_t min, Double_t max)
467 using namespace TMath;
469 fCurMin = min; fCurMax = max;
470 Int_t low_b = (Int_t) Max(Double_t(0), Floor((min-fMin)/fBinWidth));
471 Int_t high_b = (Int_t) Min(Double_t(fNBins-1), Ceil((max-fMin)/fBinWidth));
472 for(Int_t i=0; i<fNBins; ++i) {
474 fBins[i]->SetRnrSelf(i>=low_b && i<=high_b);
479 /**************************************************************************/
480 /**************************************************************************/
483 //______________________________________________________________________
487 ClassImp(NLTPointSet)
489 NLTPointSet::NLTPointSet() :
494 void NLTPointSet::SetProjection(NLTProjector* proj, NLTProjectable* model)
496 NLTProjected::SetProjection(proj, model);
498 * (TAttMarker*)this = * dynamic_cast<TAttMarker*>(fProjectable);
501 void NLTPointSet::UpdateProjection()
503 NLTProjection& proj = * fProjector->GetProjection();
504 PointSet & ps = * dynamic_cast<PointSet*>(fProjectable);
508 Float_t *o = ps.GetP(), *p = GetP();
509 for(Int_t i = 0; i < n; ++i, o+=3, p+=3)
511 p[0] = o[0]; p[1] = o[1]; p[2] = o[2];
512 proj.ProjectPoint(p[0], p[1], p[2]);