Project
Loading...
Searching...
No Matches
NoiseCalibrator.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
12#include "Framework/Logger.h"
16#include "CPVBase/Geometry.h"
18#include "CCDB/CcdbApi.h"
20
21namespace o2
22{
23namespace cpv
24{
26// NoiseCalibData
27//_____________________________________________________________________________
28NoiseCalibData::NoiseCalibData(float noiseThreshold)
29{
30 mNoiseThreshold = noiseThreshold;
31 for (int i = 0; i < Geometry::kNCHANNELS; i++) {
32 mOccupancyMap.push_back(0);
33 }
34}
35//_____________________________________________________________________________
36void NoiseCalibData::fill(const gsl::span<const Digit> digits)
37{
38 for (auto& dig : digits) {
39 if (dig.getAmplitude() > mNoiseThreshold) {
40 mOccupancyMap[dig.getAbsId()]++;
41 }
42 }
43 mNEvents++;
44}
45//_____________________________________________________________________________
47{
48 for (int i = 0; i < Geometry::kNCHANNELS; i++) {
49 mOccupancyMap[i] += prev->mOccupancyMap[i];
50 }
51 mNEvents += prev->mNEvents;
52 LOG(info) << "Merged TimeSlot with previous one. Now we have " << mNEvents << " events.";
53}
54//_____________________________________________________________________________
56{
57 LOG(info) << "NoiseCalibData::mNEvents = " << mNEvents;
58}
59//_____________________________________________________________________________
60// NoiseCalibrator
61//_____________________________________________________________________________
63{
64 LOG(info) << "NoiseCalibrator::NoiseCalibrator() : "
65 << "Noise calibrator created!";
66}
67//_____________________________________________________________________________
69{
70 auto& cpvParams = CPVCalibParams::Instance();
71 mMinEvents = cpvParams.noiseMinEvents;
72 mToleratedChannelEfficiencyLow = cpvParams.noiseToleratedChannelEfficiencyLow;
73 mToleratedChannelEfficiencyHigh = cpvParams.noiseToleratedChannelEfficiencyHigh;
74 mNoiseFrequencyCriteria = cpvParams.noiseFrequencyCriteria;
75 mNoiseThreshold = cpvParams.noiseThreshold;
76 LOG(info) << "NoiseCalibrator::configParameters() : following parameters configured:";
77 LOG(info) << "mMinEvents = " << mMinEvents;
78 LOG(info) << "mToleratedChannelEfficiencyLow = " << mToleratedChannelEfficiencyLow;
79 LOG(info) << "mToleratedChannelEfficiencyHigh = " << mToleratedChannelEfficiencyHigh;
80 LOG(info) << "mNoiseFrequencyCriteria = " << mNoiseFrequencyCriteria;
81 LOG(info) << "mNoiseThreshold = " << mNoiseThreshold;
82}
83//_____________________________________________________________________________
85{
86 LOG(info) << "NoiseCalibrator::initOutput() : output vectors cleared";
87 mCcdbInfoBadChannelMapVec.clear();
88 mBadChannelMapVec.clear();
89}
90//_____________________________________________________________________________
92{
93 NoiseCalibData* calibData = slot.getContainer();
94 LOG(info) << "NoiseCalibrator::finalizeSlot() : finalizing slot "
95 << slot.getTFStart() << " <= TF <= " << slot.getTFEnd() << " with " << calibData->mNEvents << " events.";
97 bool badMapBool[Geometry::kNCHANNELS] = {false};
98
99 // persistent bad channels from ccdb
100 if (mPersistentBadChannels) {
101 LOG(info) << "NoiseCalibrator::finalizeSlot() : adding " << mPersistentBadChannels->size() << " permanent bad channels";
102 for (int i = 0; i < mPersistentBadChannels->size(); i++) {
103 badMapBool[(*mPersistentBadChannels)[i]] = true;
104 }
105 }
106
107 // handle data from pedestal run first
108 // check pedestal efficiencies
109 int badEfficiencyChannels = 0;
110 if (mPedEfficiencies) {
111 LOG(info) << "NoiseCalibrator::finalizeSlot() : checking ped efficiencies from pedestal run";
112 for (int i = 0; i < Geometry::kNCHANNELS; i++) {
113 if ((*mPedEfficiencies)[i] > mToleratedChannelEfficiencyHigh ||
114 (*mPedEfficiencies)[i] < mToleratedChannelEfficiencyLow) {
115 badMapBool[i] = true;
116 badEfficiencyChannels++;
117 }
118 }
119 LOG(info) << "NoiseCalibrator::finalizeSlot() : found " << badEfficiencyChannels << " bad ped efficiency channels";
120 }
121
122 // check dead channels
123 if (mDeadChannels) {
124 LOG(info) << "NoiseCalibrator::finalizeSlot() : adding " << mDeadChannels->size() << " dead channels from pedestal run";
125 for (int i = 0; i < mDeadChannels->size(); i++) {
126 badMapBool[(*mDeadChannels)[i]] = true;
127 }
128 }
129
130 // check channels with very high pedestal value (> 511)
131 if (mHighPedChannels) {
132 LOG(info) << "NoiseCalibrator::finalizeSlot() : adding " << mHighPedChannels->size() << " high ped channels from pedestal run";
133 for (int i = 0; i < mHighPedChannels->size(); i++) {
134 badMapBool[(*mHighPedChannels)[i]] = true;
135 }
136 }
137
138 // find noisy channels
139 int noisyChannels = 0;
140 LOG(info) << "NoiseCalibrator::finalizeSlot() : checking noisy channels";
141 for (int i = 0; i < Geometry::kNCHANNELS; i++) {
142 if (float(calibData->mOccupancyMap[i]) / calibData->mNEvents > mNoiseFrequencyCriteria) {
143 badMapBool[i] = true;
144 noisyChannels++;
145 }
146 }
147 LOG(info) << "NoiseCalibrator::finalizeSlot() : found " << noisyChannels << " noisy channels";
148
149 // fill BadChannelMap and send it to output
150 int totalBadChannels = 0;
151 for (unsigned short i = 0; i < Geometry::kNCHANNELS; i++) {
152 if (badMapBool[i]) {
153 badMap->addBadChannel(i);
154 totalBadChannels++;
155 }
156 }
157 LOG(info) << "NoiseCalibrator::finalizeSlot() : created bad channel map with " << totalBadChannels << " bad channels in total";
158
159 mBadChannelMapVec.push_back(*badMap);
160 // metadata for o2::cpv::BadChannelMap
161 std::map<std::string, std::string> metaData;
162 auto className = o2::utils::MemFileHelper::getClassName(*badMap);
163 auto fileName = o2::ccdb::CcdbApi::generateFileName(className);
164 auto timeStamp = o2::ccdb::getCurrentTimestamp();
165 mCcdbInfoBadChannelMapVec.emplace_back("CPV/Calib/BadChannelMap", className, fileName, metaData, timeStamp, timeStamp + 31536000000); // one year validity time (in milliseconds!)
166}
167//_____________________________________________________________________________
169{
170 LOG(info) << "NoiseCalibrator::emplaceNewSlot() : emplacing new Slot from tstart = " << tstart << " to " << tend;
171 auto& cont = getSlots();
172 auto& slot = front ? cont.emplace_front(tstart, tend) : cont.emplace_back(tstart, tend);
173 slot.setContainer(std::make_unique<NoiseCalibData>(mNoiseThreshold));
174 return slot;
175}
176//_____________________________________________________________________________
177} // end namespace cpv
178} // end namespace o2
Utils and constants for calibration and related workflows.
int32_t i
TFType getTFEnd() const
Definition TimeSlot.h:47
const Container * getContainer() const
Definition TimeSlot.h:53
TFType getTFStart() const
Definition TimeSlot.h:46
static std::string generateFileName(const std::string &inp)
Definition CcdbApi.cxx:798
CCDB container for bad (masked) channels in CPV.
void addBadChannel(unsigned short channelID)
Add bad cell to the container.
static constexpr short kNCHANNELS
Definition Geometry.h:30
NoiseTimeSlot & emplaceNewSlot(bool front, TFType tstart, TFType tend) final
void finalizeSlot(NoiseTimeSlot &slot) final
long getCurrentTimestamp()
returns the timestamp in long corresponding to "now"
o2::calibration::TimeSlot< o2::cpv::NoiseCalibData > NoiseTimeSlot
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
void merge(const NoiseCalibData *prev)
void fill(const gsl::span< const o2::cpv::Digit > data)
NoiseCalibData(float noiseThreshold=10.)
std::vector< int > mOccupancyMap
static std::string getClassName(const T &obj)
get the class name of the object
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Digit > digits