Belle II Software development
SVDShaperDigit.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <vxd/dataobjects/VxdID.h>
12#include <framework/dataobjects/DigitBase.h>
13#include <cstdint>
14#include <sstream>
15#include <string>
16#include <algorithm>
17#include <limits>
18
19namespace Belle2 {
32 class SVDShaperDigit : public DigitBase {
33
34 public:
35
37 static const std::size_t c_nAPVSamples = 6;
38
43 typedef uint8_t APVRawSampleType;
44 typedef std::array<APVRawSampleType, c_nAPVSamples> APVRawSamples;
48 typedef float APVFloatSampleType;
49 typedef std::array<APVFloatSampleType, c_nAPVSamples> APVFloatSamples;
59 template<typename T>
60 SVDShaperDigit(VxdID sensorID, bool isU, short cellID,
61 T samples[c_nAPVSamples], int8_t FADCTime = 0
62 ):
63 m_sensorID(sensorID), m_isU(isU), m_cellID(cellID), m_FADCTime(FADCTime)
64 {
65 std::transform(samples, samples + c_nAPVSamples, m_samples.begin(),
66 [](T x)->APVRawSampleType { return trimToSampleRange(x); }
67 );
68 }
69
78 template<typename T>
79 SVDShaperDigit(VxdID sensorID, bool isU, short cellID, T samples,
80 int8_t FADCTime = 0):
81 m_sensorID(sensorID), m_isU(isU), m_cellID(cellID), m_FADCTime(FADCTime)
82 {
83 std::transform(samples.begin(), samples.end(), m_samples.begin(),
84 [](typename T::value_type x)->APVRawSampleType
85 { return trimToSampleRange(x); }
86 );
87 }
88
91 0, true, 0, APVRawSamples({{0, 0, 0, 0, 0, 0}})
92 )
93 { }
94
98 VxdID getSensorID() const { return m_sensorID; }
99
105
109 bool isUStrip() const { return m_isU; }
110
114 short int getCellID() const { return m_cellID; }
115
120 {
121 APVFloatSamples returnSamples;
122 std::transform(m_samples.begin(), m_samples.end(), returnSamples.begin(),
123 [](APVRawSampleType x) { return static_cast<APVFloatSampleType>(x); });
124 return returnSamples;
125 }
126
127
132 int getMaxTimeBin() const
133 {
134 APVFloatSamples samples = this->getSamples();
135 const auto maxBinIterator = std::max_element(begin(samples), end(samples));
136 const int maxBin = std::distance(begin(samples), maxBinIterator);
137 return maxBin;
138 }
139
144 int getMaxADCCounts() const
145 {
146 APVFloatSamples samples = this->getSamples();
147 const float amplitude = *std::max_element(begin(samples), end(samples));
148 return amplitude;
149 }
150
155 float getFADCTime() const { return static_cast<float>(m_FADCTime); }
156
157
164 {
165 T trimmedX = std::min(
166 static_cast<T>(std::numeric_limits<SVDShaperDigit::APVRawSampleType>::max()),
167 std::max(
168 static_cast<T>(std::numeric_limits<SVDShaperDigit::APVRawSampleType>::lowest()),
169 x));
170 return static_cast<SVDShaperDigit::APVRawSampleType>(trimmedX);
171 }
172
174 std::string toString() const
175 {
176 VxdID thisSensorID(m_sensorID);
177
178 std::ostringstream os;
179 os << "VXDID : " << m_sensorID << " = " << std::string(thisSensorID) << " strip: "
180 << ((m_isU) ? "U-" : "V-") << m_cellID << " samples: ";
181 std::copy(m_samples.begin(), m_samples.end(),
182 std::ostream_iterator<unsigned int>(os, " "));
183 os << "FADC time: " << (unsigned int)m_FADCTime << std::endl;
184 return os.str();
185 }
186
194 unsigned int getUniqueChannelID() const override
195 { return m_cellID + ((m_isU ? 1 : 0) << 11) + (m_sensorID << 12); }
196
205 {
206 // Don't modify and don't append when bg points nowhere.
207 if (!bg) return DigitBase::c_DontAppend;
208
209 const auto& bgSamples = dynamic_cast<const SVDShaperDigit*>(bg)->getSamples();
210
211 // Add background samples to the digit's and trim back to range
212 if (s_APVSampleMode == 3) {
213 std::transform(m_samples.begin(), m_samples.end() - 3, bgSamples.begin() + s_APVSampleBegin,
214 m_samples.begin(),
215 [](APVRawSampleType x, APVFloatSampleType y)->APVRawSampleType
216 { return trimToSampleRange(x + y); }
217 );
218 } else {
219 std::transform(m_samples.begin(), m_samples.end(), bgSamples.begin(),
220 m_samples.begin(),
221 [](APVRawSampleType x, APVFloatSampleType y)->APVRawSampleType
222 { return trimToSampleRange(x + y); }
223 );
224 }
225
226 // FIXME: Reset FADC time flag in mode byte.
228 }
229
233 void adjustAppendedBGDigit() override
234 {
235 if (s_APVSampleMode != 3) return;
236 if (s_APVSampleBegin > 0) {
237 for (size_t i = 0; i < 3; i++) m_samples[i] = m_samples[i + s_APVSampleBegin];
238 }
239 for (size_t i = 3; i < 6; i++) m_samples[i] = 0;
240 }
241
246 bool operator < (const SVDShaperDigit& x)const
247 {
248 if (getSensorID() != x.getSensorID())
249 return getSensorID() < x. getSensorID();
250 if (isUStrip() != x.isUStrip())
251 return isUStrip();
252 else
253 return getCellID() < x.getCellID();
254 }
255
262 bool passesZS(int nSamples, float cutMinSignal) const
263 {
264 int nOKSamples = 0;
266 for (size_t k = 0; k < c_nAPVSamples; k++)
267 if (samples_vec[k] >= cutMinSignal)
268 nOKSamples++;
269
270 if (nOKSamples >= nSamples)
271 return true;
272
273 return false;
274 }
275
281 static void setAPVMode(size_t mode, size_t firstSample)
282 {
283 s_APVSampleMode = mode;
284 s_APVSampleBegin = firstSample;
285 }
286
287
288 private:
289
291 bool m_isU = false;
292 short m_cellID = 0;
294 int8_t m_FADCTime = 0;
296 static size_t s_APVSampleMode;
297 static size_t s_APVSampleBegin;
299 ClassDefOverride(SVDShaperDigit, 5)
300
301 }; // class SVDShaperDigit
302
304} // end namespace Belle2
A common base for subdetector Digits.
Definition: DigitBase.h:26
EAppendStatus
Enum for return state of addBGDigit function.
Definition: DigitBase.h:32
@ c_DontAppend
do not append BG digit to digits
Definition: DigitBase.h:33
The SVD ShaperDigit class.
SVDShaperDigit(VxdID sensorID, bool isU, short cellID, T samples[c_nAPVSamples], int8_t FADCTime=0)
Constructor using c-array of samples.
DigitBase::EAppendStatus addBGDigit(const DigitBase *bg) override
Implementation of base class function.
static void setAPVMode(size_t mode, size_t firstSample)
set APV mode for the event
bool m_isU
True if U, false if V.
std::string toString() const
Display main parameters in this object.
static const std::size_t c_nAPVSamples
Number of APV samples stored.
VxdID::baseType m_sensorID
Compressed sensor identifier.
static SVDShaperDigit::APVRawSampleType trimToSampleRange(T x)
Convert a value to sample range.
VxdID::baseType getRawSensorID() const
Get raw sensor ID.
bool operator<(const SVDShaperDigit &x) const
unsigned int getUniqueChannelID() const override
Implementation of base class function.
std::array< APVRawSampleType, c_nAPVSamples > APVRawSamples
array of APVRawSamplesType objects
uint8_t APVRawSampleType
Types for array of samples received from DAQ.
std::array< APVFloatSampleType, c_nAPVSamples > APVFloatSamples
array of APVFloatSampleType objects
float APVFloatSampleType
Types for array of samples for processing.
bool passesZS(int nSamples, float cutMinSignal) const
does the strip pass the ZS cut?
short m_cellID
Strip coordinate in pitch units.
VxdID getSensorID() const
Get the sensor ID.
APVFloatSamples getSamples() const
Get array of samples.
SVDShaperDigit()
Default constructor for the ROOT IO.
int8_t m_FADCTime
digit time estimate from the FADC, in ns
short int getCellID() const
Get strip ID.
bool isUStrip() const
Get strip direction.
float getFADCTime() const
Get digit FADCTime estimate.
int getMaxTimeBin() const
Get the max bin.
SVDShaperDigit(VxdID sensorID, bool isU, short cellID, T samples, int8_t FADCTime=0)
Constructor using a stl container of samples.
int getMaxADCCounts() const
Get the ADC counts corresponding to the higher sample amplitude.
APVRawSamples m_samples
6 APV signals from the strip.
void adjustAppendedBGDigit() override
Modify already appended BG digit if aquisition mode is 3 sample.
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
unsigned short baseType
The base integer type for VxdID.
Definition: VxdID.h:36
static size_t s_APVSampleBegin
first sample number for 3 sample acquisition mode (0 - 3)
static size_t s_APVSampleMode
APV acquisition mode (3 or 6)
Abstract base class for different kinds of events.