16 string boolToString(
bool val) {
17 return val ?
"true" :
"false";
27 : m_LogLevel(ps.
get<
int>(
"LogLevel")),
28 m_SigFracMax(ps.
get<
float>(
"SigFracMax")),
29 m_ThresholdMin(ps.
get<
float>(
"ThresholdMin")),
30 m_ThresholdRatio(ps.
get<
float>(
"ThresholdRatio")),
31 m_ThresholdRatioTol(ps.
get<
float>(
"ThresholdRatioTol")),
32 m_MaxLoop(ps.
get<unsigned
int>(
"MaxLoop")),
33 m_BinsBefore(ps.
get<unsigned
int>(
"BinsBefore")),
34 m_BinsAfter(ps.
get<unsigned
int>(
"BinsAfter")),
35 m_FlagPositive(ps.
get<
bool>(
"FlagPositive")),
36 m_FlagNegative(ps.
get<
bool>(
"FlagNegative")) {
37 const string myname =
"AdcNoiseSignalFinder::ctor: ";
39 cout << myname <<
"Configuration parameters:" <<
endl;
56 const string myname =
"AdcNoiseSignalFinder::update: ";
68 cout << myname <<
"ERROR: No samples found in channel " << acd.
channel() <<
endl;
82 float thrTooHigh = 1.e20;
90 acd.
signal.resize(nsam,
false);
91 for (
AdcIndex isam=0; isam<nsam; ++isam ) {
96 AdcIndex jsam1 = isam > nsamlo ? isam - nsamlo : 0;
97 if ( jsam1 < isamUnknown ) jsam1 = isamUnknown;
99 if ( jsam2 > nsam ) jsam2 = nsam;
100 if (
m_LogLevel >= 5 ) cout << myname <<
"Trigger: " << isam <<
", range: [" 101 << jsam1 <<
", " << jsam2 <<
")" <<
endl;
102 for (
AdcIndex jsam=jsam1; jsam<jsam2; ++jsam ) acd.
signal[jsam] =
true;
110 for (
AdcIndex isam=0; isam<nsam; ++isam ) {
119 noise = nnsg ? sqrt(ssqsum/nnsg) : 0.0;
120 sigfrac =
float(nsig)/nsam;
124 cout << myname <<
" Loop " << nloop <<
endl;
125 cout << myname <<
" Threshold: " << thr <<
endl;
126 cout << myname <<
" Noise: " << noise <<
endl;
127 cout << myname <<
" Thr/noise: " << (noise > 0.0 ? thr/noise : -999) << endl;
128 cout << myname <<
" # ticks above threshold: " << nsamAbove <<
endl;
129 cout << myname <<
" SigFrac: " << sigfrac <<
endl;
131 cout << myname <<
" # ROI: " << acd.
rois.size() <<
endl;
134 cout << myname <<
"WARNING: Channel " << acd.
channel() <<
" exiting after " 135 << nloop <<
" loops." <<
endl;
139 float thrtgt = trtgt*noise;
140 float thrmin = trmin*noise;
141 float thrmax = trmax*noise;
148 float thrEst = thrtgt > thr ? 2.0*thrtgt : 2.0*
thr;
149 if ( thrEst < thrTooHigh ) thr = thrEst;
150 else thr = 0.5*(thr + thrTooHigh);
153 }
else if ( thrmax >= thr ) {
160 if ( thrtgt > thrTooLow ) thr = thrtgt;
161 else thr = 0.5*(thr + thrTooLow);
163 float dthrmax = 0.001*thrOld;
165 if ( fabs(thr - thrOld) < dthrmax ) {
168 string schstat = chstat==0 ?
"Good" :
170 chstat==2 ?
"Noisy" :
"UnkownStatus";
171 cout << myname <<
"WARNING: " << schstat <<
" channel " << acd.
channel()
172 <<
" exiting prematurely due to threshold convergence." <<
endl;
179 ret.
setFloat(
"nsfSigFrac", sigfrac);
182 ret.
setInt(
"nsfLoopCount", nloop);
185 acd.
metadata[
"nsfSigFrac"] = sigfrac;
188 acd.
metadata[
"nsfLoopCount"] = nloop;
void setFloat(Name name, float val)
DataMap & setStatus(int stat)
void print(std::ostream *pout) const
float m_ThresholdRatioTol
AdcNoiseSignalFinder(fhicl::ParameterSet const &ps)
DataMap view(const AdcChannelData &acd) const override
void setInt(Name name, int val)
static constexpr double ps
unsigned int m_BinsBefore
Index channelStatus() const
auto const & get(AssnsNode< L, R, D > const &r)
DataMap update(AdcChannelData &acd) const override
QTextStream & endl(QTextStream &s)