37 m_LogLevel(ps.
get<
int>(
"LogLevel")),
38 m_BinsToAverageForPedestal(ps.
get<
AdcIndex>(
"BinsToAverageForPedestal")),
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 =
"AdcDPhase3x1x1LocalRoiBuilder::ctor: ";
51 cout << myname <<
" Configuration: " <<
endl;
76 const string myname =
"AdcDPhase3x1x1LocalRoiBuilder: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 SumPedestal=0.;
117 double SumADCMinusPedestalSquared=0.;
118 double StandardDeviationPedestal=0.;
124 SumPedestal+=sigs[isig];
152 ROIEnd.push_back(isig-1);
156 bool KeepThisROI =
false;
158 AdcIndex NConsecBinsAboveThreshold2Count=0;
160 for(
AdcIndex isigroi = ROIStart[ROICount-1]; isigroi <= ROIEnd[ROICount-1]; isigroi++)
164 NConsecBinsAboveThreshold2Count++;
165 if(NConsecBinsAboveThreshold2Count == m_NConsecBinsAboveThreshold2Temp)
173 NConsecBinsAboveThreshold2Count = 0;
181 for(
AdcIndex isigroi = ROIStart[ROICount-1]; isigroi <= ROIEnd[ROICount-1]; isigroi++)
194 for(
AdcIndex isigroi = ROIStart[ROICount-1]; isigroi <= ROIEnd[ROICount-1]; isigroi++)
196 signal[isigroi] =
false;
198 SumPedestal -= sigs[FirstEntryInPedestalSum];
199 FirstEntryInPedestalSum++;
200 while(signal[FirstEntryInPedestalSum])
202 FirstEntryInPedestalSum++;
204 SumPedestal += sigs[isigroi];
214 SumPedestal -= sigs[FirstEntryInPedestalSum];
216 FirstEntryInPedestalSum++;
217 while(signal[FirstEntryInPedestalSum])
219 FirstEntryInPedestalSum++;
222 SumPedestal += sigs[isig];
227 bool ROIStartIsHere =
true;
232 ROIStartIsHere =
false;
239 ROIStart.push_back(isig);
245 SumPedestal -= sigs[FirstEntryInPedestalSum];
247 FirstEntryInPedestalSum++;
248 while(signal[FirstEntryInPedestalSum])
250 FirstEntryInPedestalSum++;
253 SumPedestal += sigs[isig];
259 if(signal[sigs.size()-1] && !signal[sigs.size()-2])
261 signal[sigs.size()-1] =
false;
267 AdcIndex PedestalIndex=sigs.size()-1;
275 SumADCMinusPedestalSquared=0.;
276 StandardDeviationPedestal=0.;
278 FirstEntryInPedestalSum=0;
287 if(!signal[PedestalIndex])
289 if(PedestalCounter == 0) FirstEntryInPedestalSum=PedestalIndex;
290 SumPedestal+=sigs[PedestalIndex];
300 PedestalIndex=sigs.size()-1;
303 if(!signal[PedestalIndex])
317 for (
AdcIndex isig = PedestalIndex; isig >= m_BinsToSkip && isig <= PedestalIndex; --isig )
319 if(signal[isig])
continue;
329 ROIEnd.push_back(isig+1);
333 bool KeepThisROI =
false;
335 AdcIndex NConsecBinsAboveThreshold2Count=0;
337 for(
AdcIndex isigroi = ROIStart[ROICount-1]; isigroi >= ROIEnd[ROICount-1]; isigroi--)
341 NConsecBinsAboveThreshold2Count++;
342 if(NConsecBinsAboveThreshold2Count == m_NConsecBinsAboveThreshold2Temp)
350 NConsecBinsAboveThreshold2Count = 0;
358 for(
AdcIndex isigroi = ROIStart[ROICount-1]; isigroi >= ROIEnd[ROICount-1]; isigroi--)
371 for(
AdcIndex isigroi = ROIStart[ROICount-1]; isigroi >= ROIEnd[ROICount-1]; isigroi--)
373 signal[isigroi] =
false;
375 SumPedestal -= sigs[FirstEntryInPedestalSum];
376 FirstEntryInPedestalSum--;
377 while(signal[FirstEntryInPedestalSum])
379 FirstEntryInPedestalSum--;
381 SumPedestal += sigs[isigroi];
390 SumPedestal -= sigs[FirstEntryInPedestalSum];
392 FirstEntryInPedestalSum--;
393 while(signal[FirstEntryInPedestalSum])
395 FirstEntryInPedestalSum--;
398 SumPedestal += sigs[isig];
404 bool ROIStartIsHere =
true;
409 ROIStartIsHere =
false;
416 ROIStart.push_back(isig);
422 SumPedestal -= sigs[FirstEntryInPedestalSum];
423 FirstEntryInPedestalSum--;
425 while(signal[FirstEntryInPedestalSum])
427 FirstEntryInPedestalSum--;
429 SumPedestal += sigs[isig];
435 if(signal[m_BinsToSkip] && !signal[m_BinsToSkip+1])
444 cout << myname <<
" ROIs before merge (size = " << rois.size() <<
"):" <<
endl;
445 for (
const AdcRoi& roi : rois ) {
446 cout << myname <<
setw(8) << roi.first <<
" " <<
setw(8) << roi.second <<
endl;
449 cout << myname <<
" ROI count before merge: " << data.
rois.size() <<
endl;
451 if ( rois.size() == 0 )
return res;
453 unsigned int isig1 = 0;
454 unsigned int isig2 = 0;
455 for (
AdcRoi roi : rois ) {
458 for (
unsigned int isig=isig1; isig<isig2; ++isig ) signal[isig] =
true;
459 isig1 = roi.second + 1;
461 if ( isig2 > nsig ) isig2 = nsig;
462 for (
unsigned int isig=isig1; isig<isig2; ++isig ) signal[isig] =
true;
468 cout << myname <<
" ROIs after merge (size = " << rois.size() <<
"):" <<
endl;
469 for (
const AdcRoi& roi : rois ) {
470 cout << myname <<
setw(8) << roi.first <<
" " <<
setw(8) << roi.second <<
endl;
473 cout << myname <<
" ROI count after merge: " << data.
rois.size() <<
endl;
AdcIndex m_NConsecBinsAboveThreshold1
bool m_UseStandardDeviation
AdcIndex m_NConsecBinsAboveThreshold2
~AdcDPhase3x1x1LocalRoiBuilder() override
std::pair< AdcIndex, AdcIndex > AdcRoi
void setInt(Name name, int val)
AdcIndex m_BinsToAverageForPedestal
static int max(int a, int b)
static constexpr double 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)
std::vector< AdcSignal > AdcSignalVector
AdcDPhase3x1x1LocalRoiBuilder(fhicl::ParameterSet const &ps)
auto const & get(AssnsNode< L, R, D > const &r)
DataMap update(AdcChannelData &acd) const override
QTextStream & endl(QTextStream &s)