9 #include "art/Framework/Core/EDProducer.h"
10 #include "art/Framework/Principal/Event.h"
11 #include "art/Framework/Principal/Handle.h"
12 #include "art/Framework/Services/Registry/ServiceHandle.h"
13 #include "art/Persistency/Common/PtrMaker.h"
14 #include "art/Utilities/ToolMacros.h"
15 #include "art/Utilities/make_tool.h"
16 #include "cetlib/cpu_timer.h"
17 #include "fhiclcpp/ParameterSet.h"
18 #include "messagefacility/MessageLogger/MessageLogger.h"
23 #include "sbndaq-artdaq-core/Overlays/ICARUS/PhysCrateFragment.hh"
28 #include "icarus_signal_processing/WaveformTools.h"
29 #include "icarus_signal_processing/Denoising.h"
30 #include "icarus_signal_processing/Filters/FFTFilterFunctions.h"
64 virtual void configure(
const fhicl::ParameterSet&)
override;
72 const artdaq::Fragment&)
override;
194 std::cout <<
"TPCDecoderFilter1D is calling configure method" << std::endl;
230 fThreshold = pset.get<std::vector<float> >(
"Threshold", std::vector<float>()={5.0,3.5,3.5});
233 fFilterModeVec = pset.get<std::vector<std::string>>(
"FilterModeVec", std::vector<std::string>()={
"e",
"g",
"d"});
240 for(
const auto& idPair : tempIDVec)
fFragmentIDMap[idPair.first] = idPair.second;
242 fGeometry = art::ServiceHandle<geo::Geometry const>{}.get();
243 fChannelMap = art::ServiceHandle<icarusDB::IICARUSChannelMap const>{}.get();
249 for(
int plane = 0; plane < 3; plane++)
251 if (plane < 3)
fFFTFilterFunctionVec.emplace_back(std::make_unique<icarus_signal_processing::WindowFFTFilter>(fFFTSigmaValsVec[plane], fFFTCutoffValsVec[plane]));
254 mf::LogInfo(
"TPCDecoderFilter1D") <<
"FFT setup for plane " << plane <<
", SigmaVals: " << fFFTSigmaValsVec[plane].first <<
"/" << fFFTSigmaValsVec[plane].second <<
", cutoff: " << fFFTCutoffValsVec[plane].first <<
"/" << fFFTCutoffValsVec[plane].second << std::endl;
262 const artdaq::Fragment &fragment)
264 cet::cpu_timer theClockTotal;
266 theClockTotal.start();
269 icarus::PhysCrateFragment physCrateFragment(fragment);
271 size_t nBoardsPerFragment = physCrateFragment.nBoards();
272 size_t nChannelsPerBoard = physCrateFragment.nChannelsPerBoard();
273 size_t nSamplesPerChannel = physCrateFragment.nSamplesPerChannel();
277 artdaq::detail::RawFragmentHeader::fragment_id_t fragmentID = fragment.fragmentID();
286 theClockTotal.stop();
315 for(
const auto& boardID : readoutIDVec)
322 std::cout <<
"*** COULD NOT FIND BOARD ***" << std::endl;
323 std::cout <<
" - boardID: " << std::hex << boardID <<
", board map size: " << readoutIDVec.size() <<
", nBoardsPerFragment: " << nBoardsPerFragment << std::endl;
331 boardIDVec[boardSlot] = boardID;
336 std::cout <<
" - # boards: " << boardIDVec.size() <<
", boards: ";
337 for(
const auto&
id : boardIDVec)
std::cout <<
id <<
" ";
342 const size_t maxChannelsPerFragment(576);
344 if (
fSelectVals.empty())
fSelectVals = icarus_signal_processing::ArrayBool(maxChannelsPerFragment, icarus_signal_processing::VectorBool(nSamplesPerChannel));
345 if (
fROIVals.empty())
fROIVals = icarus_signal_processing::ArrayBool(maxChannelsPerFragment, icarus_signal_processing::VectorBool(nSamplesPerChannel));
346 if (
fRawWaveforms.empty())
fRawWaveforms = icarus_signal_processing::ArrayFloat(maxChannelsPerFragment, icarus_signal_processing::VectorFloat(nSamplesPerChannel));
347 if (
fPedCorWaveforms.empty())
fPedCorWaveforms = icarus_signal_processing::ArrayFloat(maxChannelsPerFragment, icarus_signal_processing::VectorFloat(nSamplesPerChannel));
348 if (
fIntrinsicRMS.empty())
fIntrinsicRMS = icarus_signal_processing::ArrayFloat(maxChannelsPerFragment, icarus_signal_processing::VectorFloat(nSamplesPerChannel));
349 if (
fCorrectedMedians.empty())
fCorrectedMedians = icarus_signal_processing::ArrayFloat(maxChannelsPerFragment, icarus_signal_processing::VectorFloat(nSamplesPerChannel));
350 if (
fWaveLessCoherent.empty())
fWaveLessCoherent = icarus_signal_processing::ArrayFloat(maxChannelsPerFragment, icarus_signal_processing::VectorFloat(nSamplesPerChannel));
351 if (
fMorphedWaveforms.empty())
fMorphedWaveforms = icarus_signal_processing::ArrayFloat(maxChannelsPerFragment, icarus_signal_processing::VectorFloat(nSamplesPerChannel));
358 if (
fRangeBins.empty())
fRangeBins = icarus_signal_processing::VectorInt(maxChannelsPerFragment);
365 icarus_signal_processing::Denoiser1D denoiser;
366 icarus_signal_processing::WaveformTools<float> waveformTools;
368 cet::cpu_timer theClockPedestal;
370 theClockPedestal.start();
374 for(
size_t board = 0; board < boardIDVec.size(); board++)
377 if (board >= nBoardsPerFragment)
379 mf::LogInfo(
"TPCDecoderFilter1D") <<
" Asking for board beyond number in fragment, want board " << board <<
", maximum is " << nBoardsPerFragment << std::endl;
385 uint32_t boardSlot = physCrateFragment.DataTileHeader(board)->StatusReg_SlotID();
389 std::cout <<
"********************************************************************************" << std::endl;
390 std::cout <<
"FragmentID: " << std::hex << fragmentID <<
", Crate: " << crateName << std::dec <<
", boardID: " << boardIDVec[boardSlot] <<
", slot: " << boardSlot <<
"/" << nBoardsPerFragment <<
", size " << channelPlanePairVec.size() <<
"/" << nChannelsPerBoard <<
", ";
395 size_t boardOffset = nChannelsPerBoard * board;
398 const icarus::A2795DataBlock::data_t* dataBlock = physCrateFragment.BoardData(board);
401 for(
size_t chanIdx = 0; chanIdx < nChannelsPerBoard; chanIdx++)
404 size_t channelOnBoard = boardOffset + chanIdx;
406 icarus_signal_processing::VectorFloat& rawDataVec =
fRawWaveforms[channelOnBoard];
409 rawDataVec[
tick] = -dataBlock[chanIdx +
tick * nChannelsPerBoard];
411 icarus_signal_processing::VectorFloat& pedCorDataVec =
fPedCorWaveforms[channelOnBoard];
414 fChannelIDVec[channelOnBoard] = channelPlanePairVec[chanIdx].first;
417 unsigned int plane = channelPlanePairVec[chanIdx].second;
424 std::cout <<
"*** COMPLETELY SCREWUP YOU IMBECILE! plane is " << plane <<
" for chanIdx " << chanIdx << std::endl;
446 std::cout <<
"***** FOUND NO MATCH FOR TYPE: " <<
fFilterModeVec[plane] <<
", plane " << plane <<
" DURING INITIALIZATION OF FILTER FUNCTIONS IN TPCDecoderFilter1D" << std::endl;
451 waveformTools.getPedestalCorrectedWaveform(rawDataVec,
467 if (widVec.empty())
std::cout << channelPlanePairVec[chanIdx].first <<
"/" << chanIdx <<
"=" <<
fFullRMSVals[channelOnBoard] <<
" * ";
468 else std::cout <<
fChannelIDVec[channelOnBoard] <<
"-" << widVec[0].Cryostat <<
"/" << widVec[0].TPC <<
"/" << widVec[0].Plane <<
"/" << widVec[0].Wire <<
"=" <<
fFullRMSVals[channelOnBoard] <<
" * ";
504 if (nBoardsPerFragment < 9)
509 theClockPedestal.stop();
511 double pedestalTime = theClockPedestal.accumulated_real_time();
513 cet::cpu_timer theClockDenoise;
515 theClockDenoise.start();
536 theClockDenoise.stop();
538 double denoiseTime = theClockDenoise.accumulated_real_time();
540 theClockDenoise.start();
561 theClockDenoise.stop();
563 double cohPedSubTime = theClockDenoise.accumulated_real_time() - denoiseTime;
566 theClockTotal.stop();
568 double totalTime = theClockTotal.accumulated_real_time();
570 mf::LogDebug(
"TPCDecoderFilter1D") <<
" *totalTime: " << totalTime <<
", pedestal: " << pedestalTime <<
", noise: " << denoiseTime <<
", ped cor: " << cohPedSubTime << std::endl;
uint32_t fFragment_id_offset
std::vector< FragmentIDPair > FragmentIDVec
virtual void configure(const fhicl::ParameterSet &) override
Interface for configuring the particular algorithm tool.
icarus_signal_processing::ArrayBool fSelectVals
std::vector< ChannelPlanePair > ChannelPlanePairVec
icarus_signal_processing::VectorFloat fPedestalVals
std::vector< std::string > fFilterModeVec
const icarus_signal_processing::ArrayFloat getCorrectedMedians() const override
Recover the correction median values.
const icarus_signal_processing::VectorFloat getTruncRMSVals() const override
Recover the truncated RMS noise.
std::vector< float > fThreshold
std::vector< unsigned int > ReadoutIDVec
virtual const ReadoutIDVec & getReadoutBoardVec(const unsigned int) const =0
const icarus_signal_processing::VectorInt getNumTruncBins() const override
Recover the number of bins after truncation.
const icarus_signal_processing::ArrayFloat getRawWaveforms() const override
Recover the pedestal subtracted waveforms.
const icarus_signal_processing::VectorInt getChannelIDs() const override
Recover the channels for the processed fragment.
icarus_signal_processing::ArrayBool fROIVals
size_t fCoherentNoiseGrouping
icarus_signal_processing::FilterFunctionVec fFilterFunctionVec
IDecoderFilter interface class definiton.
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
size_t fCoherentNoiseOffset
icarus_signal_processing::ArrayFloat fPedCorWaveforms
icarus_signal_processing::VectorFloat fTruncRMSVals
This provides an art tool interface definition for tools which "decode" artdaq fragments into LArSoft...
icarus_signal_processing::VectorInt fNumTruncBins
~TPCDecoderFilter1D()
Destructor.
virtual void process_fragment(detinfo::DetectorClocksData const &, const artdaq::Fragment &) override
Given a set of recob hits, run DBscan to form 3D clusters.
virtual const std::string & getCrateName(const unsigned int) const =0
FloatPairVec fFFTCutoffValsVec
const icarus_signal_processing::ArrayBool getROIVals() const override
Recover the ROI values.
const icarus_signal_processing::ArrayFloat getIntrinsicRMS() const override
Recover the "intrinsic" RMS.
virtual bool hasBoardID(const unsigned int) const =0
std::pair< unsigned int, unsigned int > FragmentIDPair
icarus_signal_processing::ArrayFloat fIntrinsicRMS
virtual const ChannelPlanePairVec & getChannelPlanePair(const unsigned int) const =0
icarus_signal_processing::ArrayFloat fWaveLessCoherent
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
const icarus_signal_processing::VectorFloat getFullRMSVals() const override
Recover the full RMS before coherent noise.
virtual bool hasFragmentID(const unsigned int) const =0
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
const geo::Geometry * fGeometry
const icarus_signal_processing::VectorFloat getPedestalVals() const override
Recover the pedestals for each channel.
The geometry of one entire detector, as served by art.
FloatPairVec fFFTSigmaValsVec
TPCDecoderFilter1D(fhicl::ParameterSet const &pset)
Constructor.
icarus_signal_processing::FFTFilterFunctionVec fFFTFilterFunctionVec
Contains all timing reference information for the detector.
icarus_signal_processing::ArrayFloat fMorphedWaveforms
const icarus_signal_processing::ArrayFloat getPedCorWaveforms() const override
Recover the pedestal subtracted waveforms.
const icarus_signal_processing::ArrayFloat getWaveLessCoherent() const override
Recover the waveforms less coherent noise.
FragmentIDMap fFragmentIDMap
virtual unsigned int getBoardSlot(const unsigned int) const =0
const icarus_signal_processing::ArrayBool getSelectionVals() const override
Recover the selection values.
icarus_signal_processing::ArrayFloat fRawWaveforms
icarus_signal_processing::VectorInt fChannelIDVec
icarus_signal_processing::ArrayFloat fCorrectedMedians
icarus_signal_processing::VectorInt fRangeBins
icarus_signal_processing::VectorFloat fFullRMSVals
size_t fStructuringElement
art framework interface to geometry description
BEGIN_PROLOG could also be cout
std::vector< std::pair< float, float >> FloatPairVec
TPCDecoderFilter1D class definiton.
std::map< unsigned int, unsigned int > FragmentIDMap
const icarusDB::IICARUSChannelMap * fChannelMap
icarus_signal_processing::VectorFloat fThresholdVec
float fSigmaForTruncation
const icarus_signal_processing::ArrayFloat getMorphedWaveforms() const override
Recover the morphological filter waveforms.