18 #ifndef QC_MODULE_TOF_COUNTER_H 19 #define QC_MODULE_TOF_COUNTER_H 31 #include <fairlogger/Logger.h> 38 template <const
unsigned size, const
char* labels[size]>
50 void Count(
const unsigned int& v)
53 LOG(FATAL) <<
"Incrementing counter too far! " << v <<
"/" <<
Size();
55 #ifdef ENABLE_COUNTER_DEBUG_MODE 56 LOG(INFO) <<
"Incrementing " << v <<
"/" <<
Size() <<
" to " << counter[v];
64 LOG(INFO) <<
"Resetting Counter";
65 for (
unsigned int i = 0; i < size; i++) {
72 uint32_t
HowMany(
const unsigned int& pos)
const {
return counter[pos]; }
78 LOG(INFO) <<
"Making Histogram " << h->GetName() <<
" to accomodate counter of size " << size;
79 TAxis* axis = h->GetXaxis();
80 if (static_cast<unsigned int>(axis->GetNbins()) < size) {
81 LOG(FATAL) <<
"The histogram size (" << axis->GetNbins() <<
") is not large enough to accomodate the counter size (" << size <<
")";
84 unsigned int histo_size = size;
85 for (
unsigned int i = 0; i < size; i++) {
86 if (labels[i] && labels[i][0]) {
90 if (histo_size == 0) {
91 LOG(FATAL) <<
"Asked to produce a histogram with size " << histo_size <<
", check counter bin labels";
93 axis->Set(histo_size, 0, histo_size);
94 unsigned int binx = 1;
95 for (
unsigned int i = 0; i < size; i++) {
96 if (labels[i] && labels[i][0]) {
99 LOG(INFO) <<
"Setting bin " << binx <<
"/" << histo_size <<
" to contain counter for " << labels[i] <<
" (index " << i <<
"/" << size - 1 <<
")";
100 if (histo_size < binx) {
101 LOG(FATAL) <<
"Making bin outside of histogram limits!";
103 axis->SetBinLabel(binx++, labels[i]);
106 #ifdef ENABLE_PRINT_HISTOGRAMS_MODE 115 void FillHistogram(TH1* h,
const unsigned int& biny = 0,
const unsigned int& binz = 0)
const 117 LOG(INFO) <<
"Filling Histogram " << h->GetName() <<
" with counter contents";
118 unsigned int binx = 1;
119 const unsigned int nbinsx = h->GetNbinsX();
120 for (
unsigned int i = 0; i < size; i++) {
121 if (labels[i] && labels[i][0]) {
122 if (counter[i] > 0) {
123 LOG(FATAL) <<
"Counter at position " << i <<
" was non empty (" << counter[i] <<
") but was discarded because of empty labels";
127 #ifdef ENABLE_COUNTER_DEBUG_MODE 128 LOG(INFO) <<
"Filling bin " << binx <<
" of position " << i <<
" of label " << labels[i] <<
" with " << counter[i];
131 LOG(FATAL) <<
"Filling histogram " << h->GetName() <<
" at position " << binx <<
" i.e. past its size (" << nbinsx <<
")!";
133 const char* bin_label = h->GetXaxis()->GetBinLabel(binx);
134 if (strcmp(labels[i], bin_label) != 0) {
135 LOG(FATAL) <<
"Bin " << binx <<
" does not have the expected label '" << bin_label <<
"' vs '" << labels[i] <<
"'";
137 if (counter[i] > 0) {
140 h->SetBinContent(binx, biny, binz, counter[i]);
142 h->SetBinContent(binx, biny, counter[i]);
145 h->SetBinContent(binx, counter[i]);
150 #ifdef ENABLE_PRINT_HISTOGRAMS_MODE 156 unsigned int Size()
const {
return size; }
161 std::array<uint32_t, size> counter = { 0 };
166 #endif // QC_MODULE_TOF_COUNTER_H
uint32_t HowMany(const unsigned int &pos) const
Definition: Counter.h:72
~Counter()=default
Destructor.
Class to count events.
Definition: Counter.h:39
void MakeHistogram(TH1 *h) const
Definition: Counter.h:76
Counter()=default
Constructor.
void Count(const unsigned int &v)
Definition: Counter.h:50
void Reset()
Function to reset counters to zero.
Definition: Counter.h:62
unsigned int Size() const
Definition: Counter.h:156
void FillHistogram(TH1 *h, const unsigned int &biny=0, const unsigned int &binz=0) const
Definition: Counter.h:115