67 const string myname =
"AdcCodeMitigator::view: ";
69 Index nsam = acd.samples.size();
70 if ( acd.flags.size() != acd.samples.size() ) {
71 cout << myname <<
"ERROR: Flag and sample sizes disagree: " 72 << acd.flags.size() <<
" != " << nsam <<
endl;
77 for (
Index isam=0; isam<nsam; ++isam ) {
81 acd.samples[isam] = 0.0;
92 for (
Index isam=0; isam<nsam; ++isam ) {
99 haveLo2 = isamLo1 != isamLo2;
105 bool haveHi1 = isamHi1 > isam && isamHi1 < nsam;
106 if ( ! haveHi1 && isamHi1 < nsam ) {
108 while ( !haveHi1 && ++isamHi1 < nsam ) haveHi1 =
m_skipSet.find(acd.flags[isamHi1]) ==
m_skipSet.end();
110 bool haveHi2 =
false;
112 haveHi2 = isamHi2 > isamHi1 && isamHi2 < nsam;
115 while ( !haveHi2 && ++isamHi2 < nsam ) haveHi2 =
m_skipSet.find(acd.flags[isamHi2]) ==
m_skipSet.end();
116 if ( ! haveHi2 ) isamHi2 = isamHi1;
120 cout << myname <<
"Samples: " << isamLo2 <<
" " << isamLo1 <<
" | " << isam
121 <<
" | " << isamHi1 <<
" " << isamHi2 <<
endl;
128 double ylo1 = acd.samples[isamLo1];
129 double ylo2 = acd.samples[isamLo2];
130 double yhi1 = acd.samples[isamHi1];
131 double yhi2 = acd.samples[isamHi2];
137 double adiflo = fabs(ylo2 - ylo1);
138 double adifhi = fabs(yhi2 - yhi1);
142 cout << myname <<
"Lo, hi jumps for sample " << isam <<
": " << adiflo <<
", " << adifhi <<
endl;
144 if ( doFixedCurvature ) {
156 int jlo2 =
int(isamLo2) -
int(isamLo1);
157 int jhi2 =
int(isamHi2) -
int(isamLo1);
158 int klo2 =
int(isamLo2) -
int(isamHi1);
159 int khi2 =
int(isamHi2) -
int(isamHi1);
160 double a = yhi1/(isamHi1 - isamLo1);
161 double b = -ylo1/(isamHi1 - isamLo1);
165 double w0 = acd.pedestalRms;
166 if ( w0 < 1.0 ) w0 = 1.0;
167 double wlo = adifhi + w0;
168 double whi = adiflo + w0;
169 double den = wlo*jlo2*klo2 + whi*jhi2*khi2;
173 double num = wlo*ylo2 + whi*yhi2 - a*(wlo*jlo2+whi*jhi2) - b*(wlo*klo2+whi*khi2);
176 cout << myname <<
"Quadratic interpolation for sample " << isam <<
endl;
177 cout << myname <<
" isamLo2: " << isamLo2 <<
endl;
178 cout << myname <<
" isamLo1: " << isamLo1 <<
endl;
179 cout << myname <<
" isamHi1: " << isamHi1 <<
endl;
180 cout << myname <<
" isamHi2: " << isamHi2 <<
endl;
181 cout << myname <<
" ylo2: " << ylo2 <<
endl;
182 cout << myname <<
" ylo1: " << ylo1 <<
endl;
183 cout << myname <<
" yhi1: " << yhi1 <<
endl;
184 cout << myname <<
" yhi2: " << yhi2 <<
endl;
185 cout << myname <<
" a: " << a <<
endl;
186 cout << myname <<
" b: " << b <<
endl;
187 cout << myname <<
" c: " << c <<
endl;
189 int jsam = isam - isamLo1;
190 int ksam = isam - isamHi1;
191 y = a*jsam + b*ksam + c*jsam*ksam;
195 cout << myname <<
"Skipping quadratic interpolation for den=0 for sample " << isam <<
endl;
202 if (
m_LogLevel >= 3 ) cout << myname <<
"Quadratic interpolation: isam=" << isam
203 <<
": [" << isamLo1 <<
"], [" << isamHi1 <<
"] ==> " << y <<
endl;
204 }
else if ( haveLo1 && haveHi1 ) {
205 double ylo = acd.samples[isamLo1];
206 double yhi = acd.samples[isamHi1];
207 double x01 = isam - isamLo1;
208 double x12 = isamHi1 - isamLo1;
209 y = ylo + (yhi - ylo)*x01/x12;
211 if (
m_LogLevel >= 3 ) cout << myname <<
"Linear interpolating isam=" << isam
212 <<
": [" << isamLo1 <<
"], [" << isamHi1 <<
"] ==> " << y <<
endl;
214 }
else if ( haveLo1 ) {
215 y = acd.samples[isamLo1];
217 if (
m_LogLevel >= 3 ) cout << myname <<
"Setting low extrapolation for isam=" << isam
218 <<
": [" << isamLo1 <<
"] = " << y <<
endl;
220 }
else if ( haveHi1 ) {
221 y = acd.samples[isamHi1];
223 if (
m_LogLevel >= 3 ) cout << myname <<
"Setting high extrapolation for isam=" << isam
224 <<
": [" << isamHi1 <<
"] = " << y <<
endl;
229 acd.samples[isam] =
y;
230 acd.flags[isam] = iflg;
233 ret.
setInt(
"mitCount", mitCount);
DataMap & setStatus(int stat)
const AdcFlag AdcSetFixed
void setInt(Name name, int val)
const AdcFlag AdcExtrapolated
IndexSet m_interpolateSet
const AdcFlag AdcInterpolated
QTextStream & endl(QTextStream &s)