Project
Loading...
Searching...
No Matches
BadChannelCalibrator.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14#include "Framework/Logger.h"
17#include "MathUtils/fit.h"
18#include <algorithm>
19#include <cassert>
20#include <iostream>
21#include <iterator>
22#include <numeric>
23#include <sstream>
24
26{
27
28void BadChannelCalibrator::initOutput()
29{
30 mPedestalsVector.clear();
31 mBadChannelsVector.clear();
32}
33
34bool BadChannelCalibrator::readyToSend(std::string& reason) const
35{
36 reason = "";
37
38 // let's check our hypothesis about this object (nslots=1) is actually true
39 auto nslots = getNSlots();
40 if (nslots != 1) {
41 LOGP(error, "nslots={} while it is expected to be 1", nslots);
42 return false;
43 }
44
45 auto& slot = getFirstSlot();
46 bool statIsEnough = hasEnoughData(slot);
47 if (statIsEnough) {
48 reason = "enough statistics";
49 const o2::mch::calibration::PedestalData* pedData = slot.getContainer();
50 }
51 return statIsEnough;
52}
53
54void BadChannelCalibrator::finalize()
55{
56 // let's check our hypothesis about this object (nslots=1) is actually true
57 auto nslots = getNSlots();
58 if (nslots != 1) {
59 LOGP(fatal, "nslots={} while it is expected to be 1", nslots);
60 }
61
62 auto& slot = getSlot(0);
63 finalizeSlot(slot);
64}
65
66bool BadChannelCalibrator::hasEnoughData(const Slot& slot) const
67{
68 const int minNofEntries = BadChannelCalibratorParam::Instance().minRequiredNofEntriesPerChannel;
70 auto nofChannels = pedData->size();
71 const int requiredChannels = static_cast<int>(BadChannelCalibratorParam::Instance().minRequiredCalibratedFraction * nofChannels);
72
73 auto nofCalibrated = std::count_if(pedData->cbegin(), pedData->cend(),
74 [&](const PedestalChannel& c) { return c.mEntries > minNofEntries; });
75
76 bool hasEnough = nofCalibrated > requiredChannels;
77
78 LOGP(info,
79 "nofChannelWithEnoughStat(>{})={} nofChannels={} requiredChannels={} hasEnough={}",
80 minNofEntries, nofCalibrated, nofChannels, requiredChannels, hasEnough);
81
82 return hasEnough;
83}
84
85void BadChannelCalibrator::finalizeSlot(Slot& slot)
86{
87 // Extract results for the single slot
88 auto pedestalThreshold = BadChannelCalibratorParam::Instance().maxPed;
89 auto noiseThreshold = BadChannelCalibratorParam::Instance().maxNoise;
90
91 mPedestalsVector.clear();
92 mBadChannelsVector.clear();
93
95 LOG(info) << "Finalize slot " << slot.getTFStart() << " <= TF <= " << slot.getTFEnd();
96
97 // keep track of first TimeFrame
98 if (slot.getTFStart() < mTFStart) {
99 mTFStart = slot.getTFStart();
100 }
101
102 for (const auto& ped : *pedestalData) {
103 if (ped.mEntries == 0) {
104 continue;
105 }
106 mPedestalsVector.emplace_back(ped);
107 bool bad = true;
108 if (ped.mPedestal < pedestalThreshold) {
109 if (ped.getRms() < noiseThreshold) {
110 bad = false;
111 }
112 }
113 if (bad) {
114 LOG(info) << ped;
115 mBadChannelsVector.emplace_back(ped.dsChannelId);
116 }
117 }
118}
119
121 BadChannelCalibrator::emplaceNewSlot(bool front, TFType tstart, TFType tend)
122{
123 auto& cont = getSlots();
124 auto& slot = front ? cont.emplace_front(tstart, tend) : cont.emplace_back(tstart, tend);
125 slot.setContainer(std::make_unique<PedestalData>());
126 return slot;
127}
128
129} // namespace o2::mch::calibration
MCH calibrator to produce a bad channel map, using pedestal data.
Utils and constants for calibration and related workflows.
uint32_t c
Definition RawData.h:2
TFType getTFEnd() const
Definition TimeSlot.h:47
const Container * getContainer() const
Definition TimeSlot.h:53
TFType getTFStart() const
Definition TimeSlot.h:46
bool hasEnoughData(const Slot &slot) const final
Compute and store the mean and RMS of the pedestal digit amplitudes.
Pedestal mean and sigma for one channel.
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"