17#ifndef AliceO2_TPC_FastHisto_H
18#define AliceO2_TPC_FastHisto_H
62 FastHisto(
const unsigned int nBins = 20,
const float xmin = 0.f,
const float xmax = 2.f,
const bool useUnderflow =
true,
const bool useOverflow =
true)
63 : mNBins(nBins), mXmin(xmin), mXmax(xmax), mUseUnderflow(useUnderflow), mUseOverflow(useOverflow), mBinCont(nBins + useUnderflow + useOverflow), mBinWidth((mXmax - mXmin) / mNBins){};
82 std::fill(mBinCont.begin(), mBinCont.end(), 0);
98 void print(
const int prec = 2)
const;
110 return mBinCont[
index];
121 const float val = (bin - mUseUnderflow) * binWidth + mXmin;
149 unsigned int vecsize = mBinCont.size();
150 if (bin >= vecsize) {
161 unsigned int mNBins{};
164 bool mUseUnderflow =
true;
165 bool mUseOverflow =
true;
167 std::vector<T> mBinCont{};
168 unsigned int mBinCount{0};
170 ClassDefNV(FastHisto, 1)
177 const int indexBin = findBin(
val);
178 if ((indexBin < 0) || (indexBin >
static_cast<int>(mBinCont.size()) - 1)) {
181 fillBin(indexBin,
weight);
188 LOGP(info,
"\n Entries: {}", mBinCount);
189 LOGP(info,
"Truncated Mean: {}",
data.mCOG);
190 LOGP(info,
"Standard Deviation: {}",
data.mStdDev);
191 LOGP(info,
"sum of content: {}",
data.mSum);
193 const int maxEle = *std::max_element(mBinCont.begin(), mBinCont.end());
202 for (
int i = 2;
i <= maxEle; ++
i) {
206 LOGP(info,
"{}",
stream.str());
207 stream.str(std::string());
209 for (
int i = 0;
i <= maxEle; ++
i) {
212 LOGP(info,
"{}",
stream.str());
214 const float binWidth = getBinWidth();
215 const int totalBins = mBinCont.size();
217 for (
int i = 0;
i < totalBins; ++
i) {
218 stream.str(std::string());
219 if (
i == 0 && mUseUnderflow) {
221 stream << std::right <<
"U_Flow | ";
222 }
else if (
i == totalBins - 1 && mUseOverflow) {
224 stream << std::right <<
"O_Flow | ";
227 const float xPos = mXmin + binWidth * (
i - mUseUnderflow);
228 stream << std::fixed << std::setprecision(prec) << xPos;
229 const std::string sIn =
" | ";
233 for (
int j = 1;
j <= getBinContent(
i); ++
j) {
234 const std::string sIn =
"x ";
237 std::string xPosString =
stream.str();
238 LOGP(info,
"{}", xPosString);
249 if (mBinCont.size() == 0) {
257 const T integral = std::accumulate(mBinCont.begin(), mBinCont.end(), 0);
261 const float lowerBound = integral * low;
262 const float upperBound = integral * high;
263 const unsigned int lastBin = mBinCont.size() - 1;
270 const float binWidth = getBinWidth();
271 const int shiftBin = mUseUnderflow ? -1 : 0;
274 bool isLowerFrac =
false;
275 unsigned int bin = 0;
276 for (bin = 0; bin <= lastBin; ++bin) {
277 countContent += mBinCont[bin];
279 if (countContent - lowerBound <= 0) {
281 }
else if (countContent >= upperBound) {
285 const float xcenter = mXmin + (bin + 0.5f + shiftBin) * binWidth;
286 const float tmpBinCont = isLowerFrac ? mBinCont[bin] : countContent - lowerBound;
287 const float tmpMean = tmpBinCont * xcenter;
290 rms2 += tmpMean * xcenter;
294 if (!checkBin(bin)) {
300 const float xcenter = mXmin + (bin + 0.5f + shiftBin) * binWidth;
301 const T upFrac = mBinCont[bin] - (
static_cast<float>(countContent) - upperBound);
302 const float tmpMean = upFrac * xcenter;
305 rms2 += tmpMean * xcenter;
314 data.mStdDev = std::sqrt(std::abs(rms2 - mean * mean));
323 if (!mUseUnderflow) {
324 LOGP(warning,
"findBin: UNDERFLOW BIN: BIN IS NOT IN HISTOGRAM RANGE!");
333 LOGP(warning,
"findBin: OVERFLOW BIN: BIN IS NOT IN HISTOGRAM RANGE!");
336 return mBinCont.size() - 1;
340 const float binWidth = getBinWidth();
341 const int bin = (
val - mXmin) / binWidth + mUseUnderflow;
348 if (
other.mBinCount == 0) {
353 if (mNBins !=
other.mNBins || mXmin !=
other.mXmin || mXmax !=
other.mXmax || mUseUnderflow !=
other.mUseUnderflow || mUseOverflow !=
other.mUseOverflow) {
354 static int errCount = 0;
355 if (mBinCount && errCount < 10) {
357 LOGP(warning,
"mBinCount {} other.mBinCount: {} mNBins {}, other.mNBins {}, mXmin {}, other.mXmin {}, mXmax {}, other.mXmax {}, mUseUnderflow {}, other.mUseUnderflow {}, mUseOverflow {}, other.mUseOverflow {}", mBinCount,
other.mBinCount, mNBins,
other.mNBins, mXmin,
other.mXmin, mXmax,
other.mXmax, mUseUnderflow,
other.mUseUnderflow, mUseOverflow,
other.mUseOverflow);
362 mBinCount +=
other.mBinCount;
363 std::transform(mBinCont.begin(), mBinCont.end(),
other.mBinCont.begin(), mBinCont.begin(), std::plus<T>());
templated 1D-histogram class.
float getBinWidth() const
~FastHisto()=default
default destructor
unsigned int getEntries() const
int findBin(const float val) const
T getBinContent(unsigned int index) const
unsigned int getNBins() const
bool checkBin(int bin) const
void fillBin(int index, T weight)
FastHisto(const unsigned int nBins=20, const float xmin=0.f, const float xmax=2.f, const bool useUnderflow=true, const bool useOverflow=true)
void fill(const float val, T weight=1)
bool isUnderflowSet() const
bool isOverflowSet() const
const FastHisto & operator+=(const FastHisto &other)
overload of operator +
math_utils::StatisticsData getStatisticsData(const float low=0.05f, const float high=0.6f) const
void print(const int prec=2) const
void reset()
this function resets the bin content in the histogram
float getBinCenter(int bin) const
GLuint GLuint GLfloat weight
DataT sum(const Vector< DataT, N > &a)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
double mCOG
calculated centre of gravity
VectorOfTObjectPtrs other