Belle II Software  release-05-01-25
CDCDedxCosineCor.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Jake Bennett *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <framework/logging/Logger.h>
14 
15 #include <TObject.h>
16 #include <cmath>
17 
18 namespace Belle2 {
28  class CDCDedxCosineCor: public TObject {
29 
30  public:
31 
36 
40  explicit CDCDedxCosineCor(const std::vector<double>& cosgains): m_cosgains(cosgains) {};
41 
45  ~CDCDedxCosineCor() {};
46 
51  {
52  if (m_cosgains.size() % rhs.getSize() != 0) {
53  B2WARNING("Cosine gain parameters do not match, cannot merge!");
54  return *this;
55  }
56  std::vector<double> rhsgains = rhs.getCosCor();
57  int scale = std::floor(m_cosgains.size() / rhs.getSize() + 0.001);
58  for (unsigned int bin = 0; bin < m_cosgains.size(); ++bin) {
59  m_cosgains[bin] *= rhsgains[std::floor(bin / scale + 0.001)];
60  }
61  return *this;
62  }
63 
66  unsigned int getSize() const { return m_cosgains.size(); };
67 
70  std::vector<double> getCosCor() const {return m_cosgains; };
71 
74  void setCosCor(int bin, double value)
75  {
76  m_cosgains[bin] = value;
77  }
78 
82  double getMean(unsigned int bin) const
83  {
84  if (bin > m_cosgains.size()) return 1.0;
85  else return m_cosgains[bin];
86  }
87 
91  double getMean(double costh) const
92  {
93  if (std::abs(costh) > 1) return 0;
94 
95  // gains are stored at the center of the bins
96  // find the bin center immediately preceding this value of costh
97  double binsize = 2.0 / m_cosgains.size();
98  int bin = std::floor((costh - 0.5 * binsize + 1.0) / binsize);
99 
100  // extrapolation
101  // extrapolate backward for lowest half-bin and center positive half-bin
102  // extrapolate forward for highest half-bin and center negative half-bin
103  int thisbin = bin, nextbin = bin + 1;
104  if ((costh + 1) < (binsize / 2) || (costh > 0 && std::fabs(costh) < (binsize / 2))) {
105  thisbin = bin + 1; nextbin = bin + 2;
106  } else {
107  if ((costh - 1) > -1.0 * (binsize / 2) || (costh < 0 && std::fabs(costh) < (binsize / 2))) {
108  thisbin = bin - 1; nextbin = bin;
109  }
110  }
111  double frac = ((costh - 0.5 * binsize + 1.0) / binsize) - thisbin;
112 
113  if (thisbin < 0 || (unsigned)nextbin >= m_cosgains.size()) {
114  B2WARNING("Problem with extrapolation of CDC dE/dx cosine correction");
115  return 1.0;
116  }
117  return ((m_cosgains[nextbin] - m_cosgains[thisbin]) * frac + m_cosgains[thisbin]);
118  };
119 
120  private:
121  std::vector<double> m_cosgains;
124  };
126 } // end namespace Belle2
Belle2::CDCDedxCosineCor::m_cosgains
std::vector< double > m_cosgains
dE/dx gains in cos(theta) bins
Definition: CDCDedxCosineCor.h:126
Belle2::CDCDedxCosineCor::operator*=
CDCDedxCosineCor & operator*=(CDCDedxCosineCor const &rhs)
Combine payloads.
Definition: CDCDedxCosineCor.h:58
Belle2::CDCDedxCosineCor::~CDCDedxCosineCor
~CDCDedxCosineCor()
Destructor.
Definition: CDCDedxCosineCor.h:53
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::CDCDedxCosineCor::setCosCor
void setCosCor(int bin, double value)
Set the cosine correction.
Definition: CDCDedxCosineCor.h:82
Belle2::CDCDedxCosineCor::CDCDedxCosineCor
CDCDedxCosineCor()
Default constructor.
Definition: CDCDedxCosineCor.h:43
Belle2::CDCDedxCosineCor::getCosCor
std::vector< double > getCosCor() const
Get the cosine correction.
Definition: CDCDedxCosineCor.h:78
Belle2::CDCDedxCosineCor::getMean
double getMean(unsigned int bin) const
Return dE/dx mean value for the given bin.
Definition: CDCDedxCosineCor.h:90
Belle2::CDCDedxCosineCor::ClassDef
ClassDef(CDCDedxCosineCor, 8)
ClassDef.
Belle2::CDCDedxCosineCor::getSize
unsigned int getSize() const
Get the number of bins for the cosine correction.
Definition: CDCDedxCosineCor.h:74