37 m_LogLevel(ps.
get<
int>(
"LogLevel")),
38 m_BinsToAverageForRMS(ps.
get<
AdcIndex>(
"BinsToAverageForRMS")),
40 m_UseStandardDeviation(ps.
get<
bool>(
"UseStandardDeviation")),
41 m_NConsecBinsAboveThreshold1(ps.
get<
AdcIndex>(
"NConsecBinsAboveThreshold1")),
44 m_NConsecBinsAboveThreshold2(ps.
get<
AdcIndex>(
"NConsecBinsAboveThreshold2")),
49 const string myname =
"AdcDPhase3x1x1RoiBuilder::ctor: ";
51 cout << myname <<
" Configuration: " <<
endl;
76 const string myname =
"AdcDPhase3x1x1RoiBuilder:build: ";
77 if (
m_LogLevel >= 2 ) cout << myname <<
"Building ROIs for channel " 93 signal.resize(sigs.size(),
false);
102 std::vector<AdcIndex> ROIStart;
103 std::vector<AdcIndex> ROIEnd;
109 <<
" has no samples." <<
endl;
116 double SumADCMinusPedestalSquared=0.;
117 double StandardDeviationPedestal=0.;
124 SumADCMinusPedestalSquared+=
pow(sigs[isig],2);
137 if ( sig > siglow1 && isig < sigs.size()-1)
143 ROIEnd.push_back(isig-1);
147 bool KeepThisROI =
false;
149 AdcIndex NConsecBinsAboveThreshold2Count=0;
151 for(
AdcIndex isigroi = ROIStart[ROICount-1]; isigroi <= ROIEnd[ROICount-1]; isigroi++)
153 if( sigs[isigroi] >= sighigh2 )
155 NConsecBinsAboveThreshold2Count++;
156 if(NConsecBinsAboveThreshold2Count == m_NConsecBinsAboveThreshold2Temp)
164 NConsecBinsAboveThreshold2Count = 0;
172 for(
AdcIndex isigroi = ROIStart[ROICount-1]; isigroi <= ROIEnd[ROICount-1]; isigroi++)
174 if( sigs[isigroi] >= sigmax )
185 for(
AdcIndex isigroi = ROIStart[ROICount-1]; isigroi <= ROIEnd[ROICount-1]; isigroi++)
187 signal[isigroi] =
false;
200 bool ROIStartIsHere =
true;
203 if(sigs[isignext] < sighigh1 )
205 ROIStartIsHere =
false;
212 ROIStart.push_back(isig);
220 if(signal[sigs.size()-1] && !signal[sigs.size()-2])
222 signal[sigs.size()-1] =
false;
228 AdcIndex StandardDeviationIndex=sigs.size()-1;
229 AdcIndex StandardDeviationCounter=0;
235 SumADCMinusPedestalSquared=0.;
236 StandardDeviationPedestal=0.;
246 StandardDeviationCounter=0;
247 StandardDeviationIndex=sigs.size()-1;
250 if(!signal[StandardDeviationIndex])
252 SumADCMinusPedestalSquared+=
pow(sigs[StandardDeviationIndex],2);
253 StandardDeviationCounter++;
255 StandardDeviationIndex--;
264 for (
AdcIndex isig = StandardDeviationIndex; isig >=
m_BinsToSkip && isig <= StandardDeviationIndex; --isig )
266 if(signal[isig])
continue;
276 ROIEnd.push_back(isig+1);
280 bool KeepThisROI =
false;
282 AdcIndex NConsecBinsAboveThreshold2Count=0;
284 for(
AdcIndex isigroi = ROIStart[ROICount-1]; isigroi >= ROIEnd[ROICount-1]; isigroi--)
286 if( sigs[isigroi] >= sighigh2 )
288 NConsecBinsAboveThreshold2Count++;
289 if(NConsecBinsAboveThreshold2Count == m_NConsecBinsAboveThreshold2Temp)
297 NConsecBinsAboveThreshold2Count = 0;
305 for(
AdcIndex isigroi = ROIStart[ROICount-1]; isigroi >= ROIEnd[ROICount-1]; isigroi--)
307 if( sigs[isigroi] >= sigmax )
318 for(
AdcIndex isigroi = ROIStart[ROICount-1]; isigroi >= ROIEnd[ROICount-1]; isigroi--)
320 signal[isigroi] =
false;
333 bool ROIStartIsHere =
true;
336 if(sigs[isignext] < sighigh1 )
338 ROIStartIsHere =
false;
345 ROIStart.push_back(isig);
362 cout << myname <<
" ROIs before merge (size = " << rois.size() <<
"):" <<
endl;
363 for (
const AdcRoi& roi : rois ) {
364 cout << myname <<
setw(8) << roi.first <<
" " <<
setw(8) << roi.second <<
endl;
367 cout << myname <<
" ROI count before merge: " << data.
rois.size() <<
endl;
369 if ( rois.size() == 0 )
return res;
371 unsigned int isig1 = 0;
372 unsigned int isig2 = 0;
373 for (
AdcRoi roi : rois ) {
376 for (
unsigned int isig=isig1; isig<isig2; ++isig ) signal[isig] =
true;
377 isig1 = roi.second + 1;
379 if ( isig2 > nsig ) isig2 = nsig;
380 for (
unsigned int isig=isig1; isig<isig2; ++isig ) signal[isig] =
true;
386 cout << myname <<
" ROIs after merge (size = " << rois.size() <<
"):" <<
endl;
387 for (
const AdcRoi& roi : rois ) {
388 cout << myname <<
setw(8) << roi.first <<
" " <<
setw(8) << roi.second <<
endl;
391 cout << myname <<
" ROI count after merge: " << data.
rois.size() <<
endl;
AdcIndex m_NConsecBinsAboveThreshold2
std::pair< AdcIndex, AdcIndex > AdcRoi
AdcIndex m_BinsToAverageForRMS
void setInt(Name name, int val)
static int max(int a, int b)
static constexpr double ps
AdcDPhase3x1x1RoiBuilder(fhicl::ParameterSet const &ps)
Q_EXPORT QTSManip setw(int w)
std::vector< AdcRoi > AdcRoiVector
std::vector< bool > AdcFilterVector
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
AdcIndex m_NConsecBinsAboveThreshold1
bool m_UseStandardDeviation
std::vector< AdcSignal > AdcSignalVector
auto const & get(AssnsNode< L, R, D > const &r)
QTextStream & endl(QTextStream &s)
DataMap update(AdcChannelData &acd) const override
~AdcDPhase3x1x1RoiBuilder() override