Logo ROOT   6.10/09
Reference Guide
candlehisto.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
7 /// \macro_code
8 ///
9 /// \author Georg Troska
10 
11 void candlehisto()
12 {
13  TCanvas *c1 = new TCanvas("c1", "Candle Presets", 800, 600);
14  c1->Divide(3, 2);
15 
16  TRandom *rand = new TRandom();
17  TH2I *h1 = new TH2I("h1", "Sin", 18, 0, 360, 100, -1.5, 1.5);
18  h1->GetXaxis()->SetTitle("Deg");
19 
20  float myRand;
21  for (int i = 0; i < 360; i+= 10) {
22  for (int j = 0; j < 100; j++) {
23  myRand = rand->Gaus(sin(i * 3.14 / 180), 0.2);
24  h1->Fill(i, myRand);
25  }
26  }
27 
28  for (int i = 1; i < 7; i++) {
29  c1->cd(i);
30  TString title = TString::Format("CANDLEX%d", i);
31  TH2I *myhist = (TH2I*)h1->DrawCopy(title);
32  myhist->SetTitle(title);
33  }
34 
35  TCanvas *c2 = new TCanvas("c2", "Violin Presets", 800, 300);
36  c2->Divide(2, 1);
37 
38  for (int i = 1; i < 3; i++) {
39  c2->cd(i);
40  TString title = TString::Format("VIOLINX%d", i);
41  TH2I *myhist = (TH2I*)h1->DrawCopy(title);
42  myhist->SetFillColor(kGray + 2);
43  }
44 
45  TCanvas *c3 = new TCanvas("c3", "Playing with candle and violin-options", 800, 600);
46  c3->Divide(3, 2);
47  TString myopt[6] = {"1000000", "2000000", "3000000", "1112111", "112111", "112111"};
48  for (int i = 0; i < 6; i++) {
49  c3->cd(i + 1);
50  TString title = TString::Format("candlex(%s)", myopt[i].Data());
51  TH2I *myhist = (TH2I*)h1->DrawCopy(title);
52  myhist->SetFillColor(kYellow);
53  if (i == 4) {
54  TH2I *myhist2 = (TH2I*)h1->DrawCopy("candlex(1000000) same");
55  myhist2->SetFillColor(kRed);
56  }
57  if (i == 5) {
58  myhist->SetBarWidth(0.2);
59  myhist->SetBarOffset(0.25);
60  TH2I *myhist2 = (TH2I*)h1->DrawCopy("candlex(2000000) same");
61  myhist2->SetFillColor(kRed);
62  myhist2->SetBarWidth(0.6);
63  myhist2->SetBarOffset(-0.5);
64  }
65  myhist->SetTitle(title);
66  }
67 }
virtual void SetBarOffset(Float_t offset=0.25)
Definition: TH1.h:337
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition: TRandom.cxx:235
return c1
Definition: legend1.C:41
Definition: Rtypes.h:56
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:679
Definition: Rtypes.h:55
Basic string class.
Definition: TString.h:129
virtual TH1 * DrawCopy(Option_t *option="", const char *name_postfix="_copy") const
Copy this histogram and Draw in the current pad.
Definition: TH1.cxx:2898
Definition: Rtypes.h:56
virtual void SetBarWidth(Float_t width=0.5)
Definition: TH1.h:338
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:2345
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
std::vector< std::vector< double > > Data
TH1F * h1
Definition: legend1.C:5
double sin(double)
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
The Canvas class.
Definition: TCanvas.h:31
return c2
Definition: legend2.C:14
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:1135
THist< 2, int, THistStatContent > TH2I
Definition: THist.hxx:319
virtual void SetTitle(const char *title)
Change (i.e.
Definition: TH1.cxx:6028
tomato 2-D histogram with an int per channel (see TH1 documentation)}
Definition: TH2.h:210
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:292
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:155
return c3
Definition: legend3.C:15
TAxis * GetXaxis()
Definition: TH1.h:300