9#include <top/dbobjects/TOPASICPedestals.h>
10#include <framework/logging/Logger.h>
27 if (!profile)
return bad;
30 B2ERROR(
"TOPASICPedestals::setPedestals: TProfile with wrong number of bins");
34 if (profile->GetEntries() == 0) {
35 B2WARNING(
"TOPASICPedestals::setPedestals: TProfile with no entries");
39 std::vector<unsigned> values;
40 std::vector<unsigned> errors;
42 values.push_back(
int(profile->GetBinContent(i + 1) + average + 0.5));
43 errors.push_back(
int(profile->GetBinError(i + 1) + 0.5));
46 unsigned maxDif = 1 <<
c_Bits; maxDif--;
47 unsigned maxErr = 1 << (
sizeof(
unsigned short) * 8 -
c_Bits); maxErr--;
52 if (dif > maxDif)
continue;
53 unsigned err = errors[i];
54 if (err > maxErr)
continue;
55 if (err == 0) err = 1;
66 const std::vector<unsigned>& errors,
71 std::set<unsigned> sortedValues;
72 for (
unsigned i = 0; i < values.size(); i++) {
73 if (errors[i] > maxErr)
continue;
74 sortedValues.insert(values[i]);
77 unsigned nprev = sortedValues.size();
79 for (
auto it = sortedValues.begin(); it != sortedValues.end(); ++it) {
81 for (
auto back = sortedValues.crbegin(); *back - *it > maxDif; ++back) {
84 unsigned nbad = nl + nr;
85 if (nbad == 0)
return *it;
86 if (nbad >= nprev)
return *(--it);
91 return *sortedValues.begin();
unsigned short m_pedestals[c_WindowSize]
pedestals (packed: value, error)
unsigned short m_offset
common pedestal offset
@ c_Bits
number of bits reserved for pedestal value
@ c_WindowSize
number of samples
unsigned getOptimizedOffset(const std::vector< unsigned > &values, const std::vector< unsigned > &errors, unsigned maxDif, unsigned maxErr)
Return the offset that can allow for the maximal number of good pedestal samples.
int setPedestals(const TProfile *profile, double average=0)
Set pedestals from profile histogram with c_WindowSize bins.
Abstract base class for different kinds of events.