Logo ROOT  
Reference Guide
parallelcoordtrans.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_tree
3/// \notebook
4/// Use of transparency with ||-Coord.
5///
6/// It displays the same data set twice. The first time without transparency and
7/// the second time with transparency. On the second plot, several clusters
8/// appear.
9///
10/// ### Images without and with transparency
11///
12/// \macro_image
13///
14/// ### Transparency works in PDF files
15///
16/// \macro_image (parallelcoordtrans.pdf)
17///
18/// \macro_code
19///
20/// \author Olivier Couet
21
22#include "TFile.h"
23#include "TCanvas.h"
24#include "TStyle.h"
25#include "TRandom.h"
26#include "TNtuple.h"
27#include "TParallelCoord.h"
28#include "TParallelCoordVar.h"
29#include "TParallelCoordRange.h"
30
31Double_t r1,r2,r3,r4,r5,r6,r7,r8,r9;
32Double_t dr = 3.5;
33TRandom *r;
34
35void generate_random(Int_t i) {
36 r->Rannor(r1,r4);
37 r->Rannor(r7,r9);
38 r2 = (2*dr*r->Rndm(i))-dr;
39 r3 = (2*dr*r->Rndm(i))-dr;
40 r5 = (2*dr*r->Rndm(i))-dr;
41 r6 = (2*dr*r->Rndm(i))-dr;
42 r8 = (2*dr*r->Rndm(i))-dr;
43}
44
45void parallelcoordtrans() {
46 Double_t x,y,z,u,v,w,a,b,c;
47 Double_t s1x, s1y, s1z;
48 Double_t s2x, s2y, s2z;
49 Double_t s3x, s3y, s3z;
50 r = new TRandom();;
51
52 TCanvas *c1 = new TCanvas("c1", "c1",0,0,900,1000);
53 c1->Divide(1,2);
54
55 TNtuple *nt = new TNtuple("nt","Demo ntuple","x:y:z:u:v:w:a:b:c");
56
57 int n=0;
58 for (Int_t i=0; i<1500; i++) {
59 r->Sphere(s1x, s1y, s1z, 0.1);
60 r->Sphere(s2x, s2y, s2z, 0.2);
61 r->Sphere(s3x, s3y, s3z, 0.05);
62
63 generate_random(i);
64 nt->Fill(r1, r2, r3, r4, r5, r6, r7, r8, r9);
65 n++;
66
67 generate_random(i);
68 nt->Fill(s1x, s1y, s1z, s2x, s2y, s2z, r7, r8, r9);
69 n++;
70
71 generate_random(i);
72 nt->Fill(r1, r2, r3, r4, r5, r6, r7, s3y, r9);
73 n++;
74
75 generate_random(i);
76 nt->Fill(s2x-1, s2y-1, s2z, s1x+.5, s1y+.5, s1z+.5, r7, r8, r9);
77 n++;
78
79 generate_random(i);
80 nt->Fill(r1, r2, r3, r4, r5, r6, r7, r8, r9);
81 n++;
82
83 generate_random(i);
84 nt->Fill(s1x+1, s1y+1, s1z+1, s3x-2, s3y-2, s3z-2, r7, r8, r9);
85 n++;
86
87 generate_random(i);
88 nt->Fill(r1, r2, r3, r4, r5, r6, s3x, r8, s3z );
89 n++;
90 }
91
93
94 c1->cd(1);
95
96 // ||-Coord plot without transparency
97 nt->Draw("x:y:z:u:v:w:a:b:c","","para");
98 TParallelCoord* para1 = (TParallelCoord*)gPad->GetListOfPrimitives()->FindObject("ParaCoord");
99 para1->SetLineColor(25);
100 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("x"); pcv->SetHistogramHeight(0.);
101 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("y"); pcv->SetHistogramHeight(0.);
102 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("z"); pcv->SetHistogramHeight(0.);
103 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("a"); pcv->SetHistogramHeight(0.);
104 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("b"); pcv->SetHistogramHeight(0.);
105 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("c"); pcv->SetHistogramHeight(0.);
106 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("u"); pcv->SetHistogramHeight(0.);
107 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("v"); pcv->SetHistogramHeight(0.);
108 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("w"); pcv->SetHistogramHeight(0.);
109
110
111 // ||-Coord plot with transparency
112 TColor *col26 = gROOT->GetColor(26); col26->SetAlpha(0.01);
113 c1->cd(2);
114 nt->Draw("x:y:z:u:v:w:a:b:c","","para");
115 TParallelCoord* para2 = (TParallelCoord*)gPad->GetListOfPrimitives()->FindObject("ParaCoord");
116 para2->SetLineColor(26);
117 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("x"); pcv->SetHistogramHeight(0.);
118 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("y"); pcv->SetHistogramHeight(0.);
119 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("z"); pcv->SetHistogramHeight(0.);
120 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("a"); pcv->SetHistogramHeight(0.);
121 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("b"); pcv->SetHistogramHeight(0.);
122 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("c"); pcv->SetHistogramHeight(0.);
123 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("u"); pcv->SetHistogramHeight(0.);
124 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("v"); pcv->SetHistogramHeight(0.);
125 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("w"); pcv->SetHistogramHeight(0.);
126
127 // Produce transparent lines in interactive and batch mode
128 c1->Print("parallelcoordtrans.pdf");
129 c1->Print("parallelcoordtrans.svg");
130
131 // Produce transparent lines in batch mode only
132 c1->Print("parallelcoordtrans.gif");
133 c1->Print("parallelcoordtrans.jpg");
134 c1->Print("parallelcoordtrans.png");
135}
ROOT::R::TRInterface & r
Definition: Object.C:4
#define b(i)
Definition: RSha256.hxx:100
#define c(i)
Definition: RSha256.hxx:101
int Int_t
Definition: RtypesCore.h:43
double Double_t
Definition: RtypesCore.h:57
#define gROOT
Definition: TROOT.h:406
#define gPad
Definition: TVirtualPad.h:287
The Canvas class.
Definition: TCanvas.h:27
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:577
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
virtual void Draw(Option_t *opt)
Default Draw method for all objects.
Definition: TTree.h:426
return c1
Definition: legend1.C:41
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
auto * a
Definition: textangle.C:12