Logo ROOT   6.12/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");
93  TParallelCoord* para1 = (TParallelCoord*)gPad->GetListOfPrimitives()->FindObject("ParaCoord");
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");
110  TParallelCoord* para2 = (TParallelCoord*)gPad->GetListOfPrimitives()->FindObject("ParaCoord");
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:66
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:481
void SetLineColor(Color_t col)
return c1
Definition: legend1.C:41
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:688
#define gROOT
Definition: TROOT.h:402
int Int_t
Definition: RtypesCore.h:41
virtual TObject * FindObject(const char *name) const
Delete a TObjLink object.
Definition: TList.cxx:574
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:27
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandom.cxx:533
ROOT::R::TRInterface & r
Definition: Object.C:4
A simple TTree restricted to a list of float variables only.
Definition: TNtuple.h:28
SVector< double, 2 > v
Definition: Dict.h:5
auto * a
Definition: textangle.C:12
virtual void Print(const char *filename="") const
Save Pad contents in a file in one of various formats.
Definition: TPad.cxx:4599
The Canvas class.
Definition: TCanvas.h:31
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:355
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:19
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:609
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)
Automatic pad generation by division.
Definition: TPad.cxx:1153
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
#define gPad
Definition: TVirtualPad.h:285
const Int_t n
Definition: legend1.C:16