Belle II Software development
PXDGainCalibrator.cc
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
9#include <pxd/reconstruction/PXDGainCalibrator.h>
10#include <vxd/geometry/GeoCache.h>
11#include <framework/gearbox/Const.h>
12
13using namespace std;
14
15
17{
18 m_gainsFromDB = unique_ptr<Belle2::DBObjPtr<Belle2::PXDGainMapPar>>(new Belle2::DBObjPtr<Belle2::PXDGainMapPar>());
19
20 if ((*m_gainsFromDB).isValid()) {
21 setGains();
22 (*m_gainsFromDB).addCallback(this, &Belle2::PXD::PXDGainCalibrator::setGains);
23 }
24}
25
26
28{
29 static std::unique_ptr<Belle2::PXD::PXDGainCalibrator> instance(new Belle2::PXD::PXDGainCalibrator());
30 return *instance;
31}
32
33
34float Belle2::PXD::PXDGainCalibrator::getGainCorrection(Belle2::VxdID id, unsigned int uid, unsigned int vid) const
35{
36 unsigned int rowsPerBin = Belle2::VXD::GeoCache::getInstance().getSensorInfo(id).getVCells() / m_gains.getBinsV();
37 unsigned int drainsPerBin = 4 * Belle2::VXD::GeoCache::getInstance().getSensorInfo(id).getUCells() / m_gains.getBinsU();
38 unsigned int uBin = (uid * 4 + vid % 4) / drainsPerBin;
39 unsigned int vBin = vid / rowsPerBin;
40 return m_gains.getContent(id.getID(), uBin, vBin);
41}
42
43float Belle2::PXD::PXDGainCalibrator::getADUToEnergy(Belle2::VxdID id, unsigned int uid, unsigned int vid) const
44{
45 // FIXME: These constants are hardcoded as intermediate solution.
46 // They should be obtained from GeoCache and ultimately from the condDB.
47 float ADCUnit = 130.0;
48 float Gq = 0.6;
49 return Const::ehEnergy * ADCUnit / Gq / getGainCorrection(id, uid, vid);
50}
51
52
53
54unsigned short Belle2::PXD::PXDGainCalibrator::getBinU(VxdID id, unsigned int uid, unsigned int vid, unsigned short nBinsU) const
55{
56 unsigned int drainsPerBin = 4 * Belle2::VXD::GeoCache::getInstance().getSensorInfo(id).getUCells() / nBinsU;
57 return (uid * 4 + vid % 4) / drainsPerBin;
58}
59
60unsigned short Belle2::PXD::PXDGainCalibrator::getBinU(VxdID id, unsigned int uid, unsigned int vid) const
61{
62 return getBinU(id, uid, vid, m_gains.getBinsU());
63}
64
65unsigned short Belle2::PXD::PXDGainCalibrator::getBinV(VxdID id, unsigned int vid, unsigned short nBinsV) const
66{
67 unsigned int rowsPerBin = Belle2::VXD::GeoCache::getInstance().getSensorInfo(id).getVCells() / nBinsV;
68 return vid / rowsPerBin;
69}
70
71unsigned short Belle2::PXD::PXDGainCalibrator::getBinV(VxdID id, unsigned int vid) const
72{
73 return getBinV(id, vid, m_gains.getBinsV());
74}
75
76unsigned short Belle2::PXD::PXDGainCalibrator::getGlobalID(VxdID id, unsigned int uid, unsigned int vid) const
77{
78 auto uBin = getBinU(id, uid, vid);
79 auto vBin = getBinV(id, vid);
80 return m_gains.getGlobalID(uBin, vBin);
81}
82
83
85{
86 m_gains = **m_gainsFromDB;
87}
88
89
90
static const double ehEnergy
Energy needed to create an electron-hole pair in Si at std.
Definition: Const.h:697
Class for accessing objects in the database.
Definition: DBObjPtr.h:21
Singleton class for managing gain corrections for the PXD.
unsigned short getGlobalID(VxdID id, unsigned int uid, unsigned int vid) const
Get global ID for gain correction on a sensor.
unsigned short getBinV(VxdID id, unsigned int vid) const
Get gain correction bin along sensor v side.
void initialize()
Initialize the PXDGainCalibrator.
float getGainCorrection(VxdID id, unsigned int uid, unsigned int vid) const
Get gain correction.
unsigned short getBinU(VxdID id, unsigned int uid, unsigned int vid) const
Get gain correction bin along sensor u side.
float getADUToEnergy(VxdID id, unsigned int uid, unsigned int vid) const
Get conversion factor from ADU to energy.
std::unique_ptr< DBObjPtr< PXDGainMapPar > > m_gainsFromDB
Masked pixels retrieved from DB.
void setGains()
Set gains from DB.
static PXDGainCalibrator & getInstance()
Main (and only) way to access the PXDGainCalibrator.
const SensorInfoBase & getSensorInfo(Belle2::VxdID id) const
Return a referecne to the SensorInfo of a given SensorID.
Definition: GeoCache.cc:67
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:214
int getVCells() const
Return number of pixel/strips in v direction.
int getUCells() const
Return number of pixel/strips in u direction.
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
int getID(const std::vector< double > &breaks, double t)
get id of the time point t
Definition: calibTools.h:60
unsigned short getBinU(VxdID id, unsigned int uid, unsigned int vid, unsigned short nBinsU)
Function to return a bin number for equal sized binning in U.
Definition: PXDUtilities.h:161
unsigned short getBinV(VxdID id, unsigned int vid, unsigned short nBinsV)
Function to return a bin number for equal sized binning in V.
Definition: PXDUtilities.h:171
STL namespace.