Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
draw_rh1.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-2019, 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 #include "ROOT/RHistDrawable.hxx"
23 #include "ROOT/RCanvas.hxx"
24 #include "TRandom.h"
25 
26 // macro must be here while cling is not capable to load
27 // library automatically for outlined function see ROOT-10336
28 R__LOAD_LIBRARY(libROOTHistDraw)
29 
30 using namespace ROOT::Experimental;
31 
32 void draw_rh1()
33 {
34  // Create the histogram.
35  RAxisConfig xaxis(25, 0., 10.);
36  auto pHist = std::make_shared<RH1D>(xaxis);
37  auto pHist2 = std::make_shared<RH1D>(xaxis);
38 
39  for (int n=0;n<1000;n++) {
40  pHist->Fill(gRandom->Gaus(3,0.8));
41  pHist2->Fill(gRandom->Gaus(7,1.2));
42  }
43 
44  // Create a canvas to be displayed.
45  auto canvas = RCanvas::Create("Canvas Title");
46  auto draw1 = canvas->Draw(pHist);
47  draw1->AttrLine().SetColor(RColor::kRed).SetWidth(2);
48 
49  auto draw2 = canvas->Draw(pHist2);
50  draw2->AttrLine().SetColor(RColor::kBlue).SetWidth(4);
51 
52  canvas->Show();
53 }