Belle II Software  release-08-01-10
TOPASICPedestals.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 <TObject.h>
12 #include <TProfile.h>
13 #include <vector>
14 
15 namespace Belle2 {
24  class TOPASICPedestals : public TObject {
25  public:
26 
30  enum {c_WindowSize = 64,
31  c_Bits = 9
32  };
33 
38  {
39  for (unsigned i = 0; i < c_WindowSize; i++) m_pedestals[i] = 0;
40  }
41 
46  explicit TOPASICPedestals(unsigned short asicWindow): m_asicWindow(asicWindow),
47  m_offset(0)
48  {
49  for (unsigned i = 0; i < c_WindowSize; i++) m_pedestals[i] = 0;
50  }
51 
58  int setPedestals(const TProfile* profile, double average = 0);
59 
64  unsigned getASICWindow() const {return m_asicWindow;}
65 
70  unsigned getSize() const {return c_WindowSize;}
71 
77  float getValue(unsigned i) const
78  {
79  if (i < c_WindowSize) {
80  unsigned short mask = (1 << c_Bits);
81  mask--;
82  return (m_pedestals[i] & mask) + m_offset;
83  }
84  return 0;
85  }
86 
92  float getError(unsigned i) const
93  {
94  if (i < c_WindowSize) {
95  return (m_pedestals[i] >> c_Bits);
96  }
97  return 0;
98  }
99 
105  bool isValid(unsigned i) const
106  {
107  if (i < c_WindowSize) {
108  return (m_pedestals[i] != 0);
109  }
110  return false;
111  }
112 
113 
118  unsigned getNumofUnvalid() const
119  {
120  unsigned bad = 0;
121  for (int i = 0; i < c_WindowSize; i++) {
122  if (!isValid(i)) bad++;
123  }
124  return bad;
125  }
126 
127  private:
128 
137  unsigned getOptimizedOffset(const std::vector<unsigned>& values,
138  const std::vector<unsigned>& errors,
139  unsigned maxDif,
140  unsigned maxErr);
141 
142  unsigned short m_asicWindow;
143  unsigned short m_offset;
144  unsigned short m_pedestals[c_WindowSize];
148  };
149 
151 } // end namespace Belle2
152 
Calibration constants of a single ASIC window: pedestals.
ClassDef(TOPASICPedestals, 1)
ClassDef.
@ c_Bits
number of bits reserved for pedestal value
@ c_WindowSize
number of samples
unsigned short m_pedestals[c_WindowSize]
pedestals (packed: value, error)
float getValue(unsigned i) const
Return pedestal value of i-th sample.
unsigned getSize() const
Return window size (number of pedestal samples)
TOPASICPedestals(unsigned short asicWindow)
Constructor with ASIC window number.
unsigned getNumofUnvalid() const
Return number of un-valid pedestals (e.g.
float getError(unsigned i) const
Return pedestal uncertainly of i-th sample.
unsigned getASICWindow() const
Return ASIC window number.
unsigned short m_asicWindow
ASIC window number.
TOPASICPedestals()
Default constructor.
unsigned short m_offset
common pedestal offset
bool isValid(unsigned i) const
Check whether the pedestal of i-th sample is valid.
unsigned getOptimizedOffset(const std::vector< unsigned > &values, const std::vector< unsigned > &errors, unsigned maxDif, unsigned maxErr)
Return the offset that can allow for the maximal number of good pedestal samples.
int setPedestals(const TProfile *profile, double average=0)
Set pedestals from profile histogram with c_WindowSize bins.
Abstract base class for different kinds of events.