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 //______________________________________________________________________________
37 PointSet::PointSet(Int_t n_points, TreeVarType_e tv_type) :
38 RenderElement(fMarkerColor),
39 TPointSet3D(n_points),
40 TPointSelectorConsumer(tv_type),
51 //______________________________________________________________________________
52 PointSet::PointSet(const Text_t* name, Int_t n_points, TreeVarType_e tv_type) :
53 RenderElement(fMarkerColor),
54 TPointSet3D(n_points),
55 TPointSelectorConsumer(tv_type),
67 //______________________________________________________________________________
75 /**************************************************************************/
77 //______________________________________________________________________________
78 void PointSet::ComputeBBox()
80 // Override of virtual method from TAttBBox.
82 TPointSet3D::ComputeBBox();
83 AssertBBoxExtents(0.1);
86 //______________________________________________________________________________
87 void PointSet::Reset(Int_t n_points, Int_t n_int_ids)
89 // Drop all data and set-up the data structures to recive new data.
90 // n_points specifies the initial size of the arrays.
91 // n_int_ids specifies the number of integer ids per point.
95 if(fN) fP = new Float_t [3*fN];
96 memset(fP, 0, 3*fN*sizeof(Float_t));
99 delete fIntIds; fIntIds = 0;
100 fIntIdsPerPoint = n_int_ids;
101 if (fIntIdsPerPoint > 0) fIntIds = new TArrayI(fIntIdsPerPoint*fN);
105 //______________________________________________________________________________
106 Int_t PointSet::GrowFor(Int_t n_points)
108 // Resizes internal array to allow additional n_points to be stored.
109 // Returns the old size which is also the location where one can
110 // start storing new data.
111 // The caller is *obliged* to fill the new point slots.
113 Int_t old_size = Size();
114 Int_t new_size = old_size + n_points;
115 SetPoint(new_size - 1, 0, 0, 0);
117 fIntIds->Set(fIntIdsPerPoint * new_size);
121 /**************************************************************************/
123 //______________________________________________________________________________
124 inline void PointSet::AssertIntIdsSize()
126 // Assert that size of IntId array is compatible with the size of
129 Int_t exp_size = GetN()*fIntIdsPerPoint;
130 if (fIntIds->GetSize() < exp_size)
131 fIntIds->Set(exp_size);
134 //______________________________________________________________________________
135 Int_t* PointSet::GetPointIntIds(Int_t p) const
137 // Return a pointer to integer ids of point with index p.
138 // Existence of integer id array is checked, 0 is returned if it
140 // Validity of p is *not* checked.
143 return fIntIds->GetArray() + p*fIntIdsPerPoint;
147 //______________________________________________________________________________
148 Int_t PointSet::GetPointIntId(Int_t p, Int_t i) const
150 // Return i-th integer id of point with index p.
151 // Existence of integer id array is checked, kMinInt is returned if
152 // it does not exist.
153 // Validity of p and i is *not* checked.
156 return * (fIntIds->GetArray() + p*fIntIdsPerPoint + i);
160 //______________________________________________________________________________
161 void PointSet::SetPointIntIds(Int_t* ids)
163 // Set integer ids for the last point that was registerd (most
164 // probably via TPolyMarker3D::SetNextPoint(x,y,z)).
166 SetPointIntIds(fLastPoint, ids);
169 //______________________________________________________________________________
170 void PointSet::SetPointIntIds(Int_t n, Int_t* ids)
172 // Set integer ids for point with index n.
174 if (!fIntIds) return;
176 Int_t* x = fIntIds->GetArray() + n*fIntIdsPerPoint;
177 for (Int_t i=0; i<fIntIdsPerPoint; ++i)
181 /**************************************************************************/
183 //______________________________________________________________________________
184 void PointSet::SetRnrElNameTitle(const Text_t* name, const Text_t* title)
186 // Set name and title of point-set.
187 // Virtual in RenderElement.
193 /******************************************************************************/
195 //______________________________________________________________________________
196 void PointSet::Paint(Option_t* option)
200 if(fRnrSelf == kFALSE) return;
202 TPointSet3D::Paint(option);
205 /**************************************************************************/
207 //______________________________________________________________________________
208 void PointSet::InitFill(Int_t subIdNum)
210 // Initialize point-set for new filling.
211 // subIdNum gives the number of integer ids that can be assigned to
215 fIntIdsPerPoint = subIdNum;
217 fIntIds = new TArrayI(fIntIdsPerPoint*GetN());
219 fIntIds->Set(fIntIdsPerPoint*GetN());
221 delete fIntIds; fIntIds = 0;
226 //______________________________________________________________________________
227 void PointSet::TakeAction(TPointSelector* sel)
229 // Called from TPointSelector when internal arrays of the tree-selector
230 // are filled up and need to be processed.
231 // Virtual from TPointSelectorConsumer.
233 static const Exc_t eH("PointSet::TakeAction ");
236 throw(eH + "selector is <null>.");
238 Int_t n = sel->GetNfill();
239 Int_t beg = GrowFor(n);
241 // printf("PointSet::TakeAction beg=%d n=%d size=%d nsubid=%d dim=%d\n",
242 // beg, n, Size(), sel->GetSubIdNum(), sel->GetDimension());
244 Double_t *vx = sel->GetV1(), *vy = sel->GetV2(), *vz = sel->GetV3();
245 Float_t *p = fP + 3*beg;
250 p[0] = *vx; p[1] = *vy; p[2] = *vz;
257 p[0] = *vx * TMath::Cos(*vy); p[1] = *vx * TMath::Sin(*vy); p[2] = *vz;
263 throw(eH + "unknown tree variable type.");
267 Double_t** subarr = new Double_t* [fIntIdsPerPoint];
268 for (Int_t i=0; i<fIntIdsPerPoint; ++i) {
269 subarr[i] = sel->GetVal(sel->GetDimension() - fIntIdsPerPoint + i);
271 throw(eH + "sub-id array not available.");
273 Int_t* ids = fIntIds->GetArray() + fIntIdsPerPoint*beg;
276 for (Int_t i=0; i<fIntIdsPerPoint; ++i) {
277 ids[i] = TMath::Nint(*subarr[i]);
280 ids += fIntIdsPerPoint;
286 /**************************************************************************/
288 //______________________________________________________________________________
289 TClass* PointSet::ProjectedClass() const
291 // Virtual from NLTProjectable, returns NLTPointSet class.
293 return NLTPointSet::Class();
297 /**************************************************************************/
298 /**************************************************************************/
300 //______________________________________________________________________________
303 // An array of point-sets with each point-set playing a role of a bin
304 // in a histogram. When a new point is added to a PointSetArray, an
305 // additional separating quantity needs to be specified: it determines
306 // into which PointSet (bin) the point will actually be stored.
308 // By using the TPointSelector the points and the separating
309 // quantities can be filled directly from a TTree holding the source
311 // Setting of per-point TRef's is not supported.
313 // After the filling, the range of separating variable can be
314 // controlled with a slider to choose a sub-set of PointSets that are
318 ClassImp(PointSetArray)
320 //______________________________________________________________________________
321 PointSetArray::PointSetArray(const Text_t* name,
322 const Text_t* title) :
323 RenderElement(fMarkerColor),
326 fBins(0), fDefPointSetCapacity(128), fNBins(0), fLastBin(-1),
327 fMin(0), fCurMin(0), fMax(0), fCurMax(0),
334 //______________________________________________________________________________
335 PointSetArray::~PointSetArray()
337 // Destructor: deletes the fBins array. Actual removal of
338 // elements done by RenderElement.
340 // printf("PointSetArray::~PointSetArray()\n");
341 delete [] fBins; fBins = 0;
344 //______________________________________________________________________________
345 void PointSetArray::Paint(Option_t* option)
347 // Paint the subjugated PointSet's.
350 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
351 if ((*i)->GetRnrSelf())
352 (*i)->GetObject()->Paint(option);
357 //______________________________________________________________________________
358 void PointSetArray::RemoveElementLocal(RenderElement* el)
360 // Virtual from RenderElement, provide bin management.
362 for (Int_t i=0; i<fNBins; ++i) {
363 if (fBins[i] == el) {
370 //______________________________________________________________________________
371 void PointSetArray::RemoveElementsLocal()
373 // Virtual from RenderElement, provide bin management.
375 delete [] fBins; fBins = 0; fLastBin = -1;
378 /**************************************************************************/
380 //______________________________________________________________________________
381 void PointSetArray::SetMarkerColor(Color_t tcolor)
383 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
384 TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject());
385 if (m && m->GetMarkerColor() == fMarkerColor)
386 m->SetMarkerColor(tcolor);
388 TAttMarker::SetMarkerColor(tcolor);
391 //______________________________________________________________________________
392 void PointSetArray::SetMarkerStyle(Style_t mstyle)
394 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
395 TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject());
396 if (m && m->GetMarkerStyle() == fMarkerStyle)
397 m->SetMarkerStyle(mstyle);
399 TAttMarker::SetMarkerStyle(mstyle);
402 //______________________________________________________________________________
403 void PointSetArray::SetMarkerSize(Size_t msize)
405 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
406 TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject());
407 if (m && m->GetMarkerSize() == fMarkerSize)
408 m->SetMarkerSize(msize);
410 TAttMarker::SetMarkerSize(msize);
413 /**************************************************************************/
415 //______________________________________________________________________________
416 void PointSetArray::TakeAction(TPointSelector* sel)
418 // Called from TPointSelector when internal arrays of the tree-selector
419 // are filled up and need to be processed.
420 // Virtual from TPointSelectorConsumer.
422 static const Exc_t eH("PointSetArray::TakeAction ");
425 throw(eH + "selector is <null>.");
427 Int_t n = sel->GetNfill();
429 // printf("PointSetArray::TakeAction n=%d\n", n);
431 Double_t *vx = sel->GetV1(), *vy = sel->GetV2(), *vz = sel->GetV3();
432 Double_t *qq = sel->GetV4();
435 throw(eH + "requires 4-d varexp.");
440 Fill(*vx, *vy, *vz, *qq);
441 ++vx; ++vy; ++vz; ++qq;
446 Fill(*vx * TMath::Cos(*vy), *vx * TMath::Sin(*vy), *vz, *qq);
447 ++vx; ++vy; ++vz; ++qq;
451 throw(eH + "unknown tree variable type.");
455 /**************************************************************************/
457 //______________________________________________________________________________
458 void PointSetArray::InitBins(const Text_t* quant_name,
459 Int_t nbins, Double_t min, Double_t max,
462 static const Exc_t eH("PointSetArray::InitBins ");
464 if (nbins < 1) throw(eH + "nbins < 1.");
465 if (min > max) throw(eH + "min > max.");
469 fQuantName = quant_name;
472 fMin = fCurMin = min;
473 fMax = fCurMax = max;
474 fBinWidth = (fMax - fMin)/fNBins;
476 fBins = new Reve::PointSet*[fNBins];
477 for (Int_t i=0; i<fNBins; ++i) {
478 fBins[i] = new Reve::PointSet
479 (Form("Slice %d [%4.3lf, %4.3lf]", i, fMin + i*fBinWidth, fMin + (i+1)*fBinWidth),
480 fDefPointSetCapacity);
481 fBins[i]->SetMarkerColor(fMarkerColor);
482 fBins[i]->SetMarkerStyle(fMarkerStyle);
483 fBins[i]->SetMarkerSize(fMarkerSize);
485 gReve->AddRenderElement(fBins[i], this);
487 AddElement(fBins[i]);
491 //______________________________________________________________________________
492 void PointSetArray::Fill(Double_t x, Double_t y, Double_t z, Double_t quant)
494 fLastBin = Int_t( (quant - fMin)/fBinWidth );
495 if (fLastBin >= 0 && fLastBin < fNBins && fBins[fLastBin] != 0)
496 fBins[fLastBin]->SetNextPoint(x, y, z);
501 //______________________________________________________________________________
502 void PointSetArray::SetPointId(TObject* id)
505 fBins[fLastBin]->SetPointId(id);
508 //______________________________________________________________________________
509 void PointSetArray::CloseBins()
511 for (Int_t i=0; i<fNBins; ++i) {
513 // HACK! PolyMarker3D does half-management of array size.
514 // In fact, the error is mine, in pointset3d(gl) i use fN instead of Size().
515 // Fixed in my root, but not elsewhere.
516 fBins[i]->fN = fBins[i]->fLastPoint;
518 fBins[i]->ComputeBBox();
524 /**************************************************************************/
526 //______________________________________________________________________________
527 void PointSetArray::SetOwnIds(Bool_t o)
529 for (Int_t i=0; i<fNBins; ++i)
532 fBins[i]->SetOwnIds(o);
536 /**************************************************************************/
538 //______________________________________________________________________________
539 void PointSetArray::SetRange(Double_t min, Double_t max)
541 using namespace TMath;
543 fCurMin = min; fCurMax = max;
544 Int_t low_b = (Int_t) Max(Double_t(0), Floor((min-fMin)/fBinWidth));
545 Int_t high_b = (Int_t) Min(Double_t(fNBins-1), Ceil((max-fMin)/fBinWidth));
546 for (Int_t i=0; i<fNBins; ++i) {
548 fBins[i]->SetRnrSelf(i>=low_b && i<=high_b);
553 /******************************************************************************/
554 /******************************************************************************/
556 //______________________________________________________________________________
560 ClassImp(NLTPointSet)
562 //______________________________________________________________________________
563 NLTPointSet::NLTPointSet() :
567 // Default contructor.
570 //______________________________________________________________________________
571 void NLTPointSet::SetProjection(NLTProjector* proj, NLTProjectable* model)
573 NLTProjected::SetProjection(proj, model);
575 * (TAttMarker*)this = * dynamic_cast<TAttMarker*>(fProjectable);
578 //______________________________________________________________________________
579 void NLTPointSet::UpdateProjection()
581 NLTProjection& proj = * fProjector->GetProjection();
582 PointSet & ps = * dynamic_cast<PointSet*>(fProjectable);
586 Float_t *o = ps.GetP(), *p = GetP();
587 for (Int_t i = 0; i < n; ++i, o+=3, p+=3)
589 p[0] = o[0]; p[1] = o[1]; p[2] = o[2];
590 proj.ProjectPoint(p[0], p[1], p[2]);