Belle II Software development
CDCDedxInjectionTime.h
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#pragma once
10
11#include <framework/logging/Logger.h>
12
13#include <TObject.h>
14
15namespace Belle2 {
20
24
25 class CDCDedxInjectionTime: public TObject {
26
27 public:
28
33
37 explicit CDCDedxInjectionTime(const std::vector<std::vector<double>>& vinjcalib): m_injectionvar(vinjcalib) {};
38
43
44
49 void printCorrection(const std::string& svar, const std::string& sfx) const;
50
51
55 const std::vector<std::vector<double>>& getConstVector() const
56 {
57 return m_injectionvar;
58 };
59
63 const std::vector<double>& getTimeVector(unsigned int ring) const
64 {
65 if (ring > 1) B2ERROR("wrong index for injection ring ");
66 if (ring * 3 >= m_injectionvar.size()) B2FATAL("CDCDedxInjectionTime: vector-of-vectors too short");
67 return m_injectionvar[ring * 3];
68 };
69
73 const std::vector<double>& getMeanVector(unsigned int ring) const
74 {
75 if (ring > 1) B2ERROR("wrong index for injection ring ");
76 if (ring * 3 + 1 >= m_injectionvar.size()) B2FATAL("CDCDedxInjectionTime: vector-of-vectors too short");
77 return m_injectionvar[ring * 3 + 1];
78 };
79
83 const std::vector<double>& getResoVector(unsigned int ring) const
84 {
85 if (ring > 1) B2ERROR("wrong index for injection ring ");
86 if (ring * 3 + 2 >= m_injectionvar.size()) B2FATAL("CDCDedxInjectionTime: vector-of-vectors too short");
87 return m_injectionvar[ring * 3 + 2];
88 };
89
94 int getTimeBin(const std::vector<unsigned int>& array, unsigned int value) const
95 {
96 int nabove = array.size() + 1;
97 int nbelow = 0;
98
99 while (nabove - nbelow > 1) {
100 int middle = (nabove + nbelow) / 2;
101
102 if (value == array[middle - 1]) return middle - 1;
103 if (value < array[middle - 1]) nabove = middle;
104 else nbelow = middle;
105 }
106
107 return nbelow - 1;
108 }
109
115 double getCorrection(const std::string& svar, unsigned int ring, unsigned int time) const;
116
117 private:
118
125 double getSafely(unsigned int iv, int k) const
126 {
127 const auto& vector = m_injectionvar[iv]; // assuming iv is valid index and vector not empty
128 int last = vector.size() - 1;
129 if (k < 0) k = 0;
130 else if (k > last) k = last;
131 return vector[k];
132 }
133
134
138 std::vector<std::vector<double>> m_injectionvar;
140
141 };
142
143} // end namespace Belle2
CDCDedxInjectionTime(const std::vector< std::vector< double > > &vinjcalib)
Constructor.
int getTimeBin(const std::vector< unsigned int > &array, unsigned int value) const
Return time bin for the given time array.
double getSafely(unsigned int iv, int k) const
Helper: safe access to a vector element.
const std::vector< std::vector< double > > & getConstVector() const
Return vector of all constant vector of payload.
const std::vector< double > & getResoVector(unsigned int ring) const
Return dedx reso vector.
const std::vector< double > & getTimeVector(unsigned int ring) const
Return time vector.
void printCorrection(const std::string &svar, const std::string &sfx) const
Return dE/dx mean or norm-reso value for the given time and ring.
CDCDedxInjectionTime()
Default constructor.
const std::vector< double > & getMeanVector(unsigned int ring) const
Return dedx mean vector.
double getCorrection(const std::string &svar, unsigned int ring, unsigned int time) const
Return dE/dx mean or norm-reso value for the given time and ring.
ClassDef(CDCDedxInjectionTime, 1)
ClassDef.
std::vector< std::vector< double > > m_injectionvar
CDC dE/dx injection time payloads for dEdx mean and reso.
STL class.
STL class.
Abstract base class for different kinds of events.