ATLAS Offline Software
Loading...
Searching...
No Matches
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,
50 Var_t xLo, Var_t xHi, Var_t yLo, Var_t yHi,
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
80bool
84
85std::string
87 const std::string s(" ");
88
89 return name + s + histoType + s + title + s + std::to_string(nBinsX) + s + std::to_string(nBinsY) + s + std::to_string(nBinsZ) +
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
96bool
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
103bool
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
125std::string
129
130std::string
132 const std::string s(";");
133
134 return title + s + xTitle + s + yTitle + s + zTitle;
135}
136
137std::string
138SingleHistogramDefinition::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}
std::string titleDigest() const
produce single-line representation of the titles (titles separated by the ';' delimiter)
std::string str() const
String representation of the histogram definition.
bool isValid() const
Is the histogram definition valid.
IHistogramDefinitionSvc::axesLimits_t zAxis
bool empty() const
Is the histogram definition empty?
IHistogramDefinitionSvc::axesLimits_t xAxis
std::string stringIndex() const
add the folder path to produce the full histogram name e.g. myFolder/myHisto
IHistogramDefinitionSvc::axesLimits_t yAxis
bool validType() const
Does the histogram definition have a valid type (TH1, TH2 etc)?
STL namespace.