Belle II Software  release-05-01-25
TOPPmtQE.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Marko Staric, Alessandro Gaz *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <top/dbobjects/TOPPmtQE.h>
12 #include <framework/logging/Logger.h>
13 #include <algorithm>
14 
15 using namespace std;
16 
17 namespace Belle2 {
23  const std::vector<float>& TOPPmtQE::getQE(unsigned pmtPixel) const
24  {
25  pmtPixel--;
26  if (pmtPixel < c_NumPmtPixels) return m_QE[pmtPixel];
27 
28  B2ERROR("TOPPmtQE::getQE: invalid pixel ID, returning empty vector");
29  m_envelopeQE.clear();
30  return m_envelopeQE;
31  }
32 
33  double TOPPmtQE::getQE(unsigned pmtPixel, double lambda) const
34  {
35  pmtPixel--;
36  if (pmtPixel < c_NumPmtPixels) return interpolate(lambda, m_QE[pmtPixel]);
37  return 0;
38  }
39 
40  const std::vector<float>& TOPPmtQE::getEnvelopeQE() const
41  {
42  setEnvelopeQE();
43  return m_envelopeQE;
44  }
45 
46  double TOPPmtQE::getEnvelopeQE(double lambda) const
47  {
48  setEnvelopeQE();
49  return interpolate(lambda, m_envelopeQE);
50  }
51 
52  double TOPPmtQE::getEfficiency(unsigned pmtPixel, double lambda, bool BfieldOn) const
53  {
54  if (BfieldOn) {
55  return getQE(pmtPixel, lambda) * m_CE_withB;
56  } else {
57  return getQE(pmtPixel, lambda) * m_CE_noB;
58  }
59  }
60 
61  double TOPPmtQE::getCE(bool BfieldOn) const
62  {
63  if (BfieldOn) {
64  return m_CE_withB;
65  } else {
66  return m_CE_noB;
67  }
68  }
69 
70  double TOPPmtQE::getLambdaLast() const
71  {
72  size_t size = 0;
73  for (unsigned pixel = 0; pixel < c_NumPmtPixels; pixel++) {
74  const auto& QE = m_QE[pixel];
75  size = std::max(size, QE.size());
76  }
77  return m_lambdaFirst + (size - 1) * m_lambdaStep;
78  }
79 
80  double TOPPmtQE::getLambdaLast(unsigned pmtPixel) const
81  {
82  pmtPixel--;
83  if (pmtPixel < c_NumPmtPixels) {
84  return m_lambdaFirst + (m_QE[pmtPixel].size() - 1) * m_lambdaStep;
85  }
86  return 0;
87  }
88 
89  void TOPPmtQE::setEnvelopeQE() const
90  {
91  if (!m_envelopeQE.empty()) return;
92 
93  size_t size = 0;
94  for (unsigned pixel = 0; pixel < c_NumPmtPixels; pixel++) {
95  const auto& QE = m_QE[pixel];
96  size = std::max(size, QE.size());
97  }
98  m_envelopeQE.resize(size, 0);
99  for (unsigned pixel = 0; pixel < c_NumPmtPixels; pixel++) {
100  const auto& QE = m_QE[pixel];
101  for (size_t i = 0; i < QE.size(); i++) {
102  m_envelopeQE[i] = std::max(m_envelopeQE[i], QE[i]);
103  }
104  }
105  }
106 
107  double TOPPmtQE::interpolate(double lambda, const std::vector<float>& QE) const
108  {
109  double dlam = lambda - m_lambdaFirst;
110  if (dlam < 0 or dlam > (QE.size() - 1) * m_lambdaStep) return 0;
111  unsigned i = int(dlam / m_lambdaStep);
112  if (i > QE.size() - 2) return QE.back();
113  return QE[i] + (QE[i + 1] - QE[i]) / m_lambdaStep * (dlam - i * m_lambdaStep);
114  }
115 
116 
118 } // end Belle2 namespace
119 
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19