Project
Loading...
Searching...
No Matches
CommonModeCorrection.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
15
16#ifndef AliceO2_TPC_CommonModeCorrection_H_
17#define AliceO2_TPC_CommonModeCorrection_H_
18
19#include <gsl/span>
20#include <string_view>
21#include <vector>
22
24#include "TPCBase/FEEConfig.h"
25
26namespace o2::tpc
27{
28
34{
35 public:
36 struct CMdata {
37 std::vector<float> adcValues;
38 std::vector<float> cmKValues;
39 std::vector<float> pedestals;
40
41 void resize(size_t newSize)
42 {
43 adcValues.resize(newSize);
44 cmKValues.resize(newSize);
45 pedestals.resize(newSize);
46 }
47
48 void clear()
49 {
50 adcValues.clear();
51 cmKValues.clear();
52 pedestals.clear();
53 }
54 };
55
56 struct CMInfo {
57 float cmValue{};
58 float cmValueStd{};
59 float cmValueCRU{};
60 float sumPos{};
61 float sumNeg{};
62 uint16_t nPadsUsed{};
63 uint16_t nNeg{};
64 uint16_t nOccupancy{};
65 uint16_t nSaturation{};
66 };
67
68 struct CMDebug {
69 std::vector<uint8_t> nPadsOk{};
70 std::vector<uint16_t> adcDist{};
71 };
72
73 using CalPadMapType = std::unordered_map<std::string, CalPad>;
74
81 CMInfo getCommonMode(gsl::span<const float> values, gsl::span<const float> cmKValues, gsl::span<const float> pedestals, CMDebug* cmDebug = nullptr) const;
82 CMInfo getCommonMode(const std::vector<float>& values, const std::vector<float>& cmKValues, const std::vector<float>& pedestals) const { return getCommonMode(gsl::span(values), gsl::span(cmKValues), gsl::span(pedestals)); }
83
84 CMInfo getCommonMode(const CMdata& cmData) const { return getCommonMode(std::span(cmData.adcValues), std::span(cmData.cmKValues), std::span(cmData.pedestals)); }
85
86 void setNPadsCompRandom(int n) { mNPadsCompRamdom = n; }
87 int getNPadsCompRandom() const { return mNPadsCompRamdom; }
88
89 void setNPadsCompMin(int n) { mNPadsCompMin = n; }
90 int getNPadsCompMin() const { return mNPadsCompMin; }
91
93 void setNPadsMinCM(int n) { mNPadsMinCM = n; }
94 int getNPadsMinCM() const { return mNPadsMinCM; }
95
96 void setQEmpty(float q) { mQEmpty = q; }
97 float getQEmpty() const { return mQEmpty; }
98
99 void setQComp(float q) { mQComp = q; }
100 float getQComp() const { return mQComp; }
101
103 void setQCompScaleThreshold(float q) { mQCompScaleThreshold = q; }
104 float getQCompScaleThreshold() const { return mQCompScaleThreshold; }
105
107 void setQCompScale(float q) { mQCompScale = q; }
108 float getQCompScale() const { return mQCompScale; }
109
111 void setSumPosThreshold(float threshold) { mSumPosThreshold = threshold; }
112 float getSumPosThreshold() const { return mSumPosThreshold; }
113
115 void setOccupancyThreshold(float threshold) { mOccupancyThreshold = threshold; }
116 float getOccupancyThreshold() const { return mOccupancyThreshold; }
117
119 void setPadMaps(CalPadMapType& padMaps) { mPadMaps = padMaps; }
120
125 void loadCalPad(std::string_view fileName, std::string_view nameInFile, std::string_view namePadMap = "");
126
128 void loadCMkValues(std::string_view fileName) { loadCalPad(fileName, "CMkValues"); }
129
131 void loadPedestals(std::string_view fileName) { loadCalPad(fileName, "Pedestals"); }
132
134 void setCalPad(const CalPad& calPad, std::string_view name) { mPadMaps[name.data()] = calPad; }
135
137 float getCMkValue(int sector, int row, int pad) { return mPadMaps["CMkValues"].getValue(sector, row, pad); }
138
140 float getPedestalValue(int sector, int row, int pad) { return mPadMaps["Pedestals"].getValue(sector, row, pad); }
141
143 void
145
146 CMdata collectCMdata(const std::vector<Digit>& digits, int cru, int timeBin);
147
148 int getCommonMode(std::vector<Digit>& digits, std::vector<std::vector<CMInfo>>& cmValues, bool negativeOnly = false, bool hasInjectedCMValue = false, std::vector<std::vector<CMDebug>>* cmDebug = nullptr, int minTimeBin = -1, int maxTimeBin = -1) const;
149
154 int correctDigits(std::vector<Digit>& digits, std::vector<std::vector<CMInfo>>& cmValues, bool negativeOnly = false, bool hasInjectedCMValue = false, std::vector<std::vector<CMDebug>>* cmDebug = nullptr, int minTimeBin = -1, int maxTimeBin = -1) const;
155
156 void correctDigits(std::string_view digiFileIn, Long64_t maxEntries = -1, std::string_view digitFileOut = "tpcdigit_cmcorr.root", std::string_view cmFileOut = "CommonModeValues.root", bool negativeOnly = false, int nThreads = 1, bool writeOnlyCM = false, bool writeDebug = false, bool hasInjectedCMValue = false, int minTimeBin = -1, int maxTimeBin = -1);
157
158 void limitKFactorPrecision(bool limit = true) { mLimitKFactor = limit; }
159 void limitPedestalPrecision(bool limit = true) { mLimitPedestal = limit; }
160
163 static void setNThreads(const int nThreads) { sNThreads = nThreads; }
164
166 static int getNThreads() { return sNThreads; }
167
169 void addCommonMode(float cm) { mArtificialCM = cm; }
170
171 void setCorrectOutputForPedestal(bool corret = true) { mCorrectOutputForPedestal = corret; }
172 bool getCorrectOutputForPedestal() const { return mCorrectOutputForPedestal; }
173
175 void setAddSubthreshold(bool addSubthreshold) { mSubthreshold = addSubthreshold; }
176 bool getAddSubthreshold() const { return mSubthreshold; }
177
178 static float decodeInjectedCMValue(float lower, float upper);
179
180 private:
181 inline static int sNThreads{1};
182 int mNPadsCompRamdom{10};
183 int mNPadsCompMin{7};
184 int mNPadsMinCM{0};
185 float mQEmpty{2};
186 float mQComp{1};
187 float mQCompScaleThreshold{0};
188 float mQCompScale{0};
189 float mSumPosThreshold{2};
190 float mOccupancyThreshold{3};
191 bool mLimitKFactor{false};
192 bool mLimitPedestal{false};
193 int mSubthreshold{0};
194 float mArtificialCM{};
195 bool mCorrectOutputForPedestal{false};
196
197 CalPadMapType mPadMaps;
198
199 struct pos {
200 int row;
201 int pad;
202 };
203
204 // positions of lower words per CRU in sector
205 const std::array<pos, 10> mCMInjectIDLower{
206 // row0 pad0 row1 pad1
207 pos{0, 2},
208 pos{20, 1},
209 pos{32, 2},
210 pos{51, 1},
211 pos{63, 1},
212 pos{84, 1},
213 pos{97, 1},
214 pos{116, 2},
215 pos{127, 2},
216 pos{142, 0},
217 };
218
219 // positions of upper words per CRU in sector
220 const std::array<pos, 10> mCMInjectIDUpper{
221 // row0 pad0 row1 pad1
222 pos{0, 3},
223 pos{20, 3},
224 pos{32, 3},
225 pos{51, 3},
226 pos{63, 2},
227 pos{84, 4},
228 pos{97, 2},
229 pos{115, 5},
230 pos{127, 3},
231 pos{142, 4},
232 };
233
238 float getCalPadValue(const std::string calibName, int icru, int pad) const;
239
240 bool padMapExists(const std::string& calibName);
241
242 ClassDefNV(CommonModeCorrection, 2);
243};
244
245} // namespace o2::tpc
246#endif
Definition of the TPC Digit.
Frontend electronics configuration values.
uint16_t pos
Definition RawData.h:3
float getPedestalValue(int sector, int row, int pad)
pedestal value
void setPadMaps(CalPadMapType &padMaps)
Pad maps loaded from FEEConfig.
CMdata collectCMdata(const std::vector< Digit > &digits, int cru, int timeBin)
void loadPedestals(std::string_view fileName)
load Pedestals from file, assuming it is stored under the name "Pedestals
void setCalPad(const CalPad &calPad, std::string_view name)
Custom setting of CalPad, overwriting what was set in mPadMaps.
CMInfo getCommonMode(gsl::span< const float > values, gsl::span< const float > cmKValues, gsl::span< const float > pedestals, CMDebug *cmDebug=nullptr) const
void addCommonMode(float cm)
add artificial common mode, only works when using the 'correctDigits' function
int correctDigits(std::vector< Digit > &digits, std::vector< std::vector< CMInfo > > &cmValues, bool negativeOnly=false, bool hasInjectedCMValue=false, std::vector< std::vector< CMDebug > > *cmDebug=nullptr, int minTimeBin=-1, int maxTimeBin=-1) const
void loadCalPad(std::string_view fileName, std::string_view nameInFile, std::string_view namePadMap="")
float getCMkValue(int sector, int row, int pad)
cmk value
void setNPadsMinCM(int n)
Minimum number of pads required in the CM calculation to be used for digit correction.
void setOccupancyThreshold(float threshold)
Threshold above which a signal is considered for the occupancy.
void setAddSubthreshold(bool addSubthreshold)
Add zeros for pads without signal.
static void setNThreads(const int nThreads)
CMInfo getCommonMode(const std::vector< float > &values, const std::vector< float > &cmKValues, const std::vector< float > &pedestals) const
static float decodeInjectedCMValue(float lower, float upper)
CMInfo getCommonMode(const CMdata &cmData) const
void loadCMkValues(std::string_view fileName)
load CMkValues from file, assuming it is stored under the name "CMkValues
std::unordered_map< std::string, CalPad > CalPadMapType
void setCorrectOutputForPedestal(bool corret=true)
void setQCompScale(float q)
The mQComp will be set to (cm - mQCompScaleThreshold) * mQCompScale, if cm > mQCompScaleThreshold.
void limitKFactorPrecision(bool limit=true)
void loadDefaultPadMaps(FEEConfig::Tags feeTag=FEEConfig::Tags::Physics30sigma)
load the Pad maps from CCDB
void setSumPosThreshold(float threshold)
Threshold above which a signal is considered for sumPos, if debug information is used.
void limitPedestalPrecision(bool limit=true)
void setQCompScaleThreshold(float q)
The mQComp will be set to (cm - mQCompScaleThreshold) * mQCompScale, if cm > mQCompScaleThreshold.
GLdouble n
Definition glcorearb.h:1982
GLuint const GLchar * name
Definition glcorearb.h:781
GLenum GLsizei GLsizei GLint * values
Definition glcorearb.h:1576
Global TPC definitions and constants.
Definition SimTraits.h:167
float cmValueCRU
common mode value from firmware, if available
uint16_t nSaturation
number of pads in saturation
float cmValueStd
std dev of common mode values from pseudo code
uint16_t nPadsUsed
number of pads used for CM calculation
float sumNeg
sum of negative signals <= mSumPosThreshold, corrected for k-factor
uint16_t nOccupancy
number of CM corrected pads larger than mOccupancyThreshold
float sumPos
sum of positive signals > mSumPosThreshold
float cmValue
common mode value from pseudo code
uint16_t nNeg
number of pads used for sumNeg
Tags
Tag definitions for TPC/Config/FEE.
Definition FEEConfig.h:50
@ Physics30sigma
Physics configuration with 3.0 sigma thresholds.
std::vector< Digit > digits
std::vector< int > row