Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
draw_rh2_large.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_v7
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_code
8///
9/// \date 2020-06-26
10/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
11/// \author Sergey Linev <s.linev@gsi.de>
12
13/*************************************************************************
14 * Copyright (C) 1995-2020, 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
22#include "ROOT/RCanvas.hxx"
23#include "ROOT/RFrameTitle.hxx"
24#include "ROOT/RHistStatBox.hxx"
25#include "ROOT/RFrame.hxx"
26#include "TString.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_rh2_large()
35{
36 const int nbins = 2000;
37
38 // Create the histogram.
39 RAxisConfig xaxis("x", nbins, 0., nbins);
40 RAxisConfig yaxis("y", nbins, 0., nbins);
41 auto pHist = std::make_shared<RH2D>(xaxis, yaxis);
42
43 for(int i=0;i<nbins;++i)
44 for(int j=0;j<nbins;++j)
45 pHist->Fill({1.*i,1.*j}, i+j);
46
47 // Create a canvas to be displayed.
48 auto canvas = RCanvas::Create("Canvas Title");
49
50 auto frame = canvas->GetOrCreateFrame();
51
52 // should we made special style for frame with palette?
53 // frame->Margins().SetRight(0.2_normal);
54
55 frame->SetGridX(false).SetGridY(false);
56 frame->AttrX().SetZoom(nbins*0.2, nbins*0.8);
57 frame->AttrY().SetZoom(nbins*0.2, nbins*0.8);
58
59 canvas->Draw<RFrameTitle>(TString::Format("Large RH2D histogram with %d x %d bins",nbins,nbins).Data());
60
61 auto draw = canvas->Draw(pHist);
62
63 draw->AttrLine().SetColor(RColor::kLime);
64 // draw->Contour(); // configure cont draw option
65 // draw->Scatter(); // configure scatter draw option
66 // draw->Arrow(); // configure arrow draw option
67 draw->Color(); // configure color draw option (default)
68 // draw->Text(true); // configure text drawing (can be enabled with most 2d options)
69 // draw->Box(1); // configure box1 draw option
70 // draw->Surf(2); // configure surf4 draw option, 3d
71 // draw->Lego(2); // configure lego2 draw option, 3d
72 // draw->Error(); // configure error drawing, 3d
73
74 draw->Optimize(true); // enable draw optimization, reduced data set will be send to clients
75
76 auto stat = canvas->Draw<RHist2StatBox>(pHist, "hist");
77 stat->AttrFill().SetColor(RColor::kBlue);
78
79 canvas->SetSize(1000, 700);
80 canvas->Show();
81}
#define R__LOAD_LIBRARY(LIBRARY)
Definition Rtypes.h:472
RAttrFill & SetColor(const RColor &color)
The fill color.
Definition RAttrFill.hxx:39
Objects used to configure the different axis types.
RAttrFill & AttrFill()
Definition RPave.hxx:67
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:2331