Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
parallelcoordtrans.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_cocoa
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_code
9///
10/// \authors Timur Pocheptsov, Olivier Couet
11
12//All these includes are (only) to make the macro
13//ACLiCable.
14#include <cassert>
15
16#include "TParallelCoordVar.h"
17#include "TParallelCoord.h"
18#include "TVirtualX.h"
19#include "TNtuple.h"
20#include "TCanvas.h"
21#include "TRandom.h"
22#include "TColor.h"
23#include "Rtypes.h"
24#include "TError.h"
25#include "TList.h"
26#include "TROOT.h"
27
28namespace ROOT {
29namespace CocoaTutorials {
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}//CocoaTutorials
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 //It does not demonstrate the right memory management/error handling.
57 //Requires OS X and ROOT configured with --enable-cocoa.
58
59 using namespace ROOT::CocoaTutorials;
60
61 Double_t s1x = 0., s1y = 0., s1z = 0.;
62 Double_t s2x = 0., s2y = 0., s2z = 0.;
63 Double_t s3x = 0., s3y = 0., s3z = 0.;
64
65 TCanvas *c1 = new TCanvas("parallel coords", "parallel coords", 0, 0, 900, 1000);
66
67 if (gVirtualX && !gVirtualX->InheritsFrom("TGCocoa")) {
68 ::Error("generate_random", "This macro works only on OS X with --enable-cocoa");
69 delete c1;
70 return;
71 }
72
73 TNtuple * const nt = new TNtuple("nt", "Demo ntuple", "x:y:z:u:v:w:a:b:c");
74
75 for (Int_t i = 0; i < 1500; ++i) {
76 r.Sphere(s1x, s1y, s1z, 0.1);
77 r.Sphere(s2x, s2y, s2z, 0.2);
78 r.Sphere(s3x, s3y, s3z, 0.05);
79
80 generate_random(i);
81 nt->Fill(r1, r2, r3, r4, r5, r6, r7, r8, r9);
82
83 generate_random(i);
84 nt->Fill(s1x, s1y, s1z, s2x, s2y, s2z, r7, r8, r9);
85
86 generate_random(i);
87 nt->Fill(r1, r2, r3, r4, r5, r6, r7, s3y, r9);
88
89 generate_random(i);
90 nt->Fill(s2x - 1, s2y - 1, s2z, s1x + .5, s1y + .5, s1z + .5, r7, r8, r9);
91
92 generate_random(i);
93 nt->Fill(r1, r2, r3, r4, r5, r6, r7, r8, r9);
94
95 generate_random(i);
96 nt->Fill(s1x + 1, s1y + 1, s1z + 1, s3x - 2, s3y - 2, s3z - 2, r7, r8, r9);
97
98 generate_random(i);
99 nt->Fill(r1, r2, r3, r4, r5, r6, s3x, r8, s3z);
100 }
101
102 c1->Divide(1, 2);
103 c1->cd(1);
104
105 // ||-Coord plot without transparency
106 nt->Draw("x:y:z:u:v:w:a:b:c", "", "para");
107 TParallelCoord * const para1 = (TParallelCoord*)gPad->GetListOfPrimitives()->FindObject("ParaCoord");
108 assert(para1 != 0 && "parallelcoordtrans, 'ParaCoord' is null");
109
110 para1->SetLineColor(25);
112 pcv->SetHistogramHeight(0.);
113
114 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("y");
115 pcv->SetHistogramHeight(0.);
116
117 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("z");
118 pcv->SetHistogramHeight(0.);
119
120 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("a");
121 pcv->SetHistogramHeight(0.);
122
123 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("b");
124 pcv->SetHistogramHeight(0.);
125
126 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("c");
127 pcv->SetHistogramHeight(0.);
128
129 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("u");
130 pcv->SetHistogramHeight(0.);
131
132 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("v");
133 pcv->SetHistogramHeight(0.);
134
135 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("w");
136 pcv->SetHistogramHeight(0.);
137
138 // ||-Coord plot with transparency
139 // We modify a 'system' color! You'll probably
140 // have to restart ROOT or reset this color later.
141 TColor * const col26 = gROOT->GetColor(26);
142 assert(col26 != 0 && "parallelcoordtrans, color with index 26 not found");
143
144 col26->SetAlpha(0.01);
145
146 c1->cd(2);
147 nt->Draw("x:y:z:u:v:w:a:b:c","","para");
148 TParallelCoord * const para2 = (TParallelCoord*)gPad->GetListOfPrimitives()->FindObject("ParaCoord");
149 assert(para2 != 0 && "parallelcoordtrans, 'ParaCoord' is null");
150
151 para2->SetLineColor(26);
152
153 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("x");
154 pcv->SetHistogramHeight(0.);
155
156 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("y");
157 pcv->SetHistogramHeight(0.);
158
159 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("z");
160 pcv->SetHistogramHeight(0.);
161
162 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("a");
163 pcv->SetHistogramHeight(0.);
164
165 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("b");
166 pcv->SetHistogramHeight(0.);
167
168 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("c");
169 pcv->SetHistogramHeight(0.);
170
171 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("u");
172 pcv->SetHistogramHeight(0.);
173
174 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("v");
175 pcv->SetHistogramHeight(0.);
176
177 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("w");
178 pcv->SetHistogramHeight(0.);
179}
ROOT::R::TRInterface & r
Definition Object.C:4
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:187
#define gROOT
Definition TROOT.h:404
#define gPad
#define gVirtualX
Definition TVirtualX.h:338
The Canvas class.
Definition TCanvas.h:23
The color creation and management class.
Definition TColor.h:19
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
Definition TColor.cxx:1822
virtual void SetAlpha(Float_t a)
Definition TColor.h:68
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition TList.cxx:578
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:169
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition TObject.cxx:393
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
virtual void Draw(Option_t *opt)
Default Draw method for all objects.
Definition TTree.h:428
return c1
Definition legend1.C:41
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...