17 CountHelper::CountHelper(
const std::shared_ptr<unsigned int> &resultCount,
unsigned int nSlots)
18 : fResultCount(resultCount), fCounts(nSlots, 0)
22 void CountHelper::Exec(
unsigned int slot)
27 void CountHelper::Finalize()
30 for (
auto &c : fCounts) {
35 void FillHelper::UpdateMinMax(
unsigned int slot,
double v)
37 auto &thisMin = fMin[slot];
38 auto &thisMax = fMax[slot];
39 thisMin = std::min(thisMin, v);
40 thisMax = std::max(thisMax, v);
43 FillHelper::FillHelper(
const std::shared_ptr<Hist_t> &
h,
unsigned int nSlots)
44 : fResultHist(h), fNSlots(nSlots), fBufSize(fgTotalBufSize / nSlots),
45 fMin(nSlots,
std::numeric_limits<BufEl_t>::max()), fMax(nSlots,
std::numeric_limits<BufEl_t>::lowest())
47 fBuffers.reserve(fNSlots);
48 fWBuffers.reserve(fNSlots);
49 for (
unsigned int i = 0; i < fNSlots; ++i) {
52 fBuffers.emplace_back(v);
53 fWBuffers.emplace_back(v);
57 void FillHelper::Exec(
unsigned int slot,
double v)
59 UpdateMinMax(slot, v);
60 fBuffers[slot].emplace_back(v);
63 void FillHelper::Exec(
unsigned int slot,
double v,
double w)
65 UpdateMinMax(slot, v);
66 fBuffers[slot].emplace_back(v);
67 fWBuffers[slot].emplace_back(w);
70 void FillHelper::Finalize()
72 for (
unsigned int i = 0; i < fNSlots; ++i) {
73 if (!fWBuffers[i].empty() && fBuffers[i].size() != fWBuffers[i].size()) {
74 throw std::runtime_error(
"Cannot fill weighted histogram with values in containers of different sizes.");
78 BufEl_t globalMin = *std::min_element(fMin.begin(), fMin.end());
79 BufEl_t globalMax = *std::max_element(fMax.begin(), fMax.end());
81 if (fResultHist->CanExtendAllAxes() && globalMin != std::numeric_limits<BufEl_t>::max() &&
82 globalMax != std::numeric_limits<BufEl_t>::lowest()) {
83 fResultHist->SetBins(fResultHist->GetNbinsX(), globalMin, globalMax);
86 for (
unsigned int i = 0; i < fNSlots; ++i) {
88 if (fWBuffers[i].empty()) {
89 fWBuffers[i].resize(fBuffers[i].size(), 1.);
91 fResultHist->FillN(fBuffers[i].size(), fBuffers[i].
data(), fWBuffers[i].
data());
95 template void FillHelper::Exec(
unsigned int,
const std::vector<float> &);
96 template void FillHelper::Exec(
unsigned int,
const std::vector<double> &);
97 template void FillHelper::Exec(
unsigned int,
const std::vector<char> &);
98 template void FillHelper::Exec(
unsigned int,
const std::vector<int> &);
99 template void FillHelper::Exec(
unsigned int,
const std::vector<unsigned int> &);
100 template void FillHelper::Exec(
unsigned int,
const std::vector<float> &,
const std::vector<float> &);
101 template void FillHelper::Exec(
unsigned int,
const std::vector<double> &,
const std::vector<double> &);
102 template void FillHelper::Exec(
unsigned int,
const std::vector<char> &,
const std::vector<char> &);
103 template void FillHelper::Exec(
unsigned int,
const std::vector<int> &,
const std::vector<int> &);
104 template void FillHelper::Exec(
unsigned int,
const std::vector<unsigned int> &,
const std::vector<unsigned int> &);
106 MinHelper::MinHelper(
const std::shared_ptr<double> &minVPtr,
unsigned int nSlots)
107 : fResultMin(minVPtr), fMins(nSlots,
std::numeric_limits<double>::max())
111 void MinHelper::Exec(
unsigned int slot,
double v)
113 fMins[slot] = std::min(v, fMins[slot]);
116 void MinHelper::Finalize()
118 *fResultMin = std::numeric_limits<double>::max();
119 for (
auto &
m : fMins) *fResultMin = std::min(
m, *fResultMin);
122 template void MinHelper::Exec(
unsigned int,
const std::vector<float> &);
123 template void MinHelper::Exec(
unsigned int,
const std::vector<double> &);
124 template void MinHelper::Exec(
unsigned int,
const std::vector<char> &);
125 template void MinHelper::Exec(
unsigned int,
const std::vector<int> &);
126 template void MinHelper::Exec(
unsigned int,
const std::vector<unsigned int> &);
128 MaxHelper::MaxHelper(
const std::shared_ptr<double> &maxVPtr,
unsigned int nSlots)
129 : fResultMax(maxVPtr), fMaxs(nSlots,
std::numeric_limits<double>::lowest())
133 void MaxHelper::Exec(
unsigned int slot,
double v)
135 fMaxs[slot] = std::max(v, fMaxs[slot]);
138 void MaxHelper::Finalize()
140 *fResultMax = std::numeric_limits<double>::lowest();
141 for (
auto &
m : fMaxs) {
142 *fResultMax = std::max(
m, *fResultMax);
146 template void MaxHelper::Exec(
unsigned int,
const std::vector<float> &);
147 template void MaxHelper::Exec(
unsigned int,
const std::vector<double> &);
148 template void MaxHelper::Exec(
unsigned int,
const std::vector<char> &);
149 template void MaxHelper::Exec(
unsigned int,
const std::vector<int> &);
150 template void MaxHelper::Exec(
unsigned int,
const std::vector<unsigned int> &);
152 MeanHelper::MeanHelper(
const std::shared_ptr<double> &meanVPtr,
unsigned int nSlots)
153 : fResultMean(meanVPtr), fCounts(nSlots, 0), fSums(nSlots, 0)
157 void MeanHelper::Exec(
unsigned int slot,
double v)
163 void MeanHelper::Finalize()
165 double sumOfSums = 0;
166 for (
auto &s : fSums) sumOfSums += s;
167 Count_t sumOfCounts = 0;
168 for (
auto &c : fCounts) sumOfCounts += c;
169 *fResultMean = sumOfSums / (sumOfCounts > 0 ? sumOfCounts : 1);
172 template void MeanHelper::Exec(
unsigned int,
const std::vector<float> &);
173 template void MeanHelper::Exec(
unsigned int,
const std::vector<double> &);
174 template void MeanHelper::Exec(
unsigned int,
const std::vector<char> &);
175 template void MeanHelper::Exec(
unsigned int,
const std::vector<int> &);
176 template void MeanHelper::Exec(
unsigned int,
const std::vector<unsigned int> &);
Namespace for new ROOT classes and functions.