Belle II Software  release-08-01-10
TOPRawDigit.cc
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 #include <top/dataobjects/TOPRawDigit.h>
10 
11 #include <framework/logging/Logger.h>
12 
13 #include <math.h>
14 
15 using namespace std;
16 
17 namespace Belle2 {
23  bool TOPRawDigit::isPedestalJump() const
24  {
25  if (m_sampleRise == 0) {
26  if ((m_dSampleFall + 1) % 64 == 0) return true;
27  } else if ((m_sampleRise + 1) % 64 == 0) {
28  if (m_dSampleFall % 64 == 0) return true;
29  }
30  return false;
31  }
32 
33 
34  bool TOPRawDigit::isAtWindowDiscontinuity(unsigned short storageDepth) const
35  {
36  if (m_windows.empty()) return false;
37 
38  unsigned size = m_windows.size();
39  unsigned i0 = getSampleRise() / c_WindowSize;
40  if (i0 >= size) i0 = size - 1;
41  unsigned i1 = (getSampleFall() + 1) / c_WindowSize;
42  if (i1 >= size) i1 = size - 1;
43  if (i0 == i1) return false;
44 
45  int diff = m_windows[i1] - m_windows[i0];
46  if (diff < 0) diff += storageDepth;
47  if (diff != 1) return true;
48  return false;
49  }
50 
51 
52  bool TOPRawDigit::areWindowsInOrder(unsigned short storageDepth) const
53  {
54  unsigned lastSample = getSampleFall() + 1;
55  unsigned last = lastSample / c_WindowSize + 1;
56  unsigned size = m_windows.size();
57  for (unsigned i = 1; i < std::min(last, size); i++) {
58  int diff = m_windows[i] - m_windows[i - 1];
59  if (diff < 0) diff += storageDepth;
60  if (diff != 1) return false;
61  }
62  return true;
63  }
64 
65 
66  double TOPRawDigit::correctTime(double time, unsigned short storageDepth) const
67  {
68  if (m_windows.empty()) return time;
69 
70  unsigned last = int(time) / c_WindowSize + 1;
71  unsigned size = m_windows.size();
72  int missing = 0;
73  for (unsigned i = 1; i < std::min(last, size); i++) {
74  int diff = m_windows[i] - m_windows[i - 1];
75  if (diff < 0) diff += storageDepth;
76  if (diff != 1) missing += diff - 1;
77  if (diff == 0) B2ERROR("TOPRawDigit: two consecutive windows with the same number");
78  }
79 
80  return time + missing * c_WindowSize;
81  }
82 
83 
84  double TOPRawDigit::timeErrorCoefficient(double y1, double y2) const
85  {
86  double dy = y2 - y1;
87  double ym = m_VPeak / 2.0;
88  double a = 1.0 / (2.0 * dy);
89  double b = (ym - y2) / (dy * dy);
90  double c = (ym - y1) / (dy * dy);
91 
92  return sqrt(a * a + b * b + c * c);
93  }
94 
96 } // end Belle2 namespace
97 
98 
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.