391 PlaneIDToDataPairMap::const_iterator mapItr = planeIDToDataPairMap.find(planeID);
393 if (mapItr == planeIDToDataPairMap.end())
395 std::cout <<
"We know this cannot happen" << std::endl;
401 const icarus_signal_processing::ArrayFloat& dataArray = planeIDToDataPair.second();
402 const std::vector<raw::ChannelID_t>& channelVec = planeIDToDataPair.first;
405 icarus_signal_processing::ArrayFloat outputArray(dataArray.size(),icarus_signal_processing::VectorFloat(dataArray[0].
size(),0.));
406 icarus_signal_processing::ArrayBool selectedVals(dataArray.size(),icarus_signal_processing::VectorBool(dataArray[0].
size(),
false));
408 fROIToolMap.at(planeID.
Plane)->FindROIs(event, dataArray, channelVec, mapItr->first, outputArray, selectedVals);
415 for(
size_t waveIdx = 0; waveIdx < outputArray.size(); waveIdx++)
418 if (channelVec[idx] >= 100000)
continue;
425 ROIVec.
add_range(0, std::move(outputArray[waveIdx]));
438 using CandidateROI = std::pair<size_t, size_t>;
439 using CandidateROIVec = std::vector<CandidateROI>;
443 for(
size_t waveIdx = 0; waveIdx < selectedVals.size(); waveIdx++)
446 if (channelVec[waveIdx] >= 100000)
448 std::cout <<
"==> found an unexpected channel number: " << channelVec[waveIdx] << std::endl;
453 CandidateROIVec candidateROIVec;
456 const icarus_signal_processing::VectorBool& selVals = selectedVals[waveIdx];
460 while(idx < selVals.size())
464 Size_t startTick = idx >= leadTrail ? idx - leadTrail : 0;
466 while(idx < selVals.size() && selVals[idx]) idx++;
468 size_t stopTick = idx < selVals.size() - leadTrail ? idx + leadTrail : selVals.size();
470 candidateROIVec.emplace_back(startTick, stopTick);
477 if(candidateROIVec.size() > 1)
480 CandidateROIVec tempRoiVec;
483 size_t startRoi = candidateROIVec.front().first;
484 size_t stopRoi = candidateROIVec.front().second;
486 for(
auto& roi : candidateROIVec)
489 if (roi.first <= stopRoi)
492 startRoi = std::min(startRoi,roi.first);
493 stopRoi = std::max(stopRoi,roi.second);
497 tempRoiVec.emplace_back(startRoi,stopRoi);
499 startRoi = roi.first;
500 stopRoi = roi.second;
505 tempRoiVec.emplace_back(startRoi,stopRoi);
507 candidateROIVec = tempRoiVec;
511 if (!candidateROIVec.empty())
518 if (planeID.
Plane > 0)
524 if (wireIDVec.size() > 1)
526 std::vector<recob::Wire>::iterator wireItr = std::find_if(wireColVec.begin(),wireColVec.end(),[channel](
const auto& wire){
return wire.Channel() == channel;});
528 if (wireItr != wireColVec.end())
530 ROIVec = wireItr->SignalROI();
533 wireColVec.erase(wireItr);
536 std::vector<recob::ChannelROI>::iterator channelItr = std::find_if(channelROIVec.begin(),channelROIVec.end(),[channel](
const auto& channelROI){
return channelROI.Channel() == channel;});
538 if (channelItr != channelROIVec.end())
540 intROIVec = channelItr->SignalROI();
543 channelROIVec.erase(channelItr);
548 if (ROIVec.
size() != intROIVec.
size())
549 throw art::Exception(art::errors::LogicError) <<
"===> ROIVec mismatch to intROIVec, ROIVec size: " << ROIVec.
size() <<
", intROIVec size: " << intROIVec.
size() <<
"\n";
551 const icarus_signal_processing::VectorFloat& waveform = dataArray[waveIdx];
554 for(
const auto& candROI : candidateROIVec)
557 size_t roiLen = candROI.second - candROI.first;
558 size_t firstBin = candROI.first;
560 icarus_signal_processing::VectorFloat holder(roiLen);
562 std::copy(waveform.begin()+candROI.first, waveform.begin()+candROI.second, holder.begin());
570 size_t nBins = holder.size()/3;
571 icarus_signal_processing::VectorFloat::iterator firstItr = std::min_element(holder.begin(),holder.begin()+nBins);
572 icarus_signal_processing::VectorFloat::iterator lastItr = std::min_element(holder.end()-nBins,holder.end());
575 float dADC = (*lastItr - *firstItr) /
float(newSize);
578 for(
size_t binIdx = 0; binIdx < newSize; binIdx++)
580 holder[binIdx] = *(firstItr + binIdx) - offset;
586 holder.resize(newSize);
590 icarus_signal_processing::VectorShort intHolder(holder.size());
592 for(
size_t binIdx = 0; binIdx < holder.size(); binIdx++) intHolder[binIdx] = std::round(holder[binIdx]);
595 ROIVec.
add_range(firstBin, std::move(holder));
596 intROIVec.
add_range(firstBin, std::move(intHolder));
612 if (channelROIVec.size() != wireColVec.size())
613 throw art::Exception(art::errors::LogicError) <<
"===> ROI output mismatch, channelROIVec, size: " << channelROIVec.size() <<
", wireColVec, size: " << wireColVec.size() <<
"\n";
BEGIN_PROLOG TPC Trig offset(g4 rise time) ProjectToHeight
size_type size() const
Returns the size of the vector.
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
The data type to uniquely identify a Plane.
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
const datarange_t & add_range(size_type offset, ITER first, ITER last)
Adds a sequence of elements as a range with specified offset.
std::size_t size(FixedBins< T, C > const &) noexcept
Class managing the creation of a new recob::Wire object.
std::map< size_t, std::unique_ptr< icarus_tool::IROILocator > > fROIToolMap
size_t fMinSizeForCorrection
Minimum ROI length to do correction.
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
const geo::GeometryCore * fGeometry
bool fCorrectROIBaseline
Correct the ROI baseline.
PlaneID_t Plane
Index of the plane within its TPC.
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
size_t fMaxSizeForCorrection
Maximum ROI length for baseline correction.
bool fOutputMorphed
Output the morphed waveforms.
tbb::spin_mutex roifinderSpinMutex
bool empty() const
Returns whether the vector is empty.
Class managing the creation of a new recob::Wire object.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
BEGIN_PROLOG could also be cout
std::pair< std::vector< raw::ChannelID_t >, PlaneWireData > PlaneIDToDataPair