ATLAS Offline Software
SingleHistogramDefinition.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 //
5 // SingleHistogramDefinition.cpp
6 // HDef
7 //
8 // Created by sroe on 13/07/2015.
9 //
10 
12 #include <utility>
13 #include <limits>
15  name{},
16  histoType{},
17  title{},
18  nBinsX{},
19  nBinsY{},
20  nBinsZ{},
21  xAxis(std::make_pair(std::numeric_limits<float>::quiet_NaN(), std::numeric_limits<float>::quiet_NaN())),
22  yAxis(std::make_pair(std::numeric_limits<float>::quiet_NaN(), std::numeric_limits<float>::quiet_NaN())),
23  zAxis(std::make_pair(std::numeric_limits<float>::quiet_NaN(), std::numeric_limits<float>::quiet_NaN())),
24  xTitle{},
25  yTitle{},
26  zTitle{},
27  allTitles{},
28  folder{},
29  m_empty(true) {
30 }
31 
33  Titles_t thetitle, NBins_t nbinsX,
34  Var_t xLo, Var_t xHi,
35  Titles_t xName, Titles_t yName,
36  Titles_t thefolder) :
37  name(thename), histoType(thehistoType), title(thetitle),
38  nBinsX(nbinsX), nBinsY(0), nBinsZ(0),
39  xAxis(xLo, xHi),
40  yAxis(std::numeric_limits<float>::quiet_NaN(), std::numeric_limits<float>::quiet_NaN()),
41  zAxis(std::numeric_limits<float>::quiet_NaN(), std::numeric_limits<float>::quiet_NaN()),
42  xTitle(xName), yTitle(yName), zTitle(""),
43  folder(thefolder), m_empty(false) {
44 
46 }
47 
49  Titles_t thetitle, NBins_t nbinsX, NBins_t nbinsY,
51  Titles_t xName, Titles_t yName, Titles_t thefolder) :
52  name(thename), histoType(thehistoType), title(thetitle),
53  nBinsX(nbinsX), nBinsY(nbinsY), nBinsZ(0),
54  xAxis(xLo, xHi),
55  yAxis(yLo, yHi),
56  zAxis(std::numeric_limits<float>::quiet_NaN(), std::numeric_limits<float>::quiet_NaN()),
57  xTitle(xName), yTitle(yName), zTitle(""),
58  folder(thefolder), m_empty(false) {
59  // should do sanity checks here
60 
62 }
63 
65  Titles_t thetitle, NBins_t nbinsX, NBins_t nbinsY, NBins_t nbinsZ,
66  Var_t xLo, Var_t xHi, Var_t yLo, Var_t yHi, Var_t zLo, Var_t zHi,
67  Titles_t xName, Titles_t yName, Titles_t zName, Titles_t thefolder) :
68  name(thename), histoType(thehistoType), title(thetitle),
69  nBinsX(nbinsX), nBinsY(nbinsY), nBinsZ(nbinsZ),
70  xAxis(xLo, xHi),
71  yAxis(yLo, yHi),
72  zAxis(zLo, zHi),
73  xTitle(xName), yTitle(yName), zTitle(zName),
74  folder(thefolder), m_empty(false) {
75  // should do sanity checks here
76 
78 }
79 
80 bool
82  return m_empty;
83 }
84 
85 std::string
87  const std::string s(" ");
88 
90  s + std::to_string(xAxis.first) + s + std::to_string(xAxis.second) + s +
91  std::to_string(yAxis.first) + s + std::to_string(yAxis.second) + s +
92  std::to_string(zAxis.first) + s + std::to_string(zAxis.second) + s +
93  xTitle + s + yTitle + s + zTitle;
94 }
95 
96 bool
98  const std::string signature((histoType.substr(0, 3)));
99 
100  return((signature == "TH1")or(signature == "TH2")or(signature == "TH3")or(signature == "TPr") or(signature == "TEf"));
101 }
102 
103 bool
105  if (name.empty() or histoType.empty()) {
106  return false;
107  }
108  bool sane(true);
109  // note: if yaxis is left undefined, the limits should be NaN, but (NaN != NaN) is always true
110  const bool sensibleLimits = (xAxis.first != xAxis.second)and(yAxis.first != yAxis.second)and(zAxis.first != zAxis.second);
111  const bool sensibleXBins = (nBinsX != 0);
112  const bool sensibleYBins = (nBinsY != 0);
113  const bool sensibleZBins = (nBinsZ != 0);
114  const bool sensibleTitles = not (title.empty() or xTitle.empty());
115  sane = (sensibleLimits and sensibleXBins and sensibleTitles);
116  if (histoType.substr(0, 3) == "TH2") {
117  sane = (sane and sensibleYBins);
118  }
119  if (histoType.substr(0, 3) == "TH3") {
120  sane = (sane and sensibleYBins and sensibleZBins);
121  }
122  return sane;
123 }
124 
125 std::string
127  return stringIndex(name, folder);
128 }
129 
130 std::string
132  const std::string s(";");
133 
134  return title + s + xTitle + s + yTitle + s + zTitle;
135 }
136 
137 std::string
138 SingleHistogramDefinition::stringIndex(const std::string& thisname, const std::string& thisfolder) {
139  if (thisfolder.empty()) {
140  return thisname;
141  }
142  const std::string delimiter("/");
143  std::string result(thisfolder);
144  if ((thisfolder.substr(0, 1)) == delimiter) {
145  result = thisfolder.substr(1, thisfolder.size() - 2);// reduce "/myfolder" to "myfolder"
146  }
147  size_t lastChar(result.size() - 1);
148  if ((result.substr(lastChar, 1) != delimiter)) {
149  result = result + delimiter; // add a slash: "myfolder" => "myfolder/"
150  }
151  return result + thisname;
152 }
SingleHistogramDefinition::stringIndex
std::string stringIndex() const
add the folder path to produce the full histogram name e.g. myFolder/myHisto
Definition: SingleHistogramDefinition.cxx:126
SingleHistogramDefinition::nBinsX
unsigned int nBinsX
Definition: SingleHistogramDefinition.h:47
SingleHistogramDefinition.h
SingleHistogramDefinition::str
std::string str() const
String representation of the histogram definition.
Definition: SingleHistogramDefinition.cxx:86
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
get_generator_info.result
result
Definition: get_generator_info.py:21
PlotCalibFromCool.zAxis
zAxis
Definition: PlotCalibFromCool.py:76
SingleHistogramDefinition::nBinsZ
unsigned int nBinsZ
Definition: SingleHistogramDefinition.h:49
SingleHistogramDefinition::yTitle
std::string yTitle
Definition: SingleHistogramDefinition.h:54
SingleHistogramDefinition::NBins_t
const unsigned int NBins_t
Definition: SingleHistogramDefinition.h:20
SingleHistogramDefinition::histoType
std::string histoType
Definition: SingleHistogramDefinition.h:45
SingleHistogramDefinition::folder
std::string folder
Definition: SingleHistogramDefinition.h:57
SingleHistogramDefinition::xAxis
IHistogramDefinitionSvc::axesLimits_t xAxis
Definition: SingleHistogramDefinition.h:50
SingleHistogramDefinition::validType
bool validType() const
Does the histogram definition have a valid type (TH1, TH2 etc)?
Definition: SingleHistogramDefinition.cxx:97
python.AthDsoLogger.delimiter
delimiter
Definition: AthDsoLogger.py:71
SingleHistogramDefinition::SingleHistogramDefinition
SingleHistogramDefinition()
Definition: SingleHistogramDefinition.cxx:14
SingleHistogramDefinition::title
std::string title
Definition: SingleHistogramDefinition.h:46
SingleHistogramDefinition::xTitle
std::string xTitle
Definition: SingleHistogramDefinition.h:53
SingleHistogramDefinition::Var_t
const float Var_t
Definition: SingleHistogramDefinition.h:21
covarianceTool.title
title
Definition: covarianceTool.py:542
rootconvert.yLo
yLo
Definition: rootconvert.py:33
rootconvert.xLo
xLo
Definition: rootconvert.py:32
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
SingleHistogramDefinition::m_empty
bool m_empty
Definition: SingleHistogramDefinition.h:73
SingleHistogramDefinition::titleDigest
std::string titleDigest() const
produce single-line representation of the titles (titles separated by the ';' delimiter)
Definition: SingleHistogramDefinition.cxx:131
rootconvert.yHi
yHi
Definition: rootconvert.py:33
SingleHistogramDefinition::zTitle
std::string zTitle
Definition: SingleHistogramDefinition.h:55
SingleHistogramDefinition::Titles_t
const std::string & Titles_t
Definition: SingleHistogramDefinition.h:19
rootconvert.xHi
xHi
Definition: rootconvert.py:32
SingleHistogramDefinition::name
std::string name
Definition: SingleHistogramDefinition.h:44
CaloCondBlobAlgs_fillNoiseFromASCII.folder
folder
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:56
SingleHistogramDefinition::yAxis
IHistogramDefinitionSvc::axesLimits_t yAxis
Definition: SingleHistogramDefinition.h:51
SingleHistogramDefinition::isValid
bool isValid() const
Is the histogram definition valid.
Definition: SingleHistogramDefinition.cxx:104
SingleHistogramDefinition::allTitles
std::string allTitles
Definition: SingleHistogramDefinition.h:56
SingleHistogramDefinition::zAxis
IHistogramDefinitionSvc::axesLimits_t zAxis
Definition: SingleHistogramDefinition.h:52
SingleHistogramDefinition::empty
bool empty() const
Is the histogram definition empty?
Definition: SingleHistogramDefinition.cxx:81
readCCLHist.float
float
Definition: readCCLHist.py:83
SingleHistogramDefinition::nBinsY
unsigned int nBinsY
Definition: SingleHistogramDefinition.h:48