Belle II Software  release-05-02-19
DATCONSVDDigit.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Christian Wessel *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <vxd/dataobjects/VxdID.h>
14 
15 #include <cstdint>
16 #include <sstream>
17 #include <algorithm>
18 #include <limits>
19 
20 namespace Belle2 {
35 // class DATCONSVDDigit : public DigitBase {
36  class DATCONSVDDigit : public RelationsObject {
37 
38  public:
39 
41  static const std::size_t c_nAPVSamples = 6;
42 
44  typedef uint8_t APVRawSampleType;
46  typedef std::array<APVRawSampleType, c_nAPVSamples> APVRawSamples;
47 
49  typedef float APVFloatSampleType;
51  typedef std::array<APVFloatSampleType, c_nAPVSamples> APVFloatSamples;
52 
59  template<typename T>
60  DATCONSVDDigit(VxdID sensorID, bool isU, short cellID,
61  T samples[c_nAPVSamples]):
62  m_sensorID(sensorID), m_isU(isU), m_cellID(cellID), m_totalCharge(0), m_maxSampleCharge(0), m_maxSampleIndex(0)
63  {
64  std::transform(samples, samples + c_nAPVSamples, m_samples.begin(),
65  [this](T x)->APVRawSampleType { return trimToSampleRange(x); }
66  );
67  }
68 
75  template<typename T>
76  DATCONSVDDigit(VxdID sensorID, bool isU, short cellID, T samples) :
77  m_sensorID(sensorID), m_isU(isU), m_cellID(cellID), m_totalCharge(0), m_maxSampleCharge(0), m_maxSampleIndex(0)
78  {
79  std::transform(samples.begin(), samples.end(), m_samples.begin(),
80  [](typename T::value_type x)->APVRawSampleType
81  { return trimToSampleRange(x); }
82  );
83  }
84 
86  // cppcheck does not recognize initialization through other constructor
87  // cppcheck-suppress uninitMemberVar
89  0, true, 0, APVRawSamples( {{0, 0, 0, 0, 0, 0}})
90  )
91  {}
92 
94  VxdID getSensorID() const { return m_sensorID; }
95 
97  VxdID::baseType getRawSensorID() const { return m_sensorID; }
98 
100  bool isUStrip() const { return m_isU; }
101 
103  short int getCellID() const { return m_cellID; }
104 
107  {
108  APVFloatSamples returnSamples;
109  std::transform(m_samples.begin(), m_samples.end(), returnSamples.begin(),
110  [](APVRawSampleType x) { return static_cast<APVFloatSampleType>(x); });
111  return returnSamples;
112  }
113 
116  {
117  return m_samples;
118  }
119 
121  unsigned short getTotalCharge()
122  {
123  if (m_totalCharge > 0)
124  return m_totalCharge;
125  else {
126  m_totalCharge = 0;
127  for (unsigned int i = 0; i < c_nAPVSamples; i++) {
128  m_totalCharge += m_samples[i];
129  }
130  }
131  return m_totalCharge;
132  }
133 
135  unsigned short getMaxSampleCharge()
136  {
137  unsigned short maxCharge = 0;
138  for (unsigned int i = 0; i < c_nAPVSamples; i++) {
139  if (m_samples[i] > maxCharge) {
140  maxCharge = m_samples[i];
141  }
142  }
143  return maxCharge;
144  }
145 
147  unsigned short getMaxSampleIndex()
148  {
149  if (m_maxSampleIndex > 0)
150  return m_maxSampleIndex;
151  else {
152  unsigned short maxCharge = 0;
153  for (unsigned int i = 0; i < c_nAPVSamples; i++) {
154  if (m_samples[i] > maxCharge) {
155  maxCharge = m_samples[i];
156  m_maxSampleIndex = i;
157  }
158  }
159  }
160  return m_maxSampleIndex;
161  }
162 
168  template<typename T> static DATCONSVDDigit::APVRawSampleType trimToSampleRange(T x)
169  {
170  T trimmedX = std::min(
171  static_cast<T>(std::numeric_limits<DATCONSVDDigit::APVRawSampleType>::max()),
172  std::max(
173  static_cast<T>(std::numeric_limits<DATCONSVDDigit::APVRawSampleType>::lowest()),
174  x));
175  return static_cast<DATCONSVDDigit::APVRawSampleType>(trimmedX);
176  }
177 
178 
180  void setSensorID(VxdID sensorid) { m_sensorID = sensorid; }
181 
183  void setUStrip(bool isU) { m_isU = isU; }
184 
186  void setCellID(short cellID) { m_cellID = cellID; }
187 
189  void setAPVRawSamples(APVFloatSamples apvInputSamples)
190  {
191  // m_samples = apvSamples;
192  std::transform(apvInputSamples.begin(), apvInputSamples.end(), m_samples.begin(),
193  [](APVFloatSampleType x) { return static_cast<APVRawSampleType>(x); });
194  }
195 
196  private:
197 
199  bool m_isU;
200  short m_cellID;
202  unsigned short m_totalCharge;
203  unsigned short m_maxSampleCharge;
204  unsigned short m_maxSampleIndex;
207 
208  }; // class DATCONSVDDigit
209 
211 } // end namespace Belle2
Belle2::DATCONSVDDigit::setUStrip
void setUStrip(bool isU)
Setter for the strip direction (u or v).
Definition: DATCONSVDDigit.h:191
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
Belle2::DATCONSVDDigit::trimToSampleRange
static DATCONSVDDigit::APVRawSampleType trimToSampleRange(T x)
Convert a value to sample range.
Definition: DATCONSVDDigit.h:176
Belle2::DATCONSVDDigit::getRawSamples
APVRawSamples getRawSamples() const
Get int-array of of 6 APV25 samples.
Definition: DATCONSVDDigit.h:123
Belle2::DATCONSVDDigit::setSensorID
void setSensorID(VxdID sensorid)
Setter for the sensorID.
Definition: DATCONSVDDigit.h:188
Belle2::DATCONSVDDigit::APVFloatSamples
std::array< APVFloatSampleType, c_nAPVSamples > APVFloatSamples
Types for array of samples for processing.
Definition: DATCONSVDDigit.h:59
Belle2::DATCONSVDDigit::APVRawSamples
std::array< APVRawSampleType, c_nAPVSamples > APVRawSamples
Type for array of samples received from DAQ.
Definition: DATCONSVDDigit.h:54
Belle2::RelationsInterface::ClassDef
ClassDef(RelationsInterface, 0)
defines interface for accessing relations of objects in StoreArray.
Belle2::DATCONSVDDigit::APVRawSampleType
uint8_t APVRawSampleType
Type of samples received from DAQ.
Definition: DATCONSVDDigit.h:52
Belle2::DATCONSVDDigit::m_isU
bool m_isU
True if U, false if V.
Definition: DATCONSVDDigit.h:207
Belle2::DATCONSVDDigit::setCellID
void setCellID(short cellID)
Setter for the stripID / cellID.
Definition: DATCONSVDDigit.h:194
Belle2::DATCONSVDDigit
The DATCONSVDDigit class.
Definition: DATCONSVDDigit.h:44
Belle2::VxdID::baseType
unsigned short baseType
The base integer type for VxdID.
Definition: VxdID.h:46
Belle2::DATCONSVDDigit::getFloatSamples
APVFloatSamples getFloatSamples() const
Get float-array of 6 APV25 samples.
Definition: DATCONSVDDigit.h:114
Belle2::DATCONSVDDigit::getRawSensorID
VxdID::baseType getRawSensorID() const
Getter for the raw sensor ID.
Definition: DATCONSVDDigit.h:105
Belle2::DATCONSVDDigit::getMaxSampleCharge
unsigned short getMaxSampleCharge()
Getter for the charge of the biggest sample of the array in ADUs.
Definition: DATCONSVDDigit.h:143
Belle2::DATCONSVDDigit::m_maxSampleIndex
unsigned short m_maxSampleIndex
Index of charge of sample max.
Definition: DATCONSVDDigit.h:212
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::DATCONSVDDigit::getTotalCharge
unsigned short getTotalCharge()
Getter for the total charge of the array in ADUs.
Definition: DATCONSVDDigit.h:129
Belle2::DATCONSVDDigit::APVFloatSampleType
float APVFloatSampleType
Types of samples for processing.
Definition: DATCONSVDDigit.h:57
Belle2::DATCONSVDDigit::DATCONSVDDigit
DATCONSVDDigit()
Default constructor for the ROOT IO.
Definition: DATCONSVDDigit.h:96
Belle2::DATCONSVDDigit::setAPVRawSamples
void setAPVRawSamples(APVFloatSamples apvInputSamples)
Setter for the raw samples array.
Definition: DATCONSVDDigit.h:197
Belle2::DATCONSVDDigit::m_totalCharge
unsigned short m_totalCharge
Total charge of this DATCONSVDDigit.
Definition: DATCONSVDDigit.h:210
Belle2::DATCONSVDDigit::m_samples
APVRawSamples m_samples
6 APV signals from the strip.
Definition: DATCONSVDDigit.h:209
Belle2::DATCONSVDDigit::m_cellID
short m_cellID
Strip coordinate in pitch units.
Definition: DATCONSVDDigit.h:208
Belle2::DATCONSVDDigit::c_nAPVSamples
static const std::size_t c_nAPVSamples
Number of APV samples stored.
Definition: DATCONSVDDigit.h:49
Belle2::DATCONSVDDigit::getMaxSampleIndex
unsigned short getMaxSampleIndex()
Getter for the index of the biggest sample inside the cluster (0...6)
Definition: DATCONSVDDigit.h:155
Belle2::DATCONSVDDigit::m_sensorID
VxdID::baseType m_sensorID
Compressed sensor identifier.
Definition: DATCONSVDDigit.h:206
Belle2::RelationsObject
RelationsInterface< TObject > RelationsObject
Provides interface for getting/adding relations to objects in StoreArrays.
Definition: RelationsObject.h:443
Belle2::DATCONSVDDigit::getSensorID
VxdID getSensorID() const
Getter for the sensor ID.
Definition: DATCONSVDDigit.h:102
Belle2::DATCONSVDDigit::isUStrip
bool isUStrip() const
Getter for the strip direction (u or v)
Definition: DATCONSVDDigit.h:108
Belle2::DATCONSVDDigit::m_maxSampleCharge
unsigned short m_maxSampleCharge
Charge of sample max.
Definition: DATCONSVDDigit.h:211
Belle2::DATCONSVDDigit::getCellID
short int getCellID() const
Getter for the strip ID.
Definition: DATCONSVDDigit.h:111