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 float signal = ADCcounts;
162 pedestal = getPedestal(sector, globalPadInSector);
163 float pedestalCRU = getPedestalCRU(sector, globalPadInSector);
164 noise = getNoise(sector, globalPadInSector);
165 switch (MODE) {
167 signal -= commonMode;
168 signal += noise;
169 signal += pedestal;
170 return getADCSaturation(signal);
171 break;
172 }
174 signal -= commonMode;
175 signal += noise;
176 signal += pedestal;
177 signal += (tot > 0) ? 80 : 0; // TODO: improve to also add tail
178 const float signalSubtractPedestal = getADCSaturation(signal) - pedestalCRU;
179 const float zeroSuppression = getZeroSuppression(sector, globalPadInSector);
180 if (signalSubtractPedestal < zeroSuppression) {
181 return 0.f;
182 }
183 return signalSubtractPedestal;
184 break;
185 }
187 signal += noise;
188 signal += pedestal;
189 signal += (tot > 0) ? 80 : 0; // TODO: improve to also add tail
190 const float signalSubtractPedestal = getADCSaturation(signal) - pedestalCRU;
191 const float zeroSuppression = getZeroSuppression(sector, globalPadInSector);
192 if (signalSubtractPedestal < zeroSuppression) {
193 return 0.f;
194 }
195 return signalSubtractPedestal;
196 break;
197 }
199 signal -= commonMode;
200 signal += noise;
201 signal += pedestal;
202 const float signalSubtractPedestal = getADCSaturation(signal) - pedestalCRU;
203 return signalSubtractPedestal;
204 break;
205 }
207 signal -= commonMode;
208 signal += noise;
209 signal += pedestal;
210 return signal;
211 break;
212 }
214 return signal;
215 break;
216 }
217 }
218 return signal;
219}
220
221inline float SAMPAProcessing::getADCSaturation(const float signal) const
222{
223 const float adcSaturation = mEleParam->ADCsaturation;
224 if (signal > adcSaturation - 1) {
225 return adcSaturation - 1;
226 }
227 return signal;
228}
229
230template <typename T>
231inline T SAMPAProcessing::getGamma4(T time, T startTime, T ADC) const
232{
233 const auto tmp0 = (time - startTime) / mEleParam->PeakingTime;
234 const auto cond = (tmp0 > 0);
235 T tmp{};
236 if constexpr (std::is_floating_point_v<T>) {
237 if (!cond) {
238 return T{};
239 }
240 tmp = tmp0;
241 } else {
242 tmp(cond) = tmp0;
243 }
244 const auto tmp2 = tmp * tmp;
245 return 55.f * ADC * std::exp(-4.f * tmp) * tmp2 * tmp2;
246}
247
248inline TimeBin SAMPAProcessing::getTimeBin(float zPos) const
249{
250 return static_cast<TimeBin>((mDetParam->TPClength - std::abs(zPos)) / (mVDrift * mEleParam->ZbinWidth));
251}
252
253inline float SAMPAProcessing::getZfromTimeBin(float timeBin, Side s) const
254{
255 const float zSign = (s == 0) ? 1 : -1;
256 return zSign * (mDetParam->TPClength - (timeBin * mVDrift * mEleParam->ZbinWidth));
257}
258
260{
261 if (time < 0.f) {
262 // protection and convention for negative times (otherwise overflow)
263 return 0;
264 }
265 return static_cast<TimeBin>(time / mEleParam->ZbinWidth);
266}
267
268inline float SAMPAProcessing::getTimeFromBin(TimeBin timeBin) const
269{
270 return static_cast<float>(timeBin) * mEleParam->ZbinWidth;
271}
272
273inline float SAMPAProcessing::getTimeBinTime(float time) const
274{
276}
277
278inline float SAMPAProcessing::getNoise(const int sector, const int globalPadInSector)
279{
280 return mRandomNoiseRing.getNextValue() * mNoiseMap->getValue(sector, globalPadInSector);
281}
282
283inline float SAMPAProcessing::getZeroSuppression(const int sector, const int globalPadInSector) const
284{
285 return mZeroSuppression->getValue(sector, globalPadInSector);
286}
287
288inline float SAMPAProcessing::getPedestal(const int sector, const int globalPadInSector) const
289{
290 return mPedestalMap->getValue(sector, globalPadInSector);
291}
292
293inline float SAMPAProcessing::getPedestalCRU(const int sector, const int globalPadInSector) const
294{
295 return mPedestalMapCRU->getValue(sector, globalPadInSector);
296}
297} // namespace tpc
298} // namespace o2
299
300#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:154
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:132
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.