Logo ROOT  
Reference Guide
rh2_large.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_rcanvas
3///
4/// This macro generates really large RH2D histogram, fills it with predefined pattern and
5/// draw it in a RCanvas, using Optmize() drawing mode
6///
7/// \macro_image (rcanvas_js)
8/// \macro_code
9///
10/// \date 2020-06-26
11/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
12/// \author Sergey Linev <s.linev@gsi.de>
13
14/*************************************************************************
15 * Copyright (C) 1995-2020, 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
23#include "ROOT/RCanvas.hxx"
24#include "ROOT/RFrameTitle.hxx"
25#include "ROOT/RHistStatBox.hxx"
26#include "ROOT/RFrame.hxx"
27#include "TString.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 rh2_large()
36{
37 const int nbins = 2000;
38
39 // Create the histogram.
40 RAxisConfig xaxis("x", nbins, 0., nbins);
41 RAxisConfig yaxis("y", nbins, 0., nbins);
42 auto pHist = std::make_shared<RH2D>(xaxis, yaxis);
43
44 for(int i=0;i<nbins;++i)
45 for(int j=0;j<nbins;++j)
46 pHist->Fill({1.*i,1.*j}, i+j);
47
48 // Create a canvas to be displayed.
49 auto canvas = RCanvas::Create("Large 2000x2000 RH2 drawing");
50
51 auto frame = canvas->AddFrame();
52
53 // should we made special style for frame with palette?
54 // frame->margins.right = 0.2_normal;
55
56 frame->gridX = false;
57 frame->gridY = false;
58 frame->x.zoomMin = nbins*0.2;
59 frame->x.zoomMax = nbins*0.8;
60 frame->y.zoomMin = nbins*0.2;
61 frame->y.zoomMax = nbins*0.8;
62
63 canvas->Draw<RFrameTitle>(TString::Format("Large RH2D histogram with %d x %d bins",nbins,nbins).Data());
64
65 auto draw = canvas->Draw(pHist);
66
67 draw->line.color = RColor::kLime;
68 // draw->Contour(); // configure cont draw option
69 // draw->Scatter(); // configure scatter draw option
70 // draw->Arrow(); // configure arrow draw option
71 draw->Color(); // configure color draw option (default)
72 // draw->Text(true); // configure text drawing (can be enabled with most 2d options)
73 // draw->Box(1); // configure box1 draw option
74 // draw->Surf(2); // configure surf4 draw option, 3d
75 // draw->Lego(2); // configure lego2 draw option, 3d
76 // draw->Error(); // configure error drawing, 3d
77
78 draw->optimize = true; // enable draw optimization, reduced data set will be send to clients
79
80 auto stat = canvas->Draw<RHist2StatBox>(pHist, "hist");
81 stat->fill.color = RColor::kBlue;
82 stat->fill.style = RAttrFill::kSolid;
83
84 canvas->SetSize(1000, 700);
85 canvas->Show();
86}
#define R__LOAD_LIBRARY(LIBRARY)
Definition: Rtypes.h:472
@ kBlue
Definition: Rtypes.h:66
@ kSolid
Definition: TAttLine.h:48
RAttrValue< RColor > color
! fill color
Definition: RAttrFill.hxx:43
Objects used to configure the different axis types.
Definition: RAxisConfig.hxx:35
RAttrFill fill
! fill attributes
Definition: RPave.hxx:48
const char * Data() const
Definition: TString.h:369
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition: TString.cxx:2336