Belle II Software development
CDCDedxCosineCor Class Reference

dE/dx cosine gain calibration constants More...

#include <CDCDedxCosineCor.h>

Inheritance diagram for CDCDedxCosineCor:

Public Member Functions

 CDCDedxCosineCor ()
 Default constructor.
 
 CDCDedxCosineCor (const std::vector< double > &cosgains)
 Old payloads Constructor.
 
 CDCDedxCosineCor (const std::vector< std::vector< double > > &groupCosgains, const std::vector< unsigned int > &layerToGroup)
 New-style constructor: grouped cosine corrections with layer-to-group mapping.
 
 ~CDCDedxCosineCor ()
 Destructor.
 
CDCDedxCosineCoroperator*= (const CDCDedxCosineCor &rhs)
 Combine payloads.
 
bool isGrouped () const
 Check whether grouped mode is used.
 
unsigned int getNGroups () const
 Get number of groups in grouped mode.
 
unsigned int getNLayers () const
 Number of layers.
 
unsigned int getGroup (unsigned int layer) const
 Get group index for layer.
 
unsigned int getSize (unsigned int layer) const
 Get the number of bins.
 
const std::vector< double > & getCosCor () const
 Get the old-style calibration constants.
 
const std::vector< std::vector< double > > & getGroupCosCor () const
 Get the grouped calibration constants.
 
const std::vector< unsigned int > & getLayerMap () const
 Get the Layer-to-group map.
 
void setCosCor (unsigned int bin, double value)
 Set old-style cosine correction.
 
void setCosCor (unsigned int group, unsigned int bin, double value)
 Set grouped cosine correction.
 
double getMean (unsigned int bin) const
 Return dE/dx mean value for the given bin in old mode.
 
double getMean (double costh) const
 Return dE/dx mean value for given cos(theta) in old mode.
 
double getMean (unsigned int layer, unsigned int bin) const
 Return dE/dx mean value for the given layer and bin.
 
double getMean (unsigned int layer, double costh) const
 Return dE/dx mean value for given layer and cos(theta)
 

Private Member Functions

double getMeanFromVector (const std::vector< double > &gains, double costh) const
 Helper to interpolate/extrapolate from one vector of gains.
 
bool isValidGroupedPayload () const
 Validate grouped payload content.
 
bool multiplyGains (std::vector< double > &lhs, const std::vector< double > &rhs) const
 Multiply lhs by rhs with possible rebinning.
 
 ClassDef (CDCDedxCosineCor, 9)
 ClassDef.
 

Private Attributes

std::vector< double > m_cosgains
 old-style dE/dx gains in cos(theta) bins
 
std::vector< std::vector< double > > m_groupCosgains
 grouped dE/dx gains [group][bin]
 
std::vector< unsigned int > m_layerToGroup
 map from layer index to group index
 

Detailed Description

dE/dx cosine gain calibration constants

Definition at line 26 of file CDCDedxCosineCor.h.

Constructor & Destructor Documentation

◆ CDCDedxCosineCor() [1/3]

CDCDedxCosineCor ( )
inline

Default constructor.

Definition at line 33 of file CDCDedxCosineCor.h.

33: m_cosgains(), m_groupCosgains(), m_layerToGroup() {};

◆ CDCDedxCosineCor() [2/3]

CDCDedxCosineCor ( const std::vector< double > & cosgains)
inlineexplicit

Old payloads Constructor.

Parameters
cosgainsvector of calibration constants

Definition at line 39 of file CDCDedxCosineCor.h.

39 : m_cosgains(cosgains), m_groupCosgains(),
40 m_layerToGroup() {};

◆ CDCDedxCosineCor() [3/3]

CDCDedxCosineCor ( const std::vector< std::vector< double > > & groupCosgains,
const std::vector< unsigned int > & layerToGroup )

New-style constructor: grouped cosine corrections with layer-to-group mapping.

Parameters
groupCosgainsgrouped calibration constants [group][bin]
layerToGroupmap from layer index to group index

Definition at line 15 of file CDCDedxCosineCor.cc.

