ROOT   6.08/07 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 /// \macro_code
14 ///
15 /// \author Olivier Couet
16
17 #include "TFile.h"
18 #include "TCanvas.h"
19 #include "TStyle.h"
20 #include "TRandom.h"
21 #include "TNtuple.h"
22 #include "TParallelCoord.h"
23 #include "TParallelCoordVar.h"
24 #include "TParallelCoordRange.h"
25
26 Double_t r1,r2,r3,r4,r5,r6,r7,r8,r9;
27 Double_t dr = 3.5;
28 TRandom *r;
29
30 void generate_random(Int_t i) {
31  r->Rannor(r1,r4);
32  r->Rannor(r7,r9);
33  r2 = (2*dr*r->Rndm(i))-dr;
34  r3 = (2*dr*r->Rndm(i))-dr;
35  r5 = (2*dr*r->Rndm(i))-dr;
36  r6 = (2*dr*r->Rndm(i))-dr;
37  r8 = (2*dr*r->Rndm(i))-dr;
38 }
39
40 void parallelcoordtrans() {
41  Double_t x,y,z,u,v,w,a,b,c;
42  Double_t s1x, s1y, s1z;
43  Double_t s2x, s2y, s2z;
44  Double_t s3x, s3y, s3z;
45  r = new TRandom();;
46
47  TCanvas *c1 = new TCanvas("c1", "c1",0,0,900,1000);
48  c1->Divide(1,2);
49
50  TNtuple *nt = new TNtuple("nt","Demo ntuple","x:y:z:u:v:w:a:b:c");
51
52  int n=0;
53  for (Int_t i=0; i<1500; i++) {
54  r->Sphere(s1x, s1y, s1z, 0.1);
55  r->Sphere(s2x, s2y, s2z, 0.2);
56  r->Sphere(s3x, s3y, s3z, 0.05);
57
58  generate_random(i);
59  nt->Fill(r1, r2, r3, r4, r5, r6, r7, r8, r9);
60  n++;
61
62  generate_random(i);
63  nt->Fill(s1x, s1y, s1z, s2x, s2y, s2z, r7, r8, r9);
64  n++;
65
66  generate_random(i);
67  nt->Fill(r1, r2, r3, r4, r5, r6, r7, s3y, r9);
68  n++;
69
70  generate_random(i);
71  nt->Fill(s2x-1, s2y-1, s2z, s1x+.5, s1y+.5, s1z+.5, r7, r8, r9);
72  n++;
73
74  generate_random(i);
75  nt->Fill(r1, r2, r3, r4, r5, r6, r7, r8, r9);
76  n++;
77
78  generate_random(i);
79  nt->Fill(s1x+1, s1y+1, s1z+1, s3x-2, s3y-2, s3z-2, r7, r8, r9);
80  n++;
81
82  generate_random(i);
83  nt->Fill(r1, r2, r3, r4, r5, r6, s3x, r8, s3z );
84  n++;
85  }
86
87  TParallelCoordVar* pcv;
88
89  c1->cd(1);
90
91  // ||-Coord plot without transparency
92  nt->Draw("x:y:z:u:v:w:a:b:c","","para");
94  para1->SetLineColor(25);
95  pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("x"); pcv->SetHistogramHeight(0.);
96  pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("y"); pcv->SetHistogramHeight(0.);
97  pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("z"); pcv->SetHistogramHeight(0.);
98  pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("a"); pcv->SetHistogramHeight(0.);
99  pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("b"); pcv->SetHistogramHeight(0.);
100  pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("c"); pcv->SetHistogramHeight(0.);
101  pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("u"); pcv->SetHistogramHeight(0.);
102  pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("v"); pcv->SetHistogramHeight(0.);
103  pcv = (TParallelCoordVar*)para1->GetVarList()->FindObject("w"); pcv->SetHistogramHeight(0.);
104
105
106  // ||-Coord plot with transparency
107  TColor *col26 = gROOT->GetColor(26); col26->SetAlpha(0.01);
108  c1->cd(2);
109  nt->Draw("x:y:z:u:v:w:a:b:c","","para");
111  para2->SetLineColor(26);
112  pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("x"); pcv->SetHistogramHeight(0.);
113  pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("y"); pcv->SetHistogramHeight(0.);
114  pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("z"); pcv->SetHistogramHeight(0.);
115  pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("a"); pcv->SetHistogramHeight(0.);
116  pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("b"); pcv->SetHistogramHeight(0.);
117  pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("c"); pcv->SetHistogramHeight(0.);
118  pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("u"); pcv->SetHistogramHeight(0.);
119  pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("v"); pcv->SetHistogramHeight(0.);
120  pcv = (TParallelCoordVar*)para2->GetVarList()->FindObject("w"); pcv->SetHistogramHeight(0.);
121
122  // Produce transparent lines in interactive and batch mode
123  c1->Print("parallelcoordtrans.pdf");
124  c1->Print("parallelcoordtrans.svg");
125
126  // Produce transparent lines in batch mode only
127  c1->Print("parallelcoordtrans.gif");
128  c1->Print("parallelcoordtrans.jpg");
129  c1->Print("parallelcoordtrans.png");
130 }
virtual void SetAlpha(Float_t a)
Definition: TColor.h:70
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
void SetLineColor(Color_t col)
return c
return c1
Definition: legend1.C:41
Definition: TCanvas.cxx:659
#define gROOT
Definition: TROOT.h:364
int Int_t
Definition: RtypesCore.h:41
TArc * a
Definition: textangle.C:12
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:497
TParallelCoord axes.
Double_t x[n]
Definition: legend1.C:17
TList * GetVarList()
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:31
unsigned int r3[N_CITIES]
Definition: simanTSP.cxx:323
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandom.cxx:512
TRandom2 r(17)
A simple TTree restricted to a list of float variables only.
Definition: TNtuple.h:30
SVector< double, 2 > v
Definition: Dict.h:5
unsigned int r1[N_CITIES]
Definition: simanTSP.cxx:321
virtual void Print(const char *filename="") const
Save Pad contents in a file in one of various formats.
The Canvas class.
Definition: TCanvas.h:41
void SetHistogramHeight(Double_t h=0)
Set the height of the bar histogram.
double Double_t
Definition: RtypesCore.h:55
virtual void Draw(Option_t *opt)
Default Draw method for all objects.
Definition: TTree.h:367
Double_t y[n]
Definition: legend1.C:17
virtual Int_t Fill()
Fill a Ntuple with current values in fArgs.
Definition: TNtuple.cxx:170
The color creation and management class.
Definition: TColor.h:23
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.
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)