Belle II Software development
CDCDedxCosineCor.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#include <cmath>
15
16namespace Belle2 {
26 class CDCDedxCosineCor: public TObject {
27
28 public:
29
34
39 explicit CDCDedxCosineCor(const std::vector<double>& cosgains): m_cosgains(cosgains) {};
40
45
50 {
51 if (m_cosgains.size() % rhs.getSize() != 0) {
52 B2WARNING("Cosine gain parameters do not match, cannot merge!");
53 return *this;
54 }
55 std::vector<double> rhsgains = rhs.getCosCor();
56 int scale = std::floor(m_cosgains.size() / rhs.getSize() + 0.001);
57 for (unsigned int bin = 0; bin < m_cosgains.size(); ++bin) {
58 m_cosgains[bin] *= rhsgains[std::floor(bin / scale + 0.001)];
59 }
60 return *this;
61 }
62
67 unsigned int getSize() const { return m_cosgains.size(); };
68
73 const std::vector<double>& getCosCor() const {return m_cosgains; };
74
80 void setCosCor(unsigned int bin, double value)
81 {
82 if (bin < m_cosgains.size()) m_cosgains[bin] = value;
83 else B2ERROR("CDCDedxCosineCor: invalid bin number, value not set");
84 }
85
91 double getMean(unsigned int bin) const
92 {
93 if (bin < m_cosgains.size()) return m_cosgains[bin];
94 return 1.0;
95 }
96
102 double getMean(double costh) const
103 {
104 if (std::abs(costh) > 1) return 0;
105
106 // gains are stored at the center of the bins
107 // find the bin center immediately preceding this value of costh
108 double binsize = 2.0 / m_cosgains.size();
109 int bin = std::floor((costh - 0.5 * binsize + 1.0) / binsize);
110
111 // extrapolation
112 // extrapolate backward for lowest half-bin and center positive half-bin
113 // extrapolate forward for highest half-bin and center negative half-bin
114 int thisbin = bin, nextbin = bin + 1;
115 if ((costh + 1) < (binsize / 2) || (costh > 0 && std::fabs(costh) < (binsize / 2))) {
116 thisbin = bin + 1; nextbin = bin + 2;
117 } else {
118 if ((costh - 1) > -1.0 * (binsize / 2) || (costh < 0 && std::fabs(costh) < (binsize / 2))) {
119 thisbin = bin - 1; nextbin = bin;
120 }
121 }
122 double frac = ((costh - 0.5 * binsize + 1.0) / binsize) - thisbin;
123
124 if (thisbin < 0 || (unsigned)nextbin >= m_cosgains.size()) {
125 B2WARNING("Problem with extrapolation of CDC dE/dx cosine correction");
126 return 1.0;
127 }
128 return ((m_cosgains[nextbin] - m_cosgains[thisbin]) * frac + m_cosgains[thisbin]);
129 };
130
131 private:
132 std::vector<double> m_cosgains;
135 };
137} // end namespace Belle2
dE/dx wire gain calibration constants
CDCDedxCosineCor()
Default constructor.
void setCosCor(unsigned int bin, double value)
Set the cosine correction.
double getMean(double costh) const
Return dE/dx mean value for given cos(theta)
CDCDedxCosineCor(const std::vector< double > &cosgains)
Constructor.
CDCDedxCosineCor & operator*=(CDCDedxCosineCor const &rhs)
Combine payloads.
std::vector< double > m_cosgains
dE/dx gains in cos(theta) bins
const std::vector< double > & getCosCor() const
Get the calibration constants.
ClassDef(CDCDedxCosineCor, 8)
ClassDef.
double getMean(unsigned int bin) const
Return dE/dx mean value for the given bin.
unsigned int getSize() const
Get the number of bins for the cosine correction.
Abstract base class for different kinds of events.