Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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#include <cassert>
14
15#include "TParallelCoordVar.h"
16#include "TParallelCoord.h"
17#include "TNtuple.h"
18#include "TCanvas.h"
19#include "TRandom.h"
20#include "TColor.h"
21#include "TStyle.h"
22#include "TError.h"
23#include "TList.h"
24#include "TROOT.h"
25
26namespace ROOT {
27namespace GLTutorials {
28
29Double_t r1, r2, r3, r4, r5, r6, r7, r8, r9;
31
32//______________________________________________________________________
34{
35 const Double_t dr = 3.5;
36
37 r.Rannor(r1, r4);
38 r.Rannor(r7, r9);
39
40 r2 = (2 * dr * r.Rndm(i)) - dr;
41 r3 = (2 * dr * r.Rndm(i)) - dr;
42 r5 = (2 * dr * r.Rndm(i)) - dr;
43 r6 = (2 * dr * r.Rndm(i)) - dr;
44 r8 = (2 * dr * r.Rndm(i)) - dr;
45}
46
47} // namespace GLTutorials
48} // namespace ROOT
49
50void parallelcoordtrans(bool gl = true)
51{
52 // This macro shows how to use parallel coords and semi-transparent lines
53 //(the system color is updated with alpha == 0.01 (1% opaque).
54
55 using namespace ROOT::GLTutorials;
56
57 Double_t s1x = 0., s1y = 0., s1z = 0.;
58 Double_t s2x = 0., s2y = 0., s2z = 0.;
59 Double_t s3x = 0., s3y = 0., s3z = 0.;
60
62 TCanvas *c1 = new TCanvas("parallel coors", "parallel coords", 0, 0, 900, 1000);
63
64 if (!c1->UseGL() && !c1->IsWeb() && !gVirtualX->InheritsFrom("TGCocoa"))
65 ::Warning("parallelcoordtrans",
66 "To have real transparency in a canvas graphics, you need either OpenGL or Mac/Cocoa or Web rendering enabled");
67
68 TNtuple *const nt = new TNtuple("nt", "Demo ntuple", "x:y:z:u:v:w:a:b:c");
69
70 for (Int_t i = 0; i < 1500; ++i) {
71 r.Sphere(s1x, s1y, s1z, 0.1);
72 r.Sphere(s2x, s2y, s2z, 0.2);
73 r.Sphere(s3x, s3y, s3z, 0.05);
74
76 nt->Fill(r1, r2, r3, r4, r5, r6, r7, r8, r9);
77
79 nt->Fill(s1x, s1y, s1z, s2x, s2y, s2z, r7, r8, r9);
80
82 nt->Fill(r1, r2, r3, r4, r5, r6, r7, s3y, r9);
83
85 nt->Fill(s2x - 1, s2y - 1, s2z, s1x + .5, s1y + .5, s1z + .5, r7, r8, r9);
86
88 nt->Fill(r1, r2, r3, r4, r5, r6, r7, r8, r9);
89
91 nt->Fill(s1x + 1, s1y + 1, s1z + 1, s3x - 2, s3y - 2, s3z - 2, r7, r8, r9);
92
94 nt->Fill(r1, r2, r3, r4, r5, r6, s3x, r8, s3z);
95 }
96
97 c1->Divide(1, 2);
98 c1->cd(1);
99
100 // ||-Coord plot without transparency
101 nt->Draw("x:y:z:u:v:w:a:b:c", "", "para");
102 TParallelCoord *const para1 = (TParallelCoord *)gPad->GetListOfPrimitives()->FindObject("ParaCoord");
103 assert(para1 != nullptr && "parallelcoordtrans, 'ParaCoord' is null");
104
105 para1->SetLineColor(25);
106 TParallelCoordVar *pcv = (TParallelCoordVar *)para1->GetVarList()->FindObject("x");
107 pcv->SetHistogramHeight(0.);
108
109 pcv = (TParallelCoordVar *)para1->GetVarList()->FindObject("y");
110 pcv->SetHistogramHeight(0.);
111
112 pcv = (TParallelCoordVar *)para1->GetVarList()->FindObject("z");
113 pcv->SetHistogramHeight(0.);
114
115 pcv = (TParallelCoordVar *)para1->GetVarList()->FindObject("a");
116 pcv->SetHistogramHeight(0.);
117
118 pcv = (TParallelCoordVar *)para1->GetVarList()->FindObject("b");
119 pcv->SetHistogramHeight(0.);
120
121 pcv = (TParallelCoordVar *)para1->GetVarList()->FindObject("c");
122 pcv->SetHistogramHeight(0.);
123
124 pcv = (TParallelCoordVar *)para1->GetVarList()->FindObject("u");
125 pcv->SetHistogramHeight(0.);
126
127 pcv = (TParallelCoordVar *)para1->GetVarList()->FindObject("v");
128 pcv->SetHistogramHeight(0.);
129
130 pcv = (TParallelCoordVar *)para1->GetVarList()->FindObject("w");
131 pcv->SetHistogramHeight(0.);
132
133 // ||-Coord plot with transparency
134 // We modify a 'system' color! You'll probably
135 // have to restart ROOT or reset this color later.
136 TColor *const col26 = gROOT->GetColor(26);
137 assert(col26 != nullptr && "parallelcoordtrans, color with index 26 not found");
138
139 col26->SetAlpha(0.01);
140
141 c1->cd(2);
142 nt->Draw("x:y:z:u:v:w:a:b:c", "", "para");
143 TParallelCoord *const para2 = (TParallelCoord *)gPad->GetListOfPrimitives()->FindObject("ParaCoord");
144 assert(para2 != nullptr && "parallelcoordtrans, 'ParaCoord' is null");
145
146 para2->SetLineColor(26);
147
148 pcv = (TParallelCoordVar *)para2->GetVarList()->FindObject("x");
149 pcv->SetHistogramHeight(0.);
150
151 pcv = (TParallelCoordVar *)para2->GetVarList()->FindObject("y");
152 pcv->SetHistogramHeight(0.);
153
154 pcv = (TParallelCoordVar *)para2->GetVarList()->FindObject("z");
155 pcv->SetHistogramHeight(0.);
156
157 pcv = (TParallelCoordVar *)para2->GetVarList()->FindObject("a");
158 pcv->SetHistogramHeight(0.);
159
160 pcv = (TParallelCoordVar *)para2->GetVarList()->FindObject("b");
161 pcv->SetHistogramHeight(0.);
162
163 pcv = (TParallelCoordVar *)para2->GetVarList()->FindObject("c");
164 pcv->SetHistogramHeight(0.);
165
166 pcv = (TParallelCoordVar *)para2->GetVarList()->FindObject("u");
167 pcv->SetHistogramHeight(0.);
168
169 pcv = (TParallelCoordVar *)para2->GetVarList()->FindObject("v");
170 pcv->SetHistogramHeight(0.);
171
172 pcv = (TParallelCoordVar *)para2->GetVarList()->FindObject("w");
173 pcv->SetHistogramHeight(0.);
174}
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
double Double_t
Double 8 bytes.
Definition RtypesCore.h:74
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:252
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
#define gROOT
Definition TROOT.h:417
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
#define gPad
#define gVirtualX
Definition TVirtualX.h:377
The Canvas class.
Definition TCanvas.h:23
The color creation and management class.
Definition TColor.h:22
A simple TTree restricted to a list of float variables only.
Definition TNtuple.h:28
TParallelCoord axes.
Parallel Coordinates class.
This is the base class for the ROOT Random number generators.
Definition TRandom.h:28
void SetCanvasPreferGL(Bool_t prefer=kTRUE)
Definition TStyle.h:345
return c1
Definition legend1.C:41