9#include <cdc/dbobjects/CDCDedxCosineCor.h>
16 const std::vector<std::vector<double>>& groupCosgains,
17 const std::vector<unsigned int>& layerToGroup)
21 if (groupCosgains.empty()) {
22 B2ERROR(
"CDCDedxCosineCor: groupCosgains is empty.");
27 if (layerToGroup.empty()) {
28 B2ERROR(
"CDCDedxCosineCor: layerToGroup is empty.");
32 for (
size_t g = 0; g < groupCosgains.size(); ++g) {
33 if (groupCosgains[g].empty()) {
34 B2ERROR(
"CDCDedx1DCell: group " << g <<
" is empty.");
40 for (
size_t layer = 0; layer < layerToGroup.size(); layer++) {
42 if (layerToGroup[layer] >= groupCosgains.size()) {
43 B2ERROR(
"CDCDedxCosineCor: layer " << layer
44 <<
" refers to invalid group "
45 << layerToGroup[layer]);
59 B2INFO(
"layer " << layer <<
" -> group " <<
m_layerToGroup[layer]);
67 else B2ERROR(
"CDCDedxCosineCor: invalid bin number, value not set");
73 B2ERROR(
"CDCDedxCosineCor: invalid group number, value not set");
78 B2ERROR(
"CDCDedxCosineCor: invalid bin number, value not set");
89 B2ERROR(
"CDCDedxCosineCor : no gain groups");
97 for (
unsigned int layer = 0; layer <
m_layerToGroup.size(); ++layer) {
99 B2ERROR(
"CDCDedxCosineCor: layer-to-group map points to invalid group");
106 B2ERROR(
"CDCDedxCosineCor: group " << g <<
" is empty");
118 B2WARNING(
"CDCDedxCosineCor: bin out of range, returning value (1.0)");
135 B2ERROR(
"CDCDedxCosineCor: invalid layer index");
141 B2ERROR(
"CDCDedxCosineCor: invalid bin number");
157 B2ERROR(
"CDCDedxCosineCor: invalid layer index");
171 if (std::abs(costh) > 1.0)
return 0.0;
172 if (gains.empty())
return 1.0;
176 const double binsize = 2.0 / gains.size();
177 const int bin = std::floor((costh - 0.5 * binsize + 1.0) / binsize);
180 int nextbin = bin + 1;
185 double halfBin = binsize / 2.0;
186 if ((costh + 1.0) < halfBin || (costh > 0.0 && costh < halfBin)) {
189 }
else if ((costh - 1.0) > -1.0 * halfBin || (costh < 0.0 && costh > -1.0 * halfBin)) {
194 const double frac = ((costh - 0.5 * binsize + 1.0) / binsize) - thisbin;
196 if (thisbin < 0 ||
static_cast<unsigned int>(nextbin) >= gains.size()) {
197 B2WARNING(
"Problem with extrapolation of CDC dE/dx cosine correction");
201 return (gains[nextbin] - gains[thisbin]) * frac + gains[thisbin];
206 if (rhs.empty() || lhs.size() % rhs.size() != 0) {
210 const int scale = std::floor(
static_cast<double>(lhs.size()) / rhs.size() + 0.001);
212 for (
unsigned int bin = 0; bin < lhs.size(); ++bin) {
213 lhs[bin] *= rhs[std::floor(bin /
static_cast<double>(scale) + 0.001)];
224 B2WARNING(
"Cosine gain parameters do not match, cannot merge!");
232 B2WARNING(
"Invalid grouped cosine payload, cannot merge!");
237 B2WARNING(
"layer grouping does not match, cannot merge grouped cosine payloads!");
241 const std::vector<std::vector<double>>& rhsGroups = rhs.
getGroupCosCor();
244 B2WARNING(
"Number of cosine groups does not match, cannot merge!");
248 for (
unsigned int group = 0; group <
m_groupCosgains.size(); ++group) {
250 B2WARNING(
"Grouped cosine gain parameters do not match, cannot merge!");
257 B2WARNING(
"Cannot merge old-style and grouped cosine payloads directly!");
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()
Default constructor.
void setCosCor(unsigned int bin, double value)
Set old-style cosine correction.
double getMeanFromVector(const std::vector< double > &gains, double costh) const
Helper to interpolate/extrapolate from one vector of gains.
bool multiplyGains(std::vector< double > &lhs, const std::vector< double > &rhs) const
Multiply lhs by rhs with possible rebinning.
bool isGrouped() const
Check whether grouped mode is used.
const std::vector< std::vector< double > > & getGroupCosCor() const
Get the grouped calibration constants.
CDCDedxCosineCor & operator*=(const CDCDedxCosineCor &rhs)
Combine payloads.
std::vector< double > m_cosgains
old-style dE/dx gains in cos(theta) bins
bool isValidGroupedPayload() const
Validate grouped payload content.
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.
double getMean(unsigned int bin) const
Return dE/dx mean value for the given bin in old mode.
Abstract base class for different kinds of events.