Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
draw_rh1.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_v7
3///
4/// This macro generates two RH1D, fills them and draw with different options in RCanvas.
5/// The canvas is display in the web browser
6///
7/// \macro_code
8///
9/// \date 2015-03-22
10/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
11/// \authors Axel Naumann <axel@cern.ch>, Sergey Linev <s.linev@gsi.de>
12
13/*************************************************************************
14 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
15 * All rights reserved. *
16 * *
17 * For the licensing terms see $ROOTSYS/LICENSE. *
18 * For the list of contributors see $ROOTSYS/README/CREDITS. *
19 *************************************************************************/
20
21#include "ROOT/RHist.hxx"
23#include "ROOT/RFrameTitle.hxx"
24#include "ROOT/RCanvas.hxx"
25#include "ROOT/RPad.hxx"
26#include "TRandom.h"
27
28// macro must be here while cling is not capable to load
29// library automatically for outlined function see ROOT-10336
30R__LOAD_LIBRARY(libROOTHistDraw)
31
32using namespace ROOT::Experimental;
33
34void draw_rh1()
35{
36 // Create the histogram.
37 RAxisConfig xaxis(25, 0., 10.);
38 auto pHist1 = std::make_shared<RH1D>(xaxis);
39 auto pHist2 = std::make_shared<RH1D>(xaxis);
40
41 for (int n=0;n<1000;n++) {
42 pHist1->Fill(gRandom->Gaus(3,0.8));
43 pHist2->Fill(gRandom->Gaus(7,1.2));
44 }
45
46 // Create a canvas to be displayed.
47 auto canvas = RCanvas::Create("RH1 drawing options");
48
49 // histograms colors
50 auto col1 = RColor::kRed, col2 = RColor::kBlue;
51
52 // Divide canvas on 2x3 sub-pads to show different draw options
53 auto subpads = canvas->Divide(2,3);
54
55 // default draw option
56 subpads[0][0]->Draw<RFrameTitle>("Default RH1 drawing");
57 subpads[0][0]->Draw(pHist1)->AttrLine().SetColor(col1).SetWidth(2);
58 subpads[0][0]->Draw(pHist2)->AttrLine().SetColor(col2).SetWidth(4);
59
60 // errors draw options
61 subpads[1][0]->Draw<RFrameTitle>("Error() draw options");
62 subpads[1][0]->Draw(pHist1)->Error(1).AttrLine().SetColor(col1);
63 subpads[1][0]->Draw(pHist2)->Error(4).AttrFill().SetColor(col2).SetStyle(3003);
64
65 // text and marker draw options
66 subpads[0][1]->Draw<RFrameTitle>("Text() and Marker() draw options");
67 subpads[0][1]->Draw(pHist1)->Text(true).AttrText().SetColor(col1);
68 subpads[0][1]->Draw(pHist2)->Marker().AttrMarker().SetColor(col2).SetStyle(30).SetSize(1.5);
69
70 // text and marker draw options
71 subpads[1][1]->Draw<RFrameTitle>("Bar() draw options");
72 subpads[1][1]->Draw(pHist1)->Bar(0,0.5).AttrFill().SetColor(col1);
73 subpads[1][1]->Draw(pHist2)->Bar(0.5,0.5,true).AttrFill().SetColor(col2);
74
75 // line draw option
76 subpads[0][2]->Draw<RFrameTitle>("Line() draw option");
77 subpads[0][2]->Draw(pHist1)->Line().AttrLine().SetColor(col1);
78 subpads[0][2]->Draw(pHist2)->Line().AttrLine().SetColor(col2);
79
80 // lego draw option
81 subpads[1][2]->Draw<RFrameTitle>("Lego() draw option");
82 subpads[1][2]->Draw(pHist1)->Lego().AttrFill().SetColor(col1);
83
84 canvas->SetSize(1000, 700);
85 canvas->Show();
86}
#define R__LOAD_LIBRARY(LIBRARY)
Definition Rtypes.h:472
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
Objects used to configure the different axis types.
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition TRandom.cxx:274
const Int_t n
Definition legend1.C:16