9 #include <top/dbobjects/TOPASICPedestals.h>
10 #include <framework/logging/Logger.h>
23 int TOPASICPedestals::setPedestals(
const TProfile* profile,
double average)
25 int bad = c_WindowSize;
27 if (!profile)
return bad;
29 if (profile->GetNbinsX() != c_WindowSize) {
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;
41 for (
int i = 0; i < c_WindowSize; i++) {
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--;
48 m_offset = getOptimizedOffset(values, errors, maxDif, maxErr);
50 for (
int i = 0; i < c_WindowSize; i++) {
51 unsigned dif = values[i] - m_offset;
52 if (dif > maxDif)
continue;
53 unsigned err = errors[i];
54 if (err > maxErr)
continue;
55 if (err == 0) err = 1;
56 m_pedestals[i] = dif + (err << c_Bits);
65 unsigned TOPASICPedestals::getOptimizedOffset(
const std::vector<unsigned>& values,
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();
Abstract base class for different kinds of events.