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 "TArrayI.h"
20#include "TClass.h"
21
22#include <nlohmann/json.hpp>
23
24using namespace ROOT::Experimental;
25
26/** \class REvePointSet
27\ingroup REve
28REvePointSet is a render-element holding a collection of 3D points with
29optional per-point TRef and an arbitrary number of integer ids (to
30be used for signal, volume-id, track-id, etc).
31
323D point representation is implemented in base-class TPolyMarker3D.
33Per-point TRef is implemented in base-class TPointSet3D.
34
35By using the REvePointSelector the points and integer ids can be
36filled directly from a TTree holding the source data.
37Setting of per-point TRef's is not supported.
38
39REvePointSet is a REveProjectable: it can be projected by using the
40REveProjectionManager class.
41*/
42
43////////////////////////////////////////////////////////////////////////////////
44/// Constructor.
45
46REvePointSet::REvePointSet(const std::string& name, const std::string& title, Int_t n_points) :
47 REveElement(name, title),
48 TAttMarker(),
49 TAttBBox()
50{
51 fMarkerStyle = 20;
52
54
55 Reset(n_points);
56
57 // Override from REveElement.
59}
60
61////////////////////////////////////////////////////////////////////////////////
62/// Copy constructor.
63
68 TAttBBox(e)
69{
70}
71
72////////////////////////////////////////////////////////////////////////////////
73/// Destructor.
74
76{
77}
78
79////////////////////////////////////////////////////////////////////////////////
80/// Clone points and all point-related information from point-set 'e'.
81
83{
84 fPoints = e.fPoints;
85 fCapacity = e.fCapacity;
86 fSize = e.fSize;
87}
88
89////////////////////////////////////////////////////////////////////////////////
90/// Drop all data and set-up the data structures to recive new data.
91/// n_points specifies the initial size of the array.
92
94{
95 fPoints.resize(n_points);
96 fCapacity = n_points;
97 fSize = 0;
98
99 ResetBBox();
100}
101
102////////////////////////////////////////////////////////////////////////////////
103/// Resizes internal array to allow additional n_points to be stored.
104/// Returns the old size which is also the location where one can
105/// start storing new data.
106/// The caller is *obliged* to fill the new point slots.
107
109{
110 assert(n_points >= 0);
111
112 Int_t old_size = fCapacity;
113 Int_t new_size = old_size + n_points;
114
115 fPoints.resize(new_size);
116 fCapacity = new_size;
117
118 return old_size;
119}
120
121int REvePointSet::SetNextPoint(float x, float y, float z)
122{
123 return SetPoint(fSize, x, y, z);
124}
125
126int REvePointSet::SetPoint(int n, float x, float y, float z)
127{
128 if (n >= fCapacity)
129 {
130 fCapacity = std::max(n + 1, 2*fCapacity);
131 fPoints.resize(fCapacity);
132 }
133 fPoints[n].Set(x, y, z);
134 if (n >= fSize)
135 {
136 fSize = n + 1;
137 }
138 return fSize;
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// Set marker style, propagate to projecteds.
143
145{
146 for (auto &pi: fProjectedList)
147 {
148 REvePointSet* pt = dynamic_cast<REvePointSet *>(pi);
149 if (pt)
150 {
151 pt->SetMarkerStyle(mstyle);
152 pt->StampObjProps();
153 }
154 }
156}
157
158////////////////////////////////////////////////////////////////////////////////
159/// Set marker size, propagate to projecteds.
160
162{
163 for (auto &pi: fProjectedList)
164 {
165 REvePointSet* pt = dynamic_cast<REvePointSet *>(pi);
166 if (pt)
167 {
168 pt->SetMarkerSize(msize);
169 pt->StampObjProps();
170 }
171 }
174}
175
176////////////////////////////////////////////////////////////////////////////////
177/// Copy visualization parameters from element el.
178
180{
181 const REvePointSet* m = dynamic_cast<const REvePointSet*>(el);
182 if (m)
183 {
185 }
186
188}
189
190////////////////////////////////////////////////////////////////////////////////
191/// Write visualization parameters.
192
193void REvePointSet::WriteVizParams(std::ostream& out, const TString& var)
194{
196
198}
199
200////////////////////////////////////////////////////////////////////////////////
201/// Virtual from REveProjectable, returns REvePointSetProjected class.
202
204{
205 return TClass::GetClass<REvePointSetProjected>();
206}
207
208
210{
211 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
212
213 j["fMarkerSize"] = GetMarkerSize();
214 j["fMarkerColor"] = GetMarkerColor();
215
216 return ret;
217}
218
219////////////////////////////////////////////////////////////////////////////////
220/// Crates 3D point array for rendering.
221
223{
224 if (fSize > 0)
225 {
226 fRenderData = std::make_unique<REveRenderData>("makeHit", 3*fSize);
227 fRenderData->PushV(&fPoints[0].fX, 3*fSize);
228 }
229}
230
231////////////////////////////////////////////////////////////////////////////////
232/// Compute bounding box.
233
235{
236 if (fSize > 0) {
237 BBoxInit();
238 for (auto &p : fPoints)
239 {
240 BBoxCheckPoint(p.fX, p.fY, p.fZ);
241 }
242 } else {
243 BBoxZero();
244 }
245}
246
247////////////////////////////////////////////////////////////////////////////////
248/// Virtual method of base class TPointSet3D. The function call is
249/// invoked with secondary selection in TPointSet3DGL.
250
252{
253 // Emit("PointSelected(Int_t)", id);
254}
255
256
257//==============================================================================
258// REvePointSetArray
259//==============================================================================
260
261/** \class REvePointSetArray
262\ingroup REve
263An array of point-sets with each point-set playing a role of a bin
264in a histogram. When a new point is added to a REvePointSetArray,
265an additional separating quantity needs to be specified: it
266determines into which REvePointSet (bin) the point will actually be
267stored. Underflow and overflow bins are automatically created but
268they are not drawn by default.
269
270By using the REvePointSelector the points and the separating
271quantities can be filled directly from a TTree holding the source
272data.
273Setting of per-point TRef's is not supported.
274
275After the filling, the range of separating variable can be
276controlled with a slider to choose a sub-set of PointSets that are
277actually shown.
278*/
279
280////////////////////////////////////////////////////////////////////////////////
281/// Constructor.
282
284 const std::string& title) :
285 REveElement(name, title),
286
287 fBins(nullptr), fDefPointSetCapacity(128), fNBins(0), fLastBin(-1),
288 fMin(0), fCurMin(0), fMax(0), fCurMax(0),
289 fBinWidth(0),
290 fQuantName()
291{
293}
294
295////////////////////////////////////////////////////////////////////////////////
296/// Destructor: deletes the fBins array. Actual removal of
297/// elements done by REveElement.
298
300{
301 // printf("REvePointSetArray::~REvePointSetArray()\n");
302 delete [] fBins; fBins = nullptr;
303}
304
305////////////////////////////////////////////////////////////////////////////////
306/// Virtual from REveElement, provide bin management.
307
309{
310 for (Int_t i=0; i<fNBins; ++i) {
311 if (fBins[i] == el) {
312 fBins[i] = nullptr;
313 break;
314 }
315 }
316}
317
318////////////////////////////////////////////////////////////////////////////////
319/// Virtual from REveElement, provide bin management.
320
322{
323 delete [] fBins; fBins = nullptr; fLastBin = -1;
324}
325
326////////////////////////////////////////////////////////////////////////////////
327/// Set marker color, propagate to children.
328
330{
331 for (auto & el : fChildren)
332 {
333 TAttMarker* m = dynamic_cast<TAttMarker*>(el);
334 if (m && m->GetMarkerColor() == fMarkerColor)
335 m->SetMarkerColor(tcolor);
336 }
338}
339
340////////////////////////////////////////////////////////////////////////////////
341/// Set marker style, propagate to children.
342
344{
345 for (auto & el : fChildren)
346 {
347 TAttMarker* m = dynamic_cast<TAttMarker*>(el);
348 if (m && m->GetMarkerStyle() == fMarkerStyle)
349 m->SetMarkerStyle(mstyle);
350 }
352}
353
354////////////////////////////////////////////////////////////////////////////////
355/// Set marker size, propagate to children.
356
358{
359 for (auto & el : fChildren)
360 {
361 TAttMarker* m = dynamic_cast<TAttMarker*>(el);
362 if (m && m->GetMarkerSize() == fMarkerSize)
363 m->SetMarkerSize(msize);
364 }
366}
367
368////////////////////////////////////////////////////////////////////////////////
369/// Get the total number of filled points.
370/// 'under' and 'over' flags specify if under/overflow channels
371/// should be added to the sum.
372
374{
375 Int_t size = 0;
376 const Int_t min = under ? 0 : 1;
377 const Int_t max = over ? fNBins : fNBins - 1;
378 for (Int_t i = min; i < max; ++i)
379 {
380 if (fBins[i])
381 size += fBins[i]->GetSize();
382 }
383 return size;
384}
385
386////////////////////////////////////////////////////////////////////////////////
387/// Initialize internal point-sets with given binning parameters.
388/// The actual number of bins is nbins+2, bin 0 corresponding to
389/// underflow and bin nbin+1 to owerflow pointset.
390
391void REvePointSetArray::InitBins(const std::string& quant_name,
392 Int_t nbins, Double_t min, Double_t max)
393{
394 static const REveException eh("REvePointSetArray::InitBins ");
395
396 if (nbins < 1) throw eh + "nbins < 1.";
397 if (min > max) throw eh + "min > max.";
398
400
401 fQuantName = quant_name;
402 fNBins = nbins + 2; // under/overflow
403 fLastBin = -1;
404 fMin = fCurMin = min;
405 fMax = fCurMax = max;
406 fBinWidth = (fMax - fMin)/(fNBins - 2);
407
408 fBins = new REvePointSet* [fNBins];
409
410 for (Int_t i = 0; i < fNBins; ++i)
411 {
412 fBins[i] = new REvePointSet
413 (Form("Slice %d [%4.3lf, %4.3lf]", i, fMin + (i-1)*fBinWidth, fMin + i*fBinWidth),
414 "",
419 AddElement(fBins[i]);
420 }
421
422 fBins[0]->SetName("Underflow");
424
425 fBins[fNBins-1]->SetName("Overflow");
427}
428
429////////////////////////////////////////////////////////////////////////////////
430/// Add a new point. Appropriate point-set will be chosen based on
431/// the value of the separating quantity 'quant'.
432/// If the selected bin does not have an associated REvePointSet
433/// the point is discarded and false is returned.
434
436{
437 fLastBin = TMath::FloorNint((quant - fMin)/fBinWidth) + 1;
438
439 if (fLastBin < 0)
440 {
441 fLastBin = 0;
442 }
443 else if (fLastBin > fNBins - 1)
444 {
445 fLastBin = fNBins - 1;
446 }
447
448 if (fBins[fLastBin] != 0)
449 {
451 return kTRUE;
452 }
453 else
454 {
455 return kFALSE;
456 }
457}
458
459////////////////////////////////////////////////////////////////////////////////
460/// Call this after all the points have been filled.
461/// At this point we can calculate bounding-boxes of individual
462/// point-sets.
463
465{
466 for (Int_t i=0; i<fNBins; ++i)
467 {
468 if (fBins[i])
469 {
470 fBins[i]->SetTitle(Form("N=%d", fBins[i]->GetSize()));
471 fBins[i]->ComputeBBox();
472 }
473 }
474 fLastBin = -1;
475}
476
477////////////////////////////////////////////////////////////////////////////////
478/// Set active range of the separating quantity.
479/// Appropriate point-sets are tagged for rendering.
480/// Over/underflow point-sets are left as they were.
481
483{
484 using namespace TMath;
485
486 fCurMin = min; fCurMax = max;
487 Int_t low_b = Max(0, FloorNint((min-fMin)/fBinWidth)) + 1;
488 Int_t high_b = Min(fNBins-2, CeilNint ((max-fMin)/fBinWidth));
489
490 for (Int_t i = 1; i < fNBins - 1; ++i)
491 {
492 if (fBins[i])
493 fBins[i]->SetRnrSelf(i>=low_b && i<=high_b);
494 }
495}
496
497/** \class REvePointSetProjected
498\ingroup REve
499Projected copy of a REvePointSet.
500*/
501
502////////////////////////////////////////////////////////////////////////////////
503/// Default contructor.
504
506 REvePointSet (),
508{
509}
510
511////////////////////////////////////////////////////////////////////////////////
512/// Set projection manager and projection model.
513/// Virtual from REveProjected.
514
516 REveProjectable* model)
517{
518 REveProjected::SetProjection(proj, model);
519 CopyVizParams(dynamic_cast<REveElement*>(model));
520}
521
522////////////////////////////////////////////////////////////////////////////////
523/// Set depth (z-coordinate) of the projected points.
524
526{
527 SetDepthCommon(d, this, fBBox);
528
529 // XXXX rewrite
530
531 Int_t n = fSize;
532 Float_t *p = & fPoints[0].fZ;
533 for (Int_t i = 0; i < n; ++i, p+=3)
534 *p = fDepth;
535}
536
537////////////////////////////////////////////////////////////////////////////////
538/// Re-apply the projection.
539/// Virtual from REveProjected.
540
542{
544 REvePointSet &ps = * dynamic_cast<REvePointSet*>(fProjectable);
545 REveTrans *tr = ps.PtrMainTrans(kFALSE);
546
547 // XXXX rewrite
548
549 Int_t n = ps.GetSize();
550 Reset(n);
551 fSize = n;
552 const Float_t *o = & ps.RefPoint(0).fX;
553 Float_t *p = & fPoints[0].fX;
554 for (Int_t i = 0; i < n; ++i, o+=3, p+=3)
555 {
556 proj.ProjectPointfv(tr, o, p, fDepth);
557 }
558}
559
560////////////////////////////////////////////////////////////////////////////////
561/// Virtual method of base class TPointSet3D.
562/// Forward to projectable.
563
565{
566 REvePointSet *ps = dynamic_cast<REvePointSet*>(fProjectable);
567 ps->PointSelected(id);
568}
#define d(i)
Definition: RSha256.hxx:102
#define e(i)
Definition: RSha256.hxx:103
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Definition: RtypesCore.h:45
float Size_t
Definition: RtypesCore.h:96
const Bool_t kFALSE
Definition: RtypesCore.h:101
bool Bool_t
Definition: RtypesCore.h:63
double Double_t
Definition: RtypesCore.h:59
short Color_t
Definition: RtypesCore.h:92
short Style_t
Definition: RtypesCore.h:89
float Float_t
Definition: RtypesCore.h:57
const Bool_t kTRUE
Definition: RtypesCore.h:100
char name[80]
Definition: TGX11.cxx:110
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:41
Double_t fMin
Index of the last filled REvePointSet.
void CloseBins()
Call this after all the points have been filled.
void SetMarkerSize(Size_t msize=1) override
Set marker size, propagate to children.
REvePointSetArray(const REvePointSetArray &)=delete
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:345
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:80
Basic string class.
Definition: TString.h:136
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:208
Int_t FloorNint(Double_t x)
Definition: TMath.h:657
Int_t CeilNint(Double_t x)
Definition: TMath.h:649
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:176
basic_json< std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t, double, std::allocator, adl_serializer, std::vector< std::uint8_t > > json
Definition: REveElement.hxx:36
auto * m
Definition: textangle.C:8