Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
hist062_TH1_timeonaxis2.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_hist
3/// \notebook
4/// \preview Define the time offset as 2003, January 1st.
5///
6/// \macro_image
7/// \macro_code
8///
9/// \author Olivier Couet
10
11void hist062_TH1_timeonaxis2()
12{
13 auto ct2 = new TCanvas("ct2", "ct2", 10, 10, 700, 500);
14
15 TDatime T0(2003, 1, 1, 0, 0, 0);
16 int X0 = T0.Convert();
17 gStyle->SetTimeOffset(X0);
18
19 // Define the lowest histogram limit as 2002, September 23rd
20 TDatime T1(2002, 9, 23, 0, 0, 0);
21 int X1 = T1.Convert() - X0;
22
23 // Define the highest histogram limit as 2003, March 7th
24 TDatime T2(2003, 3, 7, 0, 0, 0);
25 int X2 = T2.Convert(1) - X0;
26
27 auto h1 = new TH1F("h1", "test", 100, X1, X2);
28
29 TRandom r;
30 for (Int_t i = 0; i < 30000; i++) {
31 Double_t noise = r.Gaus(0.5 * (X1 + X2), 0.1 * (X2 - X1));
32 h1->Fill(noise);
33 }
34
35 h1->GetXaxis()->SetTimeDisplay(1);
36 h1->GetXaxis()->SetLabelSize(0.03);
37 h1->GetXaxis()->SetTimeFormat("%Y/%m/%d");
38 h1->Draw();
39}
ROOT::R::TRInterface & r
Definition Object.C:4
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
externTStyle * gStyle
Definition TStyle.h:442
The Canvas class.
Definition TCanvas.h:23
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition TDatime.h:37
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:878
This is the base class for the ROOT Random number generators.
Definition TRandom.h:27
TH1F * h1
Definition legend1.C:5
#define T2
Definition md5.inl:147
#define T1
Definition md5.inl:146