ATLAS Offline Software
Loading...
Searching...
No Matches
SingleHistogramDefinition.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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>
14#include <format>
16 name{},
17 histoType{},
18 title{},
19 nBinsX{},
20 nBinsY{},
21 nBinsZ{},
22 xAxis(std::make_pair(std::numeric_limits<float>::quiet_NaN(), std::numeric_limits<float>::quiet_NaN())),
23 yAxis(std::make_pair(std::numeric_limits<float>::quiet_NaN(), std::numeric_limits<float>::quiet_NaN())),
24 zAxis(std::make_pair(std::numeric_limits<float>::quiet_NaN(), std::numeric_limits<float>::quiet_NaN())),
25 xTitle{},
26 yTitle{},
27 zTitle{},
28 allTitles{},
29 folder{},
30 m_empty(true) {
31}
32
34 Titles_t thetitle, NBins_t nbinsX,
35 Var_t xLo, Var_t xHi,
36 Titles_t xName, Titles_t yName,
37 Titles_t thefolder) :
38 name(thename), histoType(thehistoType), title(thetitle),
39 nBinsX(nbinsX), nBinsY(0), nBinsZ(0),
40 xAxis(xLo, xHi),
41 yAxis(std::numeric_limits<float>::quiet_NaN(), std::numeric_limits<float>::quiet_NaN()),
42 zAxis(std::numeric_limits<float>::quiet_NaN(), std::numeric_limits<float>::quiet_NaN()),
43 xTitle(xName), yTitle(yName), zTitle(""),
44 folder(thefolder), m_empty(false) {
45
47}
48
50 Titles_t thetitle, NBins_t nbinsX, NBins_t nbinsY,
51 Var_t xLo, Var_t xHi, Var_t yLo, Var_t yHi,
52 Titles_t xName, Titles_t yName, Titles_t thefolder) :
53 name(thename), histoType(thehistoType), title(thetitle),
54 nBinsX(nbinsX), nBinsY(nbinsY), nBinsZ(0),
55 xAxis(xLo, xHi),
56 yAxis(yLo, yHi),
57 zAxis(std::numeric_limits<float>::quiet_NaN(), std::numeric_limits<float>::quiet_NaN()),
58 xTitle(xName), yTitle(yName), zTitle(""),
59 folder(thefolder), m_empty(false) {
60 // should do sanity checks here
61
63}
64
66 Titles_t thetitle, NBins_t nbinsX, NBins_t nbinsY, NBins_t nbinsZ,
67 Var_t xLo, Var_t xHi, Var_t yLo, Var_t yHi, Var_t zLo, Var_t zHi,
68 Titles_t xName, Titles_t yName, Titles_t zName, Titles_t thefolder) :
69 name(thename), histoType(thehistoType), title(thetitle),
70 nBinsX(nbinsX), nBinsY(nbinsY), nBinsZ(nbinsZ),
71 xAxis(xLo, xHi),
72 yAxis(yLo, yHi),
73 zAxis(zLo, zHi),
74 xTitle(xName), yTitle(yName), zTitle(zName),
75 folder(thefolder), m_empty(false) {
76 // should do sanity checks here
77
79}
80
81bool
85
86std::string
88 return std::format("{} {} {} {} {} {} {:f} {:f} {:f} {:f} {:f} {:f} {} {} {}",
90 xAxis.first, xAxis.second,
91 yAxis.first, yAxis.second,
92 zAxis.first, zAxis.second,
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.