Logo ROOT   6.18/05
Reference Guide
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
17
18TEvePointSet* pointset(Int_t npoints = 512, TEveElement* parent=0)
19{
21
22 if (!gRandom) 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 {
32 ps->SetNextPoint(r.Uniform(-s,s), r.Uniform(-s,s), r.Uniform(-s,s));
33 ps->SetPointId(new TNamed(Form("Point %d", i), ""));
34 }
35
36 ps->SetMarkerColor(TMath::Nint(r.Uniform(2, 9)));
37 ps->SetMarkerSize(r.Uniform(1, 2));
38 ps->SetMarkerStyle(4);
39
40 if (parent) {
41 parent->AddElement(ps);
42 } else {
44 gEve->Redraw3D();
45 }
46
47 return ps;
48}
49
50TEvePointSet* pointset_hierarchy(Int_t level=3, Int_t nps=1, Int_t fac=2,
51 Int_t npoints=512, TEveElement* parent=0)
52{
53 // This only works in compiled mode!
54
55 TEvePointSet* ps = 0;
56 --level;
57 for (Int_t i=0; i<nps; ++i) {
58 printf("level=%d nps=%d i=%d\n", level, nps, i);
59 ps = pointset(npoints, parent);
60 if (level) {
61 pointset_hierarchy(level, nps*fac, fac, npoints/fac, ps);
62 }
63 }
64 return ps;
65}
66
67TEvePointSetArray* pointsetarray()
68{
70
71 TRandom r(0);
72
73 auto l = new TEvePointSetArray("TPC hits - Charge Slices", "");
75 l->SetMarkerColor(3);
76 l->SetMarkerStyle(4); // antialiased circle
77 l->SetMarkerSize(0.8);
78
80 l->InitBins("Charge", 9, 10, 100);
81
82 TColor::SetPalette(1, 0); // Spectrum palette
83 const Int_t nCol = TColor::GetNumberOfColors();
84 for (Int_t i = 1; i <= 9; ++i)
85 l->GetBin(i)->SetMainColor(TColor::GetColorPalette(i * nCol / 10));
86
87 l->GetBin(0) ->SetMainColor(kGray);
88 l->GetBin(10)->SetMainColor(kWhite);
89
90 Double_t rad, phi, z;
91 for (Int_t i = 0; i < 10000; ++i) {
92 rad = r.Uniform(60, 180);
93 phi = r.Uniform(0, TMath::TwoPi());
94 z = r.Uniform(-250, 250);
95 l->Fill(rad*TMath::Cos(phi), rad*TMath::Sin(phi), z, r.Uniform(0, 110));
96 }
97
98 l->CloseBins();
99
100 gEve->Redraw3D();
101
102 return l;
103}
ROOT::R::TRInterface & r
Definition: Object.C:4
int Int_t
Definition: RtypesCore.h:41
double Double_t
Definition: RtypesCore.h:55
float Float_t
Definition: RtypesCore.h:53
const Bool_t kTRUE
Definition: RtypesCore.h:87
@ kGray
Definition: Rtypes.h:63
@ kWhite
Definition: Rtypes.h:63
R__EXTERN TEveManager * gEve
Definition: TEveManager.h:243
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
char * Form(const char *fmt,...)
static void SetPalette(Int_t ncolors, Int_t *colors, Float_t alpha=1.)
Static function.
Definition: TColor.cxx:2404
static Int_t GetColorPalette(Int_t i)
Static function returning the color number i in current palette.
Definition: TColor.cxx:1390
static Int_t GetNumberOfColors()
Static function returning number of colors in the color palette.
Definition: TColor.cxx:1410
Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and...
Definition: TEveElement.h:34
void AddElement(TEveElement *element, TEveElement *parent=0)
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)
Definition: TEveManager.h:168
An array of point-sets with each point-set playing a role of a bin in a histogram.
Definition: TEvePointSet.h:111
TEvePointSet is a render-element holding a collection of 3D points with optional per-point TRef and a...
Definition: TEvePointSet.h:36
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
static constexpr double rad
static constexpr double s
static constexpr double ps
Int_t Nint(T x)
Round to nearest integer. Rounds half integers to the nearest even integer.
Definition: TMath.h:701
Double_t Cos(Double_t)
Definition: TMath.h:629
Double_t Sin(Double_t)
Definition: TMath.h:625
constexpr Double_t TwoPi()
Definition: TMath.h:45
auto * l
Definition: textangle.C:4