All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Decon1DROI_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Decon1DROI class - variant of CalWire that deconvolves in
4 // Regions Of Interest
5 //
6 // baller@fnal.gov
7 //
8 //
9 ////////////////////////////////////////////////////////////////////////
10 
11 // C/C++ standard libraries
12 #include <string>
13 #include <vector>
14 #include <utility> // std::pair<>
15 #include <memory> // std::unique_ptr<>
16 #include <iomanip>
17 #include <fstream>
18 #include <random>
19 
20 // ROOT libraries
21 #include "TH1D.h"
22 #include "TProfile.h"
23 
24 // framework libraries
25 #include "art/Framework/Core/ModuleMacros.h"
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/Utilities/make_tool.h"
31 #include "canvas/Persistency/Common/Ptr.h"
32 #include "canvas/Persistency/Common/PtrVector.h"
33 #include "messagefacility/MessageLogger/MessageLogger.h"
34 #include "cetlib/cpu_timer.h"
35 
36 // LArSoft libraries
37 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
39 #include "larcore/CoreUtils/ServiceUtil.h" // lar::providerFrom()
41 #include "lardataobj/RawData/raw.h"
50 
54 #include "icarus_signal_processing/WaveformTools.h"
55 
56 #include "tbb/parallel_for.h"
57 #include "tbb/blocked_range.h"
58 #include "tbb/task_arena.h"
59 #include "tbb/spin_mutex.h"
60 
61 ///creation of calibrated signals on wires
62 namespace caldata {
63 
64 tbb::spin_mutex deconvolutionSpinMutex;
65 
66 class Decon1DROI : public art::ReplicatedProducer
67 {
68  public:
69  // create calibrated signals on wires. this class runs
70  // an fft to remove the electronics shaping.
71  explicit Decon1DROI(fhicl::ParameterSet const &, art::ProcessingFrame const&);
72 
73  void produce(art::Event& evt, art::ProcessingFrame const&) override;
74  // void beginJob() override;
75  // void endJob() override;
76  void reconfigure(fhicl::ParameterSet const& p);
77 
78  private:
79 
80  // Define a class to handle processing for individual threads
82  {
83  public:
85  art::Event& event,
86  art::Handle<std::vector<raw::RawDigit>>& rawDigitHandle,
87  std::vector<recob::Wire>& wireColVec,
88  art::Assns<raw::RawDigit,recob::Wire>& wireAssns,
89  std::string const& instance)
90  : fDecon1DROI(parent),
91  fEvent(event),
92  fRawDigitHandle(rawDigitHandle),
93  fWireColVec(wireColVec),
94  fWireAssns(wireAssns),
95  fInstance(instance)
96  {}
97 
98  void operator()(const tbb::blocked_range<size_t>& range) const
99  {
100  for (size_t idx = range.begin(); idx < range.end(); idx++)
102  }
103  private:
105  art::Event& fEvent;
106  art::Handle<std::vector<raw::RawDigit>>& fRawDigitHandle;
107  std::vector<recob::Wire>& fWireColVec;
108  art::Assns<raw::RawDigit,recob::Wire>& fWireAssns;
109  std::string fInstance;
110  };
111 
112  // It seems there are pedestal shifts that need correcting
113  float fixTheFreakingWaveform(const std::vector<float>&, raw::ChannelID_t, std::vector<float>&) const;
114 
115  float getTruncatedRMS(const std::vector<float>&) const;
116 
117  // Function to do the work
118  void processChannel(size_t,
119  art::Event&,
120  art::Handle<std::vector<raw::RawDigit>>,
121  std::vector<recob::Wire>&,
122  art::Assns<raw::RawDigit,recob::Wire>&,
123  const std::string&) const;
124 
125  std::vector<art::InputTag> fRawDigitLabelVec; ///< Contains the input tags for finding RawDigits
126  ///< it is set by the DigitModuleLabel
127  ///< ex.: "daq:preSpill" for prespill data
128  unsigned short fNoiseSource; ///< Used to determine ROI threshold
129  int fSaveWireWF; ///< Save recob::wire object waveforms
130  size_t fEventCount; ///< count of event processed
131  int fMinAllowedChanStatus; ///< Don't consider channels with lower status
132 
133  float fTruncRMSThreshold; ///< Calculate RMS up to this threshold...
134  float fTruncRMSMinFraction; ///< or at least this fraction of time bins
135  bool fOutputHistograms; ///< Output histograms?
136 
137  std::vector<std::unique_ptr<icarus_tool::IROIFinder>> fROIFinderVec; ///< ROI finders per plane
138  std::unique_ptr<icarus_tool::IDeconvolution> fDeconvolution;
139  std::unique_ptr<icarus_tool::IBaseline> fBaseline;
140 
141  icarus_signal_processing::WaveformTools<float> fWaveformTool;
142 
143  const geo::GeometryCore* fGeometry = lar::providerFrom<geo::Geometry>();
144  const lariov::ChannelStatusProvider* fChannelFilter = lar::providerFrom<lariov::ChannelStatusService>();
145  const lariov::DetPedestalProvider* fPedRetrievalAlg = lar::providerFrom<lariov::DetPedestalService>();
146 
147  // Define here a temporary set of histograms...
148  std::vector<TH1F*> fPedestalOffsetVec;
149  std::vector<TH1F*> fFullRMSVec;
150  std::vector<TH1F*> fTruncRMSVec;
151  std::vector<TH1F*> fNumTruncBinsVec;
152  std::vector<TProfile*> fPedByChanVec;
153  std::vector<TProfile*> fTruncRMSByChanVec;
154  std::vector<TH1F*> fNumROIsHistVec;
155  std::vector<TH1F*> fROILenHistVec;
156 
157 }; // class Decon1DROI
158 
159 DEFINE_ART_MODULE(Decon1DROI)
160 
161 //-------------------------------------------------
162 Decon1DROI::Decon1DROI(fhicl::ParameterSet const & pset, art::ProcessingFrame const& frame) : art::ReplicatedProducer(pset,frame)
163 {
164  this->reconfigure(pset);
165 
166  // We create a separate output instance for each input instance
167  for(const auto& rawDigit : fRawDigitLabelVec)
168  {
169  produces< std::vector<recob::Wire> >(rawDigit.instance());
170  produces<art::Assns<raw::RawDigit, recob::Wire>>(rawDigit.instance());
171  }
172  fEventCount = 0;
173 }
174 
175 //////////////////////////////////////////////////////
176 void Decon1DROI::reconfigure(fhicl::ParameterSet const& pset)
177 {
178  // Recover the parameters
179  fRawDigitLabelVec = pset.get< std::vector<art::InputTag>> ("RawDigitLabelVec", {"daqTPC"});
180  fNoiseSource = pset.get< unsigned short > ("NoiseSource", 3);
181  fSaveWireWF = pset.get< int > ("SaveWireWF" );
182  fMinAllowedChanStatus = pset.get< int > ("MinAllowedChannelStatus" );
183  fTruncRMSThreshold = pset.get< float > ("TruncRMSThreshold", 6.);
184  fTruncRMSMinFraction = pset.get< float > ("TruncRMSMinFraction", 0.6);
185  fOutputHistograms = pset.get< bool > ("OutputHistograms", true);
186 
187  // Recover the vector of fhicl parameters for the ROI tools
188  const fhicl::ParameterSet& roiFinderTools = pset.get<fhicl::ParameterSet>("ROIFinderToolVec");
189 
190  fROIFinderVec.resize(roiFinderTools.get_pset_names().size());
191 
192  unsigned short roiPadding(std::numeric_limits<unsigned short>::max());
193 
194  for(const std::string& roiFinderTool : roiFinderTools.get_pset_names())
195  {
196  const fhicl::ParameterSet& roiFinderToolParamSet = roiFinderTools.get<fhicl::ParameterSet>(roiFinderTool);
197  size_t planeIdx = roiFinderToolParamSet.get<size_t>("Plane");
198 
199  roiPadding = std::min(roiPadding,roiFinderToolParamSet.get< std::vector<unsigned short>>("roiLeadTrailPad")[0]);
200 
201  fROIFinderVec.at(planeIdx) = art::make_tool<icarus_tool::IROIFinder>(roiFinderToolParamSet);
202  }
203 
204  std::sort(fROIFinderVec.begin(),fROIFinderVec.end(),[](const auto& left,const auto& right){return left->plane() < right->plane();});
205 
206  fDeconvolution = art::make_tool<icarus_tool::IDeconvolution>(pset.get<fhicl::ParameterSet>("Deconvolution"));
207 
208  // Recover the baseline tool
209  fhicl::ParameterSet baselineParams = pset.get<fhicl::ParameterSet>("Baseline");
210 
211  // Check if we need to set the length for setting the baseline
212  if (baselineParams.has_key("MaxROILength")) baselineParams.put_or_replace("MaxROILength",size_t(roiPadding));
213 
214  fBaseline = art::make_tool<icarus_tool::IBaseline> (baselineParams);
215 
216  if (fOutputHistograms)
217  {
218  // Access ART's TFileService, which will handle creating and writing
219  // histograms and n-tuples for us.
220  art::ServiceHandle<art::TFileService> tfs;
221 
222  fPedestalOffsetVec.resize(3);
223  fFullRMSVec.resize(3);
224  fTruncRMSVec.resize(3);
225  fNumTruncBinsVec.resize(3);
226  fPedByChanVec.resize(3);
227  fTruncRMSByChanVec.resize(3);
228  fNumROIsHistVec.resize(3);
229  fROILenHistVec.resize(3);
230 
231  for(size_t planeIdx = 0; planeIdx < 3; planeIdx++)
232  {
233  fPedestalOffsetVec[planeIdx] = tfs->make<TH1F>( Form("PedPlane_%02zu",planeIdx), ";Pedestal Offset (ADC);", 100, -5., 5.);
234  fFullRMSVec[planeIdx] = tfs->make<TH1F>( Form("RMSFPlane_%02zu",planeIdx), "Full RMS;RMS (ADC);", 400, 0., 40.);
235  fTruncRMSVec[planeIdx] = tfs->make<TH1F>( Form("RMSTPlane_%02zu",planeIdx), "Truncated RMS;RMS (ADC);", 100, 0., 10.);
236  fNumTruncBinsVec[planeIdx] = tfs->make<TH1F>( Form("NTruncBins_%02zu",planeIdx), ";# bins", 640, 0., 6400.);
237  fPedByChanVec[planeIdx] = tfs->make<TProfile>(Form("PedByWirePlane_%02zu",planeIdx), ";Wire#", fGeometry->Nwires(planeIdx), 0., fGeometry->Nwires(planeIdx), -5., 5.);
238  fTruncRMSByChanVec[planeIdx] = tfs->make<TProfile>(Form("TruncRMSByWirePlane_%02zu",planeIdx), ";Wire#", fGeometry->Nwires(planeIdx), 0., fGeometry->Nwires(planeIdx), 0., 10.);
239  fNumROIsHistVec[planeIdx] = tfs->make<TH1F>( Form("NROISplane_%02zu",planeIdx), ";# ROIs;", 100, 0, 100);
240  fROILenHistVec[planeIdx] = tfs->make<TH1F>( Form("ROISIZEplane_%02zu",planeIdx), ";ROI size;", 500, 0, 500);
241  }
242  }
243 
244  return;
245 }
246 
247 //-------------------------------------------------
248 /*void Decon1DROI::beginJob()
249 {
250  fEventCount = 0;
251 } // beginJob
252 
253 //////////////////////////////////////////////////////
254 void Decon1DROI::endJob()
255 {
256 }*/
257 
258 //////////////////////////////////////////////////////
259 void Decon1DROI::produce(art::Event& evt, art::ProcessingFrame const& frame)
260 {
261  // We loop over the collection of RawDigits in our input list
262  // This is not done multi threaded as a way to cut down on overall job memory usage...
263  for(const auto& rawDigitLabel : fRawDigitLabelVec)
264  {
265  // make a collection of Wires
266  std::unique_ptr<std::vector<recob::Wire>> wireCol(new std::vector<recob::Wire>);
267 
268  // ... and an association set
269  std::unique_ptr<art::Assns<raw::RawDigit,recob::Wire>> wireDigitAssn(new art::Assns<raw::RawDigit,recob::Wire>);
270 
271  // Read in the digit List object(s).
272  art::Handle< std::vector<raw::RawDigit>> digitVecHandle;
273 
274  evt.getByLabel(rawDigitLabel, digitVecHandle);
275 
276  if (!digitVecHandle->size())
277  {
278  std::cout << "Decon1DROI found zero length RawDigits so exiting" << std::endl;
279 
280  evt.put(std::move(wireCol), rawDigitLabel.instance());
281  evt.put(std::move(wireDigitAssn), rawDigitLabel.instance());
282  fEventCount++;
283 
284  return;
285  }
286 
287  // Reserve the room for the output
288  wireCol->reserve(digitVecHandle->size());
289 
290  // ... Launch multiple threads with TBB to do the deconvolution and find ROIs in parallel
291  multiThreadDeconvolutionProcessing deconvolutionProcessing(*this, evt, digitVecHandle, *wireCol, *wireDigitAssn, rawDigitLabel.instance());
292 
293  tbb::parallel_for(tbb::blocked_range<size_t>(0, digitVecHandle->size()), deconvolutionProcessing);
294 
295  // Time to stroe everything
296  if(wireCol->size() == 0)
297  mf::LogWarning("Decon1DROI") << "No wires made for this event.";
298 
299  //Make Histogram of recob::wire objects from Signal() vector
300  // get access to the TFile service
301  if ( fSaveWireWF ){
302  art::ServiceHandle<art::TFileService> tfs;
303  for (size_t wireN = 0; wireN < wireCol->size(); wireN++){
304  std::vector<float> sigTMP = wireCol->at(wireN).Signal();
305  TH1D* fWire = tfs->make<TH1D>(Form("Noise_Evt%04zu_N%04zu",fEventCount,wireN), ";Noise (ADC);",
306  sigTMP.size(),-0.5,sigTMP.size()-0.5);
307  for (size_t tick = 0; tick < sigTMP.size(); tick++){
308  fWire->SetBinContent(tick+1, sigTMP.at(tick) );
309  }
310  }
311  }
312 
313  // Make sure the collection is sorted
314  std::sort(wireCol->begin(), wireCol->end(), [](const auto& left, const auto& right){return left.Channel() < right.Channel();});
315 
316  evt.put(std::move(wireCol), rawDigitLabel.instance());
317  evt.put(std::move(wireDigitAssn), rawDigitLabel.instance());
318  }
319 
320  fEventCount++;
321 
322  return;
323 } // produce
324 
325 float Decon1DROI::getTruncatedRMS(const std::vector<float>& waveform) const
326 {
327  // do rms calculation - the old fashioned way and over all adc values
328  std::vector<float> locWaveform = waveform;
329 
330  // sort in ascending order so we can truncate the sume
331  std::sort(locWaveform.begin(), locWaveform.end(),[](const auto& left, const auto& right){return std::fabs(left) < std::fabs(right);});
332 
333  float threshold = fTruncRMSThreshold;
334 
335  std::vector<float>::iterator threshItr = std::find_if(locWaveform.begin(),locWaveform.end(),[threshold](const auto& val){return std::fabs(val) > threshold;});
336 
337  int minNumBins = std::max(int(fTruncRMSMinFraction * locWaveform.size()),int(std::distance(locWaveform.begin(),threshItr)));
338 
339  // Get the truncated sum
340  float truncRms = std::inner_product(locWaveform.begin(), locWaveform.begin() + minNumBins, locWaveform.begin(), 0.);
341 
342  truncRms = std::sqrt(std::max(0.,truncRms / double(minNumBins)));
343 
344  return truncRms;
345 }
346 
347 float Decon1DROI::fixTheFreakingWaveform(const std::vector<float>& waveform, raw::ChannelID_t channel, std::vector<float>& fixedWaveform) const
348 {
349  // do rms calculation - the old fashioned way and over all adc values
350  std::vector<float> locWaveform = waveform;
351 
352  // sort in ascending order so we can truncate the sume
353  std::sort(locWaveform.begin(), locWaveform.end(),[](const auto& left, const auto& right){return std::fabs(left) < std::fabs(right);});
354 
355  // Get the mean of the waveform we're checking...
356  float sumWaveform = std::accumulate(locWaveform.begin(),locWaveform.begin() + locWaveform.size()/2, 0.);
357  float meanWaveform = sumWaveform / float(locWaveform.size()/2);
358 
359  std::vector<float> locWaveformDiff(locWaveform.size()/2);
360 
361  std::transform(locWaveform.begin(),locWaveform.begin() + locWaveform.size()/2,locWaveformDiff.begin(), std::bind(std::minus<float>(),std::placeholders::_1,meanWaveform));
362 
363  float localRMS = std::inner_product(locWaveformDiff.begin(), locWaveformDiff.end(), locWaveformDiff.begin(), 0.);
364 
365  localRMS = std::sqrt(std::max(float(0.),localRMS / float(locWaveformDiff.size())));
366 
367  float threshold = 6. * localRMS;
368 
369  std::vector<float>::iterator threshItr = std::find_if(locWaveform.begin(),locWaveform.end(),[threshold](const auto& val){return std::fabs(val) > threshold;});
370 
371  int minNumBins = std::max(int(fTruncRMSMinFraction * locWaveform.size()),int(std::distance(locWaveform.begin(),threshItr)));
372 
373  // recalculate the mean
374  float aveSum = std::accumulate(locWaveform.begin(), locWaveform.begin() + minNumBins, 0.);
375  float newPedestal = aveSum / minNumBins;
376 
377  // recalculate the rms
378  locWaveformDiff.resize(minNumBins);
379 
380  std::transform(locWaveform.begin(),locWaveform.begin() + minNumBins,locWaveformDiff.begin(), std::bind(std::minus<float>(),std::placeholders::_1,newPedestal));
381 
382  localRMS = std::inner_product(locWaveform.begin(), locWaveform.begin() + minNumBins, locWaveform.begin(), 0.);
383  localRMS = std::sqrt(std::max(float(0.),localRMS / float(minNumBins)));
384 
385  // Set the waveform to the new baseline
386  std::transform(waveform.begin(), waveform.end(), fixedWaveform.begin(), [newPedestal](const auto& val){return val - newPedestal;});
387 
388  // Fill histograms
389  if (fOutputHistograms)
390  {
391  std::vector<geo::WireID> wids;
392  try
393  {
394  wids = fGeometry->ChannelToWire(channel);
395  }
396  catch(...)
397  {
398  std::cout << "Caught exception looking up channel" << std::endl;
399  return localRMS;
400  }
401 
402  // Recover plane and wire in the plane
403  size_t plane = wids[0].Plane;
404  size_t wire = wids[0].Wire;
405 
406 // float fullRMS = std::inner_product(locWaveform.begin(), locWaveform.end(), locWaveform.begin(), 0.);
407 
408 // fullRMS = std::sqrt(std::max(float(0.),fullRMS / float(locWaveform.size())));
409 
410  fPedestalOffsetVec[plane]->Fill(newPedestal,1.);
411 // fFullRMSVec[plane]->Fill(fullRMS, 1.);
412  fTruncRMSVec[plane]->Fill(localRMS, 1.);
413  fNumTruncBinsVec[plane]->Fill(minNumBins, 1.);
414  fPedByChanVec[plane]->Fill(wire, newPedestal, 1.);
415  fTruncRMSByChanVec[plane]->Fill(wire, localRMS, 1.);
416  }
417 
418  return localRMS;
419 }
420 
422  art::Event& event,
423  art::Handle<std::vector<raw::RawDigit>> digitVecHandle,
424  std::vector<recob::Wire>& wireColVec,
425  art::Assns<raw::RawDigit,recob::Wire>& wireAssns,
426  const std::string& instance) const
427 {
428  // vector that will be moved into the Wire object
431 
432  // get the reference to the current raw::RawDigit
433  art::Ptr<raw::RawDigit> digitVec(digitVecHandle, idx);
434 
435  raw::ChannelID_t channel = digitVec->Channel();
436 
437  // The following test is meant to be temporary until the "correct" solution is implemented
438  if (!fChannelFilter->IsPresent(channel)) return;
439 
440  // The waveforms should have been set to a 0. pedestal...
441  float pedestal = 0.;
442 
443  // Recover the plane info
444  std::vector<geo::WireID> wids = fGeometry->ChannelToWire(channel);
445 
446  // skip bad channels
447  if( fChannelFilter->Status(channel) < fMinAllowedChanStatus) return;
448 
449  size_t dataSize = digitVec->Samples();
450 
451  const geo::PlaneID& planeID = wids[0].planeID();
452 
453  // vector holding uncompressed adc values
454  std::vector<short> rawadc(dataSize);
455 
456  // uncompress the data
457  raw::Uncompress(digitVec->ADCs(), rawadc, digitVec->Compression());
458 
459  // loop over all adc values and subtract the pedestal
460  // When we have a pedestal database, can provide the digit timestamp as the third argument of GetPedestalMean
461  try
462  {
463  pedestal = fPedRetrievalAlg->PedMean(channel);
464  }
465  catch(...)
466  {
467  mf::LogDebug("Decon1DROI_module") << "Pedestal lookup fails with channel: " << channel << std::endl;
468  return;
469  }
470 
471 
472  // Get the pedestal subtracted data, centered in the deconvolution vector
473  std::vector<float> rawAdcLessPedVec(dataSize);
474 
475  std::transform(rawadc.begin(),rawadc.end(),rawAdcLessPedVec.begin(),std::bind(std::minus<short>(),std::placeholders::_1,pedestal));
476 
477  // It seems there are deviations from the pedestal when using wirecell for noise filtering
478  //float raw_noise = fixTheFreakingWaveform(rawAdcLessPedVec, channel, rawAdcLessPedVec);
479  float raw_noise = digitVec->GetSigma();
480 
481  // Recover a measure of the noise on the channel for use in the ROI finder
482  //float raw_noise = getTruncatedRMS(rawAdcLessPedVec);
483 
484  // Try smoothing the input waveform
485 // std::vector<float> rawAdcSmoothVec;
486 // fWaveformTool->medianSmooth(rawAdcLessPedVec,rawAdcSmoothVec);
487 
488  // Make a dummy candidate roi vec
490 
491  deconROIVec.push_back(icarus_tool::IROIFinder::CandidateROI(0,rawAdcLessPedVec.size() - 1));
492 
493  // Do the deconvolution on the full waveform
494  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(event);
495  fDeconvolution->Deconvolve(rawAdcLessPedVec, sampling_rate(clockData), channel, deconROIVec, deconVec);
496 
497  // Recover the deconvolved waveform
498  const std::vector<float>& deconvolvedWaveform = deconVec.get_ranges().front().data();
499 
500  // vector of candidate ROI begin and end bins
502 
503  // Now find the candidate ROI's
504  fROIFinderVec.at(planeID.Plane)->FindROIs(deconvolvedWaveform, channel, fEventCount, raw_noise, candRoiVec);
505 
506  std::vector<float> holder;
507 
508  // We need to copy the deconvolved (and corrected) waveform ROI's
509  for(const auto& candROI : candRoiVec)
510  {
511  // First up: copy out the relevent ADC bins into the ROI holder
512  size_t roiLen = candROI.second - candROI.first + 1;
513 
514  holder.resize(roiLen);
515 
516  std::copy(deconvolvedWaveform.begin()+candROI.first, deconvolvedWaveform.begin()+candROI.second, holder.begin());
517 
518  // Now we do the baseline determination and correct the ROI
519  //float base = fBaseline->GetBaseline(holder, channel, roiStart, roiLen);
520  float base = fBaseline->GetBaseline(holder, channel, 0, roiLen);
521 
522  std::transform(holder.begin(),holder.end(),holder.begin(),[base](auto& adcVal){return adcVal - base;});
523 
524  // add the range into ROIVec
525  ROIVec.add_range(candROI.first, std::move(holder));
526  }
527 
528  // Make some histograms?
529  if (fOutputHistograms)
530  {
531  fNumROIsHistVec.at(planeID.Plane)->Fill(candRoiVec.size(), 1.);
532 
533  for(const auto& pair : candRoiVec)
534  fROILenHistVec.at(planeID.Plane)->Fill(pair.second-pair.first, 1.);
535 
536  float fullRMS = std::inner_product(deconvolvedWaveform.begin(), deconvolvedWaveform.end(), deconvolvedWaveform.begin(), 0.);
537 
538  fullRMS = std::sqrt(std::max(float(0.),fullRMS / float(deconvolvedWaveform.size())));
539 
540  fFullRMSVec[planeID.Plane]->Fill(fullRMS, 1.);
541  }
542 
543  // Don't save empty wires
544  if (ROIVec.empty()) return;
545 
546  // First get a lock to make sure we are clear to run
547  tbb::spin_mutex::scoped_lock lock(deconvolutionSpinMutex);
548 
549  // create the new wire directly in wirecol
550  wireColVec.push_back(recob::WireCreator(std::move(ROIVec),*digitVec).move());
551 
552  // add an association between the last object in wirecol
553  // (that we just inserted) and digitVec
554  if (!util::CreateAssn(event, wireColVec, digitVec, wireAssns, instance))
555  {
556  throw art::Exception(art::errors::ProductRegistrationFailure)
557  << "Can't associate wire #" << (wireColVec.size() - 1)
558  << " with raw digit #" << digitVec.key();
559  } // if failed to add association
560 
561  return;
562 }
563 
564 } // end namespace caldata
void processChannel(size_t, art::Event &, art::Handle< std::vector< raw::RawDigit >>, std::vector< recob::Wire > &, art::Assns< raw::RawDigit, recob::Wire > &, const std::string &) const
std::vector< TH1F * > fPedestalOffsetVec
Utilities related to art service access.
Decon1DROI(fhicl::ParameterSet const &, art::ProcessingFrame const &)
static constexpr Sample_t transform(Sample_t sample)
This provides an interface for tools which are tasked with running the deconvolution algorithm...
unsigned short fNoiseSource
Used to determine ROI threshold.
Helper functions to create a wire.
walls no right
Definition: selectors.fcl:105
pdgs p
Definition: selectors.fcl:22
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
void produce(art::Event &evt, art::ProcessingFrame const &) override
float fTruncRMSMinFraction
or at least this fraction of time bins
bool fOutputHistograms
Output histograms?
const std::string instance
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.
Definition of basic raw digits.
const range_list_t & get_ranges() const
Returns the internal list of non-void ranges.
void operator()(const tbb::blocked_range< size_t > &range) const
for pfile in ack l reconfigure(.*) override"` do echo "checking $
Class managing the creation of a new recob::Wire object.
Definition: WireCreator.h:53
This provides an interface for tools which are tasked with finding the baselines in input waveforms...
int fSaveWireWF
Save recob::wire object waveforms.
size_t fEventCount
count of event processed
art::Assns< raw::RawDigit, recob::Wire > & fWireAssns
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.
std::unique_ptr< icarus_tool::IBaseline > fBaseline
void reconfigure(fhicl::ParameterSet const &p)
std::vector< TH1F * > fROILenHistVec
virtual bool IsPresent(raw::ChannelID_t channel) const =0
Returns whether the specified channel is physical and connected to wire.
icarus_signal_processing::WaveformTools< float > fWaveformTool
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
std::vector< TH1F * > fFullRMSVec
std::vector< TProfile * > fPedByChanVec
std::vector< TProfile * > fTruncRMSByChanVec
std::unique_ptr< icarus_tool::IDeconvolution > fDeconvolution
Collect all the RawData header files together.
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:75
virtual Status_t Status(raw::ChannelID_t channel) const
Returns a status integer with arbitrary meaning.
float getTruncatedRMS(const std::vector< float > &) const
std::vector< TH1F * > fNumTruncBinsVec
walls no left
Definition: selectors.fcl:105
Class providing information about the quality of channels.
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:493
Description of geometry of one entire detector.
std::vector< TH1F * > fNumROIsHistVec
virtual float PedMean(raw::ChannelID_t ch) const =0
Retrieve pedestal information.
float fixTheFreakingWaveform(const std::vector< float > &, raw::ChannelID_t, std::vector< float > &) const
const geo::GeometryCore * fGeometry
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
multiThreadDeconvolutionProcessing(Decon1DROI const &parent, art::Event &event, art::Handle< std::vector< raw::RawDigit >> &rawDigitHandle, std::vector< recob::Wire > &wireColVec, art::Assns< raw::RawDigit, recob::Wire > &wireAssns, std::string const &instance)
art::Handle< std::vector< raw::RawDigit > > & fRawDigitHandle
bool empty() const
Returns whether the vector is empty.
const lariov::DetPedestalProvider * fPedRetrievalAlg
Interface for experiment-specific channel quality info provider.
T copy(T const &v)
const lariov::ChannelStatusProvider * fChannelFilter
float fTruncRMSThreshold
Calculate RMS up to this threshold...
std::vector< art::InputTag > fRawDigitLabelVec
Declaration of basic channel signal object.
int fMinAllowedChanStatus
Don&#39;t consider channels with lower status.
std::vector< TH1F * > fTruncRMSVec
art::ServiceHandle< art::TFileService > tfs
TCEvent evt
Definition: DataStructs.cxx:8
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
std::vector< std::unique_ptr< icarus_tool::IROIFinder > > fROIFinderVec
ROI finders per plane.
Interface for experiment-specific service for channel quality info.
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:776
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
process_name can override from command line with o or output caldata
Definition: pid.fcl:40
tbb::spin_mutex deconvolutionSpinMutex
art framework interface to geometry description
BEGIN_PROLOG could also be cout