Belle II Software  release-05-01-25
CDCDedxADCNonLinearity.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 {
30  class CDCDedxADCNonLinearity: public TObject {
31  public:
32 
37 
41  explicit CDCDedxADCNonLinearity(const std::vector<std::vector<double>>& nonlinearity): m_nonlADC(nonlinearity) {};
42 
47 
53  unsigned int getSize(int layer, int axis) const
54  {
55 
56  int mylayer = 0;
57  if (layer < 0 || layer > 55) {
58  B2ERROR("CDCDedxADCNonLinearity:CDC layer out of range, choose between 0-55");
59  return 0;
60  } else {
61  if (layer >= 8) mylayer = 2;
62  }
63 
64  if (axis < 0 || axis > 1) {
65  B2ERROR("CDCDedxADCNonLinearity:Problem with X/Y axis: choose 0/1 for X/Y");
66  return 0;
67  } else {
68  mylayer = mylayer + axis;
69  }
70 
71  return m_nonlADC[mylayer].size();
72  };
73 
74 
79  double getCorrectedADC(const double& ADC, const int layer)const
80  {
81 
82  int mylayer = 0;
83  if (layer < 0 || layer > 55) {
84  B2WARNING("CDCDedxADCNonLinearity:returning uncorrected ADC as input layer is out of range: must be 0-55");
85  return ADC;
86  } else {
87  if (layer >= 8) mylayer = 2;
88  }
89 
90  std::vector<double> tempX = m_nonlADC[mylayer];//inner or outer X array
91  std::vector<double> tempY = m_nonlADC[mylayer + 1];//inner or outer Y array
92 
93  if (tempX.size() != tempY.size()) {
94  B2WARNING("CDCDedxADCNonLinearity:returning uncorrected ADC as parameters range don't match: X=Y in bins");
95  return ADC;
96  }
97 
98  //Find bin for ADC correction
99  unsigned int ibin = TMath::BinarySearch(tempY.size(), tempY.data(), double(ADC));
100 
101  if (ibin >= tempY.size() - 1)ibin = tempY.size() - 2; //overflow to last bin
102  if (ibin >= tempY.size() - 1) {
103  B2WARNING("CDCDedxADCNonLinearity:returning uncorrected ADC as bins are not in range");
104  return ADC;
105  }
106 
107  double slope = (tempY[ibin + 1] - tempY[ibin]) / (tempX[ibin + 1] - tempX[ibin]);
108  return std::round(tempX[ibin] + (ADC - tempY[ibin]) / slope);
109  }
110 
116  double getNonLinearityPar(int layer, int axis, unsigned int par) const
117  {
118 
119  int mylayer = 0;
120  if (layer < 0 || layer > 55) {
121  B2ERROR("CDCDedxADCNonLinearity:CDC layer out of range, choose between 0-55");
122  return -99.0;
123  } else {
124  if (layer >= 8) mylayer = 2;
125  }
126 
127  if (axis < 0 || axis > 1) {
128  B2ERROR("CDCDedxADCNonLinearity:Problem with X/Y axis: choose 0/1 for X/Y");
129  return -99.0;
130  } else {
131  mylayer = mylayer + axis;
132  }
133 
134  if (par >= m_nonlADC[mylayer].size()) {
135  B2ERROR("CDCDedxADCNonLinearity:Problem with par index: choose 0 and " << m_nonlADC[mylayer].size()); //
136  return -99.0;
137  }
138 
139  return m_nonlADC[mylayer][par];
140  };
141 
146  void printNonLinearityPars(int layer, int axis) const
147  {
148 
149  int mylayer = 0;
150  if (layer < 0 || layer > 55) {
151  B2ERROR("CDCDedxADCNonLinearity:CDC layer out of range, choose between 0-55");
152  return;
153  } else {
154  if (layer >= 8) mylayer = 2;
155  }
156 
157  if (axis < 0 || axis > 1) {
158  B2ERROR("CDCDedxADCNonLinearity:Problem with X/Y axis: choose 0/1 for X/Y");
159  return;
160  } else {
161  mylayer = mylayer + axis;
162  }
163 
164  B2INFO("Printing parameters for layer: " << layer << ", axis: " << axis << ", nPars:" << m_nonlADC[mylayer].size());
165  for (unsigned int iPar = 0; iPar < m_nonlADC[mylayer].size(); iPar++)
166  std::cout << "Par # " << iPar << ": " << m_nonlADC[mylayer][iPar] << std::endl;
167 
168  };
169 
176  void setNonLinearityPar(unsigned int layer, unsigned int axis, unsigned int par, double value)
177  {
178  int mylayer = 0;
179  if (layer > 55) {
180  B2ERROR("CDCDedxADCNonLinearity:CDC layer out of range, choose between 0-55");
181  return;
182  } else {
183  if (layer >= 8) mylayer = 2;
184  }
185 
186  if (axis > 1) {
187  B2ERROR("CDCDedxADCNonLinearity:Problem with X/Y axis: choose 0/1 for X/Y");
188  return;
189  } else {
190  mylayer = mylayer + axis;
191  }
192 
193  if (par >= m_nonlADC[mylayer].size()) {
194  B2ERROR("CDCDedxADCNonLinearity:Problem with par index: choose 0 and " << m_nonlADC[mylayer].size()); //
195  }
196 
197  //here set parameter to requested value
198  m_nonlADC[mylayer][par] = value;
199 
200  };
201 
202 
203  private:
204  std::vector<std::vector<double>> m_nonlADC;
206  };
208 } // end namespace Belle2
Belle2::CDCDedxADCNonLinearity::m_nonlADC
std::vector< std::vector< double > > m_nonlADC
ADC vs corrected ADC mapping.
Definition: CDCDedxADCNonLinearity.h:207
Belle2::CDCDedxADCNonLinearity::~CDCDedxADCNonLinearity
~CDCDedxADCNonLinearity()
Destructor.
Definition: CDCDedxADCNonLinearity.h:53
Belle2::CDCDedxADCNonLinearity::ClassDef
ClassDef(CDCDedxADCNonLinearity, 1)
ClassDef.
Belle2::CDCDedxADCNonLinearity::getCorrectedADC
double getCorrectedADC(const double &ADC, const int layer) const
Return corrected ADC with given parameters.
Definition: CDCDedxADCNonLinearity.h:86
Belle2::CDCDedxADCNonLinearity::getNonLinearityPar
double getNonLinearityPar(int layer, int axis, unsigned int par) const
return specific hadron parameter
Definition: CDCDedxADCNonLinearity.h:123
Belle2::CDCDedxADCNonLinearity::CDCDedxADCNonLinearity
CDCDedxADCNonLinearity()
Default constructor.
Definition: CDCDedxADCNonLinearity.h:43
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::CDCDedxADCNonLinearity::getSize
unsigned int getSize(int layer, int axis) const
Get the number of bins for the non-linearity angle correction.
Definition: CDCDedxADCNonLinearity.h:60
Belle2::CDCDedxADCNonLinearity::setNonLinearityPar
void setNonLinearityPar(unsigned int layer, unsigned int axis, unsigned int par, double value)
set specific hadron parameter
Definition: CDCDedxADCNonLinearity.h:183
Belle2::CDCDedxADCNonLinearity::printNonLinearityPars
void printNonLinearityPars(int layer, int axis) const
print requested hadron parameter array
Definition: CDCDedxADCNonLinearity.h:153