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
29using namespace ROOT::Experimental;
30
31void rh1()
32{
33 // Create the histogram.
34 RAxisConfig xaxis(25, 0., 10.);
35 auto pHist1 = std::make_shared<RH1D>(xaxis);
36 auto pHist2 = std::make_shared<RH1D>(xaxis);
37
38 for (int n=0;n<1000;n++) {
39 pHist1->Fill(gRandom->Gaus(3,0.8));
40 pHist2->Fill(gRandom->Gaus(7,1.2));
41 }
42
43 // Create a canvas to be displayed.
44 auto canvas = RCanvas::Create("RH1 drawing options");
45
46 // histograms colors
47 auto col1 = RColor::kRed, col2 = RColor::kBlue;
48
49 // Divide canvas on 2x3 sub-pads to show different draw options
50 auto subpads = canvas->Divide(2,3);
51
52 // default draw option
53 subpads[0][0]->Draw<RFrameTitle>("Default RH1 drawing");
54 auto draw001 = subpads[0][0]->Draw(pHist1);
55 draw001->line.color = col1;
56 draw001->line.width = 2;
57 auto draw002 = subpads[0][0]->Draw(pHist2);
58 draw002->line.color = col2;
59 draw002->line.width = 4;
60
61 // errors draw options
62 subpads[1][0]->Draw<RFrameTitle>("Error() draw options");
63 subpads[1][0]->Draw(pHist1)->Error(1).line.color = col1;
64 subpads[1][0]->Draw(pHist2)->Error(4).fill = RAttrFill(col2, RAttrFill::k3003);
65
66 // text and marker draw options
67 subpads[0][1]->Draw<RFrameTitle>("Text() and Marker() draw options");
68 subpads[0][1]->Draw(pHist1)->Text().text.color = col1;
69 subpads[0][1]->Draw(pHist2)->Marker().marker = RAttrMarker(col2, 0.02, RAttrMarker::kOpenStar);
70
71 // bar draw options
72 subpads[1][1]->Draw<RFrameTitle>("Bar() draw options");
73 subpads[1][1]->Draw(pHist1)->Bar(0,0.5).fill = RAttrFill(col1, RAttrFill::kSolid);
74 subpads[1][1]->Draw(pHist2)->Bar(0.5,0.5,true).fill = RAttrFill(col2, RAttrFill::kSolid);
75
76 // line draw option
77 subpads[0][2]->Draw<RFrameTitle>("Line() draw option");
78 subpads[0][2]->Draw(pHist1)->Line().line.color = col1;
79 subpads[0][2]->Draw(pHist2)->Line().line.color = col2;
80
81 // lego draw option
82 subpads[1][2]->Draw<RFrameTitle>("Lego() draw option");
83 subpads[1][2]->Draw(pHist1)->Lego().fill = RAttrFill(col1, RAttrFill::kSolid);
84
85 canvas->SetSize(1000, 700);
86 canvas->Show();
87}
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:275
const Int_t n
Definition legend1.C:16