Logo ROOT   6.14/05
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 
28 namespace ROOT {
29 namespace GLTutorials {
30 
31 Double_t r1, r2, r3, r4, r5, r6, r7, r8, r9;
32 TRandom r;
33 
34 //______________________________________________________________________
35 void 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 
52 void 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 }
virtual void SetAlpha(Float_t a)
Definition: TColor.h:66
virtual void Rannor(Float_t &a, Float_t &b)
Return 2 numbers distributed following a gaussian with mean=0 and sigma=1.
Definition: TRandom.cxx:481
void SetLineColor(Color_t col)
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
return c1
Definition: legend1.C:41
R__EXTERN TStyle * gStyle
Definition: TStyle.h:406
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:688
#define gROOT
Definition: TROOT.h:410
int Int_t
Definition: RtypesCore.h:41
virtual TObject * FindObject(const char *name) const
Delete a TObjLink object.
Definition: TList.cxx:574
TParallelCoord axes.
TList * GetVarList()
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandom.cxx:533
void SetCanvasPreferGL(Bool_t prefer=kTRUE)
Definition: TStyle.h:319
ROOT::R::TRInterface & r
Definition: Object.C:4
A simple TTree restricted to a list of float variables only.
Definition: TNtuple.h:28
The Canvas class.
Definition: TCanvas.h:31
void SetHistogramHeight(Double_t h=0)
Set the height of the bar histogram.
double Double_t
Definition: RtypesCore.h:55
virtual void Draw(Option_t *opt)
Default Draw method for all objects.
Definition: TTree.h:357
virtual Int_t Fill()
Fill a Ntuple with current values in fArgs.
Definition: TNtuple.cxx:170
The color creation and management class.
Definition: TColor.h:19
virtual void Sphere(Double_t &x, Double_t &y, Double_t &z, Double_t r)
Generates random vectors, uniformly distributed over the surface of a sphere of given radius...
Definition: TRandom.cxx:609
Parallel Coordinates class.
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1162
#define gPad
Definition: TVirtualPad.h:285
const Bool_t kTRUE
Definition: RtypesCore.h:87