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