Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rh1.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_rcanvas
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_image (rcanvas_js)
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/// \authors Axel Naumann <axel@cern.ch>, Sergey Linev <s.linev@gsi.de>
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/RHist.hxx"
24#include "ROOT/RFrameTitle.hxx"
25#include "ROOT/RCanvas.hxx"
26#include "ROOT/RPad.hxx"
27#include "TRandom.h"
28
29// macro must be here while cling is not capable to load
30// library automatically for outlined function see ROOT-10336
31R__LOAD_LIBRARY(libROOTHistDraw)
32
33using namespace ROOT::Experimental;
34
35void rh1()
36{
37 // Create the histogram.
38 RAxisConfig xaxis(25, 0., 10.);
39 auto pHist1 = std::make_shared<RH1D>(xaxis);
40 auto pHist2 = std::make_shared<RH1D>(xaxis);
41
42 for (int n=0;n<1000;n++) {
43 pHist1->Fill(gRandom->Gaus(3,0.8));
44 pHist2->Fill(gRandom->Gaus(7,1.2));
45 }
46
47 // Create a canvas to be displayed.
48 auto canvas = RCanvas::Create("RH1 drawing options");
49
50 // histograms colors
51 auto col1 = RColor::kRed, col2 = RColor::kBlue;
52
53 // Divide canvas on 2x3 sub-pads to show different draw options
54 auto subpads = canvas->Divide(2,3);
55
56 // default draw option
57 subpads[0][0]->Draw<RFrameTitle>("Default RH1 drawing");
58 auto draw001 = subpads[0][0]->Draw(pHist1);
59 draw001->line.color = col1;
60 draw001->line.width = 2;
61 auto draw002 = subpads[0][0]->Draw(pHist2);
62 draw002->line.color = col2;
63 draw002->line.width = 4;
64
65 // errors draw options
66 subpads[1][0]->Draw<RFrameTitle>("Error() draw options");
67 subpads[1][0]->Draw(pHist1)->Error(1).line.color = col1;
68 subpads[1][0]->Draw(pHist2)->Error(4).fill = RAttrFill(col2, RAttrFill::k3003);
69
70 // text and marker draw options
71 subpads[0][1]->Draw<RFrameTitle>("Text() and Marker() draw options");
72 subpads[0][1]->Draw(pHist1)->Text().text.color = col1;
73 subpads[0][1]->Draw(pHist2)->Marker().marker = RAttrMarker(col2, 0.02, RAttrMarker::kOpenStar);
74
75 // bar draw options
76 subpads[1][1]->Draw<RFrameTitle>("Bar() draw options");
77 subpads[1][1]->Draw(pHist1)->Bar(0,0.5).fill = RAttrFill(col1, RAttrFill::kSolid);
78 subpads[1][1]->Draw(pHist2)->Bar(0.5,0.5,true).fill = RAttrFill(col2, RAttrFill::kSolid);
79
80 // line draw option
81 subpads[0][2]->Draw<RFrameTitle>("Line() draw option");
82 subpads[0][2]->Draw(pHist1)->Line().line.color = col1;
83 subpads[0][2]->Draw(pHist2)->Line().line.color = col2;
84
85 // lego draw option
86 subpads[1][2]->Draw<RFrameTitle>("Lego() draw option");
87 subpads[1][2]->Draw(pHist1)->Lego().fill = RAttrFill(col1, RAttrFill::kSolid);
88
89 canvas->SetSize(1000, 700);
90 canvas->Show();
91}
#define R__LOAD_LIBRARY(LIBRARY)
Definition Rtypes.h:491
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
Drawing fill attributes for different objects.
Definition RAttrFill.hxx:26
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