Belle II Software  release-05-02-19
TOPRawWaveform.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Marko Staric *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <framework/datastore/RelationsObject.h>
14 #include <vector>
15 #include <algorithm>
16 
17 namespace Belle2 {
26  class TOPRawWaveform : public RelationsObject {
27  public:
28 
32  enum {c_WindowSize = 64
33  };
34 
38  struct FeatureExtraction {
39  int sampleRise = 0;
40  int samplePeak = 0;
41  int sampleFall = 0;
42  short vRise0 = 0;
43  short vRise1 = 0;
44  short vPeak = 0;
45  short vFall0 = 0;
46  short vFall1 = 0;
47  int integral = 0;
48  };
49 
50 
55  {}
56 
57 
68  TOPRawWaveform(int moduleID,
69  int pixelID,
70  unsigned channel,
71  unsigned scrodID,
72  unsigned window,
73  int startSample,
74  const std::vector<short>& data):
75  m_moduleID(moduleID), m_pixelID(pixelID), m_channel(channel), m_scrodID(scrodID),
76  m_window(window), m_startSample(startSample), m_data(data),
77  m_physicalWindow(window)
78  {}
79 
83  void setPedestalSubtractedFlag(bool value) {m_pedestalSubtracted = value;}
84 
88  void setPhysicalWindow(unsigned window) {m_physicalWindow = window;}
89 
93  void setLastWriteAddr(unsigned lastWriteAddr) {m_lastWriteAddr = lastWriteAddr;}
94 
98  void setStorageWindows(const std::vector<unsigned short>& windows)
99  {
100  m_windows = windows;
101  }
102 
107  void setRevo9Counter(unsigned short revo9Counter) {m_revo9Counter = revo9Counter;}
108 
113  void setOffsetWindows(int offsetWindows) {m_offsetWindows = offsetWindows;}
114 
119  int getModuleID() const { return m_moduleID; }
120 
125  int getPixelID() const { return m_pixelID; }
126 
131  unsigned getChannel() const { return m_channel; }
132 
137  unsigned getScrodID() const { return m_scrodID; }
138 
143  unsigned getStorageWindow() const { return m_window; }
144 
149  int getStartSample() const { return m_startSample;}
150 
155  bool isPedestalSubtracted() const {return m_pedestalSubtracted;}
156 
161  unsigned getPhysicalWindow() const {return m_physicalWindow;}
162 
169  unsigned getReferenceWindow() const { return m_lastWriteAddr; }
170 
175  const std::vector<unsigned short>& getStorageWindows() const { return m_windows; }
176 
181  unsigned short getRevo9Counter() const {return m_revo9Counter;}
182 
187  int getOffsetWindows() const {return m_offsetWindows;}
188 
193  unsigned getASICChannel() const {return m_channel & 0x07;}
194 
199  unsigned getASICNumber() const {return (m_channel >> 3) & 0x03;}
200 
205  unsigned getCarrierNumber() const {return (m_channel >> 5) & 0x03;}
206 
211  unsigned getBoardstackNumber() const {return (m_channel >> 7) & 0x03;}
212 
217  unsigned getSize() const {return m_data.size();}
218 
223  const std::vector<short>& getWaveform() const
224  {
225  return m_data;
226  }
227 
235  bool areWindowsInOrder(unsigned lastSample = 0xFFFFFFFF,
236  unsigned short storageDepth = 508) const
237  {
238  unsigned last = lastSample / c_WindowSize + 1;
239  unsigned size = m_windows.size();
240  for (unsigned i = 1; i < std::min(last, size); i++) {
241  int diff = m_windows[i] - m_windows[i - 1];
242  if (diff < 0) diff += storageDepth;
243  if (diff != 1) return false;
244  }
245  return true;
246  }
247 
255  int getIntegral(int sampleRise, int samplePeak, int sampleFall) const;
256 
264  int featureExtraction(int threshold, int hysteresis, int thresholdCount) const;
265 
270  const std::vector<FeatureExtraction>& getFeatureExtractionData() const
271  {
272  return m_features;
273  }
274 
275 
276  private:
277 
285  int Integral(int sampleRise, int samplePeak, int sampleFall) const;
286 
287  int m_moduleID = 0;
288  int m_pixelID = 0;
289  unsigned m_channel = 0;
290  unsigned short m_scrodID = 0;
291  unsigned short m_window = 0;
292  int m_startSample = 0;
293  std::vector<short> m_data;
294  bool m_pedestalSubtracted = false;
296  unsigned short m_physicalWindow = 0;
297  unsigned short m_lastWriteAddr = 0;
298  std::vector<unsigned short> m_windows;
300  unsigned short m_revo9Counter = 0;
301  int m_offsetWindows = 0;
304  mutable std::vector<FeatureExtraction> m_features;
305 
308  };
309 
310 
312 } // end namespace Belle2
Belle2::TOPRawWaveform::setOffsetWindows
void setOffsetWindows(int offsetWindows)
Sets number of offset windows (windows before "first one") - MC only.
Definition: TOPRawWaveform.h:121
Belle2::TOPRawWaveform::setLastWriteAddr
void setLastWriteAddr(unsigned lastWriteAddr)
Sets current (reference) window number.
Definition: TOPRawWaveform.h:101
Belle2::TOPRawWaveform::FeatureExtraction::samplePeak
int samplePeak
sample number at maximum
Definition: TOPRawWaveform.h:48
Belle2::TOPRawWaveform::areWindowsInOrder
bool areWindowsInOrder(unsigned lastSample=0xFFFFFFFF, unsigned short storageDepth=508) const
Checks if storage windows come in the consecutive order before the last sample (no gaps in between be...
Definition: TOPRawWaveform.h:243
Belle2::TOPRawWaveform::m_pixelID
int m_pixelID
software channel ID
Definition: TOPRawWaveform.h:296
Belle2::TOPRawWaveform::m_window
unsigned short m_window
hardware logic window number (storage window)
Definition: TOPRawWaveform.h:299
Belle2::TOPRawWaveform::getChannel
unsigned getChannel() const
Returns hardware channel number (0-based)
Definition: TOPRawWaveform.h:139
Belle2::TOPRawWaveform::setPedestalSubtractedFlag
void setPedestalSubtractedFlag(bool value)
Sets pedestal subtracted flag.
Definition: TOPRawWaveform.h:91
Belle2::TOPRawWaveform::setStorageWindows
void setStorageWindows(const std::vector< unsigned short > &windows)
Sets storage window numbers.
Definition: TOPRawWaveform.h:106
Belle2::TOPRawWaveform::FeatureExtraction::vFall0
short vFall0
ADC value at sampleFall.
Definition: TOPRawWaveform.h:53
Belle2::TOPRawWaveform::m_channel
unsigned m_channel
hardware channel number
Definition: TOPRawWaveform.h:297
Belle2::TOPRawWaveform::Integral
int Integral(int sampleRise, int samplePeak, int sampleFall) const
Returns integral of a peak.
Definition: TOPRawWaveform.cc:30
Belle2::TOPRawWaveform::FeatureExtraction::vRise0
short vRise0
ADC value at sampleRise.
Definition: TOPRawWaveform.h:50
Belle2::TOPRawWaveform::getBoardstackNumber
unsigned getBoardstackNumber() const
Returns boardstack number.
Definition: TOPRawWaveform.h:219
Belle2::TOPRawWaveform::setPhysicalWindow
void setPhysicalWindow(unsigned window)
Sets hardware physical window number.
Definition: TOPRawWaveform.h:96
Belle2::TOPRawWaveform::getSize
unsigned getSize() const
Returns waveform size.
Definition: TOPRawWaveform.h:225
Belle2::TOPRawWaveform::getReferenceWindow
unsigned getReferenceWindow() const
Returns IRS reference analog storage window (last write address).
Definition: TOPRawWaveform.h:177
Belle2::TOPRawWaveform::getWaveform
const std::vector< short > & getWaveform() const
Returns waveform.
Definition: TOPRawWaveform.h:231
Belle2::TOPRawWaveform::getPhysicalWindow
unsigned getPhysicalWindow() const
Returns hardware physical window number.
Definition: TOPRawWaveform.h:169
Belle2::TOPRawWaveform::m_startSample
int m_startSample
sample number of the first waveform sample
Definition: TOPRawWaveform.h:300
Belle2::TOPRawWaveform::m_physicalWindow
unsigned short m_physicalWindow
hardware physical window number
Definition: TOPRawWaveform.h:304
Belle2::TOPRawWaveform::getPixelID
int getPixelID() const
Returns pixel ID (1-based)
Definition: TOPRawWaveform.h:133
Belle2::TOPRawWaveform::m_pedestalSubtracted
bool m_pedestalSubtracted
true, if pedestals already subtracted
Definition: TOPRawWaveform.h:302
Belle2::TOPRawWaveform::setRevo9Counter
void setRevo9Counter(unsigned short revo9Counter)
Sets number of global clock tics since last revo9 flag.
Definition: TOPRawWaveform.h:115
Belle2::TOPRawWaveform
Class to store raw data waveforms.
Definition: TOPRawWaveform.h:34
Belle2::TOPRawWaveform::m_windows
std::vector< unsigned short > m_windows
storage windows of waveform segments
Definition: TOPRawWaveform.h:306
Belle2::TOPRawWaveform::FeatureExtraction::sampleFall
int sampleFall
same for falling edge
Definition: TOPRawWaveform.h:49
Belle2::TOPRawWaveform::m_revo9Counter
unsigned short m_revo9Counter
number of clock ticks since last revo9 flag
Definition: TOPRawWaveform.h:308
Belle2::TOPRawWaveform::getStorageWindows
const std::vector< unsigned short > & getStorageWindows() const
Returns storage window numbers of waveform segments.
Definition: TOPRawWaveform.h:183
Belle2::TOPRawWaveform::getScrodID
unsigned getScrodID() const
Returns SCROD ID.
Definition: TOPRawWaveform.h:145
Belle2::TOPRawWaveform::m_offsetWindows
int m_offsetWindows
number of offset windows (windows before "first one")
Definition: TOPRawWaveform.h:309
Belle2::TOPRawWaveform::m_features
std::vector< FeatureExtraction > m_features
cache for feature extraction data
Definition: TOPRawWaveform.h:312
Belle2::TOPRawWaveform::getASICNumber
unsigned getASICNumber() const
Returns ASIC number.
Definition: TOPRawWaveform.h:207
Belle2::TOPRawWaveform::isPedestalSubtracted
bool isPedestalSubtracted() const
Tells whether pedestal already subtracted or not.
Definition: TOPRawWaveform.h:163
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TOPRawWaveform::getOffsetWindows
int getOffsetWindows() const
Returns number of windows before the "first one" which defines the time origin.
Definition: TOPRawWaveform.h:195
Belle2::TOPRawWaveform::FeatureExtraction
Feature extraction data.
Definition: TOPRawWaveform.h:46
Belle2::TOPRawWaveform::FeatureExtraction::vFall1
short vFall1
ADC value at sampleFall + 1.
Definition: TOPRawWaveform.h:54
Belle2::TOPRawWaveform::m_data
std::vector< short > m_data
waveform ADC values
Definition: TOPRawWaveform.h:301
Belle2::TOPRawWaveform::featureExtraction
int featureExtraction(int threshold, int hysteresis, int thresholdCount) const
Do feature extraction.
Definition: TOPRawWaveform.cc:46
Belle2::TOPRawWaveform::getRevo9Counter
unsigned short getRevo9Counter() const
Returns 127 MHz clock ticks since last revo9 marker.
Definition: TOPRawWaveform.h:189
Belle2::TOPRawWaveform::getFeatureExtractionData
const std::vector< FeatureExtraction > & getFeatureExtractionData() const
Returns feature extraction data.
Definition: TOPRawWaveform.h:278
Belle2::TOPRawWaveform::getModuleID
int getModuleID() const
Returns module ID.
Definition: TOPRawWaveform.h:127
Belle2::RelationsObject
RelationsInterface< TObject > RelationsObject
Provides interface for getting/adding relations to objects in StoreArrays.
Definition: RelationsObject.h:443
Belle2::TOPRawWaveform::getIntegral
int getIntegral(int sampleRise, int samplePeak, int sampleFall) const
Returns integral of a peak.
Definition: TOPRawWaveform.cc:21
Belle2::TOPRawWaveform::FeatureExtraction::sampleRise
int sampleRise
sample number just before 50% CFD crossing
Definition: TOPRawWaveform.h:47
Belle2::TOPRawWaveform::ClassDef
ClassDef(TOPRawWaveform, 9)
ClassDef.
Belle2::TOPRawWaveform::FeatureExtraction::vPeak
short vPeak
ADC value at samplePeak.
Definition: TOPRawWaveform.h:52
Belle2::TOPRawWaveform::FeatureExtraction::integral
int integral
integral of a pulse (e.g.
Definition: TOPRawWaveform.h:55
Belle2::TOPRawWaveform::getStartSample
int getStartSample() const
Returns sample number of the first waveform sample.
Definition: TOPRawWaveform.h:157
Belle2::TOPRawWaveform::FeatureExtraction::vRise1
short vRise1
ADC value at sampleRise + 1.
Definition: TOPRawWaveform.h:51
Belle2::TOPRawWaveform::getStorageWindow
unsigned getStorageWindow() const
Returns hardware logic window number (storage window)
Definition: TOPRawWaveform.h:151
Belle2::TOPRawWaveform::c_WindowSize
@ c_WindowSize
number of samples per ASIC window
Definition: TOPRawWaveform.h:40
Belle2::TOPRawWaveform::m_scrodID
unsigned short m_scrodID
SCROD ID.
Definition: TOPRawWaveform.h:298
Belle2::TOPRawWaveform::m_lastWriteAddr
unsigned short m_lastWriteAddr
current (reference) window number
Definition: TOPRawWaveform.h:305
Belle2::TOPRawWaveform::m_moduleID
int m_moduleID
module ID
Definition: TOPRawWaveform.h:295
Belle2::TOPRawWaveform::getASICChannel
unsigned getASICChannel() const
Returns ASIC channel number.
Definition: TOPRawWaveform.h:201
Belle2::TOPRawWaveform::getCarrierNumber
unsigned getCarrierNumber() const
Returns carrier board number.
Definition: TOPRawWaveform.h:213
Belle2::TOPRawWaveform::TOPRawWaveform
TOPRawWaveform()
Default constructor.
Definition: TOPRawWaveform.h:62