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