Logo ROOT  
Reference Guide
REvePointSet.cxx
Go to the documentation of this file.
1// @(#)root/eve7:$Id$
2// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include <ROOT/REvePointSet.hxx>
13
14#include <ROOT/REveManager.hxx>
16#include <ROOT/REveTrans.hxx>
18
19#include "TColor.h"
20#include "TArrayI.h"
21#include "TClass.h"
22
23
24#include "json.hpp"
25
26
27using namespace ROOT::Experimental;
28namespace REX = ROOT::Experimental;
29
30/** \class REvePointSet
31\ingroup REve
32REvePointSet is a render-element holding a collection of 3D points with
33optional per-point TRef and an arbitrary number of integer ids (to
34be used for signal, volume-id, track-id, etc).
35
363D point representation is implemented in base-class TPolyMarker3D.
37Per-point TRef is implemented in base-class TPointSet3D.
38
39By using the REvePointSelector the points and integer ids can be
40filled directly from a TTree holding the source data.
41Setting of per-point TRef's is not supported.
42
43REvePointSet is a REveProjectable: it can be projected by using the
44REveProjectionManager class.
45*/
46
47////////////////////////////////////////////////////////////////////////////////
48/// Constructor.
49
50REvePointSet::REvePointSet(const std::string& name, const std::string& title, Int_t n_points) :
51 REveElement(name, title),
52 TAttMarker(),
53 TAttBBox()
54{
55 fMarkerStyle = 20;
56
58
59 Reset(n_points);
60
61 // Override from REveElement.
63}
64
65////////////////////////////////////////////////////////////////////////////////
66/// Copy constructor.
67
72 TAttBBox(e)
73{
74}
75
76////////////////////////////////////////////////////////////////////////////////
77/// Destructor.
78
80{
81}
82
83////////////////////////////////////////////////////////////////////////////////
84/// Clone points and all point-related information from point-set 'e'.
85
87{
88 fPoints = e.fPoints;
89 fCapacity = e.fCapacity;
90 fSize = e.fSize;
91}
92
93////////////////////////////////////////////////////////////////////////////////
94/// Drop all data and set-up the data structures to recive new data.
95/// n_points specifies the initial size of the array.
96
98{
99 fPoints.resize(n_points);
100 fCapacity = n_points;
101 fSize = 0;
102
103 ResetBBox();
104}
105
106////////////////////////////////////////////////////////////////////////////////
107/// Resizes internal array to allow additional n_points to be stored.
108/// Returns the old size which is also the location where one can
109/// start storing new data.
110/// The caller is *obliged* to fill the new point slots.
111
113{
114 assert(n_points >= 0);
115
116 Int_t old_size = fCapacity;
117 Int_t new_size = old_size + n_points;
118
119 fPoints.resize(new_size);
120 fCapacity = new_size;
121
122 return old_size;
123}
124
125int REvePointSet::SetNextPoint(float x, float y, float z)
126{
127 return SetPoint(fSize, x, y, z);
128}
129
130int REvePointSet::SetPoint(int n, float x, float y, float z)
131{
132 if (n >= fCapacity)
133 {
134 fCapacity = std::max(n + 1, 2*fCapacity);
135 fPoints.resize(fCapacity);
136 }
137 fPoints[n].Set(x, y, z);
138 if (n >= fSize)
139 {
140 fSize = n + 1;
141 }
142 return fSize;
143}
144
145////////////////////////////////////////////////////////////////////////////////
146/// Set marker style, propagate to projecteds.
147
149{
150 for (auto &pi: fProjectedList)
151 {
152 REvePointSet* pt = dynamic_cast<REvePointSet *>(pi);
153 if (pt)
154 {
155 pt->SetMarkerStyle(mstyle);
156 pt->StampObjProps();
157 }
158 }
160}
161
162////////////////////////////////////////////////////////////////////////////////
163/// Set marker size, propagate to projecteds.
164
166{
167 for (auto &pi: fProjectedList)
168 {
169 REvePointSet* pt = dynamic_cast<REvePointSet *>(pi);
170 if (pt)
171 {
172 pt->SetMarkerSize(msize);
173 pt->StampObjProps();
174 }
175 }
178}
179
180////////////////////////////////////////////////////////////////////////////////
181/// Copy visualization parameters from element el.
182
184{
185 const REvePointSet* m = dynamic_cast<const REvePointSet*>(el);
186 if (m)
187 {
189 }
190
192}
193
194////////////////////////////////////////////////////////////////////////////////
195/// Write visualization parameters.
196
197void REvePointSet::WriteVizParams(std::ostream& out, const TString& var)
198{
200
202}
203
204////////////////////////////////////////////////////////////////////////////////
205/// Virtual from REveProjectable, returns REvePointSetProjected class.
206
208{
209 return TClass::GetClass<REvePointSetProjected>();
210}
211
212
214{
215 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
216
217 j["fMarkerSize"] = GetMarkerSize();
218 j["fMarkerColor"] = GetMarkerColor();
219
220 return ret;
221}
222
223////////////////////////////////////////////////////////////////////////////////
224/// Crates 3D point array for rendering.
225
227{
228 if (fSize > 0)
229 {
230 fRenderData = std::make_unique<REveRenderData>("makeHit", 3*fSize);
231 fRenderData->PushV(&fPoints[0].fX, 3*fSize);
232 }
233}
234
235////////////////////////////////////////////////////////////////////////////////
236/// Compute bounding box.
237
239{
240 if (fSize > 0) {
241 BBoxInit();
242 for (auto &p : fPoints)
243 {
244 BBoxCheckPoint(p.fX, p.fY, p.fZ);
245 }
246 } else {
247 BBoxZero();
248 }
249}
250
251////////////////////////////////////////////////////////////////////////////////
252/// Virtual method of base class TPointSet3D. The function call is
253/// invoked with secondary selection in TPointSet3DGL.
254
256{
257 // Emit("PointSelected(Int_t)", id);
258}
259
260
261//==============================================================================
262// REvePointSetArray
263//==============================================================================
264
265/** \class REvePointSetArray
266\ingroup REve
267An array of point-sets with each point-set playing a role of a bin
268in a histogram. When a new point is added to a REvePointSetArray,
269an additional separating quantity needs to be specified: it
270determines into which REvePointSet (bin) the point will actually be
271stored. Underflow and overflow bins are automatically created but
272they are not drawn by default.
273
274By using the REvePointSelector the points and the separating
275quantities can be filled directly from a TTree holding the source
276data.
277Setting of per-point TRef's is not supported.
278
279After the filling, the range of separating variable can be
280controlled with a slider to choose a sub-set of PointSets that are
281actually shown.
282*/
283
284////////////////////////////////////////////////////////////////////////////////
285/// Constructor.
286
288 const std::string& title) :
289 REveElement(name, title),
290
291 fBins(nullptr), fDefPointSetCapacity(128), fNBins(0), fLastBin(-1),
292 fMin(0), fCurMin(0), fMax(0), fCurMax(0),
293 fBinWidth(0),
294 fQuantName()
295{
297}
298
299////////////////////////////////////////////////////////////////////////////////
300/// Destructor: deletes the fBins array. Actual removal of
301/// elements done by REveElement.
302
304{
305 // printf("REvePointSetArray::~REvePointSetArray()\n");
306 delete [] fBins; fBins = nullptr;
307}
308
309////////////////////////////////////////////////////////////////////////////////
310/// Virtual from REveElement, provide bin management.
311
313{
314 for (Int_t i=0; i<fNBins; ++i) {
315 if (fBins[i] == el) {
316 fBins[i] = nullptr;
317 break;
318 }
319 }
320}
321
322////////////////////////////////////////////////////////////////////////////////
323/// Virtual from REveElement, provide bin management.
324
326{
327 delete [] fBins; fBins = nullptr; fLastBin = -1;
328}
329
330////////////////////////////////////////////////////////////////////////////////
331/// Set marker color, propagate to children.
332
334{
335 for (auto & el : fChildren)
336 {
337 TAttMarker* m = dynamic_cast<TAttMarker*>(el);
338 if (m && m->GetMarkerColor() == fMarkerColor)
339 m->SetMarkerColor(tcolor);
340 }
342}
343
344////////////////////////////////////////////////////////////////////////////////
345/// Set marker style, propagate to children.
346
348{
349 for (auto & el : fChildren)
350 {
351 TAttMarker* m = dynamic_cast<TAttMarker*>(el);
352 if (m && m->GetMarkerStyle() == fMarkerStyle)
353 m->SetMarkerStyle(mstyle);
354 }
356}
357
358////////////////////////////////////////////////////////////////////////////////
359/// Set marker size, propagate to children.
360
362{
363 for (auto & el : fChildren)
364 {
365 TAttMarker* m = dynamic_cast<TAttMarker*>(el);
366 if (m && m->GetMarkerSize() == fMarkerSize)
367 m->SetMarkerSize(msize);
368 }
370}
371
372////////////////////////////////////////////////////////////////////////////////
373/// Get the total number of filled points.
374/// 'under' and 'over' flags specify if under/overflow channels
375/// should be added to the sum.
376
378{
379 Int_t size = 0;
380 const Int_t min = under ? 0 : 1;
381 const Int_t max = over ? fNBins : fNBins - 1;
382 for (Int_t i = min; i < max; ++i)
383 {
384 if (fBins[i])
385 size += fBins[i]->GetSize();
386 }
387 return size;
388}
389
390////////////////////////////////////////////////////////////////////////////////
391/// Initialize internal point-sets with given binning parameters.
392/// The actual number of bins is nbins+2, bin 0 corresponding to
393/// underflow and bin nbin+1 to owerflow pointset.
394
395void REvePointSetArray::InitBins(const std::string& quant_name,
396 Int_t nbins, Double_t min, Double_t max)
397{
398 static const REveException eh("REvePointSetArray::InitBins ");
399
400 if (nbins < 1) throw eh + "nbins < 1.";
401 if (min > max) throw eh + "min > max.";
402
404
405 fQuantName = quant_name;
406 fNBins = nbins + 2; // under/overflow
407 fLastBin = -1;
408 fMin = fCurMin = min;
409 fMax = fCurMax = max;
410 fBinWidth = (fMax - fMin)/(fNBins - 2);
411
412 fBins = new REvePointSet* [fNBins];
413
414 for (Int_t i = 0; i < fNBins; ++i)
415 {
416 fBins[i] = new REvePointSet
417 (Form("Slice %d [%4.3lf, %4.3lf]", i, fMin + (i-1)*fBinWidth, fMin + i*fBinWidth),
418 "",
423 AddElement(fBins[i]);
424 }
425
426 fBins[0]->SetName("Underflow");
428
429 fBins[fNBins-1]->SetName("Overflow");
431}
432
433////////////////////////////////////////////////////////////////////////////////
434/// Add a new point. Appropriate point-set will be chosen based on
435/// the value of the separating quantity 'quant'.
436/// If the selected bin does not have an associated REvePointSet
437/// the point is discarded and false is returned.
438
440{
441 fLastBin = TMath::FloorNint((quant - fMin)/fBinWidth) + 1;
442
443 if (fLastBin < 0)
444 {
445 fLastBin = 0;
446 }
447 else if (fLastBin > fNBins - 1)
448 {
449 fLastBin = fNBins - 1;
450 }
451
452 if (fBins[fLastBin] != 0)
453 {
455 return kTRUE;
456 }
457 else
458 {
459 return kFALSE;
460 }
461}
462
463////////////////////////////////////////////////////////////////////////////////
464/// Call this after all the points have been filled.
465/// At this point we can calculate bounding-boxes of individual
466/// point-sets.
467
469{
470 for (Int_t i=0; i<fNBins; ++i)
471 {
472 if (fBins[i])
473 {
474 fBins[i]->SetTitle(Form("N=%d", fBins[i]->GetSize()));
475 fBins[i]->ComputeBBox();
476 }
477 }
478 fLastBin = -1;
479}
480
481////////////////////////////////////////////////////////////////////////////////
482/// Set active range of the separating quantity.
483/// Appropriate point-sets are tagged for rendering.
484/// Over/underflow point-sets are left as they were.
485
487{
488 using namespace TMath;
489
490 fCurMin = min; fCurMax = max;
491 Int_t low_b = Max(0, FloorNint((min-fMin)/fBinWidth)) + 1;
492 Int_t high_b = Min(fNBins-2, CeilNint ((max-fMin)/fBinWidth));
493
494 for (Int_t i = 1; i < fNBins - 1; ++i)
495 {
496 if (fBins[i])
497 fBins[i]->SetRnrSelf(i>=low_b && i<=high_b);
498 }
499}
500
501/** \class REvePointSetProjected
502\ingroup REve
503Projected copy of a REvePointSet.
504*/
505
506////////////////////////////////////////////////////////////////////////////////
507/// Default contructor.
508
510 REvePointSet (),
512{
513}
514
515////////////////////////////////////////////////////////////////////////////////
516/// Set projection manager and projection model.
517/// Virtual from REveProjected.
518
520 REveProjectable* model)
521{
522 REveProjected::SetProjection(proj, model);
523 CopyVizParams(dynamic_cast<REveElement*>(model));
524}
525
526////////////////////////////////////////////////////////////////////////////////
527/// Set depth (z-coordinate) of the projected points.
528
530{
531 SetDepthCommon(d, this, fBBox);
532
533 // XXXX rewrite
534
535 Int_t n = fSize;
536 Float_t *p = & fPoints[0].fZ;
537 for (Int_t i = 0; i < n; ++i, p+=3)
538 *p = fDepth;
539}
540
541////////////////////////////////////////////////////////////////////////////////
542/// Re-apply the projection.
543/// Virtual from REveProjected.
544
546{
548 REvePointSet &ps = * dynamic_cast<REvePointSet*>(fProjectable);
549 REveTrans *tr = ps.PtrMainTrans(kFALSE);
550
551 // XXXX rewrite
552
553 Int_t n = ps.GetSize();
554 Reset(n);
555 fSize = n;
556 const Float_t *o = & ps.RefPoint(0).fX;
557 Float_t *p = & fPoints[0].fX;
558 for (Int_t i = 0; i < n; ++i, o+=3, p+=3)
559 {
560 proj.ProjectPointfv(tr, o, p, fDepth);
561 }
562}
563
564////////////////////////////////////////////////////////////////////////////////
565/// Virtual method of base class TPointSet3D.
566/// Forward to projectable.
567
569{
570 REvePointSet *ps = dynamic_cast<REvePointSet*>(fProjectable);
571 ps->PointSelected(id);
572}
#define d(i)
Definition: RSha256.hxx:102
#define e(i)
Definition: RSha256.hxx:103
int Int_t
Definition: RtypesCore.h:41
float Size_t
Definition: RtypesCore.h:83
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
short Color_t
Definition: RtypesCore.h:79
short Style_t
Definition: RtypesCore.h:76
float Float_t
Definition: RtypesCore.h:53
const Bool_t kTRUE
Definition: RtypesCore.h:87
char name[80]
Definition: TGX11.cxx:109
Binding & operator=(OUT(*fun)(void))
char * Form(const char *fmt,...)
void SetMainColorPtr(Color_t *colptr)
virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset)
Write core json.
virtual void AddElement(REveElement *el)
Add el to the list of children.
virtual void WriteVizParams(std::ostream &out, const TString &var)
Write-out visual parameters for this object.
void SetTitle(const std::string &title)
Set title of an element.
std::unique_ptr< REveRenderData > fRenderData
Externally assigned and controlled user data.
virtual Bool_t SetRnrSelf(Bool_t rnr)
Set render state of this element, i.e.
virtual void CopyVizParams(const REveElement *el)
Copy visualization parameters from element el.
virtual void RemoveElements()
Remove all elements.
void SetName(const std::string &name)
Set name of an element.
REveException Exception-type thrown by Eve classes.
Definition: REveTypes.hxx:40
Double_t fMin
Index of the last filled REvePointSet.
void CloseBins()
Call this after all the points have been filled.
REvePointSetArray(const REvePointSetArray &)
void SetMarkerSize(Size_t msize=1) override
Set marker size, propagate to children.
void SetMarkerColor(Color_t tcolor=1) override
Set marker color, propagate to children.
void RemoveElementsLocal() override
Virtual from REveElement, provide bin management.
void InitBins(const std::string &quant_name, Int_t nbins, Double_t min, Double_t max)
Initialize internal point-sets with given binning parameters.
Bool_t Fill(Double_t x, Double_t y, Double_t z, Double_t quant)
Add a new point.
virtual ~REvePointSetArray()
Destructor: deletes the fBins array.
void SetRange(Double_t min, Double_t max)
Set active range of the separating quantity.
void RemoveElementLocal(REveElement *el) override
Virtual from REveElement, provide bin management.
void SetMarkerStyle(Style_t mstyle=1) override
Set marker style, propagate to children.
Int_t Size(Bool_t under=kFALSE, Bool_t over=kFALSE) const
Get the total number of filled points.
void PointSelected(Int_t id)
Virtual method of base class TPointSet3D.
void SetProjection(REveProjectionManager *proj, REveProjectable *model) override
Set projection manager and projection model.
void UpdateProjection() override
Re-apply the projection.
void SetDepthLocal(Float_t d) override
Set depth (z-coordinate) of the projected points.
void PointSelected(Int_t id)
Virtual method of base class TPointSet3D.
virtual void ClonePoints(const REvePointSet &e)
Clone points and all point-related information from point-set 'e'.
void WriteVizParams(std::ostream &out, const TString &var) override
Write visualization parameters.
void SetMarkerColor(Color_t col) override
Set the marker color.
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Write core json.
void ComputeBBox() override
Compute bounding box.
virtual ~REvePointSet()
Destructor.
void SetMarkerSize(Size_t msize=1) override
Set marker size, propagate to projecteds.
void CopyVizParams(const REveElement *el) override
Copy visualization parameters from element el.
REvePointSet(const std::string &name="", const std::string &title="", Int_t n_points=0)
Constructor.
std::vector< REveVector > fPoints
int SetPoint(int n, float x, float y, float z)
int SetNextPoint(float x, float y, float z)
void Reset(Int_t n_points=0)
Drop all data and set-up the data structures to recive new data.
void SetMarkerStyle(Style_t mstyle=1) override
Set marker style, propagate to projecteds.
void BuildRenderData() override
Crates 3D point array for rendering.
TClass * ProjectedClass(const REveProjection *p) const override
Virtual from REveProjectable, returns REvePointSetProjected class.
Int_t GrowFor(Int_t n_points)
Resizes internal array to allow additional n_points to be stored.
virtual void SetProjection(REveProjectionManager *mng, REveProjectable *model)
Sets projection manager and reference in the projectable object.
void SetDepthCommon(Float_t d, REveElement *el, Float_t *bbox)
Utility function to update the z-values of the bounding-box.
REveProjectionManager Manager class for steering of projections and managing projected objects.
REveProjection Base for specific classes that implement non-linear projections.
void ProjectPointfv(Float_t *v, Float_t d)
Project float array.
Helper for management of bounding-box information.
Definition: TAttBBox.h:18
void BBoxCheckPoint(Float_t x, Float_t y, Float_t z)
Definition: TAttBBox.h:58
void ResetBBox()
Definition: TAttBBox.h:46
void BBoxZero(Float_t epsilon=0, Float_t x=0, Float_t y=0, Float_t z=0)
Create cube of volume (2*epsilon)^3 at (x,y,z).
Definition: TAttBBox.cxx:42
void BBoxInit(Float_t infinity=1e6)
Dynamic Float_t[6] X(min,max), Y(min,max), Z(min,max)
Definition: TAttBBox.cxx:29
Float_t * fBBox
Definition: TAttBBox.h:20
Marker Attributes class.
Definition: TAttMarker.h:19
virtual void SaveMarkerAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t sizdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition: TAttMarker.cxx:245
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition: TAttMarker.h:38
virtual Color_t GetMarkerColor() const
Return the marker color.
Definition: TAttMarker.h:31
Color_t fMarkerColor
Marker color.
Definition: TAttMarker.h:22
virtual Size_t GetMarkerSize() const
Return the marker size.
Definition: TAttMarker.h:33
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition: TAttMarker.h:40
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition: TAttMarker.h:41
Size_t fMarkerSize
Marker size.
Definition: TAttMarker.h:24
Style_t fMarkerStyle
Marker style.
Definition: TAttMarker.h:23
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:75
Basic string class.
Definition: TString.h:131
TPaveText * pt
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
static constexpr double pi
static constexpr double ps
TMath.
Definition: TMathBase.h:35
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
Int_t FloorNint(Double_t x)
Definition: TMath.h:697
Int_t CeilNint(Double_t x)
Definition: TMath.h:689
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:180
auto * m
Definition: textangle.C:8