Logo ROOT   6.10/09
Reference Guide
THistDrawable.cxx
Go to the documentation of this file.
1 /// \file THistDrawable.cxx
2 /// \ingroup Hist ROOT7
3 /// \author Axel Naumann <axel@cern.ch>
4 /// \date 2015-09-11
5 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
6 
7 /*************************************************************************
8  * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
9  * All rights reserved. *
10  * *
11  * For the licensing terms see $ROOTSYS/LICENSE. *
12  * For the list of contributors see $ROOTSYS/README/CREDITS. *
13  *************************************************************************/
14 
15 #include "ROOT/THistDrawable.hxx"
16 
17 #include "ROOT/THistImpl.hxx"
18 
19 #include "TH1.h"
20 #include "TH2.h"
21 #include "TH3.h"
22 #include "TSystem.h" // TSystem::Load
23 
24 #include <cassert>
25 
26 using namespace ROOT::Experimental;
27 using namespace ROOT::Experimental::Internal;
28 
30  gSystem->Load("libHistPainter");
31 }
32 
33 
34 template <int DIMENSION>
36 
37 template <int DIMENSION>
39 
40 
44 
47 
48 
49 template <int DIMENSIONS>
50 bool
52  auto implBase = fHistImpl.Get();
53  if (!implBase) {
54  fOldHist.reset();
55  return false;
56  }
57 
58  std::array<TAxisView, DIMENSIONS> axes;
59  for (int i = 0; i < DIMENSIONS; ++i)
60  axes[i] = implBase->GetAxis(i);
61 
62  TH1 *old = nullptr;
63 
64  // Create a unique name, for what it's worth.
65  std::string histName;
66  {
67  std::stringstream strm;
68  strm << "drawAdaptor" << this;
69  }
70 
71  // Create old histogram; set nbins because TH1::fNcells is not accessible.
72  switch (DIMENSIONS) {
73  case 1:
74  old = new TH1D(histName.c_str(),
75  implBase->GetTitle().c_str(),
76  axes[0].GetNBins() - 2, 0., 1.);
77  break;
78  case 2:
79  old = new TH2D(histName.c_str(),
80  implBase->GetTitle().c_str(),
81  axes[0].GetNBins() - 2, 0., 1.,
82  axes[1].GetNBins() - 2, 0., 1.);
83  break;
84  case 3:
85  old = new TH3D(histName.c_str(),
86  implBase->GetTitle().c_str(),
87  axes[0].GetNBins() - 2, 0., 1.,
88  axes[1].GetNBins() - 2, 0., 1.,
89  axes[2].GetNBins() - 2, 0., 1.);
90  break;
91  default:
92  // And anyway, this should really give a missing symbol due to the export
93  // template.
94  R__ERROR_HERE("Hist") << "Drawing of " << DIMENSIONS
95  << " dimensional histograms not supported.";
96  return false;
97  }
98 
99  old->SetDirectory(nullptr);
100 
101  // See TH1::SetBins().
102  std::array<TAxis*, 3> oldAxes{{old->GetXaxis(), old->GetYaxis(), old->GetZaxis()}};
103  for (int i = 0; i < DIMENSIONS; ++i) {
104  oldAxes[i]->SetRange(0, 0);
105  oldAxes[i]->SetTitle(axes[i].GetTitle().c_str());
106  if (axes[i].GetAsEquidistant()) {
107  oldAxes[i]->Set(axes[i].GetNBins() - 2, axes[i].GetFrom(), axes[i].GetTo());
108  } else if (const TAxisIrregular* irr = axes[i].GetAsIrregular()) {
109  oldAxes[i]->Set(axes[i].GetNBins() - 2, &irr->GetBinBorders()[0]);
110  } else {
111  assert(0 && "Logic error; the axis is neither equidistant nor irregular.");
112  }
113  }
114 
115  int nBins = implBase->GetNBins();
116  old->SetBinsLength(nBins);
117  if (implBase->HasBinUncertainty())
118  old->Sumw2();
119 
120  // Set the bin content + uncertainty.
121  for (int binidx = 0; binidx < nBins; ++binidx) {
122  old->SetBinContent(binidx, implBase->GetBinContentAsDouble(binidx));
123  old->SetBinError(binidx, implBase->GetBinUncertainty(binidx));
124  }
125  fOldHist.reset(old);
126  return true;
127 }
128 
129 
130 namespace ROOT {
131 namespace Experimental {
132 namespace Internal {
133 template class THistPainterBase<1>;
134 template class THistPainterBase<2>;
135 template class THistPainterBase<3>;
136 
137 template class THistDrawable<1>;
138 template class THistDrawable<2>;
139 template class THistDrawable<3>;
140 }
141 }
142 }
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
virtual void SetDirectory(TDirectory *dir)
By default when an histogram is created, it is added to the list of histogram objects in the current ...
Definition: TH1.cxx:8053
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition: TSystem.cxx:1825
virtual void SetBinError(Int_t bin, Double_t error)
See convention for numbering bins in TH1::GetBin.
Definition: TH1.cxx:8311
THist< 3, double, THistStatContent, THistStatUncertainty > TH3D
Definition: THist.hxx:322
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis from bin first to last.
Definition: TAxis.cxx:889
R__EXTERN TSystem * gSystem
Definition: TSystem.h:539
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
Definition: TH1.cxx:8325
TAxis * GetYaxis()
Definition: TH1.h:301
THistDrawableBase & operator=(THistDrawableBase &&)
An axis with non-equidistant bins (also known as "variable binning").
Definition: TAxis.hxx:625
The TH1 histogram class.
Definition: TH1.h:56
THist< 2, double, THistStatContent, THistStatUncertainty > TH2D
Definition: THist.hxx:316
TAxis * GetZaxis()
Definition: TH1.h:302
virtual void SetBinsLength(Int_t=-1)
Definition: TH1.h:353
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
Definition: TH1.cxx:8132
THist< 1, double, THistStatContent, THistStatUncertainty > TH1D
Definition: THist.hxx:310
#define R__ERROR_HERE(GROUP)
Definition: TLogger.hxx:122
TAxis * GetXaxis()
Definition: TH1.h:300