Logo ROOT  
Reference Guide
transparentpad.C File Reference

Detailed Description

This macro demonstrates semi-transparent pads. Requires OpenGL.

//Includes for ACLiC (cling does not need them).
#include "TCanvas.h"
#include "TStyle.h"
#include "TError.h"
#include "TColor.h"
#include "TH1F.h"
//Aux. functions for tutorials/gl.
#include "customcolorgl.h"
void transparentpad()
{
//1. Try to 'allocate' free indices for our custom colors -
//we can use hard-coded indices like 1001, 1002, 1003 ... but
//I prefer to find free indices in a ROOT's color table
//to avoid possible conflicts with other tutorials.
Int_t indices[3] = {};
::Error("transparentpad", "failed to create new custom colors");
return;
}
//2. Create a TCanvas.
TCanvas * const c1 = new TCanvas("transparent pad","transparent pad demo", 10, 10, 900, 500);
//We can check gVirtualX (its type):
if (!c1->UseGL()) {
::Warning("transparentpad", "You can see the transparency ONLY in a pdf or png output (\"File\"->\"Save As\" ->...)\n"
"To have transparency in a canvas graphics, you need OpenGL rendering enabled");
}
//2. Create special transparent colors.
new TColor(indices[0], 1., 0.2, 0.2, "transparent_pink", 0.25);
new TColor(indices[1], 0.2, 1., 0.2, "transparent_green", 0.25);
new TColor(indices[2], 0.2, 2., 1., "transparent_blue", 0.15);
//3. Some arbitrary histograms.
TH1F * const h1 = new TH1F("TH1F 1", "TH1F 1", 100, -1.5, 1.5);
h1->FillRandom("gaus");
TH1F * const h2 = new TH1F("TH1F 2", "TH1F 2", 100, -1.5, 0.);
h2->FillRandom("gaus");
TH1F * const h3 = new TH1F("TH1F 3", "TH1F 3", 100, 0.5, 2.);
h3->FillRandom("landau");
//4. Now overlapping transparent pads.
TPad * const pad1 = new TPad("transparent pad 1", "transparent pad 1", 0.1, 0.1, 0.7, 0.7);
pad1->SetFillColor(indices[0]);//here's the magic!
pad1->cd();
h1->Draw("lego2");
c1->cd();
pad1->Draw();
TPad * const pad2 = new TPad("transparent pad 2", "transparent pad 2", 0.2, 0.2, 0.8, 0.8);
pad2->SetFillColor(indices[1]);//here's the magic!
pad2->cd();
h2->Draw();
c1->cd();
pad2->Draw();
TPad * const pad3 = new TPad("transparent pad 3", "transparent pad 3", 0.3, 0.3, 0.9, 0.9);
pad3->SetFillColor(indices[2]);//here's the magic!
pad3->cd();
h3->Draw();
c1->cd();
pad3->Draw();
}
Author
Timur Pocheptsov

Definition in file transparentpad.C.

TStyle::SetCanvasPreferGL
void SetCanvasPreferGL(Bool_t prefer=kTRUE)
Definition: TStyle.h:325
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TH1F.h
Warning
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition: TError.cxx:231
ROOT::GLTutorials::FindFreeCustomColorIndices
unsigned FindFreeCustomColorIndices(T(&indices)[N])
Definition: customcolorgl.h:40
TPad
Definition: TPad.h:26
TStyle.h
Int_t
int Int_t
Definition: RtypesCore.h:45
TColor.h
TCanvas.h
h1
TH1F * h1
Definition: legend1.C:5
gStyle
R__EXTERN TStyle * gStyle
Definition: TStyle.h:412
TColor
Definition: TColor.h:19
TH1::FillRandom
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition: TH1.cxx:3444
TCanvas
Definition: TCanvas.h:23
TH1F
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:572
TPad::cd
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:594
customcolorgl.h
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2997
Error
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition: TError.cxx:187
TError.h
c1
return c1
Definition: legend1.C:41
TPad::Draw
virtual void Draw(Option_t *option="")
Draw Pad in Current pad (re-parent pad if necessary).
Definition: TPad.cxx:1285