LArSoft  v09_93_00
Liquid Argon Software toolkit - https://larsoft.org/
GausHitFinder_module.cc
Go to the documentation of this file.
1 //
3 // GaussHitFinder class
4 //
5 // jaasaadi@syr.edu
6 //
7 // This algorithm is designed to find hits on wires after deconvolution.
8 // -----------------------------------
9 // This algorithm is based on the FFTHitFinder written by Brian Page,
10 // Michigan State University, for the ArgoNeuT experiment.
11 //
12 //
13 // The algorithm walks along the wire and looks for pulses above threshold
14 // The algorithm then attempts to fit n-gaussians to these pulses where n
15 // is set by the number of peaks found in the pulse
16 // If the Chi2/NDF returned is "bad" it attempts to fit n+1 gaussians to
17 // the pulse. If this is a better fit it then uses the parameters of the
18 // Gaussian fit to characterize the "hit" object
19 //
20 // To use this simply include the following in your producers:
21 // gaushit: @local::microboone_gaushitfinder
22 // gaushit: @local::argoneut_gaushitfinder
24 
25 // C/C++ standard library
26 #include <algorithm> // std::accumulate()
27 #include <atomic>
28 #include <memory> // std::unique_ptr()
29 #include <string>
30 #include <utility> // std::move()
31 
32 // Framework includes
37 #include "art/Utilities/Globals.h"
39 #include "art_root_io/TFileService.h"
41 #include "fhiclcpp/ParameterSet.h"
42 
43 // LArSoft Includes
45 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
50 
53 
54 // ROOT Includes
55 #include "TH1F.h"
56 #include "TMath.h"
57 
58 #include "tbb/concurrent_vector.h"
59 #include "tbb/parallel_for.h"
60 
61 namespace hit {
63  public:
64  explicit GausHitFinder(fhicl::ParameterSet const& pset, art::ProcessingFrame const&);
65 
66  private:
67  void produce(art::Event& evt, art::ProcessingFrame const&) override;
68  void beginJob(art::ProcessingFrame const&) override;
69 
70  std::vector<double> FillOutHitParameterVector(const std::vector<double>& input);
71 
72  const bool fFilterHits;
73  const bool fFillHists;
74 
75  const std::string fCalDataModuleLabel;
76  const std::string fAllHitsInstanceName;
77 
78  const std::vector<int> fLongMaxHitsVec;
79  const std::vector<int> fLongPulseWidthVec;
80 
81  const size_t fMaxMultiHit;
82  const int fAreaMethod;
83  const std::vector<double>
85  const double fChi2NDF;
86 
87  const std::vector<float> fPulseHeightCuts;
88  const std::vector<float> fPulseWidthCuts;
89  const std::vector<float> fPulseRatioCuts;
90 
91  std::atomic<size_t> fEventCount{0};
92 
93  //only Standard and Morphological implementation is threadsafe.
94  std::vector<std::unique_ptr<reco_tool::ICandidateHitFinder>>
96  // only Marqdt implementation is threadsafe.
97  std::unique_ptr<reco_tool::IPeakFitter> fPeakFitterTool;
98  //HitFilterAlg implementation is threadsafe.
99  std::unique_ptr<HitFilterAlg> fHitFilterAlg;
100 
101  //only used when fFillHists is true and in single threaded mode.
102  TH1F* fFirstChi2;
103  TH1F* fChi2;
104 
105  }; // class GausHitFinder
106 
107  //-------------------------------------------------
108  //-------------------------------------------------
110  : SharedProducer{pset}
111  , fFilterHits(pset.get<bool>("FilterHits", false))
112  , fFillHists(pset.get<bool>("FillHists", false))
113  , fCalDataModuleLabel(pset.get<std::string>("CalDataModuleLabel"))
114  , fAllHitsInstanceName(pset.get<std::string>("AllHitsInstanceName", ""))
115  , fLongMaxHitsVec(pset.get<std::vector<int>>("LongMaxHits", std::vector<int>() = {25, 25, 25}))
117  pset.get<std::vector<int>>("LongPulseWidth", std::vector<int>() = {16, 16, 16}))
118  , fMaxMultiHit(pset.get<int>("MaxMultiHit"))
119  , fAreaMethod(pset.get<int>("AreaMethod"))
120  , fAreaNormsVec(FillOutHitParameterVector(pset.get<std::vector<double>>("AreaNorms")))
121  , fChi2NDF(pset.get<double>("Chi2NDF"))
123  pset.get<std::vector<float>>("PulseHeightCuts", std::vector<float>() = {3.0, 3.0, 3.0}))
124  , fPulseWidthCuts(
125  pset.get<std::vector<float>>("PulseWidthCuts", std::vector<float>() = {2.0, 1.5, 1.0}))
126  , fPulseRatioCuts(
127  pset.get<std::vector<float>>("PulseRatioCuts", std::vector<float>() = {0.35, 0.40, 0.20}))
128  {
129  if (fFillHists && art::Globals::instance()->nthreads() > 1u) {
131  << "Cannot fill histograms when multiple threads configured, please set fFillHists to "
132  "false or change number of threads to 1\n";
133  }
134  async<art::InEvent>();
135  if (fFilterHits) {
136  fHitFilterAlg = std::make_unique<HitFilterAlg>(pset.get<fhicl::ParameterSet>("HitFilterAlg"));
137  }
138 
139  // recover the tool to do the candidate hit finding
140  // Recover the vector of fhicl parameters for the ROI tools
141  const fhicl::ParameterSet& hitFinderTools = pset.get<fhicl::ParameterSet>("HitFinderToolVec");
142 
143  fHitFinderToolVec.resize(hitFinderTools.get_pset_names().size());
144 
145  for (const std::string& hitFinderTool : hitFinderTools.get_pset_names()) {
146  const fhicl::ParameterSet& hitFinderToolParamSet =
147  hitFinderTools.get<fhicl::ParameterSet>(hitFinderTool);
148  size_t planeIdx = hitFinderToolParamSet.get<size_t>("Plane");
149 
150  fHitFinderToolVec.at(planeIdx) =
151  art::make_tool<reco_tool::ICandidateHitFinder>(hitFinderToolParamSet);
152  }
153 
154  // Recover the peak fitting tool
156  art::make_tool<reco_tool::IPeakFitter>(pset.get<fhicl::ParameterSet>("PeakFitter"));
157 
158  // let HitCollectionCreator declare that we are going to produce
159  // hits and associations with wires and raw digits
160  // We want the option to output two hit collections, one filtered
161  // and one with all hits. The key to doing this will be a non-null
162  // instance name for the second collection
163  // (with no particular product label)
165  producesCollector(), fAllHitsInstanceName, true, false); //fMakeRawDigitAssns);
166 
167  // and now the filtered hits...
168  if (fAllHitsInstanceName != "")
170  producesCollector(), "", true, false); //fMakeRawDigitAssns);
171 
172  return;
173  } // GausHitFinder::GausHitFinder()
174 
175  //-------------------------------------------------
176  //-------------------------------------------------
177  std::vector<double> GausHitFinder::FillOutHitParameterVector(const std::vector<double>& input)
178  {
179  if (input.size() == 0)
180  throw std::runtime_error(
181  "GausHitFinder::FillOutHitParameterVector ERROR! Input config vector has zero size.");
182 
183  std::vector<double> output;
185  const unsigned int N_PLANES = geom->Nplanes();
186 
187  if (input.size() == 1)
188  output.resize(N_PLANES, input[0]);
189  else if (input.size() == N_PLANES)
190  output = input;
191  else
192  throw std::runtime_error("GausHitFinder::FillOutHitParameterVector ERROR! Input config "
193  "vector size !=1 and !=N_PLANES.");
194  return output;
195  }
196 
197  //-------------------------------------------------
198  //-------------------------------------------------
200  {
201  // get access to the TFile service
203 
204  // ======================================
205  // === Hit Information for Histograms ===
206  if (fFillHists) {
207  fFirstChi2 = tfs->make<TH1F>("fFirstChi2", "#chi^{2}", 10000, 0, 5000);
208  fChi2 = tfs->make<TH1F>("fChi2", "#chi^{2}", 10000, 0, 5000);
209  }
210  }
211 
212  // This algorithm uses the fact that deconvolved signals are very smooth
213  // and looks for hits as areas between local minima that have signal above
214  // threshold.
215  //-------------------------------------------------
217  {
218  unsigned int count = fEventCount.fetch_add(1);
219  //==================================================================================================
220 
221  TH1::AddDirectory(kFALSE);
222 
223  // Instantiate and Reset a stop watch
224  //TStopwatch StopWatch;
225  //StopWatch.Reset();
226 
227  // ################################
228  // ### Calling Geometry service ###
229  // ################################
231 
232  // ###############################################
233  // ### Making a ptr vector to put on the event ###
234  // ###############################################
235  // this contains the hit collection
236  // and its associations to wires and raw digits
237  recob::HitCollectionCreator allHitCol(evt, fAllHitsInstanceName, true, false);
238 
239  // Handle the filtered hits collection...
240  recob::HitCollectionCreator hcol(evt, "", true, false);
241  recob::HitCollectionCreator* filteredHitCol = 0;
242 
243  if (fFilterHits) filteredHitCol = &hcol;
244 
245  //store in a thread safe way
246  struct hitstruct {
247  recob::Hit hit_tbb;
248  art::Ptr<recob::Wire> wire_tbb;
249  };
250 
251  tbb::concurrent_vector<hitstruct> hitstruct_vec;
252  tbb::concurrent_vector<hitstruct> filthitstruct_vec;
253 
254  // if (fAllHitsInstanceName != "") filteredHitCol = &hcol;
255 
256  // ##########################################
257  // ### Reading in the Wire List object(s) ###
258  // ##########################################
260  evt.getByLabel(fCalDataModuleLabel, wireVecHandle);
261 
262  //#################################################
263  //### Set the charge determination method ###
264  //### Default is to compute the normalized area ###
265  //#################################################
266  std::function<double(double, double, double, double, int, int)> chargeFunc =
267  [](double /* peakMean */,
268  double peakAmp,
269  double peakWidth,
270  double areaNorm,
271  int /* low */,
272  int /* hi */) { return std::sqrt(2 * TMath::Pi()) * peakAmp * peakWidth / areaNorm; };
273 
274  //##############################################
275  //### Alternative is to integrate over pulse ###
276  //##############################################
277  if (fAreaMethod == 0)
278  chargeFunc = [](double peakMean,
279  double peakAmp,
280  double peakWidth,
281  double /* areaNorm */,
282  int low,
283  int hi) {
284  double charge(0);
285  for (int sigPos = low; sigPos < hi; sigPos++)
286  charge += peakAmp * TMath::Gaus(sigPos, peakMean, peakWidth);
287  return charge;
288  };
289 
290  //##############################
291  //### Looping over the wires ###
292  //##############################
293  //for(size_t wireIter = 0; wireIter < wireVecHandle->size(); wireIter++)
294  //{
295  tbb::parallel_for(
296  static_cast<std::size_t>(0),
297  wireVecHandle->size(),
298  [&](size_t& wireIter) {
299  // ####################################
300  // ### Getting this particular wire ###
301  // ####################################
302  art::Ptr<recob::Wire> wire(wireVecHandle, wireIter);
303 
304  // --- Setting Channel Number and Signal type ---
305 
306  raw::ChannelID_t channel = wire->Channel();
307 
308  // get the WireID for this hit
309  std::vector<geo::WireID> wids = geom->ChannelToWire(channel);
310  // for now, just take the first option returned from ChannelToWire
311  geo::WireID wid = wids[0];
312  // We need to know the plane to look up parameters
313  geo::PlaneID::PlaneID_t plane = wid.Plane;
314 
315  // ----------------------------------------------------------
316  // -- Setting the appropriate signal widths and thresholds --
317  // -- for the right plane. --
318  // ----------------------------------------------------------
319 
320  // #################################################
321  // ### Set up to loop over ROI's for this wire ###
322  // #################################################
323  const recob::Wire::RegionsOfInterest_t& signalROI = wire->SignalROI();
324 
325  // for (const auto& range : signalROI.get_ranges()) {
326  tbb::parallel_for(
327  static_cast<std::size_t>(0),
328  signalROI.n_ranges(),
329  [&](size_t& rangeIter) {
330  const auto& range = signalROI.range(rangeIter);
331  // ROI start time
332  raw::TDCtick_t roiFirstBinTick = range.begin_index();
333 
334  // ###########################################################
335  // ### Scan the waveform and find candidate peaks + merge ###
336  // ###########################################################
337 
340 
341  fHitFinderToolVec.at(plane)->findHitCandidates(
342  range, 0, channel, count, hitCandidateVec);
343  fHitFinderToolVec.at(plane)->MergeHitCandidates(
344  range, hitCandidateVec, mergedCandidateHitVec);
345 
346  // #######################################################
347  // ### Lets loop over the pulses we found on this wire ###
348  // #######################################################
349 
350  for (auto& mergedCands : mergedCandidateHitVec) {
351  int startT = mergedCands.front().startTick;
352  int endT = mergedCands.back().stopTick;
353 
354  // ### Putting in a protection in case things went wrong ###
355  // ### In the end, this primarily catches the case where ###
356  // ### a fake pulse is at the start of the ROI ###
357  if (endT - startT < 5) continue;
358 
359  // #######################################################
360  // ### Clearing the parameter vector for the new Pulse ###
361  // #######################################################
362 
363  // === Setting The Number Of Gaussians to try ===
364  int nGausForFit = mergedCands.size();
365 
366  // ##################################################
367  // ### Calling the function for fitting Gaussians ###
368  // ##################################################
369  double chi2PerNDF(0.);
370  int NDF(1);
371  /*stand alone
372  reco_tool::IPeakFitter::PeakParamsVec peakParamsVec(nGausForFit);
373  */
375 
376  // #######################################################
377  // ### If # requested Gaussians is too large then punt ###
378  // #######################################################
379  if (mergedCands.size() <= fMaxMultiHit) {
380  fPeakFitterTool->findPeakParameters(
381  range.data(), mergedCands, peakParamsVec, chi2PerNDF, NDF);
382 
383  // If the chi2 is infinite then there is a real problem so we bail
384  if (!(chi2PerNDF < std::numeric_limits<double>::infinity())) {
385  chi2PerNDF = 2. * fChi2NDF;
386  NDF = 2;
387  }
388 
389  if (fFillHists) fFirstChi2->Fill(chi2PerNDF);
390  }
391 
392  // #######################################################
393  // ### If too large then force alternate solution ###
394  // ### - Make n hits from pulse train where n will ###
395  // ### depend on the fhicl parameter fLongPulseWidth ###
396  // ### Also do this if chi^2 is too large ###
397  // #######################################################
398  if (mergedCands.size() > fMaxMultiHit || nGausForFit * chi2PerNDF > fChi2NDF) {
399  int longPulseWidth = fLongPulseWidthVec.at(plane);
400  int nHitsThisPulse = (endT - startT) / longPulseWidth;
401 
402  if (nHitsThisPulse > fLongMaxHitsVec.at(plane)) {
403  nHitsThisPulse = fLongMaxHitsVec.at(plane);
404  longPulseWidth = (endT - startT) / nHitsThisPulse;
405  }
406 
407  if (nHitsThisPulse * longPulseWidth < endT - startT) nHitsThisPulse++;
408 
409  int firstTick = startT;
410  int lastTick = std::min(firstTick + longPulseWidth, endT);
411 
412  peakParamsVec.clear();
413  nGausForFit = nHitsThisPulse;
414  NDF = 1.;
415  chi2PerNDF = chi2PerNDF > fChi2NDF ? chi2PerNDF : -1.;
416 
417  for (int hitIdx = 0; hitIdx < nHitsThisPulse; hitIdx++) {
418  // This hit parameters
419  double ROIsumADC =
420  std::accumulate(range.begin() + firstTick, range.begin() + lastTick, 0.);
421  double peakSigma = (lastTick - firstTick) / 3.; // Set the width...
422  double peakAmp = 0.3989 * ROIsumADC / peakSigma; // Use gaussian formulation
423  double peakMean = (firstTick + lastTick) / 2.;
424 
425  // Store hit params
427 
428  peakParams.peakCenter = peakMean;
429  peakParams.peakCenterError = 0.1 * peakMean;
430  peakParams.peakSigma = peakSigma;
431  peakParams.peakSigmaError = 0.1 * peakSigma;
432  peakParams.peakAmplitude = peakAmp;
433  peakParams.peakAmplitudeError = 0.1 * peakAmp;
434 
435  peakParamsVec.push_back(peakParams);
436 
437  // set for next loop
438  firstTick = lastTick;
439  lastTick = std::min(lastTick + longPulseWidth, endT);
440  }
441  }
442 
443  // #######################################################
444  // ### Loop through returned peaks and make recob hits ###
445  // #######################################################
446 
447  int numHits(0);
448 
449  // Make a container for what will be the filtered collection
450  std::vector<recob::Hit> filteredHitVec;
451 
452  float nextpeak(0);
453  float prevpeak(0);
454  float nextpeakSig(0);
455  float prevpeakSig(0);
456  float nsigmaADC(2.0);
457  float newright(0);
458  float newleft(0);
459  for (const auto& peakParams : peakParamsVec) {
460  // Extract values for this hit
461  float peakAmp = peakParams.peakAmplitude;
462  float peakMean = peakParams.peakCenter;
463  float peakWidth = peakParams.peakSigma;
464 
465  //std::cout<<" ans hits "<<numHits<<" gaus "<<nGausForFit<<std::endl;
466 
467  //ANS get prev and next
468  if (numHits == 0) {
469  newleft = -9999;
470  newright = 9999;
471  nextpeak = 0;
472  prevpeak = 0;
473  nextpeakSig = 0;
474  prevpeakSig = 0;
475  }
476  if (numHits < nGausForFit - 1) {
477  nextpeak = (peakParamsVec.at(numHits + 1)).peakCenter;
478  nextpeakSig = (peakParamsVec.at(numHits + 1)).peakSigma;
479  //std::cout<<" ans size "<<peakParamsVec.size()<<" hit "<<numHits<<" next peak "<<nextpeak<<" sig "<<nextpeakSig<<std::endl;
480  }
481  if (numHits > 0) {
482  prevpeak = (peakParamsVec.at(numHits - 1)).peakCenter;
483  prevpeakSig = (peakParamsVec.at(numHits - 1)).peakSigma;
484  //std::cout<<" ans size "<<peakParamsVec.size()<<"hit "<<numHits<<" prev peak "<<prevpeak<<" sig "<<prevpeakSig<<std::endl;
485  }
486 
487  // Place one bit of protection here
488  if (std::isnan(peakAmp)) {
489  std::cout << "**** hit peak amplitude is a nan! Channel: " << channel
490  << ", start tick: " << startT << std::endl;
491  continue;
492  }
493 
494  // Extract errors
495  float peakAmpErr = peakParams.peakAmplitudeError;
496  float peakMeanErr = peakParams.peakCenterError;
497  float peakWidthErr = peakParams.peakSigmaError;
498 
499  // ### Charge ###
500  float charge =
501  chargeFunc(peakMean, peakAmp, peakWidth, fAreaNormsVec[plane], startT, endT);
502  ;
503  float chargeErr =
504  std::sqrt(TMath::Pi()) * (peakAmpErr * peakWidthErr + peakWidthErr * peakAmpErr);
505 
506  // ### limits for getting sums
507  std::vector<float>::const_iterator sumStartItr = range.begin() + startT;
508  std::vector<float>::const_iterator sumEndItr = range.begin() + endT;
509 
510  //### limits for the sum of the Hit based on the gaussian peak and sigma
511  std::vector<float>::const_iterator HitsumStartItr =
512  range.begin() + peakMean - nsigmaADC * peakWidth;
514  range.begin() + peakMean + nsigmaADC * peakWidth;
515 
516  if (nGausForFit > 1) {
517  if (numHits > 0) {
518  if ((peakMean - nsigmaADC * peakWidth) < (prevpeak + nsigmaADC * prevpeakSig)) {
519  float difPeak = peakMean - prevpeak;
520  float weightpeak = prevpeakSig / (prevpeakSig + peakWidth);
521  HitsumStartItr = range.begin() + prevpeak + difPeak * weightpeak;
522  newleft = prevpeak + difPeak * weightpeak;
523  }
524  }
525 
526  if (numHits < nGausForFit - 1) {
527  if ((peakMean + nsigmaADC * peakWidth) > (nextpeak - nsigmaADC * nextpeakSig)) {
528  float difPeak = nextpeak - peakMean;
529  float weightpeak = peakWidth / (nextpeakSig + peakWidth);
530  HitsumEndItr = range.begin() + peakMean + difPeak * weightpeak;
531  newright = peakMean + difPeak * weightpeak;
532  }
533  }
534  }
535 
536  //protection to avoid negative ranges
537  if (newright - newleft < 0) continue;
538 
539  //avoid ranges out of ROI if it happens
540  if (HitsumStartItr < sumStartItr) HitsumStartItr = sumStartItr;
541 
542  if (HitsumEndItr > sumEndItr) HitsumEndItr = sumEndItr;
543 
544  // ### Sum of ADC counts
545  double ROIsumADC = std::accumulate(sumStartItr, sumEndItr, 0.);
546  double HitsumADC = std::accumulate(HitsumStartItr, HitsumEndItr, 0.);
547 
548  // ok, now create the hit
549  recob::HitCreator hitcreator(
550  *wire, // wire reference
551  wid, // wire ID
552  startT + roiFirstBinTick, // start_tick TODO check
553  endT + roiFirstBinTick, // end_tick TODO check
554  peakWidth, // rms
555  peakMean + roiFirstBinTick, // peak_time
556  peakMeanErr, // sigma_peak_time
557  peakAmp, // peak_amplitude
558  peakAmpErr, // sigma_peak_amplitude
559  charge, // hit_integral
560  chargeErr, // hit_sigma_integral
561  ROIsumADC, // summedADC of the ROI
562  HitsumADC, // summedADC of the Hit
563  nGausForFit, // multiplicity
564  numHits, // local_index TODO check that the order is correct
565  chi2PerNDF, // goodness_of_fit
566  NDF // dof
567  );
568 
569  if (filteredHitCol) filteredHitVec.push_back(hitcreator.copy());
570 
571  const recob::Hit hit(hitcreator.move());
572 
573  // This loop will store ALL hits
574  hitstruct tmp{std::move(hit), wire};
575  hitstruct_vec.push_back(std::move(tmp));
576 
577  numHits++;
578  } // <---End loop over gaussians
579 
580  // Should we filter hits?
581  if (filteredHitCol && !filteredHitVec.empty()) {
582  // #######################################################################
583  // Is all this sorting really necessary? Would it be faster to just loop
584  // through the hits and perform simple cuts on amplitude and width on a
585  // hit-by-hit basis, either here in the module (using fPulseHeightCuts and
586  // fPulseWidthCuts) or in HitFilterAlg?
587  // #######################################################################
588 
589  // Sort in ascending peak height
590  std::sort(filteredHitVec.begin(),
591  filteredHitVec.end(),
592  [](const auto& left, const auto& right) {
593  return left.PeakAmplitude() > right.PeakAmplitude();
594  });
595 
596  // Reject if the first hit fails the PH/wid cuts
597  if (filteredHitVec.front().PeakAmplitude() < fPulseHeightCuts.at(plane) ||
598  filteredHitVec.front().RMS() < fPulseWidthCuts.at(plane))
599  filteredHitVec.clear();
600 
601  // Now check other hits in the snippet
602  if (filteredHitVec.size() > 1) {
603  // The largest pulse height will now be at the front...
604  float largestPH = filteredHitVec.front().PeakAmplitude();
605 
606  // Find where the pulse heights drop below threshold
607  float threshold(fPulseRatioCuts.at(plane));
608 
610  std::find_if(filteredHitVec.begin(),
611  filteredHitVec.end(),
612  [largestPH, threshold](const auto& hit) {
613  return hit.PeakAmplitude() < 8. &&
614  hit.PeakAmplitude() / largestPH < threshold;
615  });
616 
617  // Shrink to fit
618  if (smallHitItr != filteredHitVec.end())
619  filteredHitVec.resize(std::distance(filteredHitVec.begin(), smallHitItr));
620 
621  // Resort in time order
622  std::sort(filteredHitVec.begin(),
623  filteredHitVec.end(),
624  [](const auto& left, const auto& right) {
625  return left.PeakTime() < right.PeakTime();
626  });
627  }
628 
629  // Copy the hits we want to keep to the filtered hit collection
630  for (const auto& filteredHit : filteredHitVec)
631  if (!fHitFilterAlg || fHitFilterAlg->IsGoodHit(filteredHit)) {
632  hitstruct tmp{std::move(filteredHit), wire};
633  filthitstruct_vec.push_back(std::move(tmp));
634  }
635 
636  if (fFillHists) fChi2->Fill(chi2PerNDF);
637  }
638  } //<---End loop over merged candidate hits
639  } //<---End looping over ROI's
640  ); //end tbb parallel for
641  } //<---End looping over all the wires
642  ); //end tbb parallel for
643 
644  for (size_t i = 0; i < hitstruct_vec.size(); i++) {
645  allHitCol.emplace_back(hitstruct_vec[i].hit_tbb, hitstruct_vec[i].wire_tbb);
646  }
647 
648  for (size_t j = 0; j < filthitstruct_vec.size(); j++) {
649  filteredHitCol->emplace_back(filthitstruct_vec[j].hit_tbb, filthitstruct_vec[j].wire_tbb);
650  }
651 
652  //==================================================================================================
653  // End of the event -- move the hit collection and the associations into the event
654 
655  if (filteredHitCol) {
656 
657  // If we filtered hits but no instance name was
658  // specified for the "all hits" collection, then
659  // only save the filtered hits to the event
660  if (fAllHitsInstanceName == "") {
661  filteredHitCol->put_into(evt);
662 
663  // otherwise, save both
664  }
665  else {
666  filteredHitCol->put_into(evt);
667  allHitCol.put_into(evt);
668  }
669  }
670  else {
671  allHitCol.put_into(evt);
672  }
673 
674  // Keep track of events processed
675  //fEventCount++;
676 
677  } // End of produce()
678 
680 
681 } // end of hit namespace
intermediate_table::iterator iterator
const datarange_t & range(size_t i) const
Returns the i-th non-void range (zero-based)
size_type n_ranges() const
Returns the internal list of non-void ranges.
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:102
std::vector< WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
recob::Hit const & copy() const
Returns the constructed wire.
Definition: HitCreator.h:355
std::unique_ptr< HitFilterAlg > fHitFilterAlg
algorithm used to filter out noise hits
Declaration of signal hit object.
void produce(art::Event &evt, art::ProcessingFrame const &) override
GausHitFinder(fhicl::ParameterSet const &pset, art::ProcessingFrame const &)
unsigned int PlaneID_t
Type for the ID number.
Definition: geo_types.h:464
intermediate_table::const_iterator const_iterator
Float_t tmp
Definition: plot.C:35
const std::vector< int > fLongPulseWidthVec
Sets width of hits used to describe long pulses.
static void declare_products(art::ProducesCollector &collector, std::string instance_name="", bool doWireAssns=true, bool doRawDigitAssns=true)
Declares the hit products we are going to fill.
Definition: HitCreator.cxx:261
std::unique_ptr< reco_tool::IPeakFitter > fPeakFitterTool
Perform fit to candidate peaks.
const int fAreaMethod
Type of area calculation.
const std::string fCalDataModuleLabel
const std::vector< float > fPulseWidthCuts
int TDCtick_t
Type representing a TDC tick.
Definition: RawTypes.h:25
Class managing the creation of a new recob::Hit object.
Definition: HitCreator.h:87
std::vector< std::string > get_pset_names() const
Helper functions to create a hit.
A class handling a collection of hits and its associations.
Definition: HitCreator.h:489
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
raw::ChannelID_t Channel() const
Returns the ID of the channel (or InvalidChannelID)
Definition: Wire.h:223
SharedProducer(fhicl::ParameterSet const &pset)
std::vector< double > FillOutHitParameterVector(const std::vector< double > &input)
std::atomic< size_t > fEventCount
T get(std::string const &key) const
Definition: ParameterSet.h:314
const size_t fMaxMultiHit
maximum hits for multi fit
const std::vector< int > fLongMaxHitsVec
Maximum number hits on a really long pulse train.
const RegionsOfInterest_t & SignalROI() const
Returns the list of regions of interest.
Definition: Wire.h:211
void beginJob(art::ProcessingFrame const &) override
void emplace_back(recob::Hit &&hit, art::Ptr< recob::Wire > const &wire=art::Ptr< recob::Wire >(), art::Ptr< raw::RawDigit > const &digits=art::Ptr< raw::RawDigit >())
Adds the specified hit to the data collection.
Definition: HitCreator.cxx:299
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:481
void put_into(art::Event &)
Moves the data into an event.
Definition: HitCreator.h:622
Detector simulation of raw signals on wires.
ProducesCollector & producesCollector() noexcept
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::vector< PeakFitParams_t > PeakParamsVec
Definition: IPeakFitter.h:34
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:94
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
This provides an interface for tools which are tasked with fitting peaks on input waveforms...
const std::vector< float > fPulseRatioCuts
This provides an interface for tools which are tasked with finding candidate hits on input waveforms...
const std::vector< float > fPulseHeightCuts
maximum Chisquared / NDF allowed for a hit to be saved
unsigned int Nplanes(TPCID const &tpcid=tpc_zero) const
Returns the total number of planes in the specified TPC.
Definition: GeometryCore.h:977
Declaration of basic channel signal object.
const std::string fAllHitsInstanceName
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:46
const std::vector< double > fAreaNormsVec
factors for converting area to same units as peak height
static Globals * instance()
Definition: Globals.cc:17
TCEvent evt
Definition: DataStructs.cxx:8
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
std::vector< HitCandidateVec > MergeHitCandidateVec
recob::Hit && move()
Prepares the constructed hit to be moved away.
Definition: HitCreator.h:338
Definition: fwd.h:26
art framework interface to geometry description
std::vector< std::unique_ptr< reco_tool::ICandidateHitFinder > > fHitFinderToolVec
For finding candidate hits.
std::vector< HitCandidate > HitCandidateVec