Logo ROOT   6.14/05
Reference Guide
draw.cxx
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_v7
3 ///
4 /// \macro_code
5 ///
6 /// \date 2015-03-22
7 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
8 /// is welcome!
9 /// \author Axel Naumann <axel@cern.ch>
10 
11 /*************************************************************************
12  * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
13  * All rights reserved. *
14  * *
15  * For the licensing terms see $ROOTSYS/LICENSE. *
16  * For the list of contributors see $ROOTSYS/README/CREDITS. *
17  *************************************************************************/
18 
19 #include "Rtypes.h"
20 
21 R__LOAD_LIBRARY(libROOTHistDraw);
22 
23 #include "ROOT/THist.hxx"
24 #include "ROOT/TCanvas.hxx"
25 #include "ROOT/TColor.hxx"
26 #include "ROOT/TDirectory.hxx"
27 
28 void draw()
29 {
30  using namespace ROOT;
31 
32  // Create the histogram.
33  Experimental::TAxisConfig xaxis("x", 10, 0., 1.);
34  Experimental::TAxisConfig yaxis("y", {0., 1., 2., 3., 10.});
35  auto pHist = std::make_shared<Experimental::TH2D>(xaxis, yaxis);
36 
37  // Fill a few points.
38  pHist->Fill({0.01, 1.02});
39  pHist->Fill({0.54, 3.02});
40  pHist->Fill({0.98, 1.02});
41  pHist->Fill({1.90, 1.02});
42  pHist->Fill({0.75, -0.02});
43 
44  // Register the histogram with ROOT: now it lives even after draw() ends.
45  Experimental::TDirectory::Heap().Add("hist", pHist);
46 
47  // Create a canvas to be displayed.
48  auto canvas = Experimental::TCanvas::Create("Canvas Title");
49  canvas->Draw(pHist)->SetLineColor(Experimental::TColor::kRed);
50 
51  canvas->Show();
52 }
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
Definition: Rtypes.h:59
void Add(std::string_view name, const std::shared_ptr< T > &ptr)
Add an existing object (rather a shared_ptr to it) to the TDirectory.
Definition: TDirectory.hxx:172
static TDirectory & Heap()
Dedicated, process-wide TDirectory.
Definition: TFile.cxx:23
Objects used to configure the different axis types.
Definition: TAxis.hxx:300
#define R__LOAD_LIBRARY(LIBRARY)
Definition: Rtypes.h:467
static std::shared_ptr< TCanvas > Create(const std::string &title)
Definition: TCanvas.cxx:74