ATLAS Offline Software
PixelHistoConverter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3  */
4 
6 
8 #include "GaudiKernel/ISvcLocator.h"
9 
10 #include "TAxis.h"
11 #include "TH1.h"
12 #include "TH2.h"
13 #include "TH3.h"
14 
15 #include <iostream>
16 
18 = default;
19 
21 
22  if (!histo) {
23  return StatusCode::FAILURE;
24  }
25 
26  if (!setAxis(m_xAxis, histo->GetXaxis())) {
27  return StatusCode::FAILURE;
28  }
29 
31  const std::size_t xSize = m_xAxis.nBins;
32  m_content.resize(xSize);
33 
34  for (std::size_t x = 0; x < xSize; ++x) {
35  m_content.at(x) = histo->GetBinContent(x+1);
36  }
37 
38  return StatusCode::SUCCESS;
39 }
40 
42  if (!histo) {
43  return StatusCode::FAILURE;
44  }
45 
46  if (!setAxis(m_xAxis, histo->GetXaxis())) {
47  return StatusCode::FAILURE;
48  }
49  if (!setAxis(m_yAxis, histo->GetYaxis())) {
50  return StatusCode::FAILURE;
51  }
52 
54  const std::size_t xSize = m_xAxis.nBins;
55  const std::size_t ySize = m_yAxis.nBins;
56  m_content.resize(xSize*ySize);
57 
58  for (std::size_t x = 0; x < xSize; ++x) {
59  for (std::size_t y = 0; y < ySize; ++y) {
60  const std::size_t position = x + y*xSize;
61  m_content.at(position) = histo->GetBinContent(x+1,y+1);
62  }
63  }
64 
65  return StatusCode::SUCCESS;
66 }
67 
69  if (!histo) {
70  return StatusCode::FAILURE;
71  }
72 
73  if (!setAxis(m_xAxis, histo->GetXaxis())) {
74  return StatusCode::FAILURE;
75  }
76  if (!setAxis(m_yAxis, histo->GetYaxis())) {
77  return StatusCode::FAILURE;
78  }
79  if (!setAxis(m_zAxis, histo->GetZaxis())) {
80  return StatusCode::FAILURE;
81  }
82 
84  const std::size_t xSize = m_xAxis.nBins;
85  const std::size_t ySize = m_yAxis.nBins;
86  const std::size_t zSize = m_zAxis.nBins;
87  m_content.resize(xSize*ySize*zSize);
88 
89  for (std::size_t x = 0; x < xSize; ++x) {
90  for (std::size_t y = 0; y < ySize; ++y) {
91  for (std::size_t z = 0; z < zSize; ++z) {
92  const std::size_t position = x + xSize*(y + (ySize * z));
93  m_content.at(position) = histo->GetBinContent(x+1,y+1,z+1);
94  }
95  }
96  }
97 
98  return StatusCode::SUCCESS;
99 }
100 
101 bool PixelHistoConverter::isFirstZ(const float value) const {
102  return (getBinZ(value) == 0);
103 }
104 
105 bool PixelHistoConverter::setAxis(Axis& axis, const TAxis* rootAxis) {
106 
107  if (!rootAxis) {
108  return false;
109  }
110 
111  axis.nBins = rootAxis->GetNbins();
112  axis.min = rootAxis->GetXmin();
113  axis.max = rootAxis->GetXmax();
114 
115  if (axis.nBins < 1) {
116  return false;
117  }
118 
120  const float width = rootAxis->GetBinWidth(1);
121  for (std::size_t ibin = 2; ibin <= axis.nBins; ++ibin) {
123  if (std::abs(rootAxis->GetBinWidth(ibin) - width) > 0.01*width) {
124  return false;
125  }
126  }
127 
129  axis.width = 1.*axis.nBins/(axis.max - axis.min);
130 
131  return true;
132 }
PixelHistoConverter::Axis
Definition: PixelHistoConverter.h:50
PixelHistoConverter::m_zAxis
Axis m_zAxis
Definition: PixelHistoConverter.h:59
PixelHistoConverter::setAxis
static bool setAxis(Axis &axis, const TAxis *rootAxis)
Definition: PixelHistoConverter.cxx:105
yodamerge_tmp.axis
list axis
Definition: yodamerge_tmp.py:241
PixelHistoConverter::PixelHistoConverter
PixelHistoConverter()
athena.value
value
Definition: athena.py:124
x
#define x
PixelHistoConverter::m_content
std::vector< float > m_content
Definition: PixelHistoConverter.h:61
PixelHistoConverter::setHisto1D
StatusCode setHisto1D(const TH1 *histo)
Definition: PixelHistoConverter.cxx:20
PixelHistoConverter::getBinZ
std::size_t getBinZ(Args &&...args) const
Definition: PixelHistoConverter.h:84
PixelHistoConverter.h
z
#define z
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
PixelHistoConverter::isFirstZ
bool isFirstZ(const float value) const
Definition: PixelHistoConverter.cxx:101
PixelHistoConverter::setHisto2D
StatusCode setHisto2D(const TH2 *histo)
Definition: PixelHistoConverter.cxx:41
y
#define y
Base_Fragment.width
width
Definition: Sherpa_i/share/common/Base_Fragment.py:59
PixelHistoConverter::setHisto3D
StatusCode setHisto3D(const TH3 *histo)
Definition: PixelHistoConverter.cxx:68
PixelHistoConverter::Axis::nBins
std::size_t nBins
Definition: PixelHistoConverter.h:51
PixelHistoConverter::m_yAxis
Axis m_yAxis
Definition: PixelHistoConverter.h:58
plotBeamSpotCompare.histo
histo
Definition: plotBeamSpotCompare.py:415
StoreGateSvc.h
PixelHistoConverter::m_xAxis
Axis m_xAxis
Definition: PixelHistoConverter.h:57