Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hist048_Graphics_candle_hist.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_hist
3/// \notebook
4/// Example showing how to combine the various candle plot options.
5///
6/// \macro_image (tcanvas_js)
7/// \macro_code
8///
9/// \date December 2017
10/// \author Georg Troska
11
13{
14 TCanvas *c1 = new TCanvas("c1", "Candle Presets", 800, 600);
15 c1->Divide(3, 2);
16
17 TRandom *rng = new TRandom();
18 TH2I *h1 = new TH2I("h1", "Sin", 18, 0, 360, 100, -1.5, 1.5);
19 h1->GetXaxis()->SetTitle("Deg");
20
21 float myRand;
22 for (int i = 0; i < 360; i += 10) {
23 for (int j = 0; j < 100; j++) {
24 myRand = rng->Gaus(sin(i * 3.14 / 180), 0.2);
25 h1->Fill(i, myRand);
26 }
27 }
28
29 for (int i = 1; i < 7; i++) {
30 c1->cd(i);
31 TString title = TString::Format("CANDLEX%d", i);
32 TH2I *myhist = (TH2I *)h1->DrawCopy(title);
33 myhist->SetTitle(title);
34 }
35
36 TCanvas *c2 = new TCanvas("c2", "Violin Presets", 800, 300);
37 c2->Divide(2, 1);
38
39 for (int i = 1; i < 3; i++) {
40 c2->cd(i);
41 TString title = TString::Format("VIOLINX%d", i);
42 TH2I *myhist = (TH2I *)h1->DrawCopy(title);
43 myhist->SetFillColor(kGray + 2);
44 }
45
46 TCanvas *c3 = new TCanvas("c3", "Playing with candle and violin-options", 800, 600);
47 c3->Divide(3, 2);
48 TString myopt[6] = {"1000000", "2000000", "3000000", "1112111", "112111", "112111"};
49 for (int i = 0; i < 6; i++) {
50 c3->cd(i + 1);
51 TString title = TString::Format("candlex(%s)", myopt[i].Data());
52 TH2I *myhist = (TH2I *)h1->DrawCopy(title);
53 myhist->SetFillColor(kYellow);
54 if (i == 4) {
55 TH2I *myhist2 = (TH2I *)h1->DrawCopy("candlex(1000000) same");
56 myhist2->SetFillColor(kRed);
57 }
58 if (i == 5) {
59 myhist->SetBarWidth(0.2);
60 myhist->SetBarOffset(0.25);
61 TH2I *myhist2 = (TH2I *)h1->DrawCopy("candlex(2000000) same");
62 myhist2->SetFillColor(kRed);
63 myhist2->SetBarWidth(0.6);
64 myhist2->SetBarOffset(-0.5);
65 }
66 myhist->SetTitle(title);
67 }
68}
@ kGray
Definition Rtypes.h:65
@ kRed
Definition Rtypes.h:66
@ kYellow
Definition Rtypes.h:66
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
The Canvas class.
Definition TCanvas.h:23
TAxis * GetXaxis()
Definition TH1.h:340
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3315
virtual TH1 * DrawCopy(Option_t *option="", const char *name_postfix="_copy") const
Copy this histogram and Draw in the current pad.
Definition TH1.cxx:3084
2-D histogram with an int per channel (see TH1 documentation)
Definition TH2.h:227
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:164
This is the base class for the ROOT Random number generators.
Definition TRandom.h:27
Basic string class.
Definition TString.h:139
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
return c1
Definition legend1.C:41
TH1F * h1
Definition legend1.C:5
return c2
Definition legend2.C:14
return c3
Definition legend3.C:15