18{
19
20 // 1. check groups exist
21 if (groupCosgains.empty()) {
22 B2ERROR("CDCDedxCosineCor: groupCosgains is empty.");
23 return;
24 }
25
26 // 2. check layer mapping exists
27 if (layerToGroup.empty()) {
28 B2ERROR("CDCDedxCosineCor: layerToGroup is empty.");
29 return;
30 }
31
32 for (size_t g = 0; g < groupCosgains.size(); ++g) {
33 if (groupCosgains[g].empty()) {
34 B2ERROR("CDCDedx1DCell: group " << g << " is empty.");
35 return;
36 }
37 }
38
39 // 4. check Layer -> group mapping
40 for (size_t layer = 0; layer < layerToGroup.size(); layer++) {
41
42 if (layerToGroup[layer] >= groupCosgains.size()) {
43 B2ERROR("CDCDedxCosineCor: layer " << layer
44 << " refers to invalid group "
45 << layerToGroup[layer]);
46 return;
47 }
48 }
49
50 // 5. store data only after checks pass
51 m_groupCosgains = groupCosgains;
52 m_layerToGroup = layerToGroup;
53
54// summary
55 B2INFO("Cosine groups: " << m_groupCosgains.size());
56 B2INFO("Cosine bins per group: " << m_groupCosgains[0].size());
57
58 for (size_t layer = 0; layer < m_layerToGroup.size(); layer++) {
59 B2INFO("layer " << layer << " -> group " << m_layerToGroup[layer]);
60 }
61
62}
std::vector< std::vector< double > > m_groupCosgains
grouped dE/dx gains [group][bin]
std::vector< unsigned int > m_layerToGroup
map from layer index to group index

◆ ~CDCDedxCosineCor()

~CDCDedxCosineCor ( )
inline

Destructor.

Definition at line 55 of file CDCDedxCosineCor.h.

55{};

Member Function Documentation

◆ getCosCor()

const std::vector< double > & getCosCor ( ) const
inline

Get the old-style calibration constants.

Returns
calibration constants

Definition at line 123 of file CDCDedxCosineCor.h.

124 {
125 return m_cosgains;
126 }

◆ getGroup()

unsigned int getGroup ( unsigned int layer) const
inline

Get group index for layer.

Definition at line 90 of file CDCDedxCosineCor.h.

91 {
92 if (layer >= getNLayers()) {
93 B2ERROR("Layer out of range");
94 return std::numeric_limits<unsigned int>::max();
95 }
96
97 if (!m_layerToGroup.empty()) {
98 return m_layerToGroup[layer];
99 }
100
101 B2INFO("Invalid cosine correction payload state");
102 return std::numeric_limits<unsigned int>::max();
103 };

◆ getGroupCosCor()

const std::vector< std::vector< double > > & getGroupCosCor ( ) const
inline

Get the grouped calibration constants.

Returns
grouped calibration constants

Definition at line 132 of file CDCDedxCosineCor.h.

133 {
134 return m_groupCosgains;
135 }

◆ getLayerMap()

const std::vector< unsigned int > & getLayerMap ( ) const
inline

Get the Layer-to-group map.

Returns
layer map

Definition at line 141 of file CDCDedxCosineCor.h.

142 {
143 return m_layerToGroup;
144 }

◆ getMean() [1/4]

double getMean ( double costh) const

Return dE/dx mean value for given cos(theta) in old mode.

Parameters
costhcos(theta)
Returns
mean value

Definition at line 122 of file CDCDedxCosineCor.cc.

123{
124 if (m_cosgains.empty()) return 1.0;
125 return getMeanFromVector(m_cosgains, costh);
126}
double getMeanFromVector(const std::vector< double > &gains, double costh) const
Helper to interpolate/extrapolate from one vector of gains.
std::vector< double > m_cosgains
old-style dE/dx gains in cos(theta) bins

◆ getMean() [2/4]

double getMean ( unsigned int bin) const

Return dE/dx mean value for the given bin in old mode.

Parameters
bincosine bin
Returns
mean value

Definition at line 115 of file CDCDedxCosineCor.cc.

116{
117 if (bin < m_cosgains.size()) return m_cosgains[bin];
118 B2WARNING("CDCDedxCosineCor: bin out of range, returning value (1.0)");
119 return 1.0;
120}

◆ getMean() [3/4]

double getMean ( unsigned int layer,
double costh ) const

Return dE/dx mean value for given layer and cos(theta)

Parameters
layerlayer index
costhcos(theta)
Returns
mean value

Definition at line 151 of file CDCDedxCosineCor.cc.

152{
153 if (isGrouped()) {
154 if (!isValidGroupedPayload()) return 1.0;
155
156 if (layer >= m_layerToGroup.size()) {
157 B2ERROR("CDCDedxCosineCor: invalid layer index");
158 return 1.0;
159 }
160
161 const unsigned int group = m_layerToGroup[layer];
162 return getMeanFromVector(m_groupCosgains[group], costh);
163 }
164
165 return getMean(costh);
166}
bool isGrouped() const
Check whether grouped mode is used.
bool isValidGroupedPayload() const
Validate grouped payload content.
double getMean(unsigned int bin) const
Return dE/dx mean value for the given bin in old mode.

◆ getMean() [4/4]

double getMean ( unsigned int layer,
unsigned int bin ) const

Return dE/dx mean value for the given layer and bin.

