ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
transparentpad.C
Go to the documentation of this file.
1 //Author: Timur Pocheptsov, 17/03/2014.
2 //This macro demonstrates semi-transparent pads.
3 //Requires OS X and ROOT configured with --enable-cocoa.
4 
5 //Includes for ACLiC (cling does not need them).
6 #include "TVirtualX.h"
7 #include "TCanvas.h"
8 #include "TError.h"
9 #include "TColor.h"
10 #include "TH1F.h"
11 
12 //Aux. functions for tutorials/cocoa.
13 #include "customcolor.h"
14 
16 {
17  //1. Try to 'allocate' free indices for our custom colors -
18  //we can use hard-coded indices like 1001, 1002, 1003 ... but
19  //I prefer to find free indices in a ROOT's color table
20  //to avoid possible conflicts with other tutorials.
21  Color_t indices[3] = {};
23  ::Error("transparentpad", "failed to create new custom colors");
24  return;
25  }
26 
27  //2. Create a TCanvas to force a gVirtualX initialization.
28  TCanvas * const c1 = new TCanvas("transparent pad","transparent pad demo", 10, 10, 900, 500);
29  //We can check gVirtualX (its type):
30  if (gVirtualX && !gVirtualX->InheritsFrom("TGCocoa")) {
31  ::Warning("transparentpad", "You can see the transparency ONLY in a pdf or png output (\"File\"->\"Save As\" ->...)\n"
32  "To have transparency in a canvas graphics, you need OS X version with cocoa enabled");
33  }
34 
35  //2. Create special transparent colors.
36  new TColor(indices[0], 1., 0.2, 0.2, "transparent_pink", 0.25);
37  new TColor(indices[1], 0.2, 1., 0.2, "transparent_green", 0.25);
38  new TColor(indices[2], 0.2, 2., 1., "transparent_blue", 0.15);
39 
40  //3. Some arbitrary histograms.
41  TH1F * const h1 = new TH1F("TH1F 1", "TH1F 1", 100, -1.5, 1.5);
42  h1->FillRandom("gaus");
43 
44  TH1F * const h2 = new TH1F("TH1F 2", "TH1F 2", 100, -1.5, 0.);
45  h2->FillRandom("gaus");
46 
47  TH1F * const h3 = new TH1F("TH1F 3", "TH1F 3", 100, 0.5, 2.);
48  h3->FillRandom("landau");
49 
50  //4. Now overlapping transparent pads.
51  TPad * const pad1 = new TPad("transparent pad 1", "transparent pad 1", 0.1, 0.1, 0.7, 0.7);
52  pad1->SetFillColor(indices[0]);//here's the magic!
53  pad1->cd();
54  h1->Draw("lego2");
55  c1->cd();
56  pad1->Draw();
57 
58  TPad * const pad2 = new TPad("transparent pad 2", "transparent pad 2", 0.2, 0.2, 0.8, 0.8);
59  pad2->SetFillColor(indices[1]);//here's the magic!
60  pad2->cd();
61  h2->Draw();
62  c1->cd();
63  pad2->Draw();
64 
65  TPad * const pad3 = new TPad("transparent pad 3", "transparent pad 3", 0.3, 0.3, 0.9, 0.9);
66  pad3->SetFillColor(indices[2]);//here's the magic!
67  pad3->cd();
68  h3->Draw();
69  c1->cd();
70  pad3->Draw();
71 }
72 
unsigned FindFreeCustomColorIndices(Color_t(&indices)[N])
Definition: customcolor.h:44
TCanvas * c1
Definition: legend1.C:2
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
TPad * pad1
Definition: hcons.C:13
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:570
TPad * pad3
Definition: hcons.C:13
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:514
void transparentpad()
TH2D * h2
Definition: fit2dHist.C:45
TH1F * h1
Definition: legend1.C:5
virtual void Draw(Option_t *option="")
Draw Pad in Current pad (re-parent pad if necessary).
Definition: TPad.cxx:1192
void Error(const char *location, const char *msgfmt,...)
short Color_t
Definition: RtypesCore.h:79
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition: TH1.cxx:3330
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
The most important graphics class in the ROOT system.
Definition: TPad.h:46
void Warning(const char *location, const char *msgfmt,...)
#define gVirtualX
Definition: TVirtualX.h:362
The Canvas class.
Definition: TCanvas.h:48
The color creation and management class.
Definition: TColor.h:47
TPad * pad2
Definition: hcons.C:13