Logo ROOT   6.12/07
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 
18 TEvePointSet* pointset(Int_t npoints = 512, TEveElement* parent=0)
19 {
21 
22  if (!gRandom)
23  gRandom = new TRandom(0);
24  TRandom& r= *gRandom;
25 
26  Float_t s = 100;
27 
28  TEvePointSet* ps = new TEvePointSet();
29  ps->SetOwnIds(kTRUE);
30 
31  for(Int_t i = 0; i<npoints; i++)
32  {
33  ps->SetNextPoint(r.Uniform(-s,s), r.Uniform(-s,s), r.Uniform(-s,s));
34  ps->SetPointId(new TNamed(Form("Point %d", i), ""));
35  }
36 
37  ps->SetMarkerColor(TMath::Nint(r.Uniform(2, 9)));
38  ps->SetMarkerSize(r.Uniform(1, 2));
39  ps->SetMarkerStyle(4);
40 
41  if (parent)
42  {
43  parent->AddElement(ps);
44  }
45  else
46  {
47  gEve->AddElement(ps);
48  gEve->Redraw3D();
49  }
50 
51  return ps;
52 }
53 
55 pointset_hierarchy(Int_t level=3, Int_t nps=1, Int_t fac=2,
56  Int_t npoints=512, TEveElement* parent=0)
57 {
58  // This only works in compiled mode!
59 
60  TEvePointSet* ps = 0;
61  --level;
62  for (Int_t i=0; i<nps; ++i)
63  {
64  printf("level=%d nps=%d i=%d\n", level, nps, i);
65  ps = pointset(npoints, parent);
66  if (level)
67  {
68  pointset_hierarchy(level, nps*fac, fac, npoints/fac, ps);
69  }
70  }
71  return ps;
72 }
73 
74 TEvePointSetArray* pointsetarray()
75 {
77 
78  TRandom r(0);
79 
80  TEvePointSetArray* l = new TEvePointSetArray("TPC hits - Charge Slices", "");
82  l->SetMarkerColor(3);
83  l->SetMarkerStyle(4); // antialiased circle
84  l->SetMarkerSize(0.8);
85 
86  gEve->AddElement(l);
87  l->InitBins("Charge", 9, 10, 100);
88 
89  TColor::SetPalette(1, 0); // Spectrum palette
90  const Int_t nCol = TColor::GetNumberOfColors();
91  for (Int_t i = 1; i <= 9; ++i)
92  l->GetBin(i)->SetMainColor(TColor::GetColorPalette(i * nCol / 10));
93 
94  l->GetBin(0) ->SetMainColor(kGray);
95  l->GetBin(10)->SetMainColor(kWhite);
96 
97  Double_t rad, phi, z;
98  for (Int_t i = 0; i < 10000; ++i)
99  {
100  rad = r.Uniform(60, 180);
101  phi = r.Uniform(0, TMath::TwoPi());
102  z = r.Uniform(-250, 250);
103  l->Fill(rad*TMath::Cos(phi), rad*TMath::Sin(phi), z,
104  r.Uniform(0, 110));
105  }
106 
107  l->CloseBins();
108 
109  gEve->Redraw3D();
110 
111  return l;
112 }
float Float_t
Definition: RtypesCore.h:53
TEvePointSet * GetBin(Int_t bin) const
Definition: TEvePointSet.h:153
constexpr Double_t TwoPi()
Definition: TMath.h:44
Definition: Rtypes.h:58
static Int_t GetNumberOfColors()
Static function returning number of colors in the color palette.
Definition: TColor.cxx:1397
static constexpr double ps
int Int_t
Definition: RtypesCore.h:41
virtual void SetMarkerStyle(Style_t mstyle=1)
Set marker style, propagate to projecteds.
void Redraw3D(Bool_t resetCameras=kFALSE, Bool_t dropLogicals=kFALSE)
Definition: TEveManager.h:168
static constexpr double rad
An array of point-sets with each point-set playing a role of a bin in a histogram.
Definition: TEvePointSet.h:107
virtual void SetMarkerColor(Color_t tcolor=1)
Set marker color, propagate to children.
static void SetPalette(Int_t ncolors, Int_t *colors, Float_t alpha=1.)
Static function.
Definition: TColor.cxx:2390
void AddElement(TEveElement *element, TEveElement *parent=0)
Add an element.
static Int_t GetColorPalette(Int_t i)
Static function returning the color number i in current palette.
Definition: TColor.cxx:1377
void SetPointId(TObject *id)
Set id of last point.
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual void SetMarkerColor(Color_t col)
Set the marker color.
Definition: TEvePointSet.h:81
static TEveManager * Create(Bool_t map_window=kTRUE, Option_t *opt="FIV")
If global TEveManager* gEve is not set initialize it.
void SetOwnIds(Bool_t o)
Definition: TPointSet3D.h:52
virtual void SetMarkerSize(Size_t msize=1)
Set marker size, propagate to projecteds.
Definition: Rtypes.h:58
ROOT::R::TRInterface & r
Definition: Object.C:4
Bool_t Fill(Double_t x, Double_t y, Double_t z, Double_t quant)
Add a new point.
R__EXTERN TEveManager * gEve
Definition: TEveManager.h:243
char * Form(const char *fmt,...)
TEvePointSet is a render-element holding a collection of 3D points with optional per-point TRef and a...
Definition: TEvePointSet.h:31
void CloseBins()
Call this after all the points have been filled.
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
virtual void SetMainColor(Color_t color)
Set main color of the element.
Double_t Cos(Double_t)
Definition: TMath.h:550
virtual Int_t SetNextPoint(Double_t x, Double_t y, Double_t z)
Set point following LastPoint to x, y, z.
double Double_t
Definition: RtypesCore.h:55
static constexpr double s
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition: TRandom.cxx:627
virtual void SetMarkerSize(Size_t msize=1)
Set marker size, propagate to children.
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
auto * l
Definition: textangle.C:4
Double_t Sin(Double_t)
Definition: TMath.h:547
virtual void SetMarkerStyle(Style_t mstyle=1)
Set marker style, propagate to children.
const Bool_t kTRUE
Definition: RtypesCore.h:87
Int_t Nint(T x)
Definition: TMath.h:606
Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and...
Definition: TEveElement.h:33
void InitBins(const char *quant_name, Int_t nbins, Double_t min, Double_t max)
Initialize internal point-sets with given binning parameters.
void SetSourceCS(ETreeVarType_e cs)
Definition: TEveTreeTools.h:61