Parameters
layerlayer index
bincosine bin
Returns
mean value

Definition at line 129 of file CDCDedxCosineCor.cc.

130{
131 if (isGrouped()) {
132 if (!isValidGroupedPayload()) return 1.0;
133
134 if (layer >= m_layerToGroup.size()) {
135 B2ERROR("CDCDedxCosineCor: invalid layer index");
136 return 1.0;
137 }
138
139 const unsigned int group = m_layerToGroup[layer];
140 if (bin >= m_groupCosgains[group].size()) {
141 B2ERROR("CDCDedxCosineCor: invalid bin number");
142 return 1.0;
143 }
144
145 return m_groupCosgains[group][bin];
146 }
147
148 return getMean(bin);
149}

◆ getMeanFromVector()

double getMeanFromVector ( const std::vector< double > & gains,
double costh ) const
private

Helper to interpolate/extrapolate from one vector of gains.

Parameters
gainsvector of gains
costhcos(theta)
Returns
interpolated mean value

Definition at line 169 of file CDCDedxCosineCor.cc.

170{
171 if (std::abs(costh) > 1.0) return 0.0;
172 if (gains.empty()) return 1.0;
173
174 // gains are stored at the center of the bins
175 // find the bin center immediately preceding this value of costh
176 const double binsize = 2.0 / gains.size();
177 const int bin = std::floor((costh - 0.5 * binsize + 1.0) / binsize);
178
179 int thisbin = bin;
180 int nextbin = bin + 1;
181
182 // extrapolation
183 // extrapolate backward for lowest half-bin and center positive half-bin
184 // extrapolate forward for highest half-bin and center negative half-bin
185 double halfBin = binsize / 2.0;
186 if ((costh + 1.0) < halfBin || (costh > 0.0 && costh < halfBin)) {
187 thisbin = bin + 1;
188 nextbin = bin + 2;
189 } else if ((costh - 1.0) > -1.0 * halfBin || (costh < 0.0 && costh > -1.0 * halfBin)) {
190 thisbin = bin - 1;
191 nextbin = bin;
192 }
193
194 const double frac = ((costh - 0.5 * binsize + 1.0) / binsize) - thisbin;
195
196 if (thisbin < 0 || static_cast<unsigned int>(nextbin) >= gains.size()) {
197 B2WARNING("Problem with extrapolation of CDC dE/dx cosine correction");
198 return 1.0;
199 }
200
201 return (gains[nextbin] - gains[thisbin]) * frac + gains[thisbin];
202}

◆ getNGroups()

unsigned int getNGroups ( ) const
inline

Get number of groups in grouped mode.

Returns
number of groups

Definition at line 75 of file CDCDedxCosineCor.h.

76 {
77 if (isGrouped()) return m_groupCosgains.size();
78 return (m_cosgains.empty() ? 0 : 1);
79 }

◆ getNLayers()

unsigned int getNLayers ( ) const
inline

Number of layers.

Definition at line 82 of file CDCDedxCosineCor.h.

83 {
84 if (!m_layerToGroup.empty()) return m_layerToGroup.size();
85
86 return 0;
87 };

◆ getSize()

unsigned int getSize ( unsigned int layer) const
inline

Get the number of bins.

Returns
number of bins

Definition at line 109 of file CDCDedxCosineCor.h.

110 {
111 if (isGrouped()) {
112 const unsigned int group = getGroup(layer);
113 return m_groupCosgains[group].size();
114 }
115
116 return m_cosgains.size();
117 }

◆ isGrouped()

bool isGrouped ( ) const
inline

Check whether grouped mode is used.

Returns
true if grouped constants are available

Definition at line 66 of file CDCDedxCosineCor.h.

67 {
68 return !m_groupCosgains.empty();
69 }

◆ isValidGroupedPayload()

bool isValidGroupedPayload ( ) const
private

Validate grouped payload content.

Returns
true if grouped payload is consistent

Definition at line 85 of file CDCDedxCosineCor.cc.

86{
87 // Check that grouped cosine constants exist
88 if (m_groupCosgains.empty()) {
89 B2ERROR("CDCDedxCosineCor : no gain groups");
90 return false;
91 }
92
93 // Check that the layer-to-group mapping exists
94 if (m_layerToGroup.empty()) return false;
95
96 // Verify that every layer refers to a valid group index
97 for (unsigned int layer = 0; layer < m_layerToGroup.size(); ++layer) {
98 if (m_layerToGroup[layer] >= m_groupCosgains.size()) {
99 B2ERROR("CDCDedxCosineCor: layer-to-group map points to invalid group");
100 return false;
101 }
102 }
103
104 for (unsigned int g = 0; g < m_groupCosgains.size(); ++g) {
105 if (m_groupCosgains[g].empty()) {
106 B2ERROR("CDCDedxCosineCor: group " << g << " is empty");
107 return false;
108 }
109 }
110
111 // All checks passed
112 return true;
113}

◆ multiplyGains()

bool multiplyGains ( std::vector< double > & lhs,
const std::vector< double > & rhs ) const
private

Multiply lhs by rhs with possible rebinning.

If rhs has fewer bins, each rhs bin is applied to a block of lhs bins. This allows combining payloads with different binning (e.g. coarse => fine).

Definition at line 204 of file CDCDedxCosineCor.cc.

205{
206 if (rhs.empty() || lhs.size() % rhs.size() != 0) {
207 return false;
208 }
209
210 const int scale = std::floor(static_cast<double>(lhs.size()) / rhs.size() + 0.001);
211
212 for (unsigned int bin = 0; bin < lhs.size(); ++bin) {
213 lhs[bin] *= rhs[std::floor(bin / static_cast<double>(scale) + 0.001)];
214 }
215
216 return true;
217}

◆ operator*=()

CDCDedxCosineCor & operator*= ( const CDCDedxCosineCor & rhs)

Combine payloads.

Definition at line 219 of file CDCDedxCosineCor.cc.

220{
221 // old x old
222 if (!isGrouped() && !rhs.isGrouped()) {
223 if (!multiplyGains(m_cosgains, rhs.getCosCor())) {
224 B2WARNING("Cosine gain parameters do not match, cannot merge!");
225 }
226 return *this;
227 }
228
229 // grouped x grouped
230 if (isGrouped() && rhs.isGrouped()) {
232 B2WARNING("Invalid grouped cosine payload, cannot merge!");
233 return *this;
234 }
235
236 if (m_layerToGroup != rhs.getLayerMap()) {
237 B2WARNING("layer grouping does not match, cannot merge grouped cosine payloads!");
238 return *this;
239 }
240
241 const std::vector<std::vector<double>>& rhsGroups = rhs.getGroupCosCor();
242
243 if (m_groupCosgains.size() != rhsGroups.size()) {
244 B2WARNING("Number of cosine groups does not match, cannot merge!");
245 return *this;
246 }
247
248 for (unsigned int group = 0; group < m_groupCosgains.size(); ++group) {
249 if (!multiplyGains(m_groupCosgains[group], rhsGroups[group])) {
250 B2WARNING("Grouped cosine gain parameters do not match, cannot merge!");
251 return *this;
252 }
253 }
254 return *this;
255 }
256
257 B2WARNING("Cannot merge old-style and grouped cosine payloads directly!");
258 return *this;
259}
bool multiplyGains(std::vector< double > &lhs, const std::vector< double > &rhs) const
Multiply lhs by rhs with possible rebinning.
const std::vector< std::vector< double > > & getGroupCosCor() const
Get the grouped calibration constants.
const std::vector< double > & getCosCor() const
Get the old-style calibration constants.
const std::vector< unsigned int > & getLayerMap() const
Get the Layer-to-group map.

◆ setCosCor() [1/2]

void setCosCor ( unsigned int bin,
double value )

Set old-style cosine correction.

Parameters
binbin number
valuevalue to be set

Definition at line 64 of file CDCDedxCosineCor.cc.

65{
66 if (bin < m_cosgains.size()) m_cosgains[bin] = value;
67 else B2ERROR("CDCDedxCosineCor: invalid bin number, value not set");
68}

◆ setCosCor() [2/2]

void setCosCor ( unsigned int group,
unsigned int bin,
double value )

Set grouped cosine correction.

Parameters
groupgroup number
binbin number
valuevalue to be set

Definition at line 70 of file CDCDedxCosineCor.cc.

71{
72 if (group >= m_groupCosgains.size()) {
73 B2ERROR("CDCDedxCosineCor: invalid group number, value not set");
74 return;
75 }
76
77 if (bin >= m_groupCosgains[group].size()) {
78 B2ERROR("CDCDedxCosineCor: invalid bin number, value not set");
79 return;
80 }
81
82 m_groupCosgains[group][bin] = value;
83}

Member Data Documentation

◆ m_cosgains

std::vector<double> m_cosgains
private

old-style dE/dx gains in cos(theta) bins

Definition at line 214 of file CDCDedxCosineCor.h.

◆ m_groupCosgains

std::vector<std::vector<double> > m_groupCosgains
private

grouped dE/dx gains [group][bin]

Definition at line 215 of file CDCDedxCosineCor.h.

◆ m_layerToGroup

std::vector<unsigned int> m_layerToGroup
private

map from layer index to group index

Definition at line 216 of file CDCDedxCosineCor.h.


The documentation for this class was generated from the following files: