Return calibration constant for cosine value.
92 {
93 if (m_largeCos.size() < 2) {
94 B2ERROR("CDCDedxCosineEdge: vector-of-vectors too short, returning 1");
95 return 1.0;
96 }
97
98 const std::vector<double>& temp = costh < 0 ? m_largeCos[0] : m_largeCos[1];
99 if (temp.size() < 2) {
100 B2ERROR("CDCDedxCosineEdge: vector too short, returning 1");
101 return 1.0;
102 }
103
104 double coslow = 0.0, coshigh = 0.0;
105 if (costh < 0) {
106 coslow = -0.870; coshigh = -0.850;
107 } else {
108 coslow = 0.950; coshigh = 0.960;
109 }
110
111
112 if (costh < coslow or costh > coshigh) {
113 return 1.0;
114 }
115
116 if (costh <= -0.866 or costh >= 0.9575) return 1.0;
117
118
119
120 int nbins = int(temp.size());
121 double binsize = (coshigh - coslow) / nbins;
122 int bin = std::floor((costh - 0.5 * binsize - coslow) / binsize);
123 if (bin < 0) bin = 0;
124 else if (bin > nbins - 2) bin = nbins - 2;
125
126
127
128
129 if (temp[bin + 1] - temp[bin] < -0.6) bin++;
130 else if (temp[bin + 1] - temp[bin] > 0.6) bin--;
131
132 if (bin < 0 or bin + 1 >= nbins) {
133 B2WARNING("CDCDedxCosineEdge:no constants for costh: " << costh << " as it is not in range");
134 return 1.0;
135 }
136
137 double frac = ((costh - 0.5 * binsize - coslow) / binsize) - bin;
138 return ((temp[bin + 1] - temp[bin]) * frac + temp[bin]);
139 }