Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
draw_rh1_large.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_v7
3///
4/// This macro generates really large RH1D 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-07-02
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 "TMath.h"
27#include "TString.h"
28
29
30// macro must be here while cling is not capable to load
31// library automatically for outlined function see ROOT-10336
32R__LOAD_LIBRARY(libROOTHistDraw)
33
34using namespace ROOT::Experimental;
35
36void draw_rh1_large()
37{
38 const int nbins = 5000000;
39
40 // Create the histogram.
41 RAxisConfig xaxis("x", nbins, 0., nbins);
42 auto pHist = std::make_shared<RH1D>(xaxis);
43
44 for(int i=0;i<nbins;++i)
45 pHist->Fill(1.*i, 1000.*(2+TMath::Sin(100.*i/nbins)));
46
47 // Create a canvas to be displayed.
48 auto canvas = RCanvas::Create("Canvas Title");
49
50 auto frame = canvas->GetOrCreateFrame();
51
52 frame->SetGridX(true).SetGridY(true);
53 frame->AttrX().SetZoom(nbins*0.2, nbins*0.8);
54
55 canvas->Draw<RFrameTitle>(TString::Format("Large RH1D histogram with %d bins",nbins).Data());
56
57 auto draw = canvas->Draw(pHist);
58
59 draw->AttrLine().SetColor(RColor::kLime);
60 // draw->AttrFill().SetColor(RColor::kLime);
61 // draw->Line(); // configure line draw option
62 // draw->Bar(); // configure bar draw option
63 // draw->Error(3); // configure error drawing
64 draw->Hist(); // configure hist draw option, default
65
66 draw->Optimize(true); // enable draw optimization, reduced data set will be send to clients
67
68 auto stat = canvas->Draw<RHist1StatBox>(pHist, "hist");
69 stat->AttrFill().SetColor(RColor::kBlue);
70
71 canvas->SetSize(1000, 700);
72 canvas->Show();
73}
#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
Double_t Sin(Double_t)
Definition TMath.h:639