Belle II Software  release-08-01-10
PXDGainMapPar.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 <TObject.h>
11 #include <unordered_map>
12 #include <vector>
13 
14 namespace Belle2 {
43  class PXDGainMapPar: public TObject {
44  public:
45 
47  PXDGainMapPar(int nBinsU = 4, int nBinsV = 6, float defaultValue = 1.0) : m_nBinsU(nBinsU), m_nBinsV(nBinsV),
48  m_defaultValue(defaultValue), m_sensorCalibrationMap() {}
49 
52  unsigned short getBinsU() const { return m_nBinsU; }
53 
56  unsigned short getBinsV() const { return m_nBinsV; }
57 
60  unsigned short getGlobalID(unsigned short uBin, unsigned short vBin) const { return uBin * m_nBinsV + vBin; }
61 
68  void setContent(unsigned short sensorID, unsigned short globalID, float value)
69  {
70  auto mapIter = m_sensorCalibrationMap.find(sensorID);
71  if (mapIter != m_sensorCalibrationMap.end()) {
72  // Already some values stored
73  auto& calVec = mapIter->second;
74  // Set the value
75  calVec[globalID] = value;
76  } else {
77  // Create a fresh calibration vector
78  std::vector<float> calVec(m_nBinsU * m_nBinsV, m_defaultValue);
79  // Set the value
80  calVec[globalID] = value;
81  // Add vector to map
82  m_sensorCalibrationMap[sensorID] = calVec;
83  }
84  }
85 
93  void setContent(unsigned short sensorID, unsigned short uBin, unsigned short vBin, float value)
94  {
95  setContent(sensorID, getGlobalID(uBin, vBin), value);
96  }
97 
103  float getContent(unsigned short sensorID, unsigned short globalID) const
104  {
105  auto mapIter = m_sensorCalibrationMap.find(sensorID);
106  if (mapIter != m_sensorCalibrationMap.end()) {
107  // Found sensor, return calibration value
108  auto& calVec = mapIter->second;
109  return calVec[globalID];
110  }
111  // Sensor not found, keep low profile and return default calibration value
112  return m_defaultValue;
113  }
114 
121  float getContent(unsigned short sensorID, unsigned short uBin, unsigned short vBin) const
122  {
123  return getContent(sensorID, getGlobalID(uBin, vBin));
124  }
125 
127  const std::unordered_map<unsigned short, std::vector<float> >& getCalibrationMap() const {return m_sensorCalibrationMap;}
128 
129  private:
130 
132  int m_nBinsU;
133 
135  int m_nBinsV;
136 
139 
141  std::unordered_map<unsigned short, std::vector<float> > m_sensorCalibrationMap;
142 
144  };
146 } // end of namespace Belle2
The payload class for PXD gain corrections.
Definition: PXDGainMapPar.h:43
float getContent(unsigned short sensorID, unsigned short globalID) const
Get content.
std::unordered_map< unsigned short, std::vector< float > > m_sensorCalibrationMap
Map for holding the calibrations for all PXD sensors by sensor id (unsigned short).
void setContent(unsigned short sensorID, unsigned short uBin, unsigned short vBin, float value)
Set map content.
Definition: PXDGainMapPar.h:93
int m_nBinsV
Number of bins per sensor along v side.
const std::unordered_map< unsigned short, std::vector< float > > & getCalibrationMap() const
Return unordered_map with all PXD calibrations.
unsigned short getBinsV() const
Get number of bins along sensor v side.
Definition: PXDGainMapPar.h:56
PXDGainMapPar(int nBinsU=4, int nBinsV=6, float defaultValue=1.0)
Default constructor.
Definition: PXDGainMapPar.h:47
unsigned short getBinsU() const
Get number of bins along sensor u side.
Definition: PXDGainMapPar.h:52
int m_nBinsU
Number of bins per sensor along u side.
unsigned short getGlobalID(unsigned short uBin, unsigned short vBin) const
Get global id from uBin and vBin.
Definition: PXDGainMapPar.h:60
ClassDef(PXDGainMapPar, 3)
ClassDef, must be the last term before the closing {}.
float m_defaultValue
Default value for map.
float getContent(unsigned short sensorID, unsigned short uBin, unsigned short vBin) const
Get content.
void setContent(unsigned short sensorID, unsigned short globalID, float value)
Set map content.
Definition: PXDGainMapPar.h:68
Abstract base class for different kinds of events.