17CountHelper::CountHelper(
const std::shared_ptr<ULong64_t> &resultCount,
const unsigned int nSlots)
18 : fResultCount(resultCount), fCounts(nSlots, 0)
22void CountHelper::Exec(
unsigned int slot)
27void CountHelper::Finalize()
30 for (
auto &
c : fCounts) {
35ULong64_t &CountHelper::PartialUpdate(
unsigned int slot)
40void FillHelper::UpdateMinMax(
unsigned int slot,
double v)
42 auto &thisMin = fMin[slot];
43 auto &thisMax = fMax[slot];
44 thisMin = std::min(thisMin,
v);
45 thisMax = std::max(thisMax,
v);
48FillHelper::FillHelper(
const std::shared_ptr<Hist_t> &
h,
const unsigned int nSlots)
49 : fResultHist(
h), fNSlots(nSlots), fBufSize(fgTotalBufSize / nSlots), fPartialHists(fNSlots),
50 fMin(nSlots, std::numeric_limits<BufEl_t>::max()), fMax(nSlots, std::numeric_limits<BufEl_t>::lowest())
52 fBuffers.reserve(fNSlots);
53 fWBuffers.reserve(fNSlots);
54 for (
unsigned int i = 0; i < fNSlots; ++i) {
57 fBuffers.emplace_back(
v);
58 fWBuffers.emplace_back(
v);
62void FillHelper::Exec(
unsigned int slot,
double v)
64 UpdateMinMax(slot,
v);
65 fBuffers[slot].emplace_back(
v);
68void FillHelper::Exec(
unsigned int slot,
double v,
double w)
70 UpdateMinMax(slot,
v);
71 fBuffers[slot].emplace_back(
v);
72 fWBuffers[slot].emplace_back(w);
75Hist_t &FillHelper::PartialUpdate(
unsigned int slot)
77 auto &partialHist = fPartialHists[slot];
80 partialHist = std::make_unique<Hist_t>(*fResultHist);
81 auto weights = fWBuffers[slot].empty() ? nullptr : fWBuffers[slot].data();
82 partialHist->FillN(fBuffers[slot].size(), fBuffers[slot].data(), weights);
86void FillHelper::Finalize()
88 for (
unsigned int i = 0; i < fNSlots; ++i) {
89 if (!fWBuffers[i].empty() && fBuffers[i].size() != fWBuffers[i].size()) {
90 throw std::runtime_error(
"Cannot fill weighted histogram with values in containers of different sizes.");
94 BufEl_t globalMin = *std::min_element(fMin.begin(), fMin.end());
95 BufEl_t globalMax = *std::max_element(fMax.begin(), fMax.end());
97 if (fResultHist->CanExtendAllAxes() && globalMin != std::numeric_limits<BufEl_t>::max() &&
98 globalMax != std::numeric_limits<BufEl_t>::lowest()) {
99 fResultHist->SetBins(fResultHist->GetNbinsX(), globalMin, globalMax);
102 for (
unsigned int i = 0; i < fNSlots; ++i) {
103 auto weights = fWBuffers[i].empty() ? nullptr : fWBuffers[i].data();
104 fResultHist->FillN(fBuffers[i].size(), fBuffers[i].data(), weights);
108template void FillHelper::Exec(
unsigned int,
const std::vector<float> &);
109template void FillHelper::Exec(
unsigned int,
const std::vector<double> &);
110template void FillHelper::Exec(
unsigned int,
const std::vector<char> &);
111template void FillHelper::Exec(
unsigned int,
const std::vector<int> &);
112template void FillHelper::Exec(
unsigned int,
const std::vector<unsigned int> &);
113template void FillHelper::Exec(
unsigned int,
const std::vector<float> &,
const std::vector<float> &);
114template void FillHelper::Exec(
unsigned int,
const std::vector<double> &,
const std::vector<double> &);
115template void FillHelper::Exec(
unsigned int,
const std::vector<char> &,
const std::vector<char> &);
116template void FillHelper::Exec(
unsigned int,
const std::vector<int> &,
const std::vector<int> &);
117template void FillHelper::Exec(
unsigned int,
const std::vector<unsigned int> &,
const std::vector<unsigned int> &);
132MeanHelper::MeanHelper(
const std::shared_ptr<double> &meanVPtr,
const unsigned int nSlots)
133 : fResultMean(meanVPtr), fCounts(nSlots, 0), fSums(nSlots, 0), fPartialMeans(nSlots)
137void MeanHelper::Exec(
unsigned int slot,
double v)
143void MeanHelper::Finalize()
145 double sumOfSums = 0;
146 for (
auto &
s : fSums)
149 for (
auto &
c : fCounts)
151 *fResultMean = sumOfSums / (sumOfCounts > 0 ? sumOfCounts : 1);
154double &MeanHelper::PartialUpdate(
unsigned int slot)
156 fPartialMeans[slot] = fSums[slot] / fCounts[slot];
157 return fPartialMeans[slot];
160template void MeanHelper::Exec(
unsigned int,
const std::vector<float> &);
161template void MeanHelper::Exec(
unsigned int,
const std::vector<double> &);
162template void MeanHelper::Exec(
unsigned int,
const std::vector<char> &);
163template void MeanHelper::Exec(
unsigned int,
const std::vector<int> &);
164template void MeanHelper::Exec(
unsigned int,
const std::vector<unsigned int> &);
166StdDevHelper::StdDevHelper(
const std::shared_ptr<double> &meanVPtr,
const unsigned int nSlots)
167 : fNSlots(nSlots), fResultStdDev(meanVPtr), fCounts(nSlots, 0), fMeans(nSlots, 0), fDistancesfromMean(nSlots, 0)
171void StdDevHelper::Exec(
unsigned int slot,
double v)
174 auto count = ++fCounts[slot];
175 auto delta =
v - fMeans[slot];
176 auto mean = fMeans[slot] + delta / count;
177 auto delta2 =
v - mean;
178 auto distance = fDistancesfromMean[slot] + delta * delta2;
180 fCounts[slot] = count;
182 fDistancesfromMean[slot] = distance;
185void StdDevHelper::Finalize()
188 double totalElements = 0;
189 for (
auto c : fCounts) {
192 if (totalElements == 0 || totalElements == 1) {
198 double overallMean = 0;
199 for (
unsigned int i = 0; i < fNSlots; ++i) {
200 overallMean += fCounts[i] * fMeans[i];
202 overallMean = overallMean / totalElements;
205 for (
unsigned int i = 0; i < fNSlots; ++i) {
206 if (fCounts[i] == 0) {
209 auto setVariance = fDistancesfromMean[i] / (fCounts[i]);
210 variance += (fCounts[i]) * (setVariance +
std::pow((fMeans[i] - overallMean), 2));
213 variance = variance / (totalElements - 1);
217template void StdDevHelper::Exec(
unsigned int,
const std::vector<float> &);
218template void StdDevHelper::Exec(
unsigned int,
const std::vector<double> &);
219template void StdDevHelper::Exec(
unsigned int,
const std::vector<char> &);
220template void StdDevHelper::Exec(
unsigned int,
const std::vector<int> &);
221template void StdDevHelper::Exec(
unsigned int,
const std::vector<unsigned int> &);
225template class TakeHelper<bool, bool, std::vector<bool>>;
226template class TakeHelper<unsigned int, unsigned int, std::vector<unsigned int>>;
227template class TakeHelper<unsigned long, unsigned long, std::vector<unsigned long>>;
228template class TakeHelper<unsigned long long, unsigned long long, std::vector<unsigned long long>>;
229template class TakeHelper<int, int, std::vector<int>>;
230template class TakeHelper<long, long, std::vector<long>>;
231template class TakeHelper<long long, long long, std::vector<long long>>;
232template class TakeHelper<float, float, std::vector<float>>;
233template class TakeHelper<double, double, std::vector<double>>;
unsigned long long ULong64_t
double pow(double, double)
Namespace for new ROOT classes and functions.
static constexpr double s