Logo ROOT   6.07/09
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 is welcome!
8 /// \author Axel Naumann <axel@cern.ch>
9 
10 /*************************************************************************
11  * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
12  * All rights reserved. *
13  * *
14  * For the licensing terms see $ROOTSYS/LICENSE. *
15  * For the list of contributors see $ROOTSYS/README/CREDITS. *
16  *************************************************************************/
17 
18 #include "Rtypes.h"
19 
20 R__LOAD_LIBRARY(libGpad);
21 
22 #include "ROOT/THist.hxx"
23 #include "ROOT/TCanvas.hxx"
24 #include "ROOT/TDirectory.hxx"
25 
26 void draw() {
27  using namespace ROOT;
28 
29  // Create the histogram.
30  Experimental::TAxisConfig xaxis("x", 10, 0., 1.);
31  Experimental::TAxisConfig yaxis("y", {0., 1., 2., 3.,10.});
32  auto pHist = std::make_shared<Experimental::TH2D>(xaxis, yaxis);
33 
34  // Fill a few points.
35  pHist->Fill({0.01, 1.02});
36  pHist->Fill({0.54, 3.02});
37  pHist->Fill({0.98, 1.02});
38  pHist->Fill({1.90, 1.02});
39  pHist->Fill({0.75,-0.02});
40 
41  // Register the histogram with ROOT: now it lives even after draw() ends.
42  Experimental::TDirectory::Heap().Add("hist", pHist);
43 
44  // Create a canvas to be displayed.
45  auto canvas = Experimental::TCanvas::Create("Canvas Title");
46  canvas->Draw(pHist);
47 }
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
static TDirectory & Heap()
Dedicated, process-wide TDirectory.
Definition: TFile.cxx:22
Objects used to configure the different axis types.
Definition: TAxis.hxx:706
void Add(const std::string &name, const std::shared_ptr< T > &ptr)
Add an existing object (rather a shared_ptr to it) to the TDirectory.
Definition: TDirectory.hxx:170
#define R__LOAD_LIBRARY(LIBRARY)
Definition: Rtypes.h:388
static std::shared_ptr< TCanvas > Create(const std::string &title)
Definition: TCanvas.cxx:89