Belle II Software  release-08-01-10
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 
13 using namespace std;
14 
15 namespace 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  {
40  setEnvelopeQE();
41  return m_envelopeQE;
42  }
43 
44  double TOPPmtQE::getEnvelopeQE(double lambda) const
45  {
46  setEnvelopeQE();
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 
68  double TOPPmtQE::getLambdaLast() const
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 
87  void TOPPmtQE::setEnvelopeQE() const
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 
Abstract base class for different kinds of events.