Belle II Software  release-05-01-25
CDCADCDeltaPedestals.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Makoto Uchida (original), CDC group *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <map>
13 #include <iostream>
14 #include <TObject.h>
15 
16 namespace Belle2 {
25  class CDCADCDeltaPedestals: public TObject {
26  public:
27 
32 
33 
38  void setSamplingWindow(unsigned short sample)
39  {
40  m_samplingWindow = sample;
41  }
42 
48  void setPedestal(int board, int ch, float pedestal)
49  {
50  unsigned short mask = ch == -1 ? 0x8000 : 0;
51  unsigned short id = mask == 0x8000 ? (mask | board) : (mask | (ch << 9) | board);
52  pedestal *= m_samplingWindow;
53  m_pedestals.insert(std::pair<unsigned short, float>(id, pedestal));
54  }
55 
56 
60  unsigned short getEntries() const
61  {
62  return m_pedestals.size();
63  }
64 
68  std::map<unsigned short, float> getPedestals() const
69  {
70  return m_pedestals;
71  }
72 
79  float getPedestal(const unsigned short& board, const unsigned short& ch) const
80  {
81  unsigned short id0 = (0x8000 | board);
82  std::map<unsigned short, float>::const_iterator it0 = m_pedestals.find(id0);
83  if (it0 != m_pedestals.end()) { // board by board delta pedestal
84  return it0->second;
85  } else {
86  unsigned short id = ((ch << 9) | board);
87  std::map<unsigned short, float>::const_iterator it = m_pedestals.find(id);
88  if (it != m_pedestals.end()) { //delta pedetal with (board, ch).
89  return it->second;
90  } else {
91  return 0.0;
92  }
93  }
94  }
95 
99  void dump() const
100  {
101  std::cout << " " << std::endl;
102  std::cout << "ADC pedestal list" << std::endl;
103  std::cout << "samle" << m_samplingWindow << std::endl;
104  std::cout << "# of entries= " << m_pedestals.size() << std::endl;
105  std::cout << "in order of board#, ch#, pedestal" << std::endl;
106  for (auto const& ent : m_pedestals) {
107  if ((ent.first & 0x8000) > 0) {
108  std::cout << (ent.first & 0x1ff) << " " << -1 << " " << ent.second << std::endl;
109  } else {
110  std::cout << (ent.first & 0x1ff) << " " << ((ent.first & 0x7e00) >> 9) << " " << ent.second << std::endl;
111  }
112  }
113  }
114 
115  private:
116  std::map<unsigned short, float> m_pedestals;
117  unsigned short m_samplingWindow = 10;
119  };
120 
122 } // end namespace Belle2
123 
Belle2::CDCADCDeltaPedestals::m_samplingWindow
unsigned short m_samplingWindow
ADC sampling window.
Definition: CDCADCDeltaPedestals.h:125
Belle2::CDCADCDeltaPedestals::getPedestals
std::map< unsigned short, float > getPedestals() const
Get the whole list.
Definition: CDCADCDeltaPedestals.h:76
Belle2::CDCADCDeltaPedestals::getEntries
unsigned short getEntries() const
Get the no.
Definition: CDCADCDeltaPedestals.h:68
Belle2::CDCADCDeltaPedestals::dump
void dump() const
Print out all contents.
Definition: CDCADCDeltaPedestals.h:107
Belle2::CDCADCDeltaPedestals::m_pedestals
std::map< unsigned short, float > m_pedestals
ADC pedestal list.
Definition: CDCADCDeltaPedestals.h:124
Belle2::CDCADCDeltaPedestals::setPedestal
void setPedestal(int board, int ch, float pedestal)
Set ADC pedestals in the list.
Definition: CDCADCDeltaPedestals.h:56
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::CDCADCDeltaPedestals::ClassDef
ClassDef(CDCADCDeltaPedestals, 1)
ClassDef.
Belle2::CDCADCDeltaPedestals::setSamplingWindow
void setSamplingWindow(unsigned short sample)
Set time window for sampling.
Definition: CDCADCDeltaPedestals.h:46
Belle2::CDCADCDeltaPedestals::getPedestal
float getPedestal(const unsigned short &board, const unsigned short &ch) const
Get ADC pedestal for the specified board.
Definition: CDCADCDeltaPedestals.h:87
Belle2::CDCADCDeltaPedestals::CDCADCDeltaPedestals
CDCADCDeltaPedestals()
Default constructor.
Definition: CDCADCDeltaPedestals.h:39