10 using std::istringstream;
21 : m_LogLevel(ps.
get<
int>(
"LogLevel")),
25 m_FixedCurvThresh(ps.
get<double>(
"FixedCurvThresh")) {
26 const string myname =
"AdcCodeMitigator::ctor: ";
29 cout << myname <<
"Configuration: " <<
endl;
31 cout << myname <<
" FixFlags: [";
34 if ( ! first ) cout <<
", ";
38 cout << myname <<
" InterpolateFlags: [";
41 if ( ! first ) cout <<
", ";
46 cout << myname <<
" SkipFlags: [";
49 if ( ! first ) cout <<
", ";
67 const string myname =
"AdcCodeMitigator::view: ";
71 cout << myname <<
"ERROR: Flag and sample sizes disagree: " 72 << acd.
flags.size() <<
" != " << nsam <<
endl;
77 for (
Index isam=0; isam<nsam; ++isam ) {
92 for (
Index isam=0; isam<nsam; ++isam ) {
99 haveLo2 = isamLo1 != isamLo2;
105 bool haveHi1 = isamHi1 > isam && isamHi1 < nsam;
106 if ( ! haveHi1 && isamHi1 < nsam ) {
110 bool haveHi2 =
false;
112 haveHi2 = isamHi2 > isamHi1 && isamHi2 < nsam;
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);
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 ) {
217 if (
m_LogLevel >= 3 ) cout << myname <<
"Setting low extrapolation for isam=" << isam
218 <<
": [" << isamLo1 <<
"] = " << y <<
endl;
220 }
else if ( haveHi1 ) {
223 if (
m_LogLevel >= 3 ) cout << myname <<
"Setting high extrapolation for isam=" << isam
224 <<
": [" << isamHi1 <<
"] = " << y <<
endl;
230 acd.
flags[isam] = iflg;
233 ret.
setInt(
"mitCount", mitCount);
std::vector< Index > IndexVector
DataMap & setStatus(int stat)
ChannelGroupService::Name Name
const AdcFlag AdcSetFixed
AdcCodeMitigator(fhicl::ParameterSet const &ps)
IndexVector m_InterpolateFlags
void setInt(Name name, int val)
const AdcFlag AdcExtrapolated
IndexSet m_interpolateSet
static constexpr double ps
const AdcFlag AdcInterpolated
DataMap update(AdcChannelData &acds) const override
auto const & get(AssnsNode< L, R, D > const &r)
QTextStream & endl(QTextStream &s)