Logo ROOT   6.14/05
Reference Guide
draw_th1.cxx
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_v7
3 ///
4 /// This macro generates a small V7 TH1D, fills it and draw it in a V7 canvas.
5 /// The canvas is display in the web browser and the corresponding png picture
6 /// is generated.
7 ///
8 /// \macro_code
9 ///
10 /// \date 2015-03-22
11 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
12 /// \author Axel Naumann <axel@cern.ch>
13 
14 /*************************************************************************
15  * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
16  * All rights reserved. *
17  * *
18  * For the licensing terms see $ROOTSYS/LICENSE. *
19  * For the list of contributors see $ROOTSYS/README/CREDITS. *
20  *************************************************************************/
21 
22 R__LOAD_LIBRARY(libROOTGpadv7);
23 
24 #include "ROOT/THist.hxx"
25 #include "ROOT/TCanvas.hxx"
26 
27 void draw_th1() {
28  using namespace ROOT;
29 
30  // Create the histogram.
31  Experimental::TAxisConfig xaxis(10, 0., 10.);
32  auto pHist = std::make_shared<Experimental::TH1D>(xaxis);
33  auto pHist2 = std::make_shared<Experimental::TH1D>(xaxis);
34 
35  // Fill a few points.
36  pHist->Fill(1);
37  pHist->Fill(2);
38  pHist->Fill(2);
39  pHist->Fill(3);
40 
41  pHist2->Fill(5);
42  pHist2->Fill(6);
43  pHist2->Fill(6);
44  pHist2->Fill(7);
45 
46  // Create a canvas to be displayed.
47  auto canvas = Experimental::TCanvas::Create("Canvas Title");
48  canvas->Draw(pHist)->SetLineColor(Experimental::TColor::kRed);
49  canvas->Draw(pHist2)->SetLineColor(Experimental::TColor::kBlue);
50 
51  canvas->Show();
52  canvas->SaveAs("th1.png");
53 }
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
Definition: Rtypes.h:59
Objects used to configure the different axis types.
Definition: TAxis.hxx:300
#define R__LOAD_LIBRARY(LIBRARY)
Definition: Rtypes.h:467
Definition: Rtypes.h:59
static std::shared_ptr< TCanvas > Create(const std::string &title)
Definition: TCanvas.cxx:74