Belle II Software  release-08-01-10
CDCADCDeltaPedestals.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 #pragma once
9 
10 #include <map>
11 #include <iostream>
12 #include <TObject.h>
13 
14 namespace Belle2 {
23  class CDCADCDeltaPedestals: public TObject {
24  public:
25 
30 
31 
36  void setSamplingWindow(unsigned short sample)
37  {
38  m_samplingWindow = sample;
39  }
40 
47  void setPedestal(int board, int ch, float pedestal)
48  {
49  unsigned short mask = ch == -1 ? 0x8000 : 0;
50  unsigned short id = mask == 0x8000 ? (mask | board) : (mask | (ch << 9) | board);
51  pedestal *= m_samplingWindow;
52  m_pedestals.insert(std::pair<unsigned short, float>(id, pedestal));
53  }
54 
55 
59  unsigned short getEntries() const
60  {
61  return m_pedestals.size();
62  }
63 
67  std::map<unsigned short, float> getPedestals() const
68  {
69  return m_pedestals;
70  }
71 
78  float getPedestal(const unsigned short& board, const unsigned short& ch) const
79  {
80  unsigned short id0 = (0x8000 | board);
81  std::map<unsigned short, float>::const_iterator it0 = m_pedestals.find(id0);
82  if (it0 != m_pedestals.end()) { // board by board delta pedestal
83  return it0->second;
84  } else {
85  unsigned short id = ((ch << 9) | board);
86  std::map<unsigned short, float>::const_iterator it = m_pedestals.find(id);
87  if (it != m_pedestals.end()) { //delta pedetal with (board, ch).
88  return it->second;
89  } else {
90  return 0.0;
91  }
92  }
93  }
94 
98  void dump() const
99  {
100  std::cout << " " << std::endl;
101  std::cout << "ADC pedestal list" << std::endl;
102  std::cout << "samle" << m_samplingWindow << std::endl;
103  std::cout << "# of entries= " << m_pedestals.size() << std::endl;
104  std::cout << "in order of board#, ch#, pedestal" << std::endl;
105  for (auto const& ent : m_pedestals) {
106  if ((ent.first & 0x8000) > 0) {
107  std::cout << (ent.first & 0x1ff) << " " << -1 << " " << ent.second << std::endl;
108  } else {
109  std::cout << (ent.first & 0x1ff) << " " << ((ent.first & 0x7e00) >> 9) << " " << ent.second << std::endl;
110  }
111  }
112  }
113 
114  private:
115  std::map<unsigned short, float> m_pedestals;
116  unsigned short m_samplingWindow = 10;
118  };
119 
121 } // end namespace Belle2
122 
Database object for ADC pedestals.
ClassDef(CDCADCDeltaPedestals, 1)
ClassDef.
void setSamplingWindow(unsigned short sample)
Set time window for sampling.
CDCADCDeltaPedestals()
Default constructor.
void setPedestal(int board, int ch, float pedestal)
Set ADC pedestals in the list.
std::map< unsigned short, float > getPedestals() const
Get the whole list.
unsigned short getEntries() const
Get the no.
std::map< unsigned short, float > m_pedestals
ADC pedestal list.
float getPedestal(const unsigned short &board, const unsigned short &ch) const
Get ADC pedestal for the specified board.
void dump() const
Print out all contents.
unsigned short m_samplingWindow
ADC sampling window.
Abstract base class for different kinds of events.