Project
Loading...
Searching...
No Matches
NoiseMap.h
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#ifndef ALICEO2_ITSMFT_NOISEMAP_H
15#define ALICEO2_ITSMFT_NOISEMAP_H
16
17#include "Rtypes.h" // for Double_t, ULong_t, etc
18#include <iostream>
19#include <climits>
20#include <cassert>
21#include <vector>
22#include <map>
23#include "Framework/Logger.h"
24#include "gsl/span"
25
26namespace o2
27{
28
29namespace itsmft
30{
31
32class CompClusterExt;
33
37
39{
40
41 public:
43 NoiseMap(std::vector<std::map<int, int>>& noise) { mNoisyPixels.swap(noise); }
44
46 NoiseMap() = default;
48 NoiseMap(int nchips)
49 {
50 mNoisyPixels.assign(nchips, std::map<int, int>());
51 }
53 ~NoiseMap() = default;
54
56 float getNoiseLevel(int chip, int row, int col) const
57 {
58 assert(chip < (int)mNoisyPixels.size());
59 const auto keyIt = mNoisyPixels[chip].find(getKey(row, col));
60 if (keyIt != mNoisyPixels[chip].end()) {
61 return keyIt->second;
62 }
63 return 0;
64 }
65
66 void increaseNoiseCount(int chip, int row, int col)
67 {
68 assert(chip < (int)mNoisyPixels.size());
69 mNoisyPixels[chip][getKey(row, col)]++;
70 }
71
72 void increaseNoiseCount(int chip, const std::vector<int>& rowcolKey)
73 {
74 assert(chip < (int)mNoisyPixels.size());
75 auto& ch = mNoisyPixels[chip];
76 for (const auto k : rowcolKey) {
77 ch[k]++;
78 }
79 }
80
81 int dumpAboveThreshold(int t = 3) const
82 {
83 int n = 0;
84 auto chipID = mNoisyPixels.size();
85 while (chipID--) {
86 const auto& map = mNoisyPixels[chipID];
87 for (const auto& pair : map) {
88 if (pair.second <= t) {
89 continue;
90 }
91 n++;
92 auto key = pair.first;
93 auto row = key2Row(key);
94 auto col = key2Col(key);
95 std::cout << "chip, row, col, noise: " << chipID << ' ' << row << ' ' << col << ' ' << pair.second << '\n';
96 }
97 }
98 return n;
99 }
100 int dumpAboveProbThreshold(float p = 1e-7) const
101 {
102 return dumpAboveThreshold(p * mNumOfStrobes);
103 }
104
105 void applyProbThreshold(float t, long int n, float relErr = 0.2f, int minChipID = 0, int maxChipID = 24119)
106 {
107 // Remove from the maps all pixels with the firing probability below the threshold
108 // Apply the cut only for chips between minChipID and maxChipID (included)
109 if (n < 1) {
110 LOGP(alarm, "Cannot apply threshold with {} ROFs scanned", n);
111 return;
112 }
113 mProbThreshold = t;
114 mNumOfStrobes = n;
115 float minFiredForErr = 0.f;
116 if (relErr > 0) {
117 minFiredForErr = relErr * relErr - 1. / n;
118 if (minFiredForErr <= 0.f) {
119 LOGP(alarm, "Noise threshold {} with relative error {} is not reachable with {} ROFs processed, mask all permanently fired pixels", t, relErr, n);
120 minFiredForErr = n;
121 } else {
122 minFiredForErr = 1. / minFiredForErr;
123 }
124 }
125 int minFired = std::ceil(std::max(t * mNumOfStrobes, minFiredForErr)); // min number of fired pixels exceeding requested threshold
126 auto req = getMinROFs(t, relErr);
127 if (n < req) {
128 mProbThreshold = float(minFired) / n;
129 LOGP(alarm, "Requested relative error {} with prob.threshold {} needs > {} ROFs, {} provided: pixels with noise >{} will be masked", relErr, t, req, n, mProbThreshold);
130 }
131
132 int currChipID = 0;
133 for (auto& map : mNoisyPixels) {
134 if (currChipID < minChipID || currChipID > maxChipID) { // chipID range
135 currChipID++;
136 continue;
137 }
138 for (auto it = map.begin(); it != map.end();) {
139 if (it->second < minFired) {
140 it = map.erase(it);
141 } else {
142 ++it;
143 }
144 }
145 currChipID++;
146 }
147 }
148 float getProbThreshold() const { return mProbThreshold; }
149 long int getNumOfStrobes() const { return mNumOfStrobes; }
150
151 bool isNoisy(int chip, int row, int col) const
152 {
153 assert(chip < (int)mNoisyPixels.size());
154 return (mNoisyPixels[chip].find(getKey(row, col)) != mNoisyPixels[chip].end());
155 }
156
157 bool isNoisyOrFullyMasked(int chip, int row, int col) const
158 {
159 assert(chip < (int)mNoisyPixels.size());
160 return isNoisy(chip, row, col) || isFullChipMasked(chip);
161 }
162
163 bool isNoisy(int chip) const
164 {
165 assert(chip < (int)mNoisyPixels.size());
166 return !mNoisyPixels[chip].empty();
167 }
168
169 // Methods required by the calibration framework
170 void print();
171 void fill(const gsl::span<const CompClusterExt> data);
172
173 const std::map<int, int>* getChipMap(int chip) const { return chip < (int)mNoisyPixels.size() ? &mNoisyPixels[chip] : nullptr; }
174
175 std::map<int, int>& getChip(int chip) { return mNoisyPixels[chip]; }
176 const std::map<int, int>& getChip(int chip) const { return mNoisyPixels[chip]; }
177
178 void maskFullChip(int chip, bool cleanNoisyPixels = false)
179 {
180 if (cleanNoisyPixels) {
181 resetChip(chip);
182 }
183 increaseNoiseCount(chip, -1, -1);
184 }
185
186 bool isFullChipMasked(int chip) const
187 {
188 return isNoisy(chip, -1, -1);
189 }
190
191 void resetChip(int chip)
192 {
193 assert(chip < (int)mNoisyPixels.size());
194 mNoisyPixels[chip].clear();
195 }
196
197 static long getMinROFs(float t, float relErr)
198 {
199 // calculate min number of ROFs needed to reach threshold t with relative error relErr
200 relErr = relErr >= 0.f ? relErr : 0.1;
201 t = t >= 0.f ? t : 1e-6;
202 return std::ceil((1. + 1. / t) / (relErr * relErr));
203 }
204
206 {
207 int incre = 0;
208 for (size_t i = 0; i < mNoisyPixels.size(); ++i) {
209 for (const auto& prev_np : prev->mNoisyPixels[i]) { // only enters this for loop if the "i" chip exists.
210 if (mNoisyPixels[i].find(prev_np.first) == mNoisyPixels[i].end()) {
211 mNoisyPixels[i][prev_np.first] = prev_np.second;
212 incre++;
213 }
214 } // end of for loop on elements of previous noise map
215 } // end of for loop on i (chip ID)
216 return (mNoisyPixels);
217 } // end of void merge
218
219 size_t size() const { return mNoisyPixels.size(); }
220 void setNumOfStrobes(long n) { mNumOfStrobes = n; }
221 void addStrobes(long n) { mNumOfStrobes += n; }
222 long getNumberOfStrobes() const { return mNumOfStrobes; }
223 static int getKey(int row, int col) { return (row << SHIFT) + col; }
224 static int key2Row(int key) { return key >> SHIFT; }
225 static int key2Col(int key) { return key & MASK; }
226
227 private:
228 static constexpr int SHIFT = 10, MASK = (0x1 << SHIFT) - 1;
229 std::vector<std::map<int, int>> mNoisyPixels;
230 long int mNumOfStrobes = 0;
231 float mProbThreshold = 0;
232
233 ClassDefNV(NoiseMap, 2);
234};
235} // namespace itsmft
236} // namespace o2
237
238#endif /* ALICEO2_ITSMFT_NOISEMAP_H */
int32_t i
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
configStandalone Reconstruction rec_tpc float
StringRef key
NoiseMap class for the ITS and MFT.
Definition NoiseMap.h:39
size_t size() const
Definition NoiseMap.h:219
float getProbThreshold() const
Definition NoiseMap.h:148
bool isNoisy(int chip) const
Definition NoiseMap.h:163
long getNumberOfStrobes() const
Definition NoiseMap.h:222
NoiseMap merge(const NoiseMap *prev)
Definition NoiseMap.h:205
static int getKey(int row, int col)
Definition NoiseMap.h:223
void addStrobes(long n)
Definition NoiseMap.h:221
int dumpAboveProbThreshold(float p=1e-7) const
Definition NoiseMap.h:100
bool isFullChipMasked(int chip) const
Definition NoiseMap.h:186
void increaseNoiseCount(int chip, int row, int col)
Definition NoiseMap.h:66
const std::map< int, int > * getChipMap(int chip) const
Definition NoiseMap.h:173
static int key2Col(int key)
Definition NoiseMap.h:225
void maskFullChip(int chip, bool cleanNoisyPixels=false)
Definition NoiseMap.h:178
static int key2Row(int key)
Definition NoiseMap.h:224
NoiseMap()=default
Constructor.
std::map< int, int > & getChip(int chip)
Definition NoiseMap.h:175
NoiseMap(std::vector< std::map< int, int > > &noise)
Constructor, initializing values for position, charge and readout frame.
Definition NoiseMap.h:43
void fill(const gsl::span< const CompClusterExt > data)
Definition NoiseMap.cxx:44
bool isNoisyOrFullyMasked(int chip, int row, int col) const
Definition NoiseMap.h:157
void applyProbThreshold(float t, long int n, float relErr=0.2f, int minChipID=0, int maxChipID=24119)
Definition NoiseMap.h:105
int dumpAboveThreshold(int t=3) const
Definition NoiseMap.h:81
const std::map< int, int > & getChip(int chip) const
Definition NoiseMap.h:176
void resetChip(int chip)
Definition NoiseMap.h:191
void setNumOfStrobes(long n)
Definition NoiseMap.h:220
void increaseNoiseCount(int chip, const std::vector< int > &rowcolKey)
Definition NoiseMap.h:72
long int getNumOfStrobes() const
Definition NoiseMap.h:149
static long getMinROFs(float t, float relErr)
Definition NoiseMap.h:197
NoiseMap(int nchips)
Constructor.
Definition NoiseMap.h:48
float getNoiseLevel(int chip, int row, int col) const
Get the noise level for this pixels.
Definition NoiseMap.h:56
bool isNoisy(int chip, int row, int col) const
Definition NoiseMap.h:151
~NoiseMap()=default
Destructor.
GLdouble n
Definition glcorearb.h:1982
GLuint GLuint end
Definition glcorearb.h:469
const int float col
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::vector< int > row