Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
transp.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_gl
3/// This demo shows how to use transparency.
4///
5/// \macro_image(nobatch)
6/// \macro_code
7///
8/// \author Timur Pocheptsov
9
10//Includes for ACLiC (cling does not need them).
11#include "TCanvas.h"
12#include "TColor.h"
13#include "TError.h"
14#include "TStyle.h"
15#include "TH1F.h"
16
17//Aux. functions for tutorials/gl.
18#include "customcolorgl.h"
19
20void transp()
21{
22 //1. Try to find free indices for our custom colors.
23 //We can use hard-coded indices like 1001, 1002, 1003, ... but
24 //I prefer to find free indices in a ROOT's color table
25 //to avoid possible conflicts with other tutorials.
26 Int_t indices[2] = {};
28 ::Error("transp", "failed to create new custom colors");
29 return;
30 }
31
32 //2. Now that we have indices, create our custom colors.
33 const Int_t redIndex = indices[0], greeIndex = indices[1];
34
35 new TColor(redIndex, 1., 0., 0., "red", 0.85);
36 new TColor(greeIndex, 0., 1., 0., "green", 0.5);
37
39 TCanvas * const cnv = new TCanvas("trasnparency", "transparency demo", 600, 400);
40
41 TH1F * const hist = new TH1F("a5", "b5", 10, -2., 3.);
42 TH1F * const hist2 = new TH1F("c6", "d6", 10, -3., 3.);
43 hist->FillRandom("landau", 100000);
44 hist2->FillRandom("gaus", 100000);
45
46 hist->SetFillColor(redIndex);
47 hist2->SetFillColor(greeIndex);
48
49 cnv->cd();
50 hist2->Draw();
51 hist->Draw("SAME");
52}
int Int_t
Definition RtypesCore.h:45
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:197
R__EXTERN TStyle * gStyle
Definition TStyle.h:414
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:37
The Canvas class.
Definition TCanvas.h:23
TVirtualPad * cd(Int_t subpadnumber=0) override
Set current canvas & pad.
Definition TCanvas.cxx:714
The color creation and management class.
Definition TColor.h:19
1-D histogram with a float per channel (see TH1 documentation)}
Definition TH1.h:577
virtual void FillRandom(const char *fname, Int_t ntimes=5000, TRandom *rng=nullptr)
Fill histogram following distribution in function fname.
Definition TH1.cxx:3513
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3060
void SetCanvasPreferGL(Bool_t prefer=kTRUE)
Definition TStyle.h:326
unsigned FindFreeCustomColorIndices(T(&indices)[N])