Belle II Software development
PXDClusterChargeMapPar.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
14namespace Belle2 {
30 class PXDClusterChargeMapPar: public TObject {
31 public:
32
34 PXDClusterChargeMapPar(int nBinsU = 4, int nBinsV = 6, float defaultValue = -1.0) : m_nBinsU(nBinsU), m_nBinsV(nBinsV),
35 m_defaultValue(defaultValue), m_sensorCalibrationMap() {}
36
39 unsigned short getBinsU() const { return m_nBinsU; }
40
43 unsigned short getBinsV() const { return m_nBinsV; }
44
47 unsigned short getGlobalID(unsigned short uBin, unsigned short vBin) const { return uBin * m_nBinsV + vBin; }
48
55 void setContent(unsigned short sensorID, unsigned short globalID, float value)
56 {
57 auto mapIter = m_sensorCalibrationMap.find(sensorID);
58 if (mapIter != m_sensorCalibrationMap.end()) {
59 // Already some values stored
60 auto& calVec = mapIter->second;
61 // Set the value
62 calVec[globalID] = value;
63 } else {
64 // Create a fresh calibration vector
65 std::vector<float> calVec(m_nBinsU * m_nBinsV, m_defaultValue);
66 // Set the value
67 calVec[globalID] = value;
68 // Add vector to map
69 m_sensorCalibrationMap[sensorID] = calVec;
70 }
71 }
72
80 void setContent(unsigned short sensorID, unsigned short uBin, unsigned short vBin, float value)
81 {
82 setContent(sensorID, getGlobalID(uBin, vBin), value);
83 }
84
90 float getContent(unsigned short sensorID, unsigned short globalID) const
91 {
92 auto mapIter = m_sensorCalibrationMap.find(sensorID);
93 if (mapIter != m_sensorCalibrationMap.end()) {
94 // Found sensor, return calibration value
95 auto& calVec = mapIter->second;
96 return calVec[globalID];
97 }
98 // Sensor not found, keep low profile and return default calibration value
99 return m_defaultValue;
100 }
101
108 float getContent(unsigned short sensorID, unsigned short uBin, unsigned short vBin) const
109 {
110 return getContent(sensorID, getGlobalID(uBin, vBin));
111 }
112
114 const std::unordered_map<unsigned short, std::vector<float> >& getCalibrationMap() const {return m_sensorCalibrationMap;}
115
116 private:
117
120
123
126
128 std::unordered_map<unsigned short, std::vector<float> > m_sensorCalibrationMap;
129
131 };
133} // end of namespace Belle2
The payload class for PXD cluster charge calibrations.
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.
const std::unordered_map< unsigned short, std::vector< float > > & getCalibrationMap() const
Return unordered_map with all PXD calibrations.
int m_nBinsV
Number of bins per sensor along v side.
unsigned short getBinsV() const
Get number of bins along sensor v side.
unsigned short getBinsU() const
Get number of bins along sensor u side.
int m_nBinsU
Number of bins per sensor along u side.
PXDClusterChargeMapPar(int nBinsU=4, int nBinsV=6, float defaultValue=-1.0)
Default constructor.
unsigned short getGlobalID(unsigned short uBin, unsigned short vBin) const
Get global id from uBin and vBin.
ClassDef(PXDClusterChargeMapPar, 1)
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.
Abstract base class for different kinds of events.