ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
parallelcoordtrans.C
Go to the documentation of this file.
1 // Script illustrating the use of transparency with ||-Coord.
2 // It displays the same data set twice. The first time without transparency and
3 // the second time with transparency. On the second plot, several clusters
4 // appear.
5 
6 //Authors: Olivier Couet (original macro), adapted for TGCocoa by Timur Pocheptsov (26/09/2012).
7 
8 
9 //All these includes are (only) to make the macro
10 //ACLiCable.
11 #include <cassert>
12 
13 #include "TParallelCoordVar.h"
14 #include "TParallelCoord.h"
15 #include "TVirtualX.h"
16 #include "TNtuple.h"
17 #include "TCanvas.h"
18 #include "TRandom.h"
19 #include "TColor.h"
20 #include "Rtypes.h"
21 #include "TError.h"
22 #include "TList.h"
23 #include "TROOT.h"
24 
25 namespace ROOT {
26 namespace CocoaTutorials {
27 
28 Double_t r1, r2, r3, r4, r5, r6, r7, r8, r9;
30 
31 //______________________________________________________________________
33 {
34  const Double_t dr = 3.5;
35 
36  r.Rannor(r1, r4);
37  r.Rannor(r7, r9);
38 
39  r2 = (2 * dr * r.Rndm(i)) - dr;
40  r3 = (2 * dr * r.Rndm(i)) - dr;
41  r5 = (2 * dr * r.Rndm(i)) - dr;
42  r6 = (2 * dr * r.Rndm(i)) - dr;
43  r8 = (2 * dr * r.Rndm(i)) - dr;
44 }
45 
46 }//CocoaTutorials
47 }//ROOT
48 
50 {
51  //This macro shows how to use parallel coords and semi-transparent lines
52  //(the system color is updated with alpha == 0.01 (1% opaque).
53  //It does not demonstrate the right memory management/error handling.
54  //Requires OS X and ROOT configured with --enable-cocoa.
55 
56  using namespace ROOT::CocoaTutorials;
57 
58  Double_t s1x = 0., s1y = 0., s1z = 0.;
59  Double_t s2x = 0., s2y = 0., s2z = 0.;
60  Double_t s3x = 0., s3y = 0., s3z = 0.;
61 
62  TCanvas *c1 = new TCanvas("parallel coors", "parallel coords", 0, 0, 900, 1000);
63 
64  if (gVirtualX && !gVirtualX->InheritsFrom("TGCocoa")) {
65  ::Error("generate_random", "This macro works only on OS X with --enable-cocoa");
66  delete c1;
67  return;
68  }
69 
70  TNtuple * const nt = new TNtuple("nt", "Demo ntuple", "x:y:z:u:v:w:a:b:c");
71 
72  for (Int_t i = 0; i < 1500; ++i) {
73  r.Sphere(s1x, s1y, s1z, 0.1);
74  r.Sphere(s2x, s2y, s2z, 0.2);
75  r.Sphere(s3x, s3y, s3z, 0.05);
76 
77  generate_random(i);
78  nt->Fill(r1, r2, r3, r4, r5, r6, r7, r8, r9);
79 
80  generate_random(i);
81  nt->Fill(s1x, s1y, s1z, s2x, s2y, s2z, r7, r8, r9);
82 
83  generate_random(i);
84  nt->Fill(r1, r2, r3, r4, r5, r6, r7, s3y, r9);
85 
86  generate_random(i);
87  nt->Fill(s2x - 1, s2y - 1, s2z, s1x + .5, s1y + .5, s1z + .5, r7, r8, r9);
88 
89  generate_random(i);
90  nt->Fill(r1, r2, r3, r4, r5, r6, r7, r8, r9);
91 
92  generate_random(i);
93  nt->Fill(s1x + 1, s1y + 1, s1z + 1, s3x - 2, s3y - 2, s3z - 2, r7, r8, r9);
94 
95  generate_random(i);
96  nt->Fill(r1, r2, r3, r4, r5, r6, s3x, r8, s3z);
97  }
98 
99  c1->Divide(1, 2);
100  c1->cd(1);
101 
102  // ||-Coord plot without transparency
103  nt->Draw("x:y:z:u:v:w:a:b:c", "", "para");
104  TParallelCoord * const para1 = (TParallelCoord*)gPad->GetListOfPrimitives()->FindObject("ParaCoord");
105  assert(para1 != 0 && "parallelcoordtrans, 'ParaCoord' is null");
106 
107  para1->SetLineColor(25);
108  TParallelCoordVar *pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("x");
109  pcv->SetHistogramHeight(0.);
110 
111  pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("y");
112  pcv->SetHistogramHeight(0.);
113 
114  pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("z");
115  pcv->SetHistogramHeight(0.);
116 
117  pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("a");
118  pcv->SetHistogramHeight(0.);
119 
120  pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("b");
121  pcv->SetHistogramHeight(0.);
122 
123  pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("c");
124  pcv->SetHistogramHeight(0.);
125 
126  pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("u");
127  pcv->SetHistogramHeight(0.);
128 
129  pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("v");
130  pcv->SetHistogramHeight(0.);
131 
132  pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("w");
133  pcv->SetHistogramHeight(0.);
134 
135  // ||-Coord plot with transparency
136  // We modify a 'system' color! You'll probably
137  // have to restart ROOT or reset this color later.
138  TColor * const col26 = gROOT->GetColor(26);
139  assert(col26 != 0 && "parallelcoordtrans, color with index 26 not found");
140 
141  col26->SetAlpha(0.01);
142 
143  c1->cd(2);
144  nt->Draw("x:y:z:u:v:w:a:b:c","","para");
145  TParallelCoord * const para2 = (TParallelCoord*)gPad->GetListOfPrimitives()->FindObject("ParaCoord");
146  assert(para2 != 0 && "parallelcoordtrans, 'ParaCoord' is null");
147 
148  para2->SetLineColor(26);
149 
150  pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("x");
151  pcv->SetHistogramHeight(0.);
152 
153  pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("y");
154  pcv->SetHistogramHeight(0.);
155 
156  pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("z");
157  pcv->SetHistogramHeight(0.);
158 
159  pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("a");
160  pcv->SetHistogramHeight(0.);
161 
162  pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("b");
163  pcv->SetHistogramHeight(0.);
164 
165  pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("c");
166  pcv->SetHistogramHeight(0.);
167 
168  pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("u");
169  pcv->SetHistogramHeight(0.);
170 
171  pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("v");
172  pcv->SetHistogramHeight(0.);
173 
174  pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("w");
175  pcv->SetHistogramHeight(0.);
176 }
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:460
virtual Double_t Rndm(Int_t i=0)
Machine independent random number generator.
Definition: TRandom.cxx:512
TCanvas * c1
Definition: legend1.C:2
#define assert(cond)
Definition: unittest.h:542
#define gROOT
Definition: TROOT.h:344
int Int_t
Definition: RtypesCore.h:41
TParallelCoord axes.
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:29
void parallelcoordtrans()
void generate_random(Int_t i)
#define gVirtualX
Definition: TVirtualX.h:362
double Double_t
Definition: RtypesCore.h:55
The color creation and management class.
Definition: TColor.h:47
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:588
Parallel Coordinates class.
#define gPad
Definition: TVirtualPad.h:288
Double_t dr
Definition: parallelcoord.C:14
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition: TObject.cxx:379
void Error(ErrorHandler_t func, int code, const char *va_(fmt),...)
Write error message and call a handler, if required.