Belle II Software development
CDCDedx1DCell.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 <cdc/dbobjects/CDCDedx1DCell.h>
10
11using namespace Belle2;
12
13
15 const std::vector<std::vector<double>>& groupGains,
16 const std::vector<unsigned int>& layerToGroup)
17 : m_version(version),
18 m_onedgains(groupGains),
19 m_layerToGroup(layerToGroup)
20{
21 // 1. groups exist
22 if (groupGains.empty()) {
23 B2ERROR("CDCDedx1DCell: groupGains is empty.");
24 return;
25 }
26
27 // 2. mapping exists
28 if (layerToGroup.empty()) {
29 B2ERROR("CDCDedx1DCell: layerToGroup is empty.");
30 return;
31 }
32
33 // 3. check groups not empty
34 for (size_t g = 0; g < groupGains.size(); ++g) {
35 if (groupGains[g].empty()) {
36 B2ERROR("CDCDedx1DCell: group " << g << " is empty.");
37 return;
38 }
39 }
40
41 // 4. check Layer -> group mapping
42 for (size_t layer = 0; layer < layerToGroup.size(); ++layer) {
43 if (layerToGroup[layer] >= groupGains.size()) {
44 B2ERROR("CDCDedx1DCell: layer " << layer
45 << " refers to invalid group "
46 << layerToGroup[layer]);
47 return;
48 }
49 }
50
51 m_onedgains = groupGains;
52 m_layerToGroup = layerToGroup;
53}
54
56{
57 if (m_onedgains.empty()) {
58 B2ERROR("CDCDedx1DCell: no gain groups");
59 return false;
60 }
61
62 for (unsigned int g = 0; g < m_onedgains.size(); ++g) {
63 if (m_onedgains[g].empty()) {
64 B2ERROR("CDCDedx1DCell: group " << g << " is empty");
65 return false;
66 }
67 }
68
69 // new-style payload
70 if (!m_layerToGroup.empty()) {
71
72 for (unsigned int layer = 0; layer < m_layerToGroup.size(); ++layer) {
73 if (m_layerToGroup[layer] >= m_onedgains.size()) {
74 B2ERROR("1DCell: invalid group index in layer map");
75 return false;
76 }
77 }
78
79 return true;
80 }
81
82 // old-style payload
83 if (m_onedgains.size() == 2) {
84 return true;
85 }
86
87 B2ERROR("CDCDedx1DCell: invalid legacy payload shape");
88 return false;
89}
90
91double CDCDedx1DCell::getMean(unsigned int layer, unsigned int bin) const
92{
93 const unsigned int group = getGroup(layer);
94 if (group >= m_onedgains.size()) return 1.0;
95
96 if (bin >= m_onedgains[group].size()) return 1.0;
97
98 return m_onedgains[group][bin];
99}
100
101void CDCDedx1DCell::setMean(unsigned int layer,
102 unsigned int bin,
103 double value)
104{
105 const unsigned int group = getGroup(layer);
106
107 if (group >= m_onedgains.size()) return;
108 if (bin >= m_onedgains[group].size()) return;
109
110 m_onedgains[group][bin] = value;
111}
112
113double CDCDedx1DCell::getMean(unsigned int layer, double enta) const
114{
115 const unsigned int group = getGroup(layer);
116
117 if (group >= m_onedgains.size()) return 1.0;
118 if (m_onedgains[group].empty()) return 1.0;
119
120 const double piby2 = M_PI / 2.0;
121
122 if (enta < -piby2) enta += piby2;
123 if (enta > piby2) enta -= piby2;
124
125 unsigned int nbins = m_onedgains[group].size();
126
127 double binsize = 2.0 * piby2 / nbins;
128
129 int bin = std::floor((enta + piby2) / binsize);
130
131 if (bin < 0 || static_cast<unsigned int>(bin) >= nbins) {
132 B2WARNING("Problem with CDC dE/dx 1D binning!");
133 return 1.0;
134 }
135
136 return m_onedgains[group][bin];
137}
138
140{
141 if (m_version != rhs.getVersion()) {
142 B2WARNING("1DCell versions do not match");
143 return *this;
144 }
145
147 B2WARNING("Invalid payload");
148 return *this;
149 }
150
151 if (m_layerToGroup != rhs.m_layerToGroup) {
152 B2WARNING("Layer mapping mismatch");
153 return *this;
154 }
155
156 if (m_onedgains.size() != rhs.m_onedgains.size()) {
157 B2WARNING("Group count mismatch");
158 return *this;
159 }
160
161 for (unsigned int group = 0; group < m_onedgains.size(); ++group) {
162
163 if (m_onedgains[group].size() != rhs.m_onedgains[group].size()) {
164 B2WARNING("Bin count mismatch");
165 return *this;
166 }
167
168 for (unsigned int bin = 0; bin < m_onedgains[group].size(); ++bin) {
169 m_onedgains[group][bin] *= rhs.m_onedgains[group][bin];
170 }
171 }
172
173 return *this;
174}
std::vector< unsigned int > m_layerToGroup
layer to group map
short m_version
dE/dx cleanup correction versus entrance angle may be different for different layers,...
double getMean(unsigned int layer, unsigned int bin) const
Return dE/dx mean value for the given bin.
CDCDedx1DCell & operator*=(CDCDedx1DCell const &rhs)
Combine payloads.
std::vector< std::vector< double > > m_onedgains
dE/dx means in entrance angle bins
void setMean(unsigned int layer, unsigned int bin, double value)
Reset dE/dx mean value for the given bin.
bool isValidGroupedPayload() const
Payload validation.
CDCDedx1DCell()
Default constructor.
unsigned int getGroup(unsigned int layer) const
Get group index for layer.
short getVersion() const
Get the version for the 1D cleanup.
Abstract base class for different kinds of events.