Belle II Software  release-05-02-19
SVDShaperDigit.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Peter Kvasnicka, Giulia Casarosa *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #ifndef SVD_SHAPERDIGIT_H
12 #define SVD_SHAPERDIGIT_H
13 
14 #include <vxd/dataobjects/VxdID.h>
15 #include <svd/dataobjects/SVDModeByte.h>
16 #include <framework/dataobjects/DigitBase.h>
17 #include <cstdint>
18 #include <sstream>
19 #include <string>
20 #include <algorithm>
21 #include <limits>
22 
23 namespace Belle2 {
38  class SVDShaperDigit : public DigitBase {
39 
40  public:
41 
43  static const std::size_t c_nAPVSamples = 6;
44 
49  typedef uint8_t APVRawSampleType;
50  typedef std::array<APVRawSampleType, c_nAPVSamples> APVRawSamples;
54  typedef float APVFloatSampleType;
55  typedef std::array<APVFloatSampleType, c_nAPVSamples> APVFloatSamples;
66  template<typename T>
67  SVDShaperDigit(VxdID sensorID, bool isU, short cellID,
68  T samples[c_nAPVSamples], int8_t FADCTime = 0,
69  SVDModeByte mode = SVDModeByte()):
70  m_sensorID(sensorID), m_isU(isU), m_cellID(cellID), m_FADCTime(FADCTime),
71  m_mode(mode.getID())
72  {
73  std::transform(samples, samples + c_nAPVSamples, m_samples.begin(),
74  [](T x)->APVRawSampleType { return trimToSampleRange(x); }
75  );
76  }
77 
87  template<typename T>
88  SVDShaperDigit(VxdID sensorID, bool isU, short cellID, T samples,
89  int8_t FADCTime = 0, SVDModeByte mode = SVDModeByte()):
90  m_sensorID(sensorID), m_isU(isU), m_cellID(cellID), m_FADCTime(FADCTime),
91  m_mode(mode.getID())
92  {
93  std::transform(samples.begin(), samples.end(), m_samples.begin(),
94  [](typename T::value_type x)->APVRawSampleType
95  { return trimToSampleRange(x); }
96  );
97  }
98 
101  0, true, 0, APVRawSamples( {{0, 0, 0, 0, 0, 0}})
102  )
103  { }
104 
108  VxdID getSensorID() const { return m_sensorID; }
109 
114  VxdID::baseType getRawSensorID() const { return m_sensorID; }
115 
119  bool isUStrip() const { return m_isU; }
120 
124  short int getCellID() const { return m_cellID; }
125 
130  {
131  APVFloatSamples returnSamples;
132  std::transform(m_samples.begin(), m_samples.end(), returnSamples.begin(),
133  [](APVRawSampleType x) { return static_cast<APVFloatSampleType>(x); });
134  return returnSamples;
135  }
136 
137 
142  int getMaxTimeBin() const
143  {
144  APVFloatSamples samples = this->getSamples();
145  const auto maxBinIterator = std::max_element(begin(samples), end(samples));
146  const int maxBin = std::distance(begin(samples), maxBinIterator);
147  return maxBin;
148  }
149 
154  int getMaxADCCounts() const
155  {
156  APVFloatSamples samples = this->getSamples();
157  const float amplitude = *std::max_element(begin(samples), end(samples));
158  return amplitude;
159  }
160 
161 
166  float getFADCTime() const { return static_cast<float>(m_FADCTime); }
167 
172  SVDModeByte getModeByte() const
173  { return m_mode; }
174 
180  template<typename T> static SVDShaperDigit::APVRawSampleType trimToSampleRange(T x)
181  {
182  T trimmedX = std::min(
183  static_cast<T>(std::numeric_limits<SVDShaperDigit::APVRawSampleType>::max()),
184  std::max(
185  static_cast<T>(std::numeric_limits<SVDShaperDigit::APVRawSampleType>::lowest()),
186  x));
187  return static_cast<SVDShaperDigit::APVRawSampleType>(trimmedX);
188  }
189 
191  std::string toString() const
192  {
193  VxdID thisSensorID(m_sensorID);
194  SVDModeByte thisMode(m_mode);
195 
196  std::ostringstream os;
197  os << "VXDID : " << m_sensorID << " = " << std::string(thisSensorID) << " strip: "
198  << ((m_isU) ? "U-" : "V-") << m_cellID << " samples: ";
199  std::copy(m_samples.begin(), m_samples.end(),
200  std::ostream_iterator<unsigned int>(os, " "));
201  os << "FADC time: " << (unsigned int)m_FADCTime << " Triggerbin:" << (unsigned int) thisMode.getTriggerBin() << std::endl;
202  os << "RunType: " << (unsigned int)thisMode.getRunType() << ", EventType: " << (unsigned int) thisMode.getEventType() <<
203  ", DAQMode: " << (unsigned int) thisMode.getDAQMode() << std::endl;
204  os << " SVDModeByte: " << (unsigned int)thisMode << std::endl;
205  return os.str();
206  }
207 
215  unsigned int getUniqueChannelID() const override
216  { return m_cellID + ((m_isU ? 1 : 0) << 11) + (m_sensorID << 12); }
217 
225  DigitBase::EAppendStatus addBGDigit(const DigitBase* bg) override
226  {
227  // Don't modify and don't append when bg points nowhere.
228  if (!bg) return DigitBase::c_DontAppend;
229  const auto& bgSamples = dynamic_cast<const SVDShaperDigit*>(bg)->getSamples();
230  // Add background samples to the digit's and trim back to range
231  std::transform(m_samples.begin(), m_samples.end(), bgSamples.begin(),
232  m_samples.begin(),
233  [](APVRawSampleType x, APVFloatSampleType y)->APVRawSampleType
234  { return trimToSampleRange(x + y); }
235  );
236  // FIXME: Reset FADC time flag in mode byte.
238  }
239 
245  bool operator < (const SVDShaperDigit& x)const
246  {
247  if (getSensorID() != x.getSensorID())
248  return getSensorID() < x. getSensorID();
249  if (isUStrip() != x.isUStrip())
250  return isUStrip();
251  else
252  return getCellID() < x.getCellID();
253  }
254 
261  bool passesZS(int nSamples, float cutMinSignal) const
262  {
263  int nOKSamples = 0;
265  for (int k = 0; k < c_nAPVSamples; k++)
266  if (samples_vec[k] >= cutMinSignal)
267  nOKSamples++;
268 
269  if (nOKSamples >= nSamples)
270  return true;
271 
272  return false;
273  }
274 
275 
276  private:
277 
279  bool m_isU = false;
280  short m_cellID = 0;
282  int8_t m_FADCTime = 0;
287  ClassDefOverride(SVDShaperDigit, 4)
288 
289  }; // class SVDShaperDigit
290 
292 } // end namespace Belle2
293 
294 #endif // SVD_SHAPERDIGIT_H
Belle2::DigitBase::EAppendStatus
EAppendStatus
Enum for return state of addBGDigit function.
Definition: DigitBase.h:42
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
Belle2::SVDModeByte::c_DefaultID
static const baseType c_DefaultID
Default / non-informative id 10010111 = 151 Run type: zero-suppressed, 2 Event type: global run,...
Definition: SVDModeByte.h:116
Belle2::SVDShaperDigit::operator<
bool operator<(const SVDShaperDigit &x) const
Definition: SVDShaperDigit.h:253
Belle2::SVDModeByte::getTriggerBin
baseType getTriggerBin() const
Get the triggerBin id.
Definition: SVDModeByte.h:150
Belle2::SVDShaperDigit::getSamples
APVFloatSamples getSamples() const
Get array of samples.
Definition: SVDShaperDigit.h:137
Belle2::SVDShaperDigit::m_cellID
short m_cellID
Strip coordinate in pitch units.
Definition: SVDShaperDigit.h:288
Belle2::SVDShaperDigit::getSensorID
VxdID getSensorID() const
Get the sensor ID.
Definition: SVDShaperDigit.h:116
Belle2::getID
int getID(const std::vector< double > &breaks, double t)
get id of the time point t
Definition: calibTools.h:71
Belle2::SVDShaperDigit::m_sensorID
VxdID::baseType m_sensorID
Compressed sensor identifier.
Definition: SVDShaperDigit.h:286
Belle2::SVDModeByte
Class to store SVD mode information.
Definition: SVDModeByte.h:79
Belle2::SVDShaperDigit::getModeByte
SVDModeByte getModeByte() const
Get the SVDMOdeByte object containing information on trigger FADCTime and DAQ mode.
Definition: SVDShaperDigit.h:180
Belle2::SVDModeByte::getDAQMode
baseType getDAQMode() const
Get the daqMode id.
Definition: SVDModeByte.h:152
Belle2::SVDShaperDigit::getFADCTime
float getFADCTime() const
Get digit FADCTime estimate.
Definition: SVDShaperDigit.h:174
Belle2::SVDShaperDigit::getRawSensorID
VxdID::baseType getRawSensorID() const
Get raw sensor ID.
Definition: SVDShaperDigit.h:122
Belle2::SVDShaperDigit::APVFloatSampleType
float APVFloatSampleType
Types for array of samples for processing.
Definition: SVDShaperDigit.h:62
Belle2::SVDShaperDigit
The SVD ShaperDigit class.
Definition: SVDShaperDigit.h:46
Belle2::SVDShaperDigit::APVFloatSamples
std::array< APVFloatSampleType, c_nAPVSamples > APVFloatSamples
array of APVFloatSampleType objects
Definition: SVDShaperDigit.h:63
Belle2::SVDShaperDigit::m_FADCTime
int8_t m_FADCTime
digit time estimate from the FADC, in ns
Definition: SVDShaperDigit.h:290
Belle2::SVDShaperDigit::getMaxADCCounts
int getMaxADCCounts() const
Get the ADC counts corresponding to the higher sample amplitude.
Definition: SVDShaperDigit.h:162
Belle2::DigitBase::DigitBase
DigitBase()
Constructor.
Definition: DigitBase.h:50
Belle2::VxdID::baseType
unsigned short baseType
The base integer type for VxdID.
Definition: VxdID.h:46
Belle2::DigitBase::c_DontAppend
@ c_DontAppend
do not append BG digit to digits
Definition: DigitBase.h:43
Belle2::SVDShaperDigit::SVDShaperDigit
SVDShaperDigit()
Default constructor for the ROOT IO.
Definition: SVDShaperDigit.h:108
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::SVDModeByte::baseType
uint8_t baseType
The base integer type for SVDModeByte.
Definition: SVDModeByte.h:82
Belle2::SVDShaperDigit::addBGDigit
DigitBase::EAppendStatus addBGDigit(const DigitBase *bg) override
Implementation of base class function.
Definition: SVDShaperDigit.h:233
Belle2::SVDShaperDigit::getUniqueChannelID
unsigned int getUniqueChannelID() const override
Implementation of base class function.
Definition: SVDShaperDigit.h:223
Belle2::SVDShaperDigit::m_samples
APVRawSamples m_samples
6 APV signals from the strip.
Definition: SVDShaperDigit.h:289
Belle2::SVDShaperDigit::trimToSampleRange
static SVDShaperDigit::APVRawSampleType trimToSampleRange(T x)
Convert a value to sample range.
Definition: SVDShaperDigit.h:188
Belle2::SVDModeByte::getRunType
baseType getRunType() const
Get the runMode id.
Definition: SVDModeByte.h:156
Belle2::SVDShaperDigit::passesZS
bool passesZS(int nSamples, float cutMinSignal) const
does the strip pass the ZS cut?
Definition: SVDShaperDigit.h:269
Belle2::SVDShaperDigit::m_isU
bool m_isU
True if U, false if V.
Definition: SVDShaperDigit.h:287
Belle2::SVDShaperDigit::c_nAPVSamples
static const std::size_t c_nAPVSamples
Number of APV samples stored.
Definition: SVDShaperDigit.h:51
Belle2::SVDShaperDigit::getCellID
short int getCellID() const
Get strip ID.
Definition: SVDShaperDigit.h:132
Belle2::SVDShaperDigit::APVRawSamples
std::array< APVRawSampleType, c_nAPVSamples > APVRawSamples
array of APVRawSamplesType objects
Definition: SVDShaperDigit.h:58
Belle2::SVDShaperDigit::m_mode
SVDModeByte::baseType m_mode
Mode byte, trigger FADCTime + DAQ mode.
Definition: SVDShaperDigit.h:291
Belle2::SVDShaperDigit::toString
std::string toString() const
Display main parameters in this object.
Definition: SVDShaperDigit.h:199
Belle2::SVDShaperDigit::isUStrip
bool isUStrip() const
Get strip direction.
Definition: SVDShaperDigit.h:127
Belle2::SVDShaperDigit::getMaxTimeBin
int getMaxTimeBin() const
Get the max bin.
Definition: SVDShaperDigit.h:150
Belle2::SVDShaperDigit::APVRawSampleType
uint8_t APVRawSampleType
Types for array of samples received from DAQ.
Definition: SVDShaperDigit.h:57
Belle2::SVDModeByte::getEventType
baseType getEventType() const
Get the eventMode id.
Definition: SVDModeByte.h:154