Belle II Software  release-05-01-25
PXDGainCalibrator.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Benjamin Schwenker *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <pxd/reconstruction/PXDGainCalibrator.h>
12 #include <vxd/geometry/GeoCache.h>
13 #include <framework/gearbox/Const.h>
14 
15 using namespace std;
16 
17 
19 {
20  m_gainsFromDB = unique_ptr<Belle2::DBObjPtr<Belle2::PXDGainMapPar>>(new Belle2::DBObjPtr<Belle2::PXDGainMapPar>());
21 
22  if ((*m_gainsFromDB).isValid()) {
23  setGains();
24  (*m_gainsFromDB).addCallback(this, &Belle2::PXD::PXDGainCalibrator::setGains);
25  }
26 }
27 
28 
30 {
31  static std::unique_ptr<Belle2::PXD::PXDGainCalibrator> instance(new Belle2::PXD::PXDGainCalibrator());
32  return *instance;
33 }
34 
35 
36 float Belle2::PXD::PXDGainCalibrator::getGainCorrection(Belle2::VxdID id, unsigned int uid, unsigned int vid) const
37 {
38  unsigned int rowsPerBin = Belle2::VXD::GeoCache::getInstance().get(id).getVCells() / m_gains.getBinsV();
39  unsigned int drainsPerBin = 4 * Belle2::VXD::GeoCache::getInstance().get(id).getUCells() / m_gains.getBinsU();
40  unsigned int uBin = (uid * 4 + vid % 4) / drainsPerBin;
41  unsigned int vBin = vid / rowsPerBin;
42  return m_gains.getContent(id.getID(), uBin, vBin);
43 }
44 
45 float Belle2::PXD::PXDGainCalibrator::getADUToEnergy(Belle2::VxdID id, unsigned int uid, unsigned int vid) const
46 {
47  // FIXME: These constants are hardcoded as intermediate solution.
48  // They should be obtained from GeoCache and ultimately from the condDB.
49  float ADCUnit = 130.0;
50  float Gq = 0.6;
51  return Const::ehEnergy * ADCUnit / Gq / getGainCorrection(id, uid, vid);
52 }
53 
54 
55 
56 unsigned short Belle2::PXD::PXDGainCalibrator::getBinU(VxdID id, unsigned int uid, unsigned int vid, unsigned short nBinsU) const
57 {
58  unsigned int drainsPerBin = 4 * Belle2::VXD::GeoCache::getInstance().get(id).getUCells() / nBinsU;
59  return (uid * 4 + vid % 4) / drainsPerBin;
60 }
61 
62 unsigned short Belle2::PXD::PXDGainCalibrator::getBinU(VxdID id, unsigned int uid, unsigned int vid) const
63 {
64  return getBinU(id, uid, vid, m_gains.getBinsU());
65 }
66 
67 unsigned short Belle2::PXD::PXDGainCalibrator::getBinV(VxdID id, unsigned int vid, unsigned short nBinsV) const
68 {
69  unsigned int rowsPerBin = Belle2::VXD::GeoCache::getInstance().get(id).getVCells() / nBinsV;
70  return vid / rowsPerBin;
71 }
72 
73 unsigned short Belle2::PXD::PXDGainCalibrator::getBinV(VxdID id, unsigned int vid) const
74 {
75  return getBinV(id, vid, m_gains.getBinsV());
76 }
77 
78 unsigned short Belle2::PXD::PXDGainCalibrator::getGlobalID(VxdID id, unsigned int uid, unsigned int vid) const
79 {
80  auto uBin = getBinU(id, uid, vid);
81  auto vBin = getBinV(id, vid);
82  return m_gains.getGlobalID(uBin, vBin);
83 }
84 
85 
87 {
88  m_gains = **m_gainsFromDB;
89 }
90 
91 
92 
Belle2::PXD::PXDGainCalibrator
Singleton class for managing gain corrections for the PXD.
Definition: PXDGainCalibrator.h:36
Belle2::VXD::SensorInfoBase::getUCells
int getUCells() const
Return number of pixel/strips in u direction.
Definition: SensorInfoBase.h:223
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
Belle2::PXD::PXDGainCalibrator::getBinV
unsigned short getBinV(VxdID id, unsigned int vid) const
Get gain correction bin along sensor v side.
Definition: PXDGainCalibrator.cc:73
Belle2::VXD::GeoCache::get
static const SensorInfoBase & get(Belle2::VxdID id)
Return a reference to the SensorInfo of a given SensorID.
Definition: GeoCache.h:141
Belle2::getID
int getID(const std::vector< double > &breaks, double t)
get id of the time point t
Definition: calibTools.h:71
Belle2::PXD::PXDGainCalibrator::initialize
void initialize()
Initialize the PXDGainCalibrator.
Definition: PXDGainCalibrator.cc:18
Belle2::PXD::PXDGainCalibrator::getGainCorrection
float getGainCorrection(VxdID id, unsigned int uid, unsigned int vid) const
Get gain correction.
Definition: PXDGainCalibrator.cc:36
Belle2::DBObjPtr< Belle2::PXDGainMapPar >
Belle2::PXD::PXDGainCalibrator::getGlobalID
unsigned short getGlobalID(VxdID id, unsigned int uid, unsigned int vid) const
Get global ID for gain correction on a sensor.
Definition: PXDGainCalibrator.cc:78
Belle2::PXD::PXDGainCalibrator::setGains
void setGains()
Set gains from DB.
Definition: PXDGainCalibrator.cc:86
Belle2::PXD::PXDGainCalibrator::getADUToEnergy
float getADUToEnergy(VxdID id, unsigned int uid, unsigned int vid) const
Get conversion factor from ADU to energy.
Definition: PXDGainCalibrator.cc:45
Belle2::VXD::GeoCache::getInstance
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:215
Belle2::VXD::SensorInfoBase::getVCells
int getVCells() const
Return number of pixel/strips in v direction.
Definition: SensorInfoBase.h:225
Belle2::PXD::PXDGainCalibrator::getBinU
unsigned short getBinU(VxdID id, unsigned int uid, unsigned int vid) const
Get gain correction bin along sensor u side.
Definition: PXDGainCalibrator.cc:62
Belle2::PXD::PXDGainCalibrator::getInstance
static PXDGainCalibrator & getInstance()
Main (and only) way to access the PXDGainCalibrator.
Definition: PXDGainCalibrator.cc:29