Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
tree142_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{
37 r->Rannor(r1, r4);
38 r->Rannor(r7, r9);
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
46void tree142_parallelcoordtrans()
47{
48 Double_t x, y, z, u, v, w, a, b, c;
49 Double_t s1x, s1y, s1z;
50 Double_t s2x, s2y, s2z;
51 Double_t s3x, s3y, s3z;
52 r = new TRandom();
53
54 auto c1 = new TCanvas("c1", "c1", 0, 0, 900, 1000);
55 c1->Divide(1, 2);
56
57 auto nt = new TNtuple("nt", "Demo ntuple", "x:y:z:u:v:w:a:b:c");
58
59 int n=0;
60 for (Int_t i = 0; i < 1500; i++) {
61 r->Sphere(s1x, s1y, s1z, 0.1);
62 r->Sphere(s2x, s2y, s2z, 0.2);
63 r->Sphere(s3x, s3y, s3z, 0.05);
64
65 generate_random(i);
66 nt->Fill(r1, r2, r3, r4, r5, r6, r7, r8, r9);
67 n++;
68
69 generate_random(i);
70 nt->Fill(s1x, s1y, s1z, s2x, s2y, s2z, r7, r8, r9);
71 n++;
72
73 generate_random(i);
74 nt->Fill(r1, r2, r3, r4, r5, r6, r7, s3y, r9);
75 n++;
76
77 generate_random(i);
78 nt->Fill(s2x - 1, s2y - 1, s2z, s1x + .5, s1y + .5, s1z + .5, r7, r8, r9);
79 n++;
80
81 generate_random(i);
82 nt->Fill(r1, r2, r3, r4, r5, r6, r7, r8, r9);
83 n++;
84
85 generate_random(i);
86 nt->Fill(s1x + 1, s1y + 1, s1z + 1, s3x - 2, s3y - 2, s3z - 2, r7, r8, r9);
87 n++;
88
89 generate_random(i);
90 nt->Fill(r1, r2, r3, r4, r5, r6, s3x, r8, s3z );
91 n++;
92 }
93
95
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* para1 = (TParallelCoord*)gPad->GetListOfPrimitives()->FindObject("ParaCoord");
101 para1->SetLineColor(25);
102 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("x");
103 pcv->SetHistogramHeight(0.);
104 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("y");
105 pcv->SetHistogramHeight(0.);
106 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("z");
107 pcv->SetHistogramHeight(0.);
108 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("a");
109 pcv->SetHistogramHeight(0.);
110 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("b");
111 pcv->SetHistogramHeight(0.);
112 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("c");
113 pcv->SetHistogramHeight(0.);
114 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("u");
115 pcv->SetHistogramHeight(0.);
116 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("v");
117 pcv->SetHistogramHeight(0.);
118 pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("w");
119 pcv->SetHistogramHeight(0.);
120
121 // ||-Coord plot with transparency
122 TColor *col26 = gROOT->GetColor(26);
123 col26->SetAlpha(0.01);
124 c1->cd(2);
125 nt->Draw("x:y:z:u:v:w:a:b:c", "", "para");
126 TParallelCoord* para2 = (TParallelCoord*)gPad->GetListOfPrimitives()->FindObject("ParaCoord");
127 para2->SetLineColor(26);
128 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("x");
129 pcv->SetHistogramHeight(0.);
130 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("y");
131 pcv->SetHistogramHeight(0.);
132 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("z");
133 pcv->SetHistogramHeight(0.);
134 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("a");
135 pcv->SetHistogramHeight(0.);
136 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("b");
137 pcv->SetHistogramHeight(0.);
138 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("c");
139 pcv->SetHistogramHeight(0.);
140 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("u");
141 pcv->SetHistogramHeight(0.);
142 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("v");
143 pcv->SetHistogramHeight(0.);
144 pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("w");
145 pcv->SetHistogramHeight(0.);
146
147 // Produce transparent lines in interactive and batch mode
148 c1->Print("parallelcoordtrans.pdf");
149 c1->Print("parallelcoordtrans.svg");
150
151 // Produce transparent lines in batch mode only
152 c1->Print("parallelcoordtrans.jpg");
153 c1->Print("parallelcoordtrans.png");
154}
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
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:406
#define gPad
The Canvas class.
Definition TCanvas.h:23
The color creation and management class.
Definition TColor.h:22
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:1924
virtual void SetAlpha(Float_t a)
Definition TColor.h:71
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition TList.cxx:576
A simple TTree restricted to a list of float variables only.
Definition TNtuple.h:28
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition TObject.cxx:420
TParallelCoord axes.
void SetHistogramHeight(Double_t h=0)
Set the height of the bar histogram.
void Draw(Option_t *option="") override
Draw the axis.
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
Double_t y[n]
Definition legend1.C:17
return c1
Definition legend1.C:41
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16