You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// static_assert((sizeof(labels) / sizeof(const char*)) == size, "size of the counter and the one of the labels must coincide");
96
+
static_assert(size > 0, "size of the counter cannot be 0!");
97
+
// static_assert(((labels == nullptr) || (sizeof(labels) / sizeof(const char*)) == size), "size of the counter and the one of the labels must coincide");
90
98
/// Containers to fill
91
99
std::array<uint32_t, size> counter = { 0 };
92
100
uint32_tmTotal = 0;
@@ -96,18 +104,15 @@ class Counter
96
104
// Implementation //
97
105
////////////////////
98
106
99
-
// #define ENABLE_COUNTER_DEBUG_MODE // Flag used to enable more printing and more debug
100
-
// #define ENABLE_PRINT_HISTOGRAMS_MODE // Flag used to enable more printing and more debug
107
+
// #define ENABLE_BIN_SHIFT // Flag used to enable different binning in counter and histograms
int Counter<size, labels>::MakeHistogram(TH1* histogram) const
163
177
{
164
-
LOG(DEBUG) << "Making Histogram " << h->GetName() << " to accomodate counter of size " << size;
165
-
TAxis* axis = h->GetXaxis();
178
+
LOG(DEBUG) << "Making Histogram " << histogram->GetName() << " to accomodate counter of size " << size;
179
+
TAxis* axis = histogram->GetXaxis();
166
180
if (static_cast<unsignedint>(axis->GetNbins()) < size) {
167
181
LOG(FATAL) << "The histogram size (" << axis->GetNbins() << ") is not large enough to accomodate the counter size (" << size << ")";
182
+
return1;
183
+
}
184
+
histogram->Reset();
185
+
186
+
#ifndef ENABLE_BIN_SHIFT
187
+
LOG(DEBUG) << "Asked to produce a histogram with size " << size << " out of the size " << size << " due to " << size - size << " empty labels";
188
+
axis->Set(size, 0, size);
189
+
for (unsignedint i = 0; i < size; i++) {
190
+
if (!HasLabel(i)) { // If label at position i is empty
191
+
continue;
192
+
}
193
+
LOG(DEBUG) << "Setting bin " << i + 1 << "/" << size << " to contain counter for '" << labels[i] << "' (index " << i << "/" << size - 1 << ")";
194
+
axis->SetBinLabel(i + 1, labels[i]);
168
195
}
169
-
h->Reset();
196
+
#else
170
197
unsignedint histo_size = size;
171
198
if (labels != nullptr) { // Only if labels are defined
172
199
for (unsignedint i = 0; i < size; i++) {
173
-
if (labels[i] && !labels[i][0]) { // If label at position i is empty
200
+
if (!HasLabel(i)) { // If label at position i is empty or does not exist
174
201
LOG(DEBUG) << "Skipping label '" << labels[i] << "' at position " << i << "/" << size - 1;
175
202
histo_size--;
176
203
}
177
204
}
178
205
}
179
206
if (histo_size == 0) {
180
207
LOG(FATAL) << "Asked to produce a histogram with size " << histo_size << ", check counter bin labels";
208
+
return1;
181
209
} else {
182
-
LOG(DEBUG) << "Asked to produce a histogram with size " << histo_size << " out of the size " << size << " due to empty labels";
210
+
LOG(DEBUG) << "Asked to produce a histogram with size " << histo_size << " out of the size " << size << " due to " << size - histo_size << "empty labels";
183
211
}
184
212
185
213
axis->Set(histo_size, 0, histo_size);
186
214
if (labels != nullptr) { // Only if labels are defined
187
215
unsignedint binx = 1;
188
216
for (unsignedint i = 0; i < size; i++) {
189
-
if (labels[i] && !labels[i][0]) { // If label at position i is empty
217
+
if (!HasLabel(i)) { // If label at position i is empty
190
218
continue;
191
219
}
192
-
LOG(DEBUG) << "Setting bin " << binx << "/" << histo_size << " to contain counter for '" << labels[i] << "' (index " << i << "/" << size - 1 << ")";
193
220
if (histo_size < binx) {
194
221
LOG(FATAL) << "Making bin outside of histogram limits!";
222
+
return1;
195
223
}
224
+
LOG(DEBUG) << "Setting bin " << binx << "/" << histo_size << " to contain counter for '" << labels[i] << "' (index " << i << "/" << size - 1 << ")";
0 commit comments