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