26 #include "art/Framework/Core/ReplicatedProducer.h"
27 #include "art/Framework/Principal/Event.h"
28 #include "art/Framework/Services/Registry/ServiceHandle.h"
29 #include "art_root_io/TFileService.h"
30 #include "art/Framework/Core/ModuleMacros.h"
31 #include "art/Utilities/make_tool.h"
32 #include "canvas/Persistency/Common/Ptr.h"
33 #include "messagefacility/MessageLogger/MessageLogger.h"
34 #include "cetlib/cpu_timer.h"
36 #include "tbb/parallel_for.h"
37 #include "tbb/blocked_range.h"
38 #include "tbb/task_arena.h"
39 #include "tbb/spin_mutex.h"
40 #include "tbb/concurrent_vector.h"
47 #include "sbndaq-artdaq-core/Overlays/ICARUS/PhysCrateFragment.hh"
51 #include "icarus_signal_processing/ICARUSSigProcDefs.h"
61 explicit FilterNoiseICARUS(fhicl::ParameterSet
const & pset, art::ProcessingFrame
const& frame);
65 virtual void configure(fhicl::ParameterSet
const & pset);
66 virtual void produce(art::Event &
e, art::ProcessingFrame
const& frame);
67 virtual void beginJob(art::ProcessingFrame
const& frame);
68 virtual void endJob(art::ProcessingFrame
const& frame);
87 art::Handle<artdaq::Fragments>& fragmentsHandle,
99 void operator()(
const tbb::blocked_range<size_t>& range)
const
101 for (
size_t idx = range.begin(); idx < range.end(); idx++)
114 void saveRawDigits(
const icarus_signal_processing::ArrayFloat&,
115 const icarus_signal_processing::VectorFloat&,
116 const icarus_signal_processing::VectorFloat&,
117 const icarus_signal_processing::VectorInt&,
150 art::ReplicatedProducer(pset, frame),
153 fGeometry = lar::providerFrom<geo::Geometry>();
158 int max_concurrency = tbb::this_task_arena::max_concurrency();
160 mf::LogDebug(
"FilterNoiseICARUS") <<
" ==> concurrency: " << max_concurrency << std::endl;
163 const fhicl::ParameterSet& decoderToolParams = pset.get<fhicl::ParameterSet>(
"DecoderTool");
165 fDecoderToolVec.resize(max_concurrency);
167 for(
auto& decoderTool : fDecoderToolVec)
170 decoderTool = art::make_tool<IDecoderFilter>(decoderToolParams);
175 mf::LogDebug(
"FilterNoiseICARUS") <<
"ICARUS has " << fGeometry->Nchannels() <<
" in total with " << fGeometry->Views().size() <<
" views" << std::endl;
179 mf::LogDebug(
"FilterNoiseICARUS") <<
"WireID: " << wireID << std::endl;
183 mf::LogDebug(
"FilterNoiseICARUS") <<
"From geo, first WireID: " << firstWireID << std::endl;
187 mf::LogDebug(
"FilterNoiseICARUS") <<
"Channel: " << channel << std::endl;
189 for(
size_t thePlane = 0; thePlane < 3; thePlane++)
194 mf::LogDebug(
"FilterNoiseICARUS") <<
"thePlane: " << thePlane <<
", WireID: " << tempWireID <<
", channel: " <<
195 fGeometry->PlaneWireToChannel(tempWireID) <<
", view: " << fGeometry->View(tempPlaneID) << std::endl;
198 fFragmentOffset = channel / 576;
200 produces<std::vector<raw::RawDigit>>();
202 if (fOutputPedestalCor)
203 produces<std::vector<raw::RawDigit>>(fOutputPedCorPath);
205 if (fOutputCorrection)
206 produces<std::vector<raw::RawDigit>>(fOutputCoherentPath);
209 mf::LogInfo(
"FilterNoiseICARUS") <<
"FilterNoiseICARUS configured\n";
226 fFragmentsLabel = pset.get<art::InputTag>(
"FragmentsLabel",
"daq:PHYSCRATEDATA");
254 art::Handle<artdaq::Fragments> daq_handle;
257 mf::LogDebug(
"FilterNoiseICARUS") <<
"**** Processing raw data fragments ****" << std::endl;
260 int max_concurrency = tbb::this_task_arena::max_concurrency();
262 mf::LogDebug(
"FilterNoiseICARUS") <<
" ==> concurrency: " << max_concurrency << std::endl;
264 cet::cpu_timer theClockTotal;
266 theClockTotal.start();
273 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService>()->DataFor(event);
278 concurrentRawRawDigits,
281 tbb::parallel_for(tbb::blocked_range<size_t>(0, daq_handle->size()), fragmentProcessing);
284 RawDigitCollectionPtr rawDigitCollection = std::make_unique<std::vector<raw::RawDigit>>(std::move_iterator(concurrentRawDigits.begin()),
285 std::move_iterator(concurrentRawDigits.end()));
288 std::sort(rawDigitCollection->begin(),rawDigitCollection->end(),[](
const auto&
left,
const auto&
right){
return left.Channel() <
right.Channel();});
291 event.put(std::move(rawDigitCollection));
296 RawDigitCollectionPtr rawRawDigitCollection = std::make_unique<std::vector<raw::RawDigit>>(std::move_iterator(concurrentRawRawDigits.begin()),
297 std::move_iterator(concurrentRawRawDigits.end()));
299 std::sort(rawRawDigitCollection->begin(),rawRawDigitCollection->end(),[](
const auto&
left,
const auto&
right){
return left.Channel() <
right.Channel();});
308 RawDigitCollectionPtr coherentCollection = std::make_unique<std::vector<raw::RawDigit>>(std::move_iterator(coherentRawDigits.begin()),
309 std::move_iterator(coherentRawDigits.end()));
311 std::sort(coherentCollection->begin(),coherentCollection->end(),[](
const auto&
left,
const auto&
right){
return left.Channel() <
right.Channel();});
317 theClockTotal.stop();
319 double totalTime = theClockTotal.accumulated_real_time();
321 mf::LogInfo(
"FilterNoiseICARUS") <<
"==> FilterNoiseICARUS total time: " << totalTime << std::endl;
328 art::Handle<artdaq::Fragments> fragmentHandle,
333 cet::cpu_timer theClockProcess;
335 theClockProcess.start();
337 art::Ptr<artdaq::Fragment> fragmentPtr(fragmentHandle, idx);
339 mf::LogDebug(
"FilterNoiseICARUS") <<
"--> Processing fragment ID: " << fragmentPtr->fragmentID() << std::endl;
340 mf::LogDebug(
"FilterNoiseICARUS") <<
" ==> Current thread index: " << tbb::this_task_arena::current_thread_index() << std::endl;
350 icarus::PhysCrateFragment physCrateFragment(*fragmentPtr);
358 theClockProcess.stop();
360 double totalTime = theClockProcess.accumulated_real_time();
363 const icarus_signal_processing::VectorFloat locPedsVec(decoderTool->
getWaveLessCoherent().size(),0.);
364 const icarus_signal_processing::VectorInt& channelVec = decoderTool->
getChannelIDs();
376 mf::LogDebug(
"FilterNoiseICARUS") <<
"--> Exiting fragment processing for thread: " << tbb::this_task_arena::current_thread_index() <<
", time: " << totalTime << std::endl;
381 const icarus_signal_processing::VectorFloat& pedestalVec,
382 const icarus_signal_processing::VectorFloat& rmsVec,
383 const icarus_signal_processing::VectorInt& channelVec,
386 if (!dataArray.empty())
388 cet::cpu_timer theClockSave;
390 theClockSave.start();
394 mf::LogDebug(
"FilterNoiseICARUS") <<
" --> saving rawdigits for " << dataArray.size() <<
" channels" << std::endl;
397 for(
size_t chanIdx = 0; chanIdx != dataArray.size(); chanIdx++)
399 const icarus_signal_processing::VectorFloat& dataVec = dataArray[chanIdx];
402 std::transform(dataVec.begin(),dataVec.end(),wvfm.begin(),[](
const auto& val){
return short(std::round(val));});
404 ConcurrentRawDigitCol::iterator newObjItr = rawDigitCol.emplace_back(channelVec[chanIdx],wvfm.size(),wvfm);
405 newObjItr->SetPedestal(pedestalVec[chanIdx],rmsVec[chanIdx]);
410 double totalTime = theClockSave.accumulated_real_time();
412 mf::LogDebug(
"FilterNoiseICARUS") <<
" --> done with save, time: " << totalTime << std::endl;
422 mf::LogInfo(
"FilterNoiseICARUS") <<
"Looked at " <<
fNumEvent <<
" events" << std::endl;
detinfo::DetectorClocksData const & fClockData
std::string fOutputCoherentPath
Path to assign to the output if asked for.
std::vector< std::unique_ptr< IDecoderFilter > > fDecoderToolVec
Decoder tools.
ConcurrentRawDigitCol & fRawRawDigitCollection
virtual void beginJob(art::ProcessingFrame const &frame)
Begin job method.
virtual const icarus_signal_processing::VectorFloat getTruncRMSVals() const =0
Recover the truncated RMS noise.
Utilities related to art service access.
art::Handle< artdaq::Fragments > & fFragmentsHandle
virtual const icarus_signal_processing::VectorInt getChannelIDs() const =0
Recover the channels for the processed fragment.
std::vector< raw::RawDigit > RawDigitCollection
tbb::concurrent_vector< raw::RawDigit > ConcurrentRawDigitCol
art::InputTag fFragmentsLabel
The input artdaq fragment label.
The data type to uniquely identify a Plane.
std::unique_ptr< RawDigitCollection > RawDigitCollectionPtr
std::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
IDecoderFilter interface class definiton.
size_t fFragmentOffset
The fragment offset to set channel numbering.
Definition of basic raw digits.
std::size_t size(FixedBins< T, C > const &) noexcept
ConcurrentRawDigitCol & fRawDigitCollection
FilterNoiseICARUS(fhicl::ParameterSet const &pset, art::ProcessingFrame const &frame)
int fNumEvent
Number of events seen.
virtual const icarus_signal_processing::ArrayFloat getWaveLessCoherent() const =0
Recover the waveforms less coherent noise.
This provides an art tool interface definition for tools which "decode" artdaq fragments into LArSoft...
const FilterNoiseICARUS & fFilterNoiseICARUS
unsigned int fPlaneToSimulate
Use to get fragment offset.
virtual void process_fragment(detinfo::DetectorClocksData const &clockData, const artdaq::Fragment &fragment)=0
Given a set of recob hits, run DBscan to form 3D clusters.
virtual ~FilterNoiseICARUS()
Destructor.
bool fOutputPedestalCor
Should we output pedestal corrected (not noise filtered)?
virtual const icarus_signal_processing::ArrayFloat getCorrectedMedians() const =0
Recover the correction median values.
ConcurrentRawDigitCol & fCoherentCollection
virtual void endJob(art::ProcessingFrame const &frame)
End job method.
std::string fOutputPedCorPath
Path to assign to the output if asked for.
virtual void produce(art::Event &e, art::ProcessingFrame const &frame)
multiThreadFragmentProcessing(FilterNoiseICARUS const &parent, detinfo::DetectorClocksData const &clockData, art::Handle< artdaq::Fragments > &fragmentsHandle, ConcurrentRawDigitCol &rawDigitCollection, ConcurrentRawDigitCol &rawRawDigitCollection, ConcurrentRawDigitCol &coherentCollection)
Description of geometry of one entire detector.
geo::GeometryCore const * fGeometry
pointer to Geometry service
bool fOutputCorrection
Should we output the coherent noise correction vectors?
virtual void configure(fhicl::ParameterSet const &pset)
Contains all timing reference information for the detector.
virtual const icarus_signal_processing::VectorFloat getFullRMSVals() const =0
Recover the full RMS before coherent noise.
void processSingleFragment(size_t, detinfo::DetectorClocksData const &clockData, art::Handle< artdaq::Fragments >, ConcurrentRawDigitCol &, ConcurrentRawDigitCol &, ConcurrentRawDigitCol &) const
virtual const icarus_signal_processing::VectorFloat getPedestalVals() const =0
Recover the pedestals for each channel.
void operator()(const tbb::blocked_range< size_t > &range) const
void saveRawDigits(const icarus_signal_processing::ArrayFloat &, const icarus_signal_processing::VectorFloat &, const icarus_signal_processing::VectorFloat &, const icarus_signal_processing::VectorInt &, ConcurrentRawDigitCol &) const
virtual const icarus_signal_processing::ArrayFloat getRawWaveforms() const =0
Recover the original raw waveforms.
constexpr PlaneID const & planeID() const
unsigned int ChannelID_t
Type representing the ID of a readout channel.
art framework interface to geometry description