Belle II Software development
CDCDedxADCNonLinearity.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
16namespace Belle2 {
29 class CDCDedxADCNonLinearity: public TObject {
30 public:
31
36
40 explicit CDCDedxADCNonLinearity(const std::vector<std::vector<double>>& nonlinearity): m_nonlADC(nonlinearity) {};
41
46
52 unsigned int getSize(int layer, int axis) const
53 {
54
55 unsigned int mylayer = 0;
56 if (layer < 0 || layer > 55) {
57 B2ERROR("CDCDedxADCNonLinearity:CDC layer out of range, choose between 0-55");
58 return 0;
59 } else {
60 if (layer >= 8) mylayer = 2;
61 }
62
63 if (axis < 0 || axis > 1) {
64 B2ERROR("CDCDedxADCNonLinearity:Problem with X/Y axis: choose 0/1 for X/Y");
65 return 0;
66 } else {
67 mylayer = mylayer + axis;
68 }
69
70 if (mylayer < m_nonlADC.size()) return m_nonlADC[mylayer].size();
71 return 0;
72 };
73
74
79 double getCorrectedADC(double ADC, int layer)const
80 {
81
82 unsigned 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 if (mylayer + 1 >= m_nonlADC.size()) return ADC;
91
92 const std::vector<double>& tempX = m_nonlADC[mylayer];//inner or outer X array
93 const std::vector<double>& tempY = m_nonlADC[mylayer + 1];//inner or outer Y array
94
95 if (tempX.size() < 2 or tempX.size() != tempY.size()) {
96 B2WARNING("CDCDedxADCNonLinearity:returning uncorrected ADC as parameters range don't match: X=Y in bins");
97 return ADC;
98 }
99
100 //Find bin for ADC correction
101 unsigned int ibin = TMath::BinarySearch(tempY.size(), tempY.data(), double(ADC));
102
103 if (ibin >= tempY.size() - 1) ibin = tempY.size() - 2; //overflow to last bin
104 if (ibin >= tempY.size() - 1) {
105 B2WARNING("CDCDedxADCNonLinearity:returning uncorrected ADC as bins are not in range");
106 return ADC;
107 }
108
109 double slope = (tempY[ibin + 1] - tempY[ibin]) / (tempX[ibin + 1] - tempX[ibin]);
110 return std::round(tempX[ibin] + (ADC - tempY[ibin]) / slope);
111 }
112
118 double getNonLinearityPar(int layer, int axis, unsigned int par) const
119 {
120
121 unsigned int mylayer = 0;
122 if (layer < 0 || layer > 55) {
123 B2ERROR("CDCDedxADCNonLinearity:CDC layer out of range, choose between 0-55");
124 return -99.0;
125 } else {
126 if (layer >= 8) mylayer = 2;
127 }
128
129 if (axis < 0 || axis > 1) {
130 B2ERROR("CDCDedxADCNonLinearity:Problem with X/Y axis: choose 0/1 for X/Y");
131 return -99.0;
132 } else {
133 mylayer = mylayer + axis;
134 }
135
136 if (mylayer >= m_nonlADC.size()) {
137 B2ERROR("CDCDedxADCNonLinearity: vector-of-vectors too short");
138 return -99.0;
139 }
140
141 if (par >= m_nonlADC[mylayer].size()) {
142 B2ERROR("CDCDedxADCNonLinearity:Problem with par index: choose 0 and " << m_nonlADC[mylayer].size()); //
143 return -99.0;
144 }
145
146 return m_nonlADC[mylayer][par];
147 };
148
153 void printNonLinearityPars(int layer, int axis) const
154 {
155
156 unsigned int mylayer = 0;
157 if (layer < 0 || layer > 55) {
158 B2ERROR("CDCDedxADCNonLinearity:CDC layer out of range, choose between 0-55");
159 return;
160 } else {
161 if (layer >= 8) mylayer = 2;
162 }
163
164 if (axis < 0 || axis > 1) {
165 B2ERROR("CDCDedxADCNonLinearity:Problem with X/Y axis: choose 0/1 for X/Y");
166 return;
167 } else {
168 mylayer = mylayer + axis;
169 }
170
171 if (mylayer >= m_nonlADC.size()) {
172 B2ERROR("CDCDedxADCNonLinearity: vector-of-vectors too short");
173 return;
174 }
175
176 B2INFO("Printing parameters for layer: " << layer << ", axis: " << axis << ", nPars:" << m_nonlADC[mylayer].size());
177 for (unsigned int iPar = 0; iPar < m_nonlADC[mylayer].size(); iPar++)
178 std::cout << "Par # " << iPar << ": " << m_nonlADC[mylayer][iPar] << std::endl;
179
180 };
181
188 void setNonLinearityPar(unsigned int layer, unsigned int axis, unsigned int par, double value)
189 {
190 unsigned int mylayer = 0;
191 if (layer > 55) {
192 B2ERROR("CDCDedxADCNonLinearity:CDC layer out of range, choose between 0-55");
193 return;
194 } else {
195 if (layer >= 8) mylayer = 2;
196 }
197
198 if (axis > 1) {
199 B2ERROR("CDCDedxADCNonLinearity:Problem with X/Y axis: choose 0/1 for X/Y");
200 return;
201 } else {
202 mylayer = mylayer + axis;
203 }
204
205 if (mylayer >= m_nonlADC.size()) {
206 B2ERROR("CDCDedxADCNonLinearity: vector-of-vectors too short");
207 return;
208 }
209 if (par >= m_nonlADC[mylayer].size()) {
210 B2ERROR("CDCDedxADCNonLinearity:Problem with par index: choose 0 and " << m_nonlADC[mylayer].size()); //
211 return;
212 }
213
214 //here set parameter to requested value
215 m_nonlADC[mylayer][par] = value;
216
217 };
218
219
220 private:
221 std::vector<std::vector<double>> m_nonlADC;
223 };
225} // end namespace Belle2
dE/dx electronic ADC non-linearity correction for highly ionising particles (used in offline hadron s...
ClassDef(CDCDedxADCNonLinearity, 1)
ClassDef.
CDCDedxADCNonLinearity(const std::vector< std::vector< double > > &nonlinearity)
Constructor.
std::vector< std::vector< double > > m_nonlADC
ADC vs corrected ADC mapping.
double getNonLinearityPar(int layer, int axis, unsigned int par) const
return specific hadron parameter
void setNonLinearityPar(unsigned int layer, unsigned int axis, unsigned int par, double value)
set specific hadron parameter
void printNonLinearityPars(int layer, int axis) const
print requested hadron parameter array
CDCDedxADCNonLinearity()
Default constructor.
unsigned int getSize(int layer, int axis) const
Get the number of bins for the non-linearity angle correction.
double getCorrectedADC(double ADC, int layer) const
Return corrected ADC with given parameters.
Abstract base class for different kinds of events.