Belle II Software  release-06-00-14
CDCDedxCosineEdge.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 #include <TObject.h>
11 #include <vector>
12 #include <cmath>
13 #include <framework/logging/Logger.h>
14 #include <iostream>
15 
16 namespace Belle2 {
27  class CDCDedxCosineEdge: public TObject {
28  public:
29 
34 
38  explicit CDCDedxCosineEdge(const std::vector<std::vector<double>>& largecosth): m_largeCos(largecosth) {};
39 
44 
49  int getSize(const int side) const
50  {
51  if (side < 0) {
52  return m_largeCos[0].size();
53  } else if (side > 0) {
54  return m_largeCos[1].size();
55  } else {
56  B2ERROR("CDCDedxCosineEdge:choose >0 for forward and <0 for backward side");
57  return 0;
58  }
59  };
60 
61 
66  double getMean(int side, unsigned int ibin) const
67  {
68 
69  std::vector<double> temp;
70  if (side < 0) {
71  temp = m_largeCos[0];
72  } else if (side > 0) {
73  temp = m_largeCos[1];
74  } else {
75  B2ERROR("CDCDedxCosineEdge:choose > 0 for forward and <0 for backward side");
76  return 1.0;
77  }
78 
79  if (ibin >= temp.size()) { //index starts from zero
80  B2WARNING("CDCDedxADCNonLinearity:returning (1.0) uncorrected ADC as bin: " << ibin << " is not in range");
81  return 1.0;
82  }
83  return temp[ibin];
84  };
85 
89  double getMean(double costh)const
90  {
91  double coslow = 0.0, coshigh = 0.0;
92  std::vector<double> temp;
93  if (costh < 0) {
94  temp = m_largeCos[0];
95  coslow = -0.870; coshigh = -0.850; //this is hardcoded and fixed
96  } else if (costh > 0) {
97  temp = m_largeCos[1];
98  coslow = 0.950; coshigh = 0.960; //this is hardcoded and fixed
99  } else {
100  B2ERROR("CDCDedxCosineEdge:choose > 0 for forward and <0 for backward side");
101  return 1.0;
102  }
103 
104  //don't do anything for other cosine range
105  if (costh < coslow || costh > coshigh) {
106  B2WARNING("CDCDedxCosineEdge:outside range (" << costh << ")choose in between " << coslow << " and " << coshigh);
107  return 1.0;
108  }
109 
110  double bw = abs(coshigh - coslow) / temp.size();
111  unsigned int ibin = int((costh - coslow) / bw);
112 
113  if (ibin >= temp.size()) {
114  B2WARNING("CDCDedxCosineEdge:no constants for bin ## " << ibin << " as it is not in range");
115  return 1.0;
116  }
117 
118  //nothing but a protection only
119  if (temp[ibin] <= 0.0)return 1.0;
120 
121  return temp[ibin];
122  }
123 
128  double getCosEdgePar(int side, unsigned int ibin) const
129  {
130 
131  std::vector<double> temp;
132  double coslow = 0.0, coshigh = 0.0;
133  if (side < 0) {
134  temp = m_largeCos[0];
135  coslow = -0.870; coshigh = -0.850;
136  } else if (side > 0) {
137  temp = m_largeCos[1];
138  coslow = 0.950; coshigh = 0.960;
139  } else {
140  B2ERROR("CDCDedxCosineEdge:choose > 0 for forward and <0 for backward side");
141  return -99.0;
142  }
143 
144  if (ibin >= temp.size()) {
145  B2ERROR("CDCDedxCosineEdge:Problem with bin index: choose 0 and " << temp.size() - 1); //
146  return -99.0;
147  }
148 
149  if (temp.size() == 0)return -99.0;
150  double bw = abs(coshigh - coslow) / temp.size();
151  double bc = coslow + (0.5 + ibin) * bw; //bin centre
152  std::cout << "Par # " << ibin << ", costh bin centre = " << bc << ", const =" << temp[ibin] << std::endl;
153  return temp[ibin];
154  };
155 
156 
160  void printCosEdgePars(int side)
161  {
162  std::vector<double> temp;
163  double coslow = 0.0, coshigh = 0.0;
164  if (side < 0) {
165  temp = m_largeCos[0];
166  coslow = -0.870; coshigh = -0.850;
167  } else if (side > 0) {
168  temp = m_largeCos[1];
169  coslow = 0.950; coshigh = 0.960;
170  } else {
171  B2ERROR("CDCDedxCosineEdge:choose > 0 for forward and <0 for backward side");
172  return;
173  }
174 
175  if (temp.size() == 0)return;
176  double bw = abs(coshigh - coslow) / temp.size();
177  B2INFO("Printing parameters (0=backward and 1=forward): " << side << ", nPars = " << temp.size());
178  for (unsigned int ibin = 0; ibin < temp.size(); ibin++) {
179  double bc = coslow + (0.5 + ibin) * bw; //bin centre
180  std::cout << "Par # " << ibin << ", costh bin centre = " << bc << ", const = " << temp[ibin] << std::endl;
181  }
182  temp.clear();
183  };
184 
185 
191  void setCosthEdgePar(int side, unsigned int ibin, double value)
192  {
193  int iside = -99.0;
194  if (side < 0) {
195  iside = 0;
196  } else if (side > 0) {
197  iside = 1;
198  } else {
199  B2ERROR("CDCDedxCosineEdge:choose >0 for forward and <0 for backward side");
200  return;
201  }
202 
203  if (ibin >= m_largeCos[iside].size()) {
204  B2ERROR("CDCDedxCosineEdge:Problem with bin index: choose 0 and " << m_largeCos[iside].size() - 1); //
205  return;
206  }
207 
208  m_largeCos[iside][ibin] = value;
209  std::cout << "Par # " << ibin << ", const = " << m_largeCos[iside][ibin] << std::endl;
210  };
211 
212 
213  private:
214  std::vector<std::vector<double>> m_largeCos;
216  };
218 } // end namespace Belle2
dE/dx special large cosine calibration to fix bending shoulder at large costh
CDCDedxCosineEdge()
Default constructor.
ClassDef(CDCDedxCosineEdge, 1)
ClassDef.
double getCosEdgePar(int side, unsigned int ibin) const
return specific large cosine constants on give side
void setCosthEdgePar(int side, unsigned int ibin, double value)
set specific hadron parameter
double getMean(int side, unsigned int ibin) const
return calibration constant for given side and bin #
double getMean(double costh) const
return calibration constant for cosine value
void printCosEdgePars(int side)
print large cosine constants array on requested side
CDCDedxCosineEdge(const std::vector< std::vector< double >> &largecosth)
Constructor.
std::vector< std::vector< double > > m_largeCos
ADC vs corrected ADC mapping.
int getSize(const int side) const
Get the number of bins of requested side.
Abstract base class for different kinds of events.