Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
pointset.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve
3/// Demonstrates usage of class TEvePointSet.
4///
5/// \image html eve_pointset.png
6/// \macro_code
7///
8/// \author Matevz Tadel
9
10#include <TEveManager.h>
11#include <TEvePointSet.h>
12#include <TEveRGBAPalette.h>
13#include <TColor.h>
14#include <TRandom.h>
15#include <TMath.h>
16
17TEvePointSet *pointset(Int_t npoints = 512, TEveElement *parent = nullptr)
18{
20
21 if (!gRandom)
22 gRandom = new TRandom(0);
23 TRandom &r = *gRandom;
24
25 Float_t s = 100;
26
27 auto ps = new TEvePointSet();
28 ps->SetOwnIds(kTRUE);
29
30 for (Int_t i = 0; i < npoints; i++) {
31 ps->SetNextPoint(r.Uniform(-s, s), r.Uniform(-s, s), r.Uniform(-s, s));
32 ps->SetPointId(new TNamed(Form("Point %d", i), ""));
33 }
34
35 ps->SetMarkerColor(TMath::Nint(r.Uniform(2, 9)));
36 ps->SetMarkerSize(r.Uniform(1, 2));
37 ps->SetMarkerStyle(4);
38
39 if (parent) {
40 parent->AddElement(ps);
41 } else {
42 gEve->AddElement(ps);
43 gEve->Redraw3D();
44 }
45
46 return ps;
47}
48
50pointset_hierarchy(Int_t level = 3, Int_t nps = 1, Int_t fac = 2, Int_t npoints = 512, TEveElement *parent = nullptr)
51{
52 // This only works in compiled mode!
53
54 TEvePointSet *ps = nullptr;
55 --level;
56 for (Int_t i = 0; i < nps; ++i) {
57 printf("level=%d nps=%d i=%d\n", level, nps, i);
58 ps = pointset(npoints, parent);
59 if (level) {
60 pointset_hierarchy(level, nps * fac, fac, npoints / fac, ps);
61 }
62 }
63 return ps;
64}
65
67{
69
70 TRandom r(0);
71
72 auto l = new TEvePointSetArray("TPC hits - Charge Slices", "");
74 l->SetMarkerColor(3);
75 l->SetMarkerStyle(4); // antialiased circle
76 l->SetMarkerSize(0.8);
77
79 l->InitBins("Charge", 9, 10, 100);
80
81 TColor::SetPalette(1, nullptr); // Spectrum palette
83 for (Int_t i = 1; i <= 9; ++i)
84 l->GetBin(i)->SetMainColor(TColor::GetColorPalette(i * nCol / 10));
85
86 l->GetBin(0)->SetMainColor(kGray);
87 l->GetBin(10)->SetMainColor(kWhite);
88
89 Double_t rad, phi, z;
90 for (Int_t i = 0; i < 10000; ++i) {
91 rad = r.Uniform(60, 180);
92 phi = r.Uniform(0, TMath::TwoPi());
93 z = r.Uniform(-250, 250);
94 l->Fill(rad * TMath::Cos(phi), rad * TMath::Sin(phi), z, r.Uniform(0, 110));
95 }
96
97 l->CloseBins();
98
99 gEve->Redraw3D();
100
101 return l;
102}
int Int_t
Definition RtypesCore.h:45
float Float_t
Definition RtypesCore.h:57
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
@ kGray
Definition Rtypes.h:65
@ kWhite
Definition Rtypes.h:65
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TEveManager * gEve
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
static void SetPalette(Int_t ncolors, Int_t *colors, Float_t alpha=1.)
Static function.
Definition TColor.cxx:2929
static Int_t GetColorPalette(Int_t i)
Static function returning the color number i in current palette.
Definition TColor.cxx:1508
static Int_t GetNumberOfColors()
Static function returning number of colors in the color palette.
Definition TColor.cxx:1528
Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and...
Definition TEveElement.h:36
void AddElement(TEveElement *element, TEveElement *parent=nullptr)
Add an element.
static TEveManager * Create(Bool_t map_window=kTRUE, Option_t *opt="FIV")
If global TEveManager* gEve is not set initialize it.
void Redraw3D(Bool_t resetCameras=kFALSE, Bool_t dropLogicals=kFALSE)
An array of point-sets with each point-set playing a role of a bin in a histogram.
TEvePointSet is a render-element holding a collection of 3D points with optional per-point TRef and a...
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
This is the base class for the ROOT Random number generators.
Definition TRandom.h:27
Int_t Nint(T x)
Round to nearest integer. Rounds half integers to the nearest even integer.
Definition TMath.h:697
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Definition TMath.h:598
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Definition TMath.h:592
constexpr Double_t TwoPi()
Definition TMath.h:44
TLine l
Definition textangle.C:4