Project
Loading...
Searching...
No Matches
SAMPAProcessing.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_SAMPAProcessing_H_
17#define ALICEO2_TPC_SAMPAProcessing_H_
18
19#include <Vc/Vc>
20
21#include "TPCBase/PadPos.h"
22#include "TPCBase/CalDet.h"
23#include "TPCBase/CRU.h"
28
29#include "TSpline.h"
30
31namespace o2
32{
33namespace tpc
34{
35
39
41{
42 public:
44 {
45 static SAMPAProcessing sampaProcessing;
46 return sampaProcessing;
47 }
49 ~SAMPAProcessing() = default;
50
52 void updateParameters(float vdrift = 0);
53
57 template <typename T>
58 T getADCvalue(T nElectrons) const;
59
63 float getADCSaturation(const float signal) const;
64
71 template <DigitzationMode MODE>
72 float makeSignal(float ADCcounts, const int sector, const int globalPadInSector, const float commonMode, float& pedestal, float& noise, float tot = 0);
73
80 void getShapedSignal(float ADCsignal, float driftTime, std::vector<float>& signalArray) const;
81
86 template <typename T>
87 T getGamma4(T time, T startTime, T ADC) const;
88
92 TimeBin getTimeBin(float zPos) const;
93
98 float getZfromTimeBin(float timeBin, Side s) const;
99
103 TimeBin getTimeBinFromTime(float time) const;
104
108 float getTimeFromBin(TimeBin timeBin) const;
109
113 float getTimeBinTime(float time) const;
114
119 float getNoise(const int sector, const int globalPadInSector);
120
122 float getZeroSuppression(const int sector, const int globalPadInSector) const;
123
128 float getPedestal(const int sector, const int globalPadInSector) const;
129
134 float getPedestalCRU(const int sector, const int globalPadInSector) const;
135
136 private:
138 const ParameterGas* mGasParam;
139 const ParameterDetector* mDetParam;
140 const ParameterElectronics* mEleParam;
141 const CalPad* mNoiseMap;
142 const CalPad* mPedestalMap;
143 const CalPad* mPedestalMapCRU;
144 const CalPad* mZeroSuppression;
145 math_utils::RandomRing<> mRandomNoiseRing;
146 float mVDrift = 0;
147};
148
149template <typename T>
150inline T SAMPAProcessing::getADCvalue(T nElectrons) const
151{
152 T conversion = mEleParam->ElectronCharge * 1.e15 * mEleParam->ChipGain * mEleParam->ADCsaturation /
153 mEleParam->ADCdynamicRange; // 1E-15 is to convert Coulomb in fC
154 return nElectrons * conversion;
155}
156
157template <DigitzationMode MODE>
158inline float SAMPAProcessing::makeSignal(float ADCcounts, const int sector, const int globalPadInSector, const float commonMode,
159 float& pedestal, float& noise, float tot)
160{
161 pedestal = getPedestal(sector, globalPadInSector);
162 noise = getNoise(sector, globalPadInSector);
163
164 const float signal = ADCcounts;
165 const float pedestalCRU = getPedestalCRU(sector, globalPadInSector);
166 const float fullSignal = signal - commonMode + noise + pedestal + (tot > 0 ? 80 : 0); // TODO: improve to also add tail
167
168 switch (MODE) {
170 return getADCSaturation(fullSignal);
171 break;
172 }
174 const float signalSubtractPedestal = getADCSaturation(signal) - pedestalCRU;
175 const float zeroSuppression = getZeroSuppression(sector, globalPadInSector);
176 if (signalSubtractPedestal < zeroSuppression) {
177 return 0.f;
178 }
179 return signalSubtractPedestal;
180 break;
181 }
183 // TODO: this is not really a common mode correction, since the common mode is simply not treated.
184 // Instead, the full common mode algorithm should be implemented and used
185 const float signalNoCM = signal + noise + pedestal + (tot > 0 ? 80 : 0); // TODO: improve to also add tail
186 const float signalSubtractPedestal = getADCSaturation(signalNoCM) - pedestalCRU;
187 const float zeroSuppression = getZeroSuppression(sector, globalPadInSector);
188 if (signalSubtractPedestal < zeroSuppression) {
189 return 0.f;
190 }
191 return signalSubtractPedestal;
192 break;
193 }
195 const float signalSubtractPedestal = getADCSaturation(fullSignal) - pedestalCRU;
196 return signalSubtractPedestal;
197 break;
198 }
200 return fullSignal;
201 break;
202 }
204 return signal;
205 break;
206 }
207 }
208 return signal;
209}
210
211inline float SAMPAProcessing::getADCSaturation(const float signal) const
212{
213 const float adcSaturation = mEleParam->ADCsaturation;
214 if (signal > adcSaturation - 1) {
215 return adcSaturation - 1;
216 }
217 return signal;
218}
219
220template <typename T>
221inline T SAMPAProcessing::getGamma4(T time, T startTime, T ADC) const
222{
223 const auto tmp0 = (time - startTime) / mEleParam->PeakingTime;
224 const auto cond = (tmp0 > 0);
225 T tmp{};
226 if constexpr (std::is_floating_point_v<T>) {
227 if (!cond) {
228 return T{};
229 }
230 tmp = tmp0;
231 } else {
232 tmp(cond) = tmp0;
233 }
234 const auto tmp2 = tmp * tmp;
235 return 55.f * ADC * std::exp(-4.f * tmp) * tmp2 * tmp2;
236}
237
238inline TimeBin SAMPAProcessing::getTimeBin(float zPos) const
239{
240 return static_cast<TimeBin>((mDetParam->TPClength - std::abs(zPos)) / (mVDrift * mEleParam->ZbinWidth));
241}
242
243inline float SAMPAProcessing::getZfromTimeBin(float timeBin, Side s) const
244{
245 const float zSign = (s == 0) ? 1 : -1;
246 return zSign * (mDetParam->TPClength - (timeBin * mVDrift * mEleParam->ZbinWidth));
247}
248
250{
251 if (time < 0.f) {
252 // protection and convention for negative times (otherwise overflow)
253 return 0;
254 }
255 return static_cast<TimeBin>(time / mEleParam->ZbinWidth);
256}
257
258inline float SAMPAProcessing::getTimeFromBin(TimeBin timeBin) const
259{
260 return static_cast<float>(timeBin) * mEleParam->ZbinWidth;
261}
262
263inline float SAMPAProcessing::getTimeBinTime(float time) const
264{
266}
267
268inline float SAMPAProcessing::getNoise(const int sector, const int globalPadInSector)
269{
270 return mRandomNoiseRing.getNextValue() * mNoiseMap->getValue(sector, globalPadInSector);
271}
272
273inline float SAMPAProcessing::getZeroSuppression(const int sector, const int globalPadInSector) const
274{
275 return mZeroSuppression->getValue(sector, globalPadInSector);
276}
277
278inline float SAMPAProcessing::getPedestal(const int sector, const int globalPadInSector) const
279{
280 return mPedestalMap->getValue(sector, globalPadInSector);
281}
282
283inline float SAMPAProcessing::getPedestalCRU(const int sector, const int globalPadInSector) const
284{
285 return mPedestalMapCRU->getValue(sector, globalPadInSector);
286}
287} // namespace tpc
288} // namespace o2
289
290#endif // ALICEO2_TPC_SAMPAProcessing_H_
int16_t time
Definition RawEventData.h:4
Definition of the parameter class for the detector.
Definition of the parameter class for the detector electronics.
Definition of the parameter class for the detector gas.
const T getValue(const int sec, const int globalPadInSector) const
Definition CalDet.h:160
float getZeroSuppression(const int sector, const int globalPadInSector) const
Get the zero suppression threshold for a given channel.
float getNoise(const int sector, const int globalPadInSector)
void getShapedSignal(float ADCsignal, float driftTime, std::vector< float > &signalArray) const
T getADCvalue(T nElectrons) const
static SAMPAProcessing & instance()
float getTimeBinTime(float time) const
float getTimeFromBin(TimeBin timeBin) const
float makeSignal(float ADCcounts, const int sector, const int globalPadInSector, const float commonMode, float &pedestal, float &noise, float tot=0)
float getZfromTimeBin(float timeBin, Side s) const
void updateParameters(float vdrift=0)
Update the OCDB parameters cached in the class. To be called once per event.
float getPedestalCRU(const int sector, const int globalPadInSector) const
TimeBin getTimeBin(float zPos) const
~SAMPAProcessing()=default
Destructor.
float getADCSaturation(const float signal) const
T getGamma4(T time, T startTime, T ADC) const
TimeBin getTimeBinFromTime(float time) const
float getPedestal(const int sector, const int globalPadInSector) const
@ ZeroSuppressionCMCorr
Apply noise, pedestal and saturation and then from that subtract the pedestal and apply zero suppress...
@ ZeroSuppression
Apply noise, pedestal, common mode and saturation and then from that subtract the pedestal and apply ...
@ PropagateADC
Just propagate the bare ADC value.
@ FullMode
Apply noise, pedestal and saturation.
@ SubtractPedestal
Apply noise, pedestal and saturation and then from that subtract the pedestal.
@ NoSaturation
Apply only noise and pedestal.
Side
TPC readout sidE.
Definition Defs.h:35
unsigned int TimeBin
global time bin
Definition Defs.h:115
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
float TPClength
Length of the TPC [cm].
float ADCdynamicRange
Dynamic range of the ADC [mV].
float ADCsaturation
ADC saturation [ADC counts].
float ZbinWidth
Width of a z bin [us].
float PeakingTime
Peaking time of the SAMPA [us].
float ElectronCharge
Electron charge [C].
float ChipGain
Gain of the SAMPA [mV/fC] - may be either 20 or 30.