All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
daq::MCDecoderICARUSTPCwROI Class Reference
Inheritance diagram for daq::MCDecoderICARUSTPCwROI:

Classes

class  multiThreadImageProcessing
 

Public Types

using RawDigitCollection = std::vector< raw::RawDigit >
 
using RawDigitCollectionPtr = std::unique_ptr< RawDigitCollection >
 
using WireCollection = std::vector< recob::Wire >
 
using WireCollectionPtr = std::unique_ptr< WireCollection >
 
using ConcurrentRawDigitCol = tbb::concurrent_vector< raw::RawDigit >
 
using ConcurrentWireCol = tbb::concurrent_vector< recob::Wire >
 
using PlaneIdxToImagePair = std::pair< unsigned int, icarus_signal_processing::ArrayFloat >
 
using PlaneIdxToImageMap = std::map< unsigned int, icarus_signal_processing::ArrayFloat >
 
using ChannelVec = std::vector< raw::ChannelID_t >
 
using PlaneIdxToChannelPair = std::pair< unsigned int, ChannelVec >
 
using PlaneIdxToChannelMap = std::map< unsigned int, ChannelVec >
 
using ChannelArrayPair = std::pair< daq::INoiseFilter::ChannelPlaneVec, icarus_signal_processing::ArrayFloat >
 
using ChannelArrayPairVec = std::vector< ChannelArrayPair >
 

Public Member Functions

 MCDecoderICARUSTPCwROI (fhicl::ParameterSet const &pset, art::ProcessingFrame const &frame)
 
virtual ~MCDecoderICARUSTPCwROI ()
 Destructor. More...
 
virtual void configure (fhicl::ParameterSet const &pset)
 
virtual void produce (art::Event &e, art::ProcessingFrame const &frame)
 
virtual void beginJob (art::ProcessingFrame const &frame)
 Begin job method. More...
 
virtual void endJob (art::ProcessingFrame const &frame)
 End job method. More...
 
void processSingleImage (const detinfo::DetectorClocksData &, const ChannelArrayPair &, size_t, ConcurrentRawDigitCol &, ConcurrentRawDigitCol &, ConcurrentRawDigitCol &, ConcurrentWireCol &) const
 

Private Types

using PlaneToROPPlaneMap = std::map< geo::PlaneID, unsigned int >
 
using PlaneToWireOffsetMap = std::map< geo::PlaneID, raw::ChannelID_t >
 
using ROPToNumWiresMap = std::map< unsigned int, unsigned int >
 
using WirePlanePair = std::pair< unsigned int, unsigned int >
 
using BoardWirePlanePair = std::pair< unsigned int, WirePlanePair >
 
using ChannelToBoardWirePlaneMap = std::map< unsigned int, BoardWirePlanePair >
 

Private Member Functions

void processSingleLabel (art::Event &, const art::InputTag &, detinfo::DetectorClocksData const &, ChannelArrayPairVec const &, size_t const &, ConcurrentRawDigitCol &, ConcurrentRawDigitCol &, ConcurrentRawDigitCol &, ConcurrentWireCol &) 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
 

Private Attributes

std::vector< art::InputTag > fRawDigitLabelVec
 The input artdaq fragment label vector (for more than one) More...
 
std::vector< std::string > fOutInstanceLabelVec
 The output instance labels to apply. More...
 
bool fOutputRawWaveform
 Should we output pedestal corrected (not noise filtered)? More...
 
bool fOutputCorrection
 Should we output the coherent noise correction vectors? More...
 
std::string fOutputRawWavePath
 Path to assign to the output if asked for. More...
 
std::string fOutputCoherentPath
 Path to assign to the output if asked for. More...
 
bool fDiagnosticOutput
 Set this to get lots of messages. More...
 
size_t fCoherentNoiseGrouping
 

channels in common for coherent noise

More...
 
const std::string fLogCategory
 Output category when logging messages. More...
 
int fNumEvent
 Number of events seen. More...
 
PlaneToROPPlaneMap fPlaneToROPPlaneMap
 
PlaneToWireOffsetMap fPlaneToWireOffsetMap
 
ROPToNumWiresMap fROPToNumWiresMap
 
unsigned int fNumROPs
 
ChannelToBoardWirePlaneMap fChannelToBoardWirePlaneMap
 
std::vector< std::unique_ptr
< INoiseFilter > > 
fDecoderToolVec
 Decoder tools. More...
 
geo::GeometryCore const * fGeometry
 pointer to Geometry service More...
 
const icarusDB::IICARUSChannelMapfChannelMap
 

Detailed Description

Definition at line 56 of file MCDecoderICARUSTPCwROI_module.cc.

Member Typedef Documentation

using daq::MCDecoderICARUSTPCwROI::BoardWirePlanePair = std::pair<unsigned int, WirePlanePair>
private

Definition at line 189 of file MCDecoderICARUSTPCwROI_module.cc.

using daq::MCDecoderICARUSTPCwROI::ChannelArrayPair = std::pair<daq::INoiseFilter::ChannelPlaneVec,icarus_signal_processing::ArrayFloat>

Definition at line 90 of file MCDecoderICARUSTPCwROI_module.cc.

Definition at line 91 of file MCDecoderICARUSTPCwROI_module.cc.

Definition at line 190 of file MCDecoderICARUSTPCwROI_module.cc.

Definition at line 86 of file MCDecoderICARUSTPCwROI_module.cc.

Definition at line 75 of file MCDecoderICARUSTPCwROI_module.cc.

Definition at line 76 of file MCDecoderICARUSTPCwROI_module.cc.

Definition at line 88 of file MCDecoderICARUSTPCwROI_module.cc.

Definition at line 87 of file MCDecoderICARUSTPCwROI_module.cc.

using daq::MCDecoderICARUSTPCwROI::PlaneIdxToImageMap = std::map<unsigned int,icarus_signal_processing::ArrayFloat>

Definition at line 85 of file MCDecoderICARUSTPCwROI_module.cc.

using daq::MCDecoderICARUSTPCwROI::PlaneIdxToImagePair = std::pair<unsigned int,icarus_signal_processing::ArrayFloat>

Definition at line 84 of file MCDecoderICARUSTPCwROI_module.cc.

using daq::MCDecoderICARUSTPCwROI::PlaneToROPPlaneMap = std::map<geo::PlaneID,unsigned int>
private

Definition at line 179 of file MCDecoderICARUSTPCwROI_module.cc.

Definition at line 180 of file MCDecoderICARUSTPCwROI_module.cc.

Definition at line 71 of file MCDecoderICARUSTPCwROI_module.cc.

Definition at line 72 of file MCDecoderICARUSTPCwROI_module.cc.

using daq::MCDecoderICARUSTPCwROI::ROPToNumWiresMap = std::map<unsigned int,unsigned int>
private

Definition at line 181 of file MCDecoderICARUSTPCwROI_module.cc.

Definition at line 73 of file MCDecoderICARUSTPCwROI_module.cc.

Definition at line 74 of file MCDecoderICARUSTPCwROI_module.cc.

using daq::MCDecoderICARUSTPCwROI::WirePlanePair = std::pair<unsigned int, unsigned int>
private

Definition at line 188 of file MCDecoderICARUSTPCwROI_module.cc.

Constructor & Destructor Documentation

daq::MCDecoderICARUSTPCwROI::MCDecoderICARUSTPCwROI ( fhicl::ParameterSet const &  pset,
art::ProcessingFrame const &  frame 
)
explicit

Constructor.

Arguments:

pset - Fcl parameters.

Definition at line 211 of file MCDecoderICARUSTPCwROI_module.cc.

211  :
212  art::ReplicatedProducer(pset, frame),
213  fLogCategory("MCDecoderICARUSTPCwROI"),fNumEvent(0), fNumROPs(0)
214 {
215  fGeometry = art::ServiceHandle<geo::Geometry const>{}.get();
216  fChannelMap = art::ServiceHandle<icarusDB::IICARUSChannelMap const>{}.get();
217 
218  configure(pset);
219 
220  // Check the concurrency
221  int max_concurrency = art::Globals::instance()->nthreads();
222 
223  mf::LogDebug("MCDecoderICARUSTPCwROI") << " ==> concurrency: " << max_concurrency << std::endl;
224 
225  // Recover the vector of fhicl parameters for the ROI tools
226  const fhicl::ParameterSet& decoderToolParams = pset.get<fhicl::ParameterSet>("DecoderTool");
227 
228  fDecoderToolVec.resize(max_concurrency);
229 
230  for(auto& decoderTool : fDecoderToolVec)
231  {
232  // Get instance of tool
233  decoderTool = art::make_tool<INoiseFilter>(decoderToolParams);
234  }
235 
236  // Set up our "produces"
237  // Note that we can have multiple instances input to the module
238  // Our convention will be to create a similar number of outputs with the same instance names
239  for(const auto& instanceLabel : fOutInstanceLabelVec)
240  {
241  produces<std::vector<raw::RawDigit>>(instanceLabel);
242  produces<std::vector<recob::Wire>>(instanceLabel);
243 
244  if (fOutputRawWaveform)
245  produces<std::vector<raw::RawDigit>>(instanceLabel + fOutputRawWavePath);
246 
247  if (fOutputCorrection)
248  produces<std::vector<raw::RawDigit>>(instanceLabel + fOutputCoherentPath);
249  }
250 
251  // Set up a WireID to ROP plane number table
252  PlaneToWireOffsetMap planeToLastWireOffsetMap;
253 
254  for(size_t cryoIdx = 0; cryoIdx < 2; cryoIdx++)
255  {
256  for(size_t logicalTPCIdx = 0; logicalTPCIdx < 4; logicalTPCIdx++)
257  {
258  for(size_t planeIdx = 0; planeIdx < 3; planeIdx++)
259  {
260  geo::PlaneID planeID(cryoIdx,logicalTPCIdx,planeIdx);
261 
262  raw::ChannelID_t channel = fGeometry->PlaneWireToChannel(planeID.Plane, 0, planeID.TPC, planeID.Cryostat);
263 
264  readout::ROPID ropID = fGeometry->ChannelToROP(channel);
265 
266  fPlaneToROPPlaneMap[planeID] = ropID.ROP;
267  fPlaneToWireOffsetMap[planeID] = channel;
268  planeToLastWireOffsetMap[planeID] = fGeometry->PlaneWireToChannel(planeID.Plane, fGeometry->Nwires(planeID), planeID.TPC, planeID.Cryostat);
269  fROPToNumWiresMap[ropID.ROP] = fGeometry->Nwires(planeID);
270 
271  // Special case handling
272 // if (ropID.ROP > 1) fROPToNumWiresMap[ropID.ROP] *= 2;
273 
274  if (ropID.ROP > fNumROPs) fNumROPs = ropID.ROP;
275 
276  // Watch for the middle induction and collection plane logical TPC split
277  if (ropID.ROP > 1 && (logicalTPCIdx == 1 || logicalTPCIdx == 3))
278  {
279  geo::PlaneID tempID(cryoIdx,logicalTPCIdx-1,planeIdx);
280 
281  fPlaneToWireOffsetMap[planeID] = fPlaneToWireOffsetMap[tempID];
282  fROPToNumWiresMap[ropID.ROP] = planeToLastWireOffsetMap[planeID] - fPlaneToWireOffsetMap[planeID];
283  }
284 
285  // Diagnostic output if requested
286  mf::LogDebug(fLogCategory) << "Initializing C/T/P: " << planeID.Cryostat << "/" << planeID.TPC << "/" << planeID.Plane << ", base channel: " << fPlaneToWireOffsetMap[planeID] << ", ROP: " << ropID << ", index: " << ropID.ROP;
287 
288  }
289  }
290  }
291 
292  fNumROPs++;
293 
294  // We need to build a mapping fronm channel to a readout board/wire pair
295  // Get the board ids for this fragment
297 
298  for(const auto& boardPair : readoutBoardToChannelMap)
299  {
300  // The board pair will give us the readout board and a vector of "wires"
301  unsigned int readoutBoardID = boardPair.first;
302 
303  // Loop through the vector of wires on this board
304  for(unsigned int wireIdx = 0; wireIdx < boardPair.second.second.size(); wireIdx++)
305  {
306  unsigned int channelID = boardPair.second.second[wireIdx].first;
307  unsigned int planeID = boardPair.second.second[wireIdx].second;
308 
309  fChannelToBoardWirePlaneMap[channelID] = BoardWirePlanePair(readoutBoardID,WirePlanePair(wireIdx,planeID));
310  }
311  }
312 
313 
314  // Report.
315  mf::LogInfo("MCDecoderICARUSTPCwROI") << "MCDecoderICARUSTPCwROI configured\n";
316 }
ChannelToBoardWirePlaneMap fChannelToBoardWirePlaneMap
const icarusDB::IICARUSChannelMap * fChannelMap
bool fOutputRawWaveform
Should we output pedestal corrected (not noise filtered)?
bool fOutputCorrection
Should we output the coherent noise correction vectors?
virtual const TPCReadoutBoardToChannelMap & getReadoutBoardToChannelMap() const =0
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
const std::string instance
unsigned int Nwires(unsigned int p, unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wires in the specified plane.
ROPID_t ROP
Index of the readout plane within its TPC set.
std::string fOutputCoherentPath
Path to assign to the output if asked for.
virtual void configure(fhicl::ParameterSet const &pset)
geo::GeometryCore const * fGeometry
pointer to Geometry service
Class identifying a set of planes sharing readout channels.
readout::ROPID ChannelToROP(raw::ChannelID_t channel) const
std::string fOutputRawWavePath
Path to assign to the output if asked for.
raw::ChannelID_t PlaneWireToChannel(WireID const &wireid) const
Returns the ID of the TPC channel connected to the specified wire.
std::pair< unsigned int, unsigned int > WirePlanePair
std::map< unsigned int, SlotChannelVecPair > TPCReadoutBoardToChannelMap
std::map< geo::PlaneID, raw::ChannelID_t > PlaneToWireOffsetMap
std::vector< std::unique_ptr< INoiseFilter > > fDecoderToolVec
Decoder tools.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
std::pair< unsigned int, WirePlanePair > BoardWirePlanePair
const std::string fLogCategory
Output category when logging messages.
std::vector< std::string > fOutInstanceLabelVec
The output instance labels to apply.
daq::MCDecoderICARUSTPCwROI::~MCDecoderICARUSTPCwROI ( )
virtual

Destructor.

Definition at line 320 of file MCDecoderICARUSTPCwROI_module.cc.

321 {}

Member Function Documentation

void daq::MCDecoderICARUSTPCwROI::beginJob ( art::ProcessingFrame const &  frame)
virtual

Begin job method.

Definition at line 345 of file MCDecoderICARUSTPCwROI_module.cc.

346 {
347  return;
348 }
void daq::MCDecoderICARUSTPCwROI::configure ( fhicl::ParameterSet const &  pset)
virtual

Reconfigure method.

Arguments:

pset - Fcl parameter set.

Definition at line 330 of file MCDecoderICARUSTPCwROI_module.cc.

331 {
332  fRawDigitLabelVec = pset.get<std::vector<art::InputTag>>("FragmentsLabelVec", {"daq:PHYSCRATEDATA"});
333  fOutInstanceLabelVec = pset.get<std::vector<std::string>> ("OutInstanceLabelVec", {"PHYSCRATEDATA"});
334  fOutputRawWaveform = pset.get<bool >("OutputRawWaveform", false);
335  fOutputCorrection = pset.get<bool >("OutputCorrection", false);
336  fOutputRawWavePath = pset.get<std::string >("OutputRawWavePath", "raw");
337  fOutputCoherentPath = pset.get<std::string >("OutputCoherentPath", "Cor");
338  fDiagnosticOutput = pset.get<bool >("DiagnosticOutput", false);
339  fCoherentNoiseGrouping = pset.get<size_t >("CoherentGrouping", 64);
340 
341 }
bool fOutputRawWaveform
Should we output pedestal corrected (not noise filtered)?
size_t fCoherentNoiseGrouping
channels in common for coherent noise
bool fOutputCorrection
Should we output the coherent noise correction vectors?
std::string fOutputCoherentPath
Path to assign to the output if asked for.
std::vector< art::InputTag > fRawDigitLabelVec
The input artdaq fragment label vector (for more than one)
bool fDiagnosticOutput
Set this to get lots of messages.
std::string fOutputRawWavePath
Path to assign to the output if asked for.
std::vector< std::string > fOutInstanceLabelVec
The output instance labels to apply.
void daq::MCDecoderICARUSTPCwROI::endJob ( art::ProcessingFrame const &  frame)
virtual

End job method.

Definition at line 756 of file MCDecoderICARUSTPCwROI_module.cc.

757 {
758  mf::LogInfo(fLogCategory) << "Looked at " << fNumEvent << " events" << std::endl;
759 }
const std::string fLogCategory
Output category when logging messages.
void daq::MCDecoderICARUSTPCwROI::processSingleImage ( const detinfo::DetectorClocksData clockData,
const ChannelArrayPair channelArrayPair,
size_t  coherentNoiseGrouping,
ConcurrentRawDigitCol concurrentRawDigitCol,
ConcurrentRawDigitCol concurrentRawRawDigitCol,
ConcurrentRawDigitCol coherentRawDigitCol,
ConcurrentWireCol concurrentROIs 
) const

Definition at line 617 of file MCDecoderICARUSTPCwROI_module.cc.

624 {
625  // Let's go through and fill the output vector
626  const daq::INoiseFilter::ChannelPlaneVec& channelVec = channelArrayPair.first;
627  const icarus_signal_processing::ArrayFloat& dataArray = channelArrayPair.second;
628 
629  unsigned int numChannels = dataArray.size();
630  unsigned int numTicks = dataArray[0].size();
631 
632  // Recover pointer to the decoder needed here
633  INoiseFilter* decoderTool = fDecoderToolVec[tbb::this_task_arena::current_thread_index()].get();
634 
635  //process_fragment(event, rawfrag, product_collection, header_collection);
636  decoderTool->process_fragment(clockData, channelVec, dataArray, coherentNoiseGrouping);
637 
638  // Now set up for output, we need to convert back from float to short int so use this
639  raw::RawDigit::ADCvector_t wvfm(numTicks);
640 
641  // Loop over the channels to recover the RawDigits after filtering
642  for(size_t chanIdx = 0; chanIdx < numChannels; chanIdx++)
643  {
644  // Skip if no channel data (plane is wrong)
645  if (channelVec[chanIdx].second > 2) continue;
646 
647  raw::ChannelID_t channel = channelVec[chanIdx].first;
648 
649  if (fOutputRawWaveform)
650  {
651  const icarus_signal_processing::VectorFloat& waveform = decoderTool->getPedCorWaveforms()[chanIdx];
652 
653  // Need to convert from float to short int
654  std::transform(waveform.begin(),waveform.end(),wvfm.begin(),[](const auto& val){return short(std::round(val));});
655 
656  ConcurrentRawDigitCol::iterator newRawObjItr = concurrentRawRawDigitCol.emplace_back(channel,wvfm.size(),wvfm);
657 
658  newRawObjItr->SetPedestal(decoderTool->getPedestalVals()[chanIdx],decoderTool->getFullRMSVals()[chanIdx]);
659  }
660 
661  if (fOutputCorrection)
662  {
663  const icarus_signal_processing::VectorFloat& corrections = decoderTool->getCorrectedMedians()[chanIdx];
664 
665  // Need to convert from float to short int
666  std::transform(corrections.begin(),corrections.end(),wvfm.begin(),[](const auto& val){return short(std::round(val));});
667 
668  //ConcurrentRawDigitCol::iterator newRawObjItr = coherentRawDigitCol.emplace_back(channel,wvfm.size(),wvfm);
669  ConcurrentRawDigitCol::iterator newRawObjItr = coherentRawDigitCol.push_back(raw::RawDigit(channel,wvfm.size(),wvfm));
670 
671  newRawObjItr->SetPedestal(0.,0.);
672  }
673 
674  // Recover the denoised waveform
675  const icarus_signal_processing::VectorFloat& denoised = decoderTool->getWaveLessCoherent()[chanIdx];
676 
677  // Need to convert from float to short int
678  std::transform(denoised.begin(),denoised.end(),wvfm.begin(),[](const auto& val){return short(std::round(val));});
679 
680  ConcurrentRawDigitCol::iterator newObjItr = concurrentRawDigitCol.emplace_back(channel,wvfm.size(),wvfm);
681 
682  newObjItr->SetPedestal(0.,decoderTool->getTruncRMSVals()[chanIdx]);
683 
684  // And, finally, the ROIs
685  const icarus_signal_processing::VectorBool& chanROIs = decoderTool->getROIVals()[chanIdx];
687 
688  // Go through candidate ROIs and create Wire ROIs
689  size_t roiIdx = 0;
690 
691  while(roiIdx < chanROIs.size())
692  {
693  size_t roiStartIdx = roiIdx;
694 
695  while(roiIdx < chanROIs.size() && chanROIs[roiIdx]) roiIdx++;
696 
697  if (roiIdx > roiStartIdx)
698  {
699  std::vector<float> holder(roiIdx - roiStartIdx, 10.);
700 
701  ROIVec.add_range(roiStartIdx, std::move(holder));
702  }
703 
704  roiIdx++;
705  }
706 
707  concurrentROIs.push_back(recob::WireCreator(std::move(ROIVec),channel,fGeometry->View(channel)).move());
708  }//loop over channel indices
709 
710  return;
711 }
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:69
static constexpr Sample_t transform(Sample_t sample)
bool fOutputRawWaveform
Should we output pedestal corrected (not noise filtered)?
bool fOutputCorrection
Should we output the coherent noise correction vectors?
std::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
Definition: RawDigit.h:73
const datarange_t & add_range(size_type offset, ITER first, ITER last)
Adds a sequence of elements as a range with specified offset.
Class managing the creation of a new recob::Wire object.
Definition: WireCreator.h:53
geo::GeometryCore const * fGeometry
pointer to Geometry service
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
std::vector< std::unique_ptr< INoiseFilter > > fDecoderToolVec
Decoder tools.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
std::vector< ChannelPlanePair > ChannelPlaneVec
Definition: INoiseFilter.h:54
void daq::MCDecoderICARUSTPCwROI::processSingleLabel ( art::Event &  event,
const art::InputTag &  inputLabel,
detinfo::DetectorClocksData const &  clockData,
ChannelArrayPairVec const &  channelArrayPairVec,
size_t const &  coherentNoiseGrouping,
ConcurrentRawDigitCol concurrentRawDigits,
ConcurrentRawDigitCol concurrentRawRawDigits,
ConcurrentRawDigitCol coherentRawDigits,
ConcurrentWireCol concurrentROIs 
) const
private

Definition at line 480 of file MCDecoderICARUSTPCwROI_module.cc.

489 {
490  cet::cpu_timer theClockProcess;
491 
492  theClockProcess.start();
493 
494  // Read in the digit List object(s).
495  art::Handle< std::vector<raw::RawDigit> > digitVecHandle;
496  event.getByLabel(inputLabel, digitVecHandle);
497 
498  // Require a valid handle
499  if (digitVecHandle.isValid() && digitVecHandle->size()>0 )
500  {
501  // Sadly, the RawDigits come to us in an unsorted condition which is not optimal for
502  // what we want to do here. So we make a vector of pointers to the input raw digits and sort them
503  std::vector<const raw::RawDigit*> rawDigitVec;
504 
505  // Ugliness to fill the pointer vector...
506  for(size_t idx = 0; idx < digitVecHandle->size(); idx++) rawDigitVec.emplace_back(&digitVecHandle->at(idx)); //art::Ptr<raw::RawDigit>(digitVecHandle, idx).get());
507 
508  // Sort (use a lambda to sort by channel id)
509  std::sort(rawDigitVec.begin(),rawDigitVec.end(),[](const raw::RawDigit* left, const raw::RawDigit* right) {return left->Channel() < right->Channel();});
510 
511  // Declare a temporary digit holder and resize it if downsizing the waveform
512  unsigned int dataSize = art::Ptr<raw::RawDigit>(digitVecHandle,0)->Samples(); //size of raw data vectors
513  raw::RawDigit::ADCvector_t rawDataVec(dataSize);
514 
515  using BoardToChannelArrayPairMap = std::map<unsigned int, ChannelArrayPair>;
516 
517  BoardToChannelArrayPairMap boardToChannelArrayPairMap;
518  std::map<unsigned int, int> boardWireCountMap;
519  const unsigned int MAXCHANNELS(64);
520 
521  // Commence looping over raw digits
522  for(const auto& rawDigit : rawDigitVec)
523  {
524  raw::ChannelID_t channel = rawDigit->Channel();
525 
526  ChannelToBoardWirePlaneMap::const_iterator channelToBoardItr = fChannelToBoardWirePlaneMap.find(channel);
527 
528  if (channelToBoardItr == fChannelToBoardWirePlaneMap.end())
529  {
530  std::cout << "********************************************************************************" << std::endl;
531  std::cout << "********* We did not find channel " << channel << "*****************************" << std::endl;
532  std::cout << "********************************************************************************" << std::endl;
533  continue;
534  }
535 
536  unsigned int readoutBoardID = channelToBoardItr->second.first;
537  unsigned int wireIdx = channelToBoardItr->second.second.first;
538  unsigned int planeIdx = channelToBoardItr->second.second.second;
539 
540  BoardToChannelArrayPairMap::iterator boardMapItr = boardToChannelArrayPairMap.find(readoutBoardID);
541 
542  if (boardMapItr == boardToChannelArrayPairMap.end())
543  {
544  const auto [mapItr, success] =
545  boardToChannelArrayPairMap.insert({readoutBoardID,{daq::INoiseFilter::ChannelPlaneVec(MAXCHANNELS,{0,3}),icarus_signal_processing::ArrayFloat(MAXCHANNELS,icarus_signal_processing::VectorFloat(dataSize))}});
546 
547  if (!success)
548  {
549  std::cout << "+++> failed to insert data structure! " << std::endl;
550  continue;
551  }
552 
553  boardMapItr = mapItr;
554  boardWireCountMap[readoutBoardID] = 0;
555  }
556 
557  // Decompress data into local holder
558  raw::Uncompress(rawDigit->ADCs(), rawDataVec, rawDigit->Compression());
559 
560  // Fill into the data structure
561  icarus_signal_processing::VectorFloat& boardDataVec = boardMapItr->second.second[wireIdx];
562 
563  for(size_t tick = 0; tick < dataSize; tick++) boardDataVec[tick] = rawDataVec[tick];
564 
565  boardMapItr->second.first[wireIdx] = daq::INoiseFilter::ChannelPlanePair(channel,planeIdx);
566 
567  if (++boardWireCountMap[readoutBoardID] == MAXCHANNELS)
568  {
569  processSingleImage(clockData, boardMapItr->second, coherentNoiseGrouping, concurrentRawDigits, concurrentRawRawDigits, coherentRawDigits, concurrentROIs);
570 
571  boardToChannelArrayPairMap.erase(boardMapItr);
572 
573  // Get the wireIDs for this channel
574 // std::vector<geo::WireID> wids = fGeometry->ChannelToWire(channel);
575 //
576 // // Since we work with channels we can ignore the case in the middle of the TPC where there are
577 // // wires crossing the midplane and just work with the first wire ID
578 // const geo::WireID& wireID = wids[0];
579 // const geo::PlaneID& planeID = wireID.planeID();
580 //
581 // // Ok, now store things...
582 // unsigned int planeIndex = fPlaneToROPPlaneMap.find(planeID)->second;
583 // unsigned int wire = channel - fPlaneToWireOffsetMap.find(planeID)->second;
584 //
585 // if (wire >= channelArrayPairVec[planeIndex].second.size()) continue;
586 //
587 // icarus_signal_processing::VectorFloat& dataVec = channelArrayPairVec[planeIndex].second[wire];
588 //
589 // for(size_t tick = 0; tick < dataSize; tick++) dataVec[tick] = rawDataVec[tick];
590 //
591 // // Keep track of the channel
592 // channelArrayPairVec[planeIndex].first[wire] = daq::INoiseFilter::ChannelPlanePair(channel,planeID.Plane);
593  }
594  }
595 
596  // Some detector simulations don't output channels that don't have any possibility of signal (ghost channels)
597  // Do a cleanup phase here to find these
598  for(auto& boardInfo : boardToChannelArrayPairMap)
599  {
600  if (boardWireCountMap[boardInfo.first] < 64)
601  {
602  processSingleImage(clockData, boardInfo.second, boardWireCountMap[boardInfo.first], concurrentRawDigits, concurrentRawRawDigits, coherentRawDigits, concurrentROIs);
603  }
604  }
605 
606  }
607 
608  theClockProcess.stop();
609 
610  double totalTime = theClockProcess.accumulated_real_time();
611 
612  mf::LogDebug(fLogCategory) << "--> Exiting fragment processing for thread: " << tbb::this_task_arena::current_thread_index() << ", time: " << totalTime << std::endl;
613 
614  return;
615 }
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:69
ChannelToBoardWirePlaneMap fChannelToBoardWirePlaneMap
walls no right
Definition: selectors.fcl:105
ChannelID_t Channel() const
DAQ channel this raw data was read from.
Definition: RawDigit.h:212
std::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
Definition: RawDigit.h:73
void processSingleImage(const detinfo::DetectorClocksData &, const ChannelArrayPair &, size_t, ConcurrentRawDigitCol &, ConcurrentRawDigitCol &, ConcurrentRawDigitCol &, ConcurrentWireCol &) const
std::pair< unsigned int, unsigned int > ChannelPlanePair
Given a set of recob hits, run DBscan to form 3D clusters.
Definition: INoiseFilter.h:53
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:75
walls no left
Definition: selectors.fcl:105
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:776
const std::string fLogCategory
Output category when logging messages.
BEGIN_PROLOG could also be cout
std::vector< ChannelPlanePair > ChannelPlaneVec
Definition: INoiseFilter.h:54
void daq::MCDecoderICARUSTPCwROI::produce ( art::Event &  event,
art::ProcessingFrame const &  frame 
)
virtual

Produce method.

Arguments:

evt - Art event.

This is the primary method.

Definition at line 359 of file MCDecoderICARUSTPCwROI_module.cc.

360 {
361  ++fNumEvent;
362 
363  mf::LogDebug("MCDecoderICARUSTPCwROI") << "**** Processing raw data fragments ****" << std::endl;
364 
365  // Check the concurrency
366  int max_concurrency = tbb::this_task_arena::max_concurrency();
367 
368  mf::LogDebug("MCDecoderICARUSTPCwROI") << " ==> concurrency: " << max_concurrency << std::endl;
369 
370  cet::cpu_timer theClockTotal;
371 
372  theClockTotal.start();
373 
374  // Loop through the list of input daq fragment collections one by one
375  // We are not trying to multi thread at this stage because we are trying to control
376  // overall memory usage at this level. We'll multi thread internally...
377  size_t instanceIdx(0);
378 
379  for(const auto& rawDigitLabel : fRawDigitLabelVec)
380  {
381  art::Handle<artdaq::Fragments> daq_handle;
382  event.getByLabel(rawDigitLabel, daq_handle);
383 
384  ConcurrentRawDigitCol concurrentRawDigits;
385  ConcurrentRawDigitCol concurrentRawRawDigits;
386  ConcurrentRawDigitCol coherentRawDigits;
387  ConcurrentWireCol concurrentROIs;
388 
389  PlaneIdxToImageMap planeIdxToImageMap;
390  PlaneIdxToChannelMap planeIdxToChannelMap;
391 
392  ChannelArrayPairVec channelArrayPairVec(fNumROPs);
393 
394  // Because the arrays can be variable size we need to loop to initialize
395  for(size_t ropIdx = 0; ropIdx < fNumROPs; ropIdx++)
396  {
397  ChannelArrayPair& channelArrayPair = channelArrayPairVec[ropIdx];
398 
399  channelArrayPair.first.resize(fROPToNumWiresMap[ropIdx]);
400  channelArrayPair.second.resize(fROPToNumWiresMap[ropIdx],icarus_signal_processing::VectorFloat(4096));
401 
402  mf::LogDebug("MCDecoderICARUSTPCwROI") << "**> Initializing ropIdx: " << ropIdx << " channelPairVec to " << channelArrayPair.first.size() << " channels with " << channelArrayPair.second[0].size() << " ticks" << std::endl;
403  }
404 
405  mf::LogDebug("MCDecoderICARUSTPCwROI") << "****> Let's get ready to rumble!" << std::endl;
406 
407  // Now let's process the resulting images
408  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService>()->DataFor(event);
409 
410  // ... repackage the input MC data to format suitable for noise processing
411  processSingleLabel(event, rawDigitLabel, clockData, channelArrayPairVec, fCoherentNoiseGrouping, concurrentRawDigits, concurrentRawRawDigits, coherentRawDigits, concurrentROIs);
412 
413 // multiThreadImageProcessing imageProcessing(*this, clockData, channelArrayPairVec, fCoherentNoiseGrouping, concurrentRawDigits, concurrentRawRawDigits, coherentRawDigits, concurrentROIs);
414 //
415 // tbb::parallel_for(tbb::blocked_range<size_t>(0, fNumROPs), imageProcessing);
416 
417  // Copy the raw digits from the concurrent vector to our output vector
418  RawDigitCollectionPtr rawDigitCollection = std::make_unique<std::vector<raw::RawDigit>>(std::move_iterator(concurrentRawDigits.begin()),
419  std::move_iterator(concurrentRawDigits.end()));
420 
421  // Want the RawDigits to be sorted in channel order... has to be done somewhere so why not now?
422  std::sort(rawDigitCollection->begin(),rawDigitCollection->end(),[](const auto& left,const auto&right){return left.Channel() < right.Channel();});
423 
424  // What did we get back?
425  mf::LogDebug("MCDecoderICARUSTPCwROI") << "****> Total size of map: " << planeIdxToImageMap.size() << std::endl;
426  for(const auto& planeImagePair : planeIdxToImageMap)
427  {
428  mf::LogDebug("MCDecoderICARUSTPCwROI") << " - plane: " << planeImagePair.first << " has " << planeImagePair.second.size() << " wires" << std::endl;
429  }
430 
431  // Now transfer ownership to the event store
432  event.put(std::move(rawDigitCollection), fOutInstanceLabelVec[instanceIdx]);
433 
434  // Do the same to output the candidate ROIs
435  WireCollectionPtr wireCollection = std::make_unique<std::vector<recob::Wire>>(std::move_iterator(concurrentROIs.begin()),
436  std::move_iterator(concurrentROIs.end()));
437 
438  std::sort(wireCollection->begin(),wireCollection->end(),[](const auto& left, const auto& right){return left.Channel() < right.Channel();});
439 
440  event.put(std::move(wireCollection), fOutInstanceLabelVec[instanceIdx]);
441 
442  if (fOutputRawWaveform)
443  {
444  // Copy the raw digits from the concurrent vector to our output vector
445  RawDigitCollectionPtr rawRawDigitCollection = std::make_unique<std::vector<raw::RawDigit>>(std::move_iterator(concurrentRawRawDigits.begin()),
446  std::move_iterator(concurrentRawRawDigits.end()));
447 
448  // Want the RawDigits to be sorted in channel order... has to be done somewhere so why not now?
449  std::sort(rawRawDigitCollection->begin(),rawRawDigitCollection->end(),[](const auto& left,const auto&right){return left.Channel() < right.Channel();});
450 
451  // Now transfer ownership to the event store
452  event.put(std::move(rawRawDigitCollection),fOutInstanceLabelVec[instanceIdx] + fOutputRawWavePath);
453  }
454 
455  if (fOutputCorrection)
456  {
457  // Copy the raw digits from the concurrent vector to our output vector
458  RawDigitCollectionPtr coherentCollection = std::make_unique<std::vector<raw::RawDigit>>(std::move_iterator(coherentRawDigits.begin()),
459  std::move_iterator(coherentRawDigits.end()));
460 
461  // Want the RawDigits to be sorted in channel order... has to be done somewhere so why not now?
462  std::sort(coherentCollection->begin(),coherentCollection->end(),[](const auto& left,const auto&right){return left.Channel() < right.Channel();});
463 
464  // Now transfer ownership to the event store
465  event.put(std::move(coherentCollection),fOutInstanceLabelVec[instanceIdx] + fOutputCoherentPath);
466  }
467 
468  instanceIdx++;
469  }
470 
471  theClockTotal.stop();
472 
473  double totalTime = theClockTotal.accumulated_real_time();
474 
475  mf::LogInfo(fLogCategory) << "==> MCDecoderICARUSTPCwROI total time: " << totalTime << std::endl;
476 
477  return;
478 }
bool fOutputRawWaveform
Should we output pedestal corrected (not noise filtered)?
size_t fCoherentNoiseGrouping
channels in common for coherent noise
std::vector< ChannelArrayPair > ChannelArrayPairVec
walls no right
Definition: selectors.fcl:105
bool fOutputCorrection
Should we output the coherent noise correction vectors?
std::map< unsigned int, icarus_signal_processing::ArrayFloat > PlaneIdxToImageMap
tbb::concurrent_vector< recob::Wire > ConcurrentWireCol
std::unique_ptr< RawDigitCollection > RawDigitCollectionPtr
std::pair< daq::INoiseFilter::ChannelPlaneVec, icarus_signal_processing::ArrayFloat > ChannelArrayPair
std::string fOutputCoherentPath
Path to assign to the output if asked for.
std::unique_ptr< WireCollection > WireCollectionPtr
std::vector< art::InputTag > fRawDigitLabelVec
The input artdaq fragment label vector (for more than one)
walls no left
Definition: selectors.fcl:105
std::string fOutputRawWavePath
Path to assign to the output if asked for.
std::map< unsigned int, ChannelVec > PlaneIdxToChannelMap
void processSingleLabel(art::Event &, const art::InputTag &, detinfo::DetectorClocksData const &, ChannelArrayPairVec const &, size_t const &, ConcurrentRawDigitCol &, ConcurrentRawDigitCol &, ConcurrentRawDigitCol &, ConcurrentWireCol &) const
const std::string fLogCategory
Output category when logging messages.
tbb::concurrent_vector< raw::RawDigit > ConcurrentRawDigitCol
std::vector< std::string > fOutInstanceLabelVec
The output instance labels to apply.
void daq::MCDecoderICARUSTPCwROI::saveRawDigits ( const icarus_signal_processing::ArrayFloat &  dataArray,
const icarus_signal_processing::VectorFloat &  pedestalVec,
const icarus_signal_processing::VectorFloat &  rmsVec,
const icarus_signal_processing::VectorInt &  channelVec,
ConcurrentRawDigitCol rawDigitCol 
) const
private

Definition at line 713 of file MCDecoderICARUSTPCwROI_module.cc.

718 {
719  if (!dataArray.empty())
720  {
721  cet::cpu_timer theClockSave;
722 
723  theClockSave.start();
724 
725  raw::RawDigit::ADCvector_t wvfm(dataArray[0].size());
726 
727  mf::LogDebug(fLogCategory) << " --> saving rawdigits for " << dataArray.size() << " channels" << std::endl;
728 
729  // Loop over the channels to recover the RawDigits after filtering
730  for(size_t chanIdx = 0; chanIdx != dataArray.size(); chanIdx++)
731  {
732  // Protect against case where there was no readout
733  if (channelVec[chanIdx] < 0) continue;
734 
735  const icarus_signal_processing::VectorFloat& dataVec = dataArray[chanIdx];
736 
737  // Need to convert from float to short int
738  std::transform(dataVec.begin(),dataVec.end(),wvfm.begin(),[](const auto& val){return short(std::round(val));});
739 
740  ConcurrentRawDigitCol::iterator newObjItr = rawDigitCol.emplace_back(channelVec[chanIdx],wvfm.size(),wvfm);
741  newObjItr->SetPedestal(pedestalVec[chanIdx],rmsVec[chanIdx]);
742  }//loop over channel indices
743 
744  theClockSave.stop();
745 
746  double totalTime = theClockSave.accumulated_real_time();
747 
748  mf::LogDebug(fLogCategory) << " --> done with save, time: " << totalTime << std::endl;
749  }
750 
751  return;
752 }
static constexpr Sample_t transform(Sample_t sample)
std::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
Definition: RawDigit.h:73
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
const std::string fLogCategory
Output category when logging messages.

Member Data Documentation

const icarusDB::IICARUSChannelMap* daq::MCDecoderICARUSTPCwROI::fChannelMap
private

Definition at line 199 of file MCDecoderICARUSTPCwROI_module.cc.

ChannelToBoardWirePlaneMap daq::MCDecoderICARUSTPCwROI::fChannelToBoardWirePlaneMap
private

Definition at line 192 of file MCDecoderICARUSTPCwROI_module.cc.

size_t daq::MCDecoderICARUSTPCwROI::fCoherentNoiseGrouping
private

channels in common for coherent noise

Definition at line 171 of file MCDecoderICARUSTPCwROI_module.cc.

std::vector<std::unique_ptr<INoiseFilter> > daq::MCDecoderICARUSTPCwROI::fDecoderToolVec
private

Decoder tools.

Definition at line 195 of file MCDecoderICARUSTPCwROI_module.cc.

bool daq::MCDecoderICARUSTPCwROI::fDiagnosticOutput
private

Set this to get lots of messages.

Definition at line 170 of file MCDecoderICARUSTPCwROI_module.cc.

geo::GeometryCore const* daq::MCDecoderICARUSTPCwROI::fGeometry
private

pointer to Geometry service

Definition at line 198 of file MCDecoderICARUSTPCwROI_module.cc.

const std::string daq::MCDecoderICARUSTPCwROI::fLogCategory
private

Output category when logging messages.

Definition at line 173 of file MCDecoderICARUSTPCwROI_module.cc.

int daq::MCDecoderICARUSTPCwROI::fNumEvent
private

Number of events seen.

Definition at line 176 of file MCDecoderICARUSTPCwROI_module.cc.

unsigned int daq::MCDecoderICARUSTPCwROI::fNumROPs
private

Definition at line 186 of file MCDecoderICARUSTPCwROI_module.cc.

std::vector<std::string> daq::MCDecoderICARUSTPCwROI::fOutInstanceLabelVec
private

The output instance labels to apply.

Definition at line 165 of file MCDecoderICARUSTPCwROI_module.cc.

std::string daq::MCDecoderICARUSTPCwROI::fOutputCoherentPath
private

Path to assign to the output if asked for.

Definition at line 169 of file MCDecoderICARUSTPCwROI_module.cc.

bool daq::MCDecoderICARUSTPCwROI::fOutputCorrection
private

Should we output the coherent noise correction vectors?

Definition at line 167 of file MCDecoderICARUSTPCwROI_module.cc.

bool daq::MCDecoderICARUSTPCwROI::fOutputRawWaveform
private

Should we output pedestal corrected (not noise filtered)?

Definition at line 166 of file MCDecoderICARUSTPCwROI_module.cc.

std::string daq::MCDecoderICARUSTPCwROI::fOutputRawWavePath
private

Path to assign to the output if asked for.

Definition at line 168 of file MCDecoderICARUSTPCwROI_module.cc.

PlaneToROPPlaneMap daq::MCDecoderICARUSTPCwROI::fPlaneToROPPlaneMap
private

Definition at line 183 of file MCDecoderICARUSTPCwROI_module.cc.

PlaneToWireOffsetMap daq::MCDecoderICARUSTPCwROI::fPlaneToWireOffsetMap
private

Definition at line 184 of file MCDecoderICARUSTPCwROI_module.cc.

std::vector<art::InputTag> daq::MCDecoderICARUSTPCwROI::fRawDigitLabelVec
private

The input artdaq fragment label vector (for more than one)

Definition at line 164 of file MCDecoderICARUSTPCwROI_module.cc.

ROPToNumWiresMap daq::MCDecoderICARUSTPCwROI::fROPToNumWiresMap
private

Definition at line 185 of file MCDecoderICARUSTPCwROI_module.cc.


The documentation for this class was generated from the following file: