All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RawDigitCharacterizationAlg.cxx
Go to the documentation of this file.
1 
3 
4 #include "art/Framework/Core/ModuleMacros.h"
5 #include "messagefacility/MessageLogger/MessageLogger.h"
6 
7 #include <numeric> // std::accumulate and std::inner_product
8 
9 namespace caldata
10 {
11 //----------------------------------------------------------------------------
12 /// Constructor.
13 ///
14 /// Arguments:
15 ///
16 /// pset - Fcl parameters.
17 ///
19  fHistsInitialized(false),
20  fChannelGroups(pset),
21  fPedestalRetrievalAlg(art::ServiceHandle<lariov::DetPedestalService>()->GetPedestalProvider())
22 
23 {
24  reconfigure(pset);
25 
26  // Report.
27  mf::LogInfo("RawDigitCharacterizationAlg") << "RawDigitCharacterizationAlg configured\n";
28 }
29 
30 //----------------------------------------------------------------------------
31 /// Destructor.
33 {}
34 
35 //----------------------------------------------------------------------------
36 /// Reconfigure method.
37 ///
38 /// Arguments:
39 ///
40 /// pset - Fcl parameter set.
41 ///
42 void RawDigitCharacterizationAlg::reconfigure(fhicl::ParameterSet const & pset)
43 {
44  fTruncMeanFraction = pset.get<float> ("TruncMeanFraction", 0.15);
45  fRmsRejectionCutHi = pset.get<std::vector<float>> ("RMSRejectionCutHi", std::vector<float>() = {25.0,25.0,25.0});
46  fRmsRejectionCutLow = pset.get<std::vector<float>> ("RMSRejectionCutLow", std::vector<float>() = {0.70,0.70,0.70});
47  fRmsSelectionCut = pset.get<std::vector<float>> ("RMSSelectionCut", std::vector<float>() = {1.40,1.40,1.00});
48  fMinMaxSelectionCut = pset.get<std::vector<short>> ("MinMaxSelectionCut", std::vector<short>() = {13, 13, 11});
49  fTheChosenWire = pset.get<unsigned int> ("TheChosenWire", 1200);
50  fMaxPedestalDiff = pset.get<double> ("MaxPedestalDiff", 10.);
51  fHistsWireGroup = pset.get<std::vector<size_t>>("FFTHistsWireGroup", std::vector<size_t>() = {1, 33, 34});
52  fNumWiresToGroup = pset.get<std::vector<size_t>>("NumWiresToGroup", std::vector<size_t>() = {48, 48, 96});
53  fFillHistograms = pset.get<bool> ("FillHistograms", true);
54 }
55 
56 //----------------------------------------------------------------------------
57 /// Begin job method.
58 void RawDigitCharacterizationAlg::initializeHists(art::ServiceHandle<art::TFileService>& tfs)
59 {
60  if (fFillHistograms)
61  {
62  // Define the histograms. Putting semi-colons around the title
63  // causes it to be displayed as the x-axis label if the histogram
64  // is drawn.
65  fAdcCntHist[0] = tfs->make<TH1D>("CntUPlane", ";#adc", 200, 2200., 4200.);
66  fAdcCntHist[1] = tfs->make<TH1D>("CntVPlane", ";#adc", 200, 2200., 4200.);
67  fAdcCntHist[2] = tfs->make<TH1D>("CntWPlane", ";#adc", 200, 2200., 4200.);
68  fAveValHist[0] = tfs->make<TH1D>("AveUPlane", ";Ave", 120, -20., 20.);
69  fAveValHist[1] = tfs->make<TH1D>("AveVPlane", ";Ave", 120, -20., 20.);
70  fAveValHist[2] = tfs->make<TH1D>("AveWPlane", ";Ave", 120, -20., 20.);
71  fRmsTValHist[0] = tfs->make<TH1D>("RmsTUPlane", ";RMS", 100, 0., 10.);
72  fRmsTValHist[1] = tfs->make<TH1D>("RmsTVPlane", ";RMS", 100, 0., 10.);
73  fRmsTValHist[2] = tfs->make<TH1D>("RmsTWPlane", ";RMS", 100, 0., 10.);
74  fRmsFValHist[0] = tfs->make<TH1D>("RmsFUPlane", ";RMS", 100, 0., 10.);
75  fRmsFValHist[1] = tfs->make<TH1D>("RmsFVPlane", ";RMS", 100, 0., 10.);
76  fRmsFValHist[2] = tfs->make<TH1D>("RmsFWPlane", ";RMS", 100, 0., 10.);
77  fPedValHist[0] = tfs->make<TH1D>("PedUPlane", ";Ped", 200, 1950, 2150.);
78  fPedValHist[1] = tfs->make<TH1D>("PedVPlane", ";Ped", 200, 1950, 2150.);
79  fPedValHist[2] = tfs->make<TH1D>("PedWPlane", ";Ped", 200, 350, 550.);
80 
81  fRmsValProf[0] = tfs->make<TProfile>("RmsPlane0Prof", ";Wire #", 1200, 0., 1200., 0., 100.);
82  fRmsValProf[1] = tfs->make<TProfile>("RmsPlane1Prof", ";Wire #", 5000, 0., 5000., 0., 100.);
83  fRmsValProf[2] = tfs->make<TProfile>("RmsPlane2Prof", ";Wire #", 5000, 0., 5000., 0., 100.);
84 
85  fMinMaxValProf[0] = tfs->make<TProfile>("MinMaxPlane0Prof", ";Wire #", 1200, 0., 1200., 0., 200.);
86  fMinMaxValProf[1] = tfs->make<TProfile>("MinMaxPlane1Prof", ";Wire #", 5000, 0., 5000., 0., 200.);
87  fMinMaxValProf[2] = tfs->make<TProfile>("MinMaxPlane2Prof", ";Wire #", 5000, 0., 5000., 0., 200.);
88 
89  fPedValProf[0] = tfs->make<TProfile>("PedPlane0Prof", ";Wire #", 1200, 0., 1200., 1500., 2500.);
90  fPedValProf[1] = tfs->make<TProfile>("PedPlane1Prof", ";Wire #", 5000, 0., 5000., 1500., 2500.);
91  fPedValProf[2] = tfs->make<TProfile>("PedPlane2Prof", ";Wire #", 5000, 0., 5000., 0., 1000.);
92 
93  fAverageHist[0] = tfs->make<TH1D>("Average0", ";Bin", 1000, 1500., 2500.);
94  fAverageHist[1] = tfs->make<TH1D>("Average1", ";Bin", 1000, 1500., 2500.);
95  fAverageHist[2] = tfs->make<TH1D>("Average2", ";Bin", 1000, 0., 1000.);
96 
97  fMinMaxProfiles.resize(3);
98  fSkewnessProfiles.resize(3);
99  fModeRatioProfiles.resize(3);
100 
101  for(size_t viewIdx = 0; viewIdx < 3; viewIdx++)
102  {
103  std::string minMaxName = "MinMax_" + std::to_string(viewIdx);
104 
105  fMinMaxProfiles[viewIdx] = tfs->make<TProfile>(minMaxName.c_str(), "Min/Max Profiles;Wire", fNumWiresToGroup[viewIdx], 0., fNumWiresToGroup[viewIdx], 0., 200.);
106 
107  minMaxName = "Skewness_" + std::to_string(viewIdx);
108 
109  fSkewnessProfiles[viewIdx] = tfs->make<TProfile>(minMaxName.c_str(), "Skewness Profiles;Wire", fNumWiresToGroup[viewIdx], 0., fNumWiresToGroup[viewIdx], -4., 4.);
110 
111  minMaxName = "ModeRatio_" + std::to_string(viewIdx);
112 
113  fModeRatioProfiles[viewIdx] = tfs->make<TProfile>(minMaxName.c_str(), "Mode Ratio;Wire", fNumWiresToGroup[viewIdx], 0., fNumWiresToGroup[viewIdx], 0., 1.2);
114  }
115 
116  fHistsInitialized = true;
117  }
118 
119  return;
120 }
121 
122 // Basic waveform mean, rms and pedestal offset
124  unsigned int channel,
125  unsigned int view,
126  unsigned int wire,
127  float& truncMean,
128  float& truncRms,
129  short& mean,
130  short& median,
131  short& mode,
132  float& skewness,
133  float& rms,
134  short& minMax,
135  float& neighborRatio,
136  float& pedCorVal) const
137 {
138  // We start by finding the most likely baseline which is most easily done by
139  // finding the most populated bin and the average using the neighboring bins
140  // To do this we'll use a map with key the bin number and data the count in that bin
141  int numTruncBins;
142 
143  getMeanAndTruncRms(rawWaveform, truncMean, rms, truncRms, numTruncBins);
144 
145  // The pedCorVal will transform from the average of waveform calculated here to the expected value of the pedestal.
146  pedCorVal = 0.;
147 
148  // Determine the range of ADC values on this wire
149  std::pair<RawDigitVector::const_iterator,RawDigitVector::const_iterator> minMaxItrPair = std::minmax_element(rawWaveform.begin(),rawWaveform.end());
150 
151  minMax = std::min(*minMaxItrPair.second - *minMaxItrPair.first + 1, 199); // for the purposes of histogramming
152 
153  // We also want mean, median, rms, etc., for all ticks on the waveform
154  std::vector<short> localTimeVec = rawWaveform;
155 
156  std::sort(localTimeVec.begin(),localTimeVec.end(),[](const auto& left, const auto& right){return std::fabs(left) < std::fabs(right);});
157 
158  float realMean(float(std::accumulate(localTimeVec.begin(),localTimeVec.end(),0))/float(localTimeVec.size()));
159 
160  median = localTimeVec[localTimeVec.size()/2];
161  mean = std::round(realMean);
162 
163  std::vector<float> adcLessPedVec;
164 
165  adcLessPedVec.resize(localTimeVec.size());
166 
167  std::transform(localTimeVec.begin(),localTimeVec.end(),adcLessPedVec.begin(),std::bind(std::minus<float>(),std::placeholders::_1,realMean));
168 
169  rms = std::sqrt(std::inner_product(adcLessPedVec.begin(), adcLessPedVec.end(), adcLessPedVec.begin(), 0.) / float(adcLessPedVec.size()));
170  skewness = 3. * float(realMean - median) / rms;
171 
172  // Final task is to get the mode and neighbor ratio
173  // Define the map first
174  std::unordered_map<short,short> binAdcMap;
175 
176  // Populate the map
177  for(const auto& adcVal : rawWaveform) binAdcMap[adcVal]++;
178 
179  // Find the max bin and the count
180  std::unordered_map<short,short>::iterator maxBinItr = std::max_element(binAdcMap.begin(),binAdcMap.end(),[](const auto& lhs,const auto& rhs){return lhs.second < rhs.second;});
181 
182  short neighborSum(0);
183  short leftNeighbor(maxBinItr->second);
184  short rightNeighbor(maxBinItr->second);
185  short cnt(0);
186 
187  mode = maxBinItr->first;
188 
189  if (binAdcMap.find(mode-1) != binAdcMap.end())
190  {
191  leftNeighbor = binAdcMap.find(mode-1)->second;
192  neighborSum += leftNeighbor;
193  cnt++;
194  }
195 
196  if (binAdcMap.find(mode+1) != binAdcMap.end())
197  {
198  rightNeighbor = binAdcMap.find(mode+1)->second;
199  neighborSum += rightNeighbor;
200  cnt++;
201  }
202 
203  neighborRatio = float(neighborSum) / float(2*maxBinItr->second);
204 
205  neighborRatio = float(std::min(leftNeighbor,rightNeighbor)) / float(maxBinItr->second);
206 // float leastNeighborRatio = float(std::min(leftNeighbor,rightNeighbor)) / float(maxBinItr->second);
207 
208  // Fill some histograms here
209  if (fHistsInitialized)
210  {
211  short maxVal = *std::max_element(rawWaveform.begin(),rawWaveform.end());
212  short minVal = *std::min_element(rawWaveform.begin(),rawWaveform.end());
213  short minMax = std::min(maxVal - minVal,199);
214 
215  fAdcCntHist[view]->Fill(numTruncBins, 1.);
216  fAveValHist[view]->Fill(std::max(-29.9, std::min(29.9,double(truncMean))), 1.);
217  fRmsTValHist[view]->Fill(std::min(19.9, double(truncRms)), 1.);
218  fRmsFValHist[view]->Fill(std::min(19.9, double(rms)), 1.);
219  fRmsValProf[view]->Fill(wire, double(truncRms), 1.);
220  fMinMaxValProf[view]->Fill(wire, double(minMax), 1.);
221  fPedValProf[view]->Fill(wire, truncMean, 1.);
222  fPedValHist[view]->Fill(truncMean, 1.);
223  }
224 
225 
226  if (wire / fNumWiresToGroup[view] == fHistsWireGroup[view])
227  {
228  float leastNeighborRatio = float(std::min(leftNeighbor,rightNeighbor)) / float(maxBinItr->second);
229  size_t wireIdx = wire % fNumWiresToGroup[view];
230 
231 // if (skewness > 0. && leastNeighborRatio < 0.7)
232 // {
233 // short threshold(6);
234 //
235 // RawDigitVector::const_iterator stopChirpItr = std::find_if(rawWaveform.begin(),rawWaveform.end(),[mean,threshold](const short& elem){return abs(elem - mean) > threshold;});
236 // }
237 
238  if (fHistsInitialized)
239  {
240  fMinMaxProfiles[view]->Fill(double(wireIdx+0.5), double(minMax), 1.);
241  fSkewnessProfiles[view]->Fill(double(wireIdx+0.5), double(skewness), 1.);
242  fModeRatioProfiles[view]->Fill(double(wireIdx+0.5), double(leastNeighborRatio), 1.);
243  }
244  }
245 
246  return;
247 }
249  float& pedestal,
250  float& truncRms) const
251 {
252  // do rms calculation - the old fashioned way and over all adc values
253  std::vector<float> adcLessPedVec;
254 
255  adcLessPedVec.resize(rawWaveform.size());
256 
257  // Fill the vector
258  std::transform(rawWaveform.begin(),rawWaveform.end(),adcLessPedVec.begin(),std::bind(std::minus<short>(),std::placeholders::_1,pedestal));
259 
260  // sort in ascending order so we can truncate the sume
261  std::sort(adcLessPedVec.begin(), adcLessPedVec.end(),[](const auto& left, const auto& right){return std::fabs(left) < std::fabs(right);});
262 
263  int minNumBins = (1. - fTruncMeanFraction) * rawWaveform.size();
264 
265  // Get the truncated sum
266  truncRms = std::inner_product(adcLessPedVec.begin(), adcLessPedVec.begin() + minNumBins, adcLessPedVec.begin(), 0.);
267  truncRms = std::sqrt(std::max(0.,truncRms / double(minNumBins)));
268 
269  return;
270 }
271 
273  unsigned int channel,
274  unsigned int view,
275  unsigned int wire,
276  float& truncMean,
277  float& rmsVal,
278  float& pedCorVal) const
279 {
280  // The strategy for finding the average for a given wire will be to
281  // find the most populated bin and the average using the neighboring bins
282  // To do this we'll use a map with key the bin number and data the count in that bin
283  int meanCnt;
284 
285  getMeanAndRms(rawWaveform, truncMean, rmsVal, meanCnt);
286 
287  // Recover the database version of the pedestal
288  float pedestal(0.);
289 
290  try
291  {
292  pedestal = fPedestalRetrievalAlg.PedMean(channel);
293  }
294  catch(...)
295  {
296  pedestal = truncMean;
297  }
298 
299  pedCorVal = truncMean - pedestal;
300 
301  // Fill some histograms here
302  if (fHistsInitialized)
303  {
304  short maxVal = *std::max_element(rawWaveform.begin(),rawWaveform.end());
305  short minVal = *std::min_element(rawWaveform.begin(),rawWaveform.end());
306  short minMax = std::min(maxVal - minVal,199);
307 
308  fAdcCntHist[view]->Fill(meanCnt, 1.);
309  fAveValHist[view]->Fill(std::max(-29.9, std::min(29.9,double(truncMean - pedestal))), 1.);
310  fRmsFValHist[view]->Fill(std::min(19.9, double(rmsVal)), 1.);
311  fRmsValProf[view]->Fill(wire, double(rmsVal), 1.);
312  fMinMaxValProf[view]->Fill(wire, double(minMax), 1.);
313  fPedValProf[view]->Fill(wire, truncMean, 1.);
314  fPedValHist[view]->Fill(truncMean, 1.);
315  }
316 
317  // Output a message is there is significant different to the pedestal
318  if (abs(truncMean - pedestal) > fMaxPedestalDiff)
319  {
320  mf::LogInfo("RawDigitCharacterizationAlg") << ">>> Pedestal mismatch, channel: " << channel << ", new value: " << truncMean << ", original: " << pedestal << ", rms: " << rmsVal << std::endl;
321  }
322 
323  return;
324 }
325 
327  float& aveVal,
328  float& rmsVal,
329  int& numBins) const
330 {
331  // The strategy for finding the average for a given wire will be to
332  // find the most populated bin and the average using the neighboring bins
333  // To do this we'll use a map with key the bin number and data the count in that bin
334  std::pair<RawDigitVector::const_iterator,RawDigitVector::const_iterator> minMaxValItr = std::minmax_element(rawWaveform.begin(),rawWaveform.end());
335 
336  int minVal = std::floor(*minMaxValItr.first);
337  int maxVal = std::ceil(*minMaxValItr.second);
338  int range = maxVal - minVal + 1;
339 
340  std::vector<int> frequencyVec(range, 0);
341  int mpCount(0);
342  int mpVal(0);
343 
344  for(const auto& val : rawWaveform)
345  {
346  int intVal = std::round(val) - minVal;
347 
348  frequencyVec[intVal]++;
349 
350  if (frequencyVec.at(intVal) > mpCount)
351  {
352  mpCount = frequencyVec[intVal];
353  mpVal = intVal;
354  }
355  }
356 
357  // take a weighted average of two neighbor bins
358  int meanCnt = 0;
359  int meanSum = 0;
360  int binRange = std::min(16, int(range/2 + 1));
361 
362  for(int idx = mpVal-binRange; idx <= mpVal+binRange; idx++)
363  {
364  if (idx < 0 || idx >= range) continue;
365 
366  meanSum += (idx + minVal) * frequencyVec[idx];
367  meanCnt += frequencyVec[idx];
368  }
369 
370  aveVal = float(meanSum) / float(meanCnt);
371 
372  // do rms calculation - the old fashioned way and over all adc values
373  std::vector<float> adcLessPedVec(rawWaveform.size());
374 
375  std::transform(rawWaveform.begin(),rawWaveform.end(),adcLessPedVec.begin(),std::bind(std::minus<float>(),std::placeholders::_1,aveVal));
376 
377  // recalculate the rms for truncation
378  rmsVal = std::inner_product(adcLessPedVec.begin(), adcLessPedVec.end(), adcLessPedVec.begin(), 0.);
379  rmsVal = std::sqrt(std::max(float(0.),rmsVal / float(adcLessPedVec.size())));
380  numBins = meanCnt;
381 
382  return;
383 }
384 
386  float& aveVal,
387  float& rmsVal,
388  float& rmsTrunc,
389  int& numBins) const
390 {
391  // The strategy for finding the average for a given wire will be to
392  // find the most populated bin and the average using the neighboring bins
393  // To do this we'll use a map with key the bin number and data the count in that bin
394  std::pair<RawDigitVector::const_iterator,RawDigitVector::const_iterator> minMaxValItr = std::minmax_element(rawWaveform.begin(),rawWaveform.end());
395 
396  int minVal = std::floor(*minMaxValItr.first);
397  int maxVal = std::ceil(*minMaxValItr.second);
398  int range = maxVal - minVal + 1;
399 
400  std::vector<int> frequencyVec(range, 0);
401  int mpCount(0);
402  int mpVal(0);
403 
404  for(const auto& val : rawWaveform)
405  {
406  int intVal = std::round(val) - minVal;
407 
408  frequencyVec[intVal]++;
409 
410  if (frequencyVec.at(intVal) > mpCount)
411  {
412  mpCount = frequencyVec[intVal];
413  mpVal = intVal;
414  }
415  }
416 
417  // take a weighted average of two neighbor bins
418  int meanCnt = 0;
419  int meanSum = 0;
420  int binRange = std::min(16, int(range/2 + 1));
421 
422  for(int idx = mpVal-binRange; idx <= mpVal+binRange; idx++)
423  {
424  if (idx < 0 || idx >= range) continue;
425 
426  meanSum += (idx + minVal) * frequencyVec[idx];
427  meanCnt += frequencyVec[idx];
428  }
429 
430  aveVal = float(meanSum) / float(meanCnt);
431 
432  // do rms calculation - the old fashioned way and over all adc values
433  std::vector<float> adcLessPedVec(rawWaveform.size());
434 
435  std::transform(rawWaveform.begin(),rawWaveform.end(),adcLessPedVec.begin(),std::bind(std::minus<float>(),std::placeholders::_1,aveVal));
436 
437  // recalculate the rms for truncation
438  rmsVal = std::inner_product(adcLessPedVec.begin(), adcLessPedVec.end(), adcLessPedVec.begin(), 0.);
439  rmsVal = std::sqrt(std::max(float(0.),rmsVal / float(adcLessPedVec.size())));
440 
441  // Drop the "large" rms values and recompute
442  std::vector<float>::iterator newEndItr = std::remove_if(adcLessPedVec.begin(),adcLessPedVec.end(),[rmsVal](const auto& val){return std::abs(val) > 2.5*rmsVal;});
443 
444  rmsTrunc = std::inner_product(adcLessPedVec.begin(), newEndItr, adcLessPedVec.begin(), 0.);
445  numBins = std::distance(adcLessPedVec.begin(),newEndItr);
446  rmsTrunc = std::sqrt(std::max(float(0.),rmsTrunc / float(numBins)));
447 
448  return;
449 }
450 
452  unsigned int viewIdx,
453  unsigned int wire,
454  float truncRms,
455  short minMax,
456  short mean,
457  float skewness,
458  float neighborRatio,
459  GroupToDigitIdxPairMap& groupToDigitIdxPairMap) const
460 {
461  // This simply classifies the input waveform:
462  // a) determines if it should be added to the list of waveforms to process
463  // b) if to be analyzed, places in the group of wires to process
464  bool classified(false);
465 
466  // Dereference the selection/rejection cut
467  float selectionCut = fMinMaxSelectionCut[viewIdx];
468  float rejectionCut = fRmsRejectionCutHi[viewIdx];
469 
470  // Selection to process
471  if (minMax > selectionCut && truncRms < rejectionCut)
472  {
473  size_t group = fChannelGroups.channelGroup(viewIdx,wire);
474 
475  if (groupToDigitIdxPairMap.find(group) == groupToDigitIdxPairMap.end())
476  groupToDigitIdxPairMap.insert(std::pair<size_t,RawDigitAdcIdxPair>(group,RawDigitAdcIdxPair()));
477 
478  groupToDigitIdxPairMap.at(group).first.insert(WireToRawDigitVecPair(wire,rawWaveform));
479  groupToDigitIdxPairMap.at(group).second.insert(std::pair<size_t,RawDigitVectorIdxPair>(wire,RawDigitVectorIdxPair(0,rawWaveform.size())));
480 
481  // Look for chirping wire sections. Confine this to only the V plane
482  if (viewIdx == 1)
483  {
484  // Do wire shape corrections to look for chirping wires and other oddities to avoid
485  // Recover our objects...
486  WireToAdcIdxMap& wireToAdcIdxMap = groupToDigitIdxPairMap.at(group).second;
487 
488  // Set a threshold
489  short threshold(6);
490 
491  // If going from quiescent to on again, then the min/max will be large
492  //if (skewnessWireVec[wireIdx] > 0. && minMaxWireVec[wireIdx] > 50 && truncRmsWireVec[wireIdx] > 2.)
493  if (skewness > 0. && neighborRatio < 0.7 && minMax > 50)
494  {
495  RawDigitVector::iterator stopChirpItr = std::find_if(rawWaveform.begin(),rawWaveform.end(),[mean,threshold](const short& elem){return abs(elem - mean) > threshold;});
496 
497  size_t threshIndex = std::distance(rawWaveform.begin(),stopChirpItr);
498 
499  if (threshIndex > 60) wireToAdcIdxMap[wire].first = threshIndex;
500  }
501  // Check in the reverse direction?
502  else if (minMax > 20 && neighborRatio < 0.7)
503  {
504  threshold = 3;
505 
506  RawDigitVector::reverse_iterator startChirpItr = std::find_if(rawWaveform.rbegin(),rawWaveform.rend(),[mean,threshold](const short& elem){return abs(elem - mean) > threshold;});
507 
508  size_t threshIndex = std::distance(rawWaveform.rbegin(),startChirpItr);
509 
510  if (threshIndex > 60) wireToAdcIdxMap[wire].second = rawWaveform.size() - threshIndex;
511  }
512  }
513 
514  classified = true;
515  }
516 
517  return classified;
518 }
519 
520 template<class T> T RawDigitCharacterizationAlg::getMedian(std::vector<T>& valuesVec, T defaultValue) const
521 {
522  T medianValue(defaultValue);
523 
524  if (!valuesVec.empty())
525  {
526  std::sort(valuesVec.begin(),valuesVec.end());
527 
528  size_t medianIdx = valuesVec.size() / 2;
529 
530  medianValue = valuesVec[medianIdx];
531 
532  if (valuesVec.size() > 1 && medianIdx % 2) medianValue = (medianValue + valuesVec[medianIdx+1]) / 2;
533  }
534 
535  return std::max(medianValue,defaultValue);
536 }
537 
538 }
std::vector< float > fRmsSelectionCut
Don&#39;t use/apply correction to wires below this.
RawDigitCharacterizationAlg(fhicl::ParameterSet const &pset)
std::vector< short > fMinMaxSelectionCut
Plane by plane cuts for spread cut.
static constexpr Sample_t transform(Sample_t sample)
void getMeanRmsAndPedCor(const RawDigitVector &rawWaveform, unsigned int channel, unsigned int view, unsigned int wire, float &aveVal, float &rmsVal, float &pedCorVal) const
void getMeanAndRms(const RawDigitVector &rawWaveform, float &aveVal, float &rmsVal, int &numBins) const
double fMaxPedestalDiff
Max pedestal diff to db to warn.
walls no right
Definition: selectors.fcl:105
bool classifyRawDigitVec(RawDigitVector &rawWaveform, unsigned int viewIdx, unsigned int wire, float truncRms, short minMax, short mean, float skewness, float neighborRatio, GroupToDigitIdxPairMap &groupToDigitIdxPairMap) const
bool fFillHistograms
if true then will fill diagnostic hists
raw::RawDigit::ADCvector_t RawDigitVector
void getMeanAndTruncRms(const RawDigitVector &rawWaveform, float &aveVal, float &rmsVal, float &rmsTrunc, int &numBins) const
std::pair< WireToRawDigitVecMap, WireToAdcIdxMap > RawDigitAdcIdxPair
unsigned int fTheChosenWire
For example hist.
std::pair< size_t, size_t > RawDigitVectorIdxPair
std::map< size_t, RawDigitAdcIdxPair > GroupToDigitIdxPairMap
T abs(T value)
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
size_t channelGroup(size_t view, size_t wire) const
const char mode
Definition: noise_ana.cxx:20
std::vector< float > fRmsRejectionCutLow
Minimum rms to consider channel &quot;alive&quot;.
walls no left
Definition: selectors.fcl:105
void reconfigure(fhicl::ParameterSet const &pset)
const lariov::DetPedestalProvider & fPedestalRetrievalAlg
Keep track of an instance to the pedestal retrieval alg.
virtual float PedMean(raw::ChannelID_t ch) const =0
Retrieve pedestal information.
std::pair< size_t, RawDigitVector & > WireToRawDigitVecPair
void getTruncatedRMS(const RawDigitVector &rawWaveform, float &pedestal, float &truncRms) const
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
Definition: UtilFunc.cxx:13
std::string to_string(WindowPattern const &pattern)
std::vector< size_t > fNumWiresToGroup
If smoothing, the number of wires to look at.
art::ServiceHandle< art::TFileService > tfs
std::vector< float > fRmsRejectionCutHi
Maximum rms for input channels, reject if larger.
std::vector< size_t > fHistsWireGroup
Wire Group to pick on.
void initializeHists(art::ServiceHandle< art::TFileService > &)
Begin job method.
void getWaveformParams(const RawDigitVector &rawWaveform, unsigned int channel, unsigned int view, unsigned int wire, float &truncMean, float &truncRms, short &mean, short &median, short &mode, float &skewness, float &rms, short &minMax, float &neighborRatio, float &pedCorVal) const
process_name can override from command line with o or output caldata
Definition: pid.fcl:40
float fTruncMeanFraction
Fraction for truncated mean.
std::map< size_t, RawDigitVectorIdxPair > WireToAdcIdxMap