Logo ROOT  
Reference Guide
parallelcoordtrans.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_gl
3/// Script illustrating the use of transparency with ||-Coord.
4/// It displays the same data set twice. The first time without transparency and
5/// the second time with transparency. On the second plot, several clusters
6/// appear.
7///
8/// \macro_image(nobatch)
9/// \macro_code
10///
11/// \authors Timur Pocheptsov, Olivier Couet
12
13//All these includes are (only) to make the macro
14//ACLiCable.
15#include <cassert>
16
17#include "TParallelCoordVar.h"
18#include "TParallelCoord.h"
19#include "TNtuple.h"
20#include "TCanvas.h"
21#include "TRandom.h"
22#include "TColor.h"
23#include "TStyle.h"
24#include "TError.h"
25#include "TList.h"
26#include "TROOT.h"
27
28namespace ROOT {
29namespace GLTutorials {
30
31Double_t r1, r2, r3, r4, r5, r6, r7, r8, r9;
33
34//______________________________________________________________________
35void generate_random(Int_t i)
36{
37 const Double_t dr = 3.5;
38
39 r.Rannor(r1, r4);
40 r.Rannor(r7, r9);
41
42 r2 = (2 * dr * r.Rndm(i)) - dr;
43 r3 = (2 * dr * r.Rndm(i)) - dr;
44 r5 = (2 * dr * r.Rndm(i)) - dr;
45 r6 = (2 * dr * r.Rndm(i)) - dr;
46 r8 = (2 * dr * r.Rndm(i)) - dr;
47}
48
49}//GLTutorials
50}//ROOT
51
52void parallelcoordtrans()
53{
54 //This macro shows how to use parallel coords and semi-transparent lines
55 //(the system color is updated with alpha == 0.01 (1% opaque).
56
57 using namespace ROOT::GLTutorials;
58
59 Double_t s1x = 0., s1y = 0., s1z = 0.;
60 Double_t s2x = 0., s2y = 0., s2z = 0.;
61 Double_t s3x = 0., s3y = 0., s3z = 0.;
62
64 TCanvas *c1 = new TCanvas("parallel coors", "parallel coords", 0, 0, 900, 1000);
65
66 TNtuple * const nt = new TNtuple("nt", "Demo ntuple", "x:y:z:u:v:w:a:b:c");
67
68 for (Int_t i = 0; i < 1500; ++i) {
69 r.Sphere(s1x, s1y, s1z, 0.1);
70 r.Sphere(s2x, s2y, s2z, 0.2);
71 r.Sphere(s3x, s3y, s3z, 0.05);
72
73 generate_random(i);
74 nt->Fill(r1, r2, r3, r4, r5, r6, r7, r8, r9);
75
76 generate_random(i);
77 nt->Fill(s1x, s1y, s1z, s2x, s2y, s2z, r7, r8, r9);
78
79 generate_random(i);
80 nt->Fill(r1, r2, r3, r4, r5, r6, r7, s3y, r9);
81
82 generate_random(i);
83 nt->Fill(s2x - 1, s2y - 1, s2z, s1x + .5, s1y + .5, s1z + .5, r7, r8, r9);
84
85 generate_random(i);
86 nt->Fill(r1, r2, r3, r4, r5, r6, r7, r8, r9);
87
88 generate_random(i);
89 nt->Fill(s1x + 1, s1y + 1, s1z + 1, s3x - 2, s3y - 2, s3z - 2, r7, r8, r9);
90
91 generate_random(i);
92 nt->Fill(r1, r2, r3, r4, r5, r6, s3x, r8, s3z);
93 }
94
95 c1->Divide(1, 2);
96 c1->cd(1);
97
98 // ||-Coord plot without transparency
99 nt->Draw("x:y:z:u:v:w:a:b:c", "", "para");
100 TParallelCoord * const para1 = (TParallelCoord*)gPad->GetListOfPrimitives()->FindObject("ParaCoord");
101 assert(para1 != 0 && "parallelcoordtrans, 'ParaCoord' is null");
102
103 para1->SetLineColor(25);
105 pcv->SetHistogramHeight(0.);
106
107 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("y");
108 pcv->SetHistogramHeight(0.);
109
110 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("z");
111 pcv->SetHistogramHeight(0.);
112
113 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("a");
114 pcv->SetHistogramHeight(0.);
115
116 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("b");
117 pcv->SetHistogramHeight(0.);
118
119 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("c");
120 pcv->SetHistogramHeight(0.);
121
122 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("u");
123 pcv->SetHistogramHeight(0.);
124
125 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("v");
126 pcv->SetHistogramHeight(0.);
127
128 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("w");
129 pcv->SetHistogramHeight(0.);
130
131 // ||-Coord plot with transparency
132 // We modify a 'system' color! You'll probably
133 // have to restart ROOT or reset this color later.
134 TColor * const col26 = gROOT->GetColor(26);
135 assert(col26 != 0 && "parallelcoordtrans, color with index 26 not found");
136
137 col26->SetAlpha(0.01);
138
139 c1->cd(2);
140 nt->Draw("x:y:z:u:v:w:a:b:c","","para");
141 TParallelCoord * const para2 = (TParallelCoord*)gPad->GetListOfPrimitives()->FindObject("ParaCoord");
142 assert(para2 != 0 && "parallelcoordtrans, 'ParaCoord' is null");
143
144 para2->SetLineColor(26);
145
146 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("x");
147 pcv->SetHistogramHeight(0.);
148
149 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("y");
150 pcv->SetHistogramHeight(0.);
151
152 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("z");
153 pcv->SetHistogramHeight(0.);
154
155 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("a");
156 pcv->SetHistogramHeight(0.);
157
158 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("b");
159 pcv->SetHistogramHeight(0.);
160
161 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("c");
162 pcv->SetHistogramHeight(0.);
163
164 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("u");
165 pcv->SetHistogramHeight(0.);
166
167 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("v");
168 pcv->SetHistogramHeight(0.);
169
170 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("w");
171 pcv->SetHistogramHeight(0.);
172}
ROOT::R::TRInterface & r
Definition: Object.C:4
int Int_t
Definition: RtypesCore.h:41
double Double_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define gROOT
Definition: TROOT.h:415
R__EXTERN TStyle * gStyle
Definition: TStyle.h:407
#define gPad
Definition: TVirtualPad.h:286
The Canvas class.
Definition: TCanvas.h:31
The color creation and management class.
Definition: TColor.h:19
virtual void SetAlpha(Float_t a)
Definition: TColor.h:67
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:575
A simple TTree restricted to a list of float variables only.
Definition: TNtuple.h:28
virtual Int_t Fill()
Fill a Ntuple with current values in fArgs.
Definition: TNtuple.cxx:170
TParallelCoord axes.
void SetHistogramHeight(Double_t h=0)
Set the height of the bar histogram.
Parallel Coordinates class.
void SetLineColor(Color_t col)
TList * GetVarList()
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
void SetCanvasPreferGL(Bool_t prefer=kTRUE)
Definition: TStyle.h:320
virtual void Draw(Option_t *opt)
Default Draw method for all objects.
Definition: TTree.h:419
return c1
Definition: legend1.C:41
VSD Structures.
Definition: StringConv.hxx:21