Belle II Software development
TOPPmtQE.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 <top/dbobjects/TOPPmtQE.h>
10#include <framework/logging/Logger.h>
11#include <algorithm>
12
13using namespace std;
14
15namespace Belle2 {
21 const std::vector<float>& TOPPmtQE::getQE(unsigned pmtPixel) const
22 {
23 pmtPixel--;
24 if (pmtPixel < c_NumPmtPixels) return m_QE[pmtPixel];
25
26 B2ERROR("TOPPmtQE::getQE: invalid pixel ID, returning empty vector");
27 m_envelopeQE.clear();
28 return m_envelopeQE;
29 }
30
31 double TOPPmtQE::getQE(unsigned pmtPixel, double lambda) const
32 {
33 pmtPixel--;
34 if (pmtPixel < c_NumPmtPixels) return interpolate(lambda, m_QE[pmtPixel]);
35 return 0;
36 }
37
38 const std::vector<float>& TOPPmtQE::getEnvelopeQE() const
39 {
41 return m_envelopeQE;
42 }
43
44 double TOPPmtQE::getEnvelopeQE(double lambda) const
45 {
47 return interpolate(lambda, m_envelopeQE);
48 }
49
50 double TOPPmtQE::getEfficiency(unsigned pmtPixel, double lambda, bool BfieldOn) const
51 {
52 if (BfieldOn) {
53 return getQE(pmtPixel, lambda) * m_CE_withB;
54 } else {
55 return getQE(pmtPixel, lambda) * m_CE_noB;
56 }
57 }
58
59 double TOPPmtQE::getCE(bool BfieldOn) const
60 {
61 if (BfieldOn) {
62 return m_CE_withB;
63 } else {
64 return m_CE_noB;
65 }
66 }
67
69 {
70 size_t size = 0;
71 for (unsigned pixel = 0; pixel < c_NumPmtPixels; pixel++) {
72 const auto& QE = m_QE[pixel];
73 size = std::max(size, QE.size());
74 }
75 return m_lambdaFirst + (size - 1) * m_lambdaStep;
76 }
77
78 double TOPPmtQE::getLambdaLast(unsigned pmtPixel) const
79 {
80 pmtPixel--;
81 if (pmtPixel < c_NumPmtPixels) {
82 return m_lambdaFirst + (m_QE[pmtPixel].size() - 1) * m_lambdaStep;
83 }
84 return 0;
85 }
86
88 {
89 if (!m_envelopeQE.empty()) return;
90
91 size_t size = 0;
92 for (unsigned pixel = 0; pixel < c_NumPmtPixels; pixel++) {
93 const auto& QE = m_QE[pixel];
94 size = std::max(size, QE.size());
95 }
96 m_envelopeQE.resize(size, 0);
97 for (unsigned pixel = 0; pixel < c_NumPmtPixels; pixel++) {
98 const auto& QE = m_QE[pixel];
99 for (size_t i = 0; i < QE.size(); i++) {
100 m_envelopeQE[i] = std::max(m_envelopeQE[i], QE[i]);
101 }
102 }
103 }
104
105 double TOPPmtQE::interpolate(double lambda, const std::vector<float>& QE) const
106 {
107 double dlam = lambda - m_lambdaFirst;
108 if (dlam < 0 or dlam > (QE.size() - 1) * m_lambdaStep) return 0;
109 unsigned i = int(dlam / m_lambdaStep);
110 if (i > QE.size() - 2) return QE.back();
111 return QE[i] + (QE[i + 1] - QE[i]) / m_lambdaStep * (dlam - i * m_lambdaStep);
112 }
113
114
116} // end Belle2 namespace
117
float m_CE_withB
relative collection efficiency, with B field
Definition: TOPPmtQE.h:160
float m_CE_noB
relative collection efficiency, without B field
Definition: TOPPmtQE.h:159
float m_lambdaStep
wavelength step [nm]
Definition: TOPPmtQE.h:158
std::vector< float > m_envelopeQE
cache for envelope QE
Definition: TOPPmtQE.h:163
float m_lambdaFirst
wavelength of the first data point [nm]
Definition: TOPPmtQE.h:157
std::vector< float > m_QE[c_NumPmtPixels]
QE data points.
Definition: TOPPmtQE.h:156
double getEfficiency(unsigned pmtPixel, double lambda, bool BfieldOn) const
Returns quantum times collection efficiency for a given pixel and wavelength, using linear interpolat...
Definition: TOPPmtQE.cc:50
const std::vector< float > & getEnvelopeQE() const
Returns envelope quantum efficiency data points (maximum over pixels)
Definition: TOPPmtQE.cc:38
const std::vector< float > & getQE(unsigned pmtPixel) const
Returns quantum efficiency data points for a given pixel.
Definition: TOPPmtQE.cc:21
double getCE(bool BfieldOn) const
Returns collection efficiency.
Definition: TOPPmtQE.cc:59
double getLambdaLast() const
Returns wavelenght of the last data point (maximal of pixels)
Definition: TOPPmtQE.cc:68
double interpolate(double lambda, const std::vector< float > &QE) const
Interpolate between QE datapoints (linear interpolation).
Definition: TOPPmtQE.cc:105
void setEnvelopeQE() const
Sets envelope quantum efficiency.
Definition: TOPPmtQE.cc:87
Abstract base class for different kinds of events.
STL namespace.