17 CountHelper::CountHelper(
const std::shared_ptr<ULong64_t> &resultCount,
const 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 ULong64_t &CountHelper::PartialUpdate(
unsigned int slot)
40 void 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);
48 FillHelper::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);
62 void FillHelper::Exec(
unsigned int slot,
double v)
64 UpdateMinMax(slot, v);
65 fBuffers[slot].emplace_back(v);
68 void 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);
75 Hist_t &FillHelper::PartialUpdate(
unsigned int slot)
77 auto &partialHist = fPartialHists[slot];
80 partialHist.reset(
new Hist_t(*fResultHist));
81 auto weights = fWBuffers[slot].empty() ? nullptr : fWBuffers[slot].data();
82 partialHist->FillN(fBuffers[slot].size(), fBuffers[slot].
data(), weights);
86 void 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);
108 template void FillHelper::Exec(
unsigned int,
const std::vector<float> &);
109 template void FillHelper::Exec(
unsigned int,
const std::vector<double> &);
110 template void FillHelper::Exec(
unsigned int,
const std::vector<char> &);
111 template void FillHelper::Exec(
unsigned int,
const std::vector<int> &);
112 template void FillHelper::Exec(
unsigned int,
const std::vector<unsigned int> &);
113 template void FillHelper::Exec(
unsigned int,
const std::vector<float> &,
const std::vector<float> &);
114 template void FillHelper::Exec(
unsigned int,
const std::vector<double> &,
const std::vector<double> &);
115 template void FillHelper::Exec(
unsigned int,
const std::vector<char> &,
const std::vector<char> &);
116 template void FillHelper::Exec(
unsigned int,
const std::vector<int> &,
const std::vector<int> &);
117 template void FillHelper::Exec(
unsigned int,
const std::vector<unsigned int> &,
const std::vector<unsigned int> &);
132 MeanHelper::MeanHelper(
const std::shared_ptr<double> &meanVPtr,
const unsigned int nSlots)
133 : fResultMean(meanVPtr), fCounts(nSlots, 0), fSums(nSlots, 0), fPartialMeans(nSlots)
137 void MeanHelper::Exec(
unsigned int slot,
double v)
143 void MeanHelper::Finalize()
145 double sumOfSums = 0;
146 for (
auto &
s : fSums)
149 for (
auto &
c : fCounts)
151 *fResultMean = sumOfSums / (sumOfCounts > 0 ? sumOfCounts : 1);
154 double &MeanHelper::PartialUpdate(
unsigned int slot)
156 fPartialMeans[slot] = fSums[slot] / fCounts[slot];
157 return fPartialMeans[slot];
160 template void MeanHelper::Exec(
unsigned int,
const std::vector<float> &);
161 template void MeanHelper::Exec(
unsigned int,
const std::vector<double> &);
162 template void MeanHelper::Exec(
unsigned int,
const std::vector<char> &);
163 template void MeanHelper::Exec(
unsigned int,
const std::vector<int> &);
164 template void MeanHelper::Exec(
unsigned int,
const std::vector<unsigned int> &);
Namespace for new ROOT classes and functions.
unsigned long long ULong64_t
static constexpr double s