90 {
91
92 double coslow = 0.0, coshigh = 0.0;
93 std::vector<double> temp;
94
95 if (costh < 0) {
97 coslow = -0.870; coshigh = -0.850;
98 } else if (costh > 0) {
100 coslow = 0.950; coshigh = 0.960;
101 } else {
102 B2ERROR("CDCDedxCosineEdge:choose > 0 for forward and <0 for backward side");
103 return 1.0;
104 }
105
106
107 if (costh < coslow || costh > coshigh) {
108 B2WARNING("CDCDedxCosineEdge:outside range (" << costh << ")choose in between " << coslow << " and " << coshigh);
109 return 1.0;
110 }
111
112 if (costh <= -0.866 || costh >= 0.9575) return 1.0;
113
114
115
116 double binsize = (coshigh - coslow) / temp.size();
117 int bin = std::floor((costh - 0.5 * binsize - coslow) / binsize);
118
119
120
121 int thisbin = bin, nextbin = bin + 1;
122 int nbin = int(temp.size());
123 if (bin < 0 || (temp[nextbin] - temp[thisbin] < -0.6 && bin < nbin - 1)) {
124 thisbin = bin + 1; nextbin = bin + 2;
125 } else {
126 if (bin >= nbin - 1 || (temp[nextbin] - temp[thisbin] > 0.6 && bin < nbin - 1)) {
127 thisbin = bin - 1; nextbin = bin;
128 }
129 }
130
131 double frac = ((costh - 0.5 * binsize - coslow) / binsize) - thisbin;
132
133 if (thisbin < 0 || (unsigned)nextbin >= temp.size()) {
134 B2WARNING("CDCDedxCosineEdge:no constants for costh: " << costh << " as it is not in range");
135 return 1.0;
136 }
137
138 return ((temp[nextbin] - temp[thisbin]) * frac + temp[thisbin]);
139 }