PdspNoiseRemoval.h
Go to the documentation of this file.
1 // PdspNoiseRemoval.h
2 // Jingbo Wang (UC Davis)
3 // Email: jiowang@ucdavis.edu
4 // January 2019
5 //
6 // Tool to remove noise
7 //
8 // At present, high frequency noise removal and coherent noise removal are supported. More noise removal functions will be added.
9 // The high frequency noise removal is done first, followed by the coherent noise removal. Both are configurable.
10 // The high frequency noise removal is done through a Butterworth low-pass filter.
11 // The coherent noise is caculated as the mean or median waveform of a group of channels.
12 // ProtoDUNE channel map service is used to make the online channel groups.
13 // Different grouping methods are available. By default, every 128 online channels associated to the same FEMB is grouped together.
14 // A simple threshold ROI finder is used to find the ROIs, and signals within the ROI are protected from the coherent noise calculation.
15 //
16 // Configuration:
17 // Defined in dunedataprep/DataPrep/fcl/protodune_dataprep_tools.fcl
18 // RemoveHighFrequency: false # specify if the high frequency noise removal is enabled
19 // RemoveCoherent: true # specify if the coherent noise removal is enabled.
20 // If RemoveHighFrequency is true, coherent noise removal is done afterward.
21 // CutoffFrequency: 300 # cutoff frequency in kHz for Butterworth low-pass filter
22 // CorrMode: "median" # mean or median waveform for coherent noise determination
23 // CoherentOffline16: false # remove coherent noise for groups consisting of 16 consecutive offline channels
24 // CoherentOffline16Groups: [] # remove coherent noise for all groups if list is empty
25 // CoherentDaq8: false # remove coherent noise for groups consisting of 8 online DAQ channels on the same ASIC
26 // CoherentDaq8Groups: [] # remove coherent noise for all groups if list is empty
27 // CoherentDaq16: false # remove coherent noise for groups consisting of 16 online DAQ channels on the same chip
28 // CoherentDaq16Groups: [] # remove coherent noise for all groups if list is empty
29 // CoherentFEMB128: true # remove coherent noise for groups consisting of 128 online DAQ channels on the same FEMB
30 // CoherentFEMB128Groups: [] # remove coherent noise for all groups if list is empty
31 // UseBasicROIForCNR: true # use simple threshold ROI finder
32 // RoiStartThreshold: 20 # threshold on the leading edge
33 // RoiEndThreshold: 20 # threshold on the trailing edge
34 // RoiPadLow: 8 # low bin extension
35 // RoiPadHigh: 20 # high bin extension
36 
37 // This tool was tested with ProtoDUNE-SP data Run4696.
38 
39 
40 #ifndef PdspNoiseRemoval_H
41 #define PdspNoiseRemoval_H
43 #include "fhiclcpp/ParameterSet.h"
45 #include "TFFTRealComplex.h"
46 #include "TFFTComplexReal.h"
49 namespace geo { class Geometry; }
50 namespace util { class LArFFT; }
51 using GroupChannelMap = std::unordered_map<unsigned int, std::vector<unsigned int> >;
52 
54 
55 public:
57  ~PdspNoiseRemoval() override =default;
58  DataMap updateMap(AdcChannelDataMap& acds) const override;
59 
60 private:
61 
62  // Configuration data.
64  bool fRemoveHighFrequency, fRemoveCoherent;
65  bool fCoherentOffline16, fCoherentDaq8, fCoherentDaq16, fCoherentFEMB128;
66  std::vector< size_t > fCoherentOffline16Groups;
67  std::vector< size_t > fCoherentDaq8Groups;
68  std::vector< size_t > fCoherentDaq16Groups;
69  std::vector< size_t > fCoherentFEMB128Groups;
70  std::vector< float > fLowPassCoeffs;
71  int fMode;
78 
79  // Services.
81  mutable util::LArFFT* fFFT;
82 
83  // Functions
84  // Calculate mean wavefrom
85  std::vector<float> getMeanCorrection( const std::vector<unsigned int> & channels, const AdcChannelDataMap & datamap) const;
86  // Calculate median wavefrom
87  std::vector<float> getMedianCorrection( const std::vector<unsigned int> & channels, const AdcChannelDataMap & datamap) const;
88  // Remove coherent noise
89  void removeCoherent(const GroupChannelMap & ch_groups, AdcChannelDataMap& datamap) const;
90  // Remove high frequency noise
91  void removeHighFreq(AdcChannelDataMap& datamap) const;
92  // Do FFT and remove high frequency components for the input wavefrom
93  void fftFltInPlace(std::vector< float > & adc, const std::vector< float > & coeffs) const;
94  // Do FFT and remove high frequency components. Return the filtered wavefrom.
95  std::vector< float > fftFlt(const std::vector< float > & adc, const std::vector< float > & coeffs) const;
96  // Define ROI mask using a simple threshold ROI finder
97  std::vector<bool> roiMask(const AdcChannelData & adc) const;
98  // Make groups of channels using LArSoft numbering. Channels tagged as noisy are excluded at this stage.
99  GroupChannelMap makeGroupsByOfflineChannels(size_t gsize, const std::vector< size_t > & gidx) const;
100  // Make groups of channels by DAQ channel number.
101  GroupChannelMap makeGroupsByDAQChannels(size_t gsize, const std::vector< size_t > & gidx) const;
102  // Make groups of channels by FEMB and plane type.
103  GroupChannelMap makeGroupsByFEMBPlaneType(size_t gsize, const std::vector< size_t > & gidx) const;
104  bool has(const std::vector<size_t> & v, size_t idx) const {
105  for (auto c : v) if (c == idx) return true;
106  return false;
107  }
108  // Get DAQ channel number from the LArSoft's channel index.
109  static size_t getDAQChan(size_t LAr_chan);
110 };
111 #endif
Namespace for general, non-LArSoft-specific utilities.
std::vector< size_t > fCoherentDaq16Groups
const geo::Geometry * fGeometry
std::vector< size_t > fCoherentFEMB128Groups
util::LArFFT * fFFT
int16_t adc
Definition: CRTFragment.hh:202
bool has(const std::vector< size_t > &v, size_t idx) const
std::vector< float > fLowPassCoeffs
The geometry of one entire detector, as served by art.
Definition: Geometry.h:196
static constexpr double ps
Definition: Units.h:99
std::unordered_map< unsigned int, std::vector< unsigned int > > GroupChannelMap
std::vector< size_t > fCoherentOffline16Groups
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
std::vector< size_t > fCoherentDaq8Groups
LArSoft geometry interface.
Definition: ChannelGeo.h:16