Belle II Software  release-08-01-10
PXDClusterPositionErrorPar.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 {
34  class PXDClusterPositionErrorPar: public TObject {
35  public:
36 
38  PXDClusterPositionErrorPar(unsigned short nBinsU = 1, unsigned short nBinsV = 3, unsigned short maxSize = 8,
39  float defaultValue = 0.0, float defaultFactor = 1.0):
40  m_nBinsU(nBinsU), m_nBinsV(nBinsV), m_maxSize(maxSize), m_defaultValue(defaultValue), m_defaultFactor(defaultFactor),
42 
45  unsigned short getBinsU() const { return m_nBinsU; }
46 
49  unsigned short getBinsV() const { return m_nBinsV; }
50 
53  unsigned short getMaxClusterSize() const { return m_maxSize; }
54 
55 
56 
59  unsigned short getGlobalID(unsigned short uBin, unsigned short vBin, unsigned short size) const
60  {
61  if (size > m_maxSize) size = m_maxSize;
62  return uBin * (m_nBinsV * m_maxSize) + vBin * m_maxSize + size - 1;
63  }
64 
70  void setContent(unsigned short sensorID, unsigned short globalID, float value)
71  {
72  auto mapIter = m_clusterPositionErrorMap.find(sensorID);
73  if (mapIter != m_clusterPositionErrorMap.end()) {
74  // Already some values stored
75  auto& errVec = mapIter->second;
76  // Set the value
77  errVec[globalID] = value;
78  } else {
79  // Create a fresh position error vector
80  std::vector<float> errVec(m_nBinsU * m_nBinsV * m_maxSize, m_defaultValue);
81  // Set the value
82  errVec[globalID] = value;
83  // Add vector to map
84  m_clusterPositionErrorMap[sensorID] = errVec;
85  }
86  }
87 
95  void setContent(unsigned short sensorID, unsigned short uBin, unsigned short vBin, unsigned short size, float value)
96  {
97  setContent(sensorID, getGlobalID(uBin, vBin, size), value);
98  }
99 
105  float getContent(unsigned short sensorID, unsigned short globalID) const
106  {
107  auto mapIter = m_clusterPositionErrorMap.find(sensorID);
108  if (mapIter != m_clusterPositionErrorMap.end()) {
109  // Found sensor, return position error value
110  auto& errVec = mapIter->second;
111  return errVec[globalID];
112  }
113  // Sensor not found, keep low profile and return default position error value
114  return m_defaultValue;
115  }
116 
124  float getContent(unsigned short sensorID, unsigned short uBin, unsigned short vBin, unsigned short size) const
125  {
126  return getContent(sensorID, getGlobalID(uBin, vBin, size));
127  }
128 
134  void setSensorUEdgeFactor(unsigned short sensorID, unsigned short globalID, float factor)
135  {
136  auto mapIter = m_factorSensorUEdgeMap.find(sensorID);
137  if (mapIter != m_factorSensorUEdgeMap.end()) {
138  // Already some values stored
139  auto& facVec = mapIter->second;
140  // Set the value
141  facVec[globalID] = factor;
142  } else {
143  // Create a fresh scale factor vector
144  std::vector<float> facVec(m_nBinsU * m_nBinsV * m_maxSize, m_defaultFactor);
145  // Set the value
146  facVec[globalID] = factor;
147  // Add vector to map
148  m_factorSensorUEdgeMap[sensorID] = facVec;
149  }
150  }
158  void setSensorUEdgeFactor(unsigned short sensorID, unsigned short uBin, unsigned short vBin, unsigned short size, float factor)
159  {
160  setSensorUEdgeFactor(sensorID, getGlobalID(uBin, vBin, size), factor);
161  }
162 
168  void setSensorVEdgeFactor(unsigned short sensorID, unsigned short globalID, float factor)
169  {
170  auto mapIter = m_factorSensorVEdgeMap.find(sensorID);
171  if (mapIter != m_factorSensorVEdgeMap.end()) {
172  // Already some values stored
173  auto& facVec = mapIter->second;
174  // Set the value
175  facVec[globalID] = factor;
176  } else {
177  // Create a fresh scale factor vector
178  std::vector<float> facVec(m_nBinsU * m_nBinsV * m_maxSize, m_defaultFactor);
179  // Set the value
180  facVec[globalID] = factor;
181  // Add vector to map
182  m_factorSensorVEdgeMap[sensorID] = facVec;
183  }
184  }
192  void setSensorVEdgeFactor(unsigned short sensorID, unsigned short uBin, unsigned short vBin, unsigned short size, float factor)
193  {
194  setSensorVEdgeFactor(sensorID, getGlobalID(uBin, vBin, size), factor);
195  }
196 
202  void setDeadNeighbourFactor(unsigned short sensorID, unsigned short globalID, float factor)
203  {
204  auto mapIter = m_factorDeadNeighbourMap.find(sensorID);
205  if (mapIter != m_factorDeadNeighbourMap.end()) {
206  // Already some values stored
207  auto& facVec = mapIter->second;
208  // Set the value
209  facVec[globalID] = factor;
210  } else {
211  // Create a fresh scale factor vector
212  std::vector<float> facVec(m_nBinsU * m_nBinsV * m_maxSize, m_defaultFactor);
213  // Set the value
214  facVec[globalID] = factor;
215  // Add vector to map
216  m_factorDeadNeighbourMap[sensorID] = facVec;
217  }
218  }
226  void setDeadNeighbourFactor(unsigned short sensorID, unsigned short uBin, unsigned short vBin, unsigned short size, float factor)
227  {
228  setDeadNeighbourFactor(sensorID, getGlobalID(uBin, vBin, size), factor);
229  }
230 
236  float getSensorUEdgeFactor(unsigned short sensorID, unsigned short globalID) const
237  {
238  auto mapIter = m_factorSensorUEdgeMap.find(sensorID);
239  if (mapIter != m_factorSensorUEdgeMap.end()) {
240  // Found sensor, return scale factor value
241  auto& facVec = mapIter->second;
242  return facVec[globalID];
243  }
244  // Sensor not found, keep low profile and return default scale factor value
245  return m_defaultFactor;
246  }
254  float getSensorUEdgeFactor(unsigned short sensorID, unsigned short uBin, unsigned short vBin, unsigned short size) const
255  {
256  return getSensorUEdgeFactor(sensorID, getGlobalID(uBin, vBin, size));
257  }
258 
264  float getSensorVEdgeFactor(unsigned short sensorID, unsigned short globalID) const
265  {
266  auto mapIter = m_factorSensorVEdgeMap.find(sensorID);
267  if (mapIter != m_factorSensorVEdgeMap.end()) {
268  // Found sensor, return scale factor value
269  auto& facVec = mapIter->second;
270  return facVec[globalID];
271  }
272  // Sensor not found, keep low profile and return default scale factor value
273  return m_defaultFactor;
274  }
282  float getSensorVEdgeFactor(unsigned short sensorID, unsigned short uBin, unsigned short vBin, unsigned short size) const
283  {
284  return getSensorVEdgeFactor(sensorID, getGlobalID(uBin, vBin, size));
285  }
286 
292  float getDeadNeighbourFactor(unsigned short sensorID, unsigned short globalID) const
293  {
294  auto mapIter = m_factorDeadNeighbourMap.find(sensorID);
295  if (mapIter != m_factorDeadNeighbourMap.end()) {
296  // Found sensor, return scale factor value
297  auto& facVec = mapIter->second;
298  return facVec[globalID];
299  }
300  // Sensor not found, keep low profile and return default scale factor value
301  return m_defaultFactor;
302  }
310  float getDeadNeighbourFactor(unsigned short sensorID, unsigned short uBin, unsigned short vBin, unsigned short size) const
311  {
312  return getDeadNeighbourFactor(sensorID, getGlobalID(uBin, vBin, size));
313  }
314 
316  const std::unordered_map<unsigned short, std::vector<float> >& getClusterPositionErrorMap() const {return m_clusterPositionErrorMap;}
317 
318  private:
319 
321  unsigned short m_nBinsU;
322 
324  unsigned short m_nBinsV;
325 
327  unsigned short m_maxSize;
328 
331 
334 
336  std::unordered_map<unsigned short, std::vector<float> > m_factorSensorUEdgeMap;
337 
339  std::unordered_map<unsigned short, std::vector<float> > m_factorSensorVEdgeMap;
340 
342  std::unordered_map<unsigned short, std::vector<float> > m_factorDeadNeighbourMap;
343 
345  std::unordered_map<unsigned short, std::vector<float> > m_clusterPositionErrorMap;
346 
348  };
350 } // end of namespace Belle2
The payload class for PXD cluster position error.
std::unordered_map< unsigned short, std::vector< float > > m_clusterPositionErrorMap
Map for holding the cluster position errors for all PXD sensors by sensor id (unsigned short).
float getContent(unsigned short sensorID, unsigned short globalID) const
Get content.
unsigned short m_maxSize
Maximum cluster size.
float getDeadNeighbourFactor(unsigned short sensorID, unsigned short uBin, unsigned short vBin, unsigned short size) const
Get scaling factor when neighbouring dead rows/column.
void setContent(unsigned short sensorID, unsigned short uBin, unsigned short vBin, unsigned short size, float value)
Set map content.
const std::unordered_map< unsigned short, std::vector< float > > & getClusterPositionErrorMap() const
Return unordered_map with all PXD cluster position errors.
void setDeadNeighbourFactor(unsigned short sensorID, unsigned short uBin, unsigned short vBin, unsigned short size, float factor)
Set scaling factor when neighbouring dead rows/columns.
float m_defaultFactor
Default value for scale factor map.
std::unordered_map< unsigned short, std::vector< float > > m_factorSensorUEdgeMap
Scaling factor at sensor U edge for layers 1 or 2 and FWD/BWD sensors with sensor number 1 or 2.
std::unordered_map< unsigned short, std::vector< float > > m_factorSensorVEdgeMap
Scaling factor at sensor V edge for layers 1 or 2 and FWD/BWD sensors with sensor number 1 or 2.
float getSensorVEdgeFactor(unsigned short sensorID, unsigned short uBin, unsigned short vBin, unsigned short size) const
Get scaling factor at sensor edge in V.
unsigned short getBinsV() const
Get number of bins along sensor v side.
float getSensorUEdgeFactor(unsigned short sensorID, unsigned short uBin, unsigned short vBin, unsigned short size) const
Get scaling factor at sensor edge in U.
void setSensorUEdgeFactor(unsigned short sensorID, unsigned short uBin, unsigned short vBin, unsigned short size, float factor)
Set scaling factor at sensor U edge.
float getDeadNeighbourFactor(unsigned short sensorID, unsigned short globalID) const
Get scaling factor when neighbouring dead rows/column.
float getContent(unsigned short sensorID, unsigned short uBin, unsigned short vBin, unsigned short size) const
Get content.
unsigned short getBinsU() const
Get number of bins along sensor u side.
unsigned short m_nBinsU
Number of bins per sensor along u side.
void setDeadNeighbourFactor(unsigned short sensorID, unsigned short globalID, float factor)
Set scaling factor when neighbouring dead rows/columns.
void setSensorUEdgeFactor(unsigned short sensorID, unsigned short globalID, float factor)
Set scaling factor at sensor U edge.
unsigned short getGlobalID(unsigned short uBin, unsigned short vBin, unsigned short size) const
Get global id from uBin and vBin and cluster size.
void setSensorVEdgeFactor(unsigned short sensorID, unsigned short globalID, float factor)
Set scaling factor at sensor V edge.
PXDClusterPositionErrorPar(unsigned short nBinsU=1, unsigned short nBinsV=3, unsigned short maxSize=8, float defaultValue=0.0, float defaultFactor=1.0)
Default constructor.
void setSensorVEdgeFactor(unsigned short sensorID, unsigned short uBin, unsigned short vBin, unsigned short size, float factor)
Set scaling factor at sensor V edge.
ClassDef(PXDClusterPositionErrorPar, 8)
ClassDef, must be the last term before the closing {}.
unsigned short getMaxClusterSize() const
Get maximum cluster size that the error is defined.
std::unordered_map< unsigned short, std::vector< float > > m_factorDeadNeighbourMap
Scaling factor when neighbouring dead rows/colums for FWD/BWD sensors by sensor number 1 or 2.
void setContent(unsigned short sensorID, unsigned short globalID, float value)
Set map content.
float getSensorVEdgeFactor(unsigned short sensorID, unsigned short globalID) const
Get scaling factor at sensor edge in V.
float getSensorUEdgeFactor(unsigned short sensorID, unsigned short globalID) const
Get scaling factor at sensor edge in U.
unsigned short m_nBinsV
Number of bins per sensor along v side.
Abstract base class for different kinds of events.