CnrGroupWeighted.h
Go to the documentation of this file.
1 // CnrGRoupWeighted.h
2 //
3 // David Adams
4 // November 2021
5 //
6 // Remove correlated noise by subtracting the weighted mean or median signal from
7 // the group for each channel.
8 // Channel groups are obtained from the channel group tool channelGroups.
9 // For sample s_ci (c = channel, i = tick), the correct signal is
10 // s'_ci = s_ci - w_c C_gi
11 // where w_c is the assigned channel weight (e.g. BG RMS) and C_gi (g = channel group)
12 // is the mean or median of s_ci/w_c of tick i for channels in the group.
13 // E.g. the calculation for the mean is
14 // C_gi = (SUM_c-in-g s_ci/w_c) / N_c-in-g
15 // Channels with zero weight are excluded from the calculation and left uncorrectd.
16 // Samples identified as signal are excluded from calculation but are corrected.
17 //
18 // Adapted from PdspNoiseRemoval.
19 //
20 // Configuration:
21 // LogLevel: Log frequency: 0=none, 1=initialization, 2=every event
22 // Weight: Name of variable holding the weight (blank for uniform weighting).
23 // Groups: List of group names.
24 // Options: List of options (last overrides):
25 // mean: Evaluate correction using mean of samples (default)
26 // median: Evaluate correction using median of samples
27 
28 #ifndef CnrGroupWeighted_H
29 #define CnrGroupWeighted_H
30 
32 #include "fhiclcpp/ParameterSet.h"
34 #include <string>
35 #include <vector>
36 #include <map>
37 
39 
40 public:
41 
42  // Ctor.
44 
45  // Dtor.
46  ~CnrGroupWeighted() override =default;
47 
48  // Noise removal.
49  DataMap updateMap(AdcChannelDataMap& acds) const override;
50 
51 private:
52 
53  using Name = std::string;
54  using NameVector = std::vector<Name>;
55  using Index = unsigned int;
56  using IndexVector = std::vector<Index>;
57  using ChannelGroups = std::map<Name, IndexVector>;
58  using FloatVector = std::vector<float>;
59  using FloatMap = std::map<Index, float>;
60 
61  // Configuration data.
66 
67  // Derived data.
69  bool m_useMedian =false;
70  bool m_dropSignal =true;
72 
73  void getWeights(const IndexVector& channels, const AdcChannelDataMap& acds, FloatMap& wts) const;
75  const FloatMap& wts) const;
76 
77 };
78 
79 #endif
std::vector< Name > NameVector
FloatVector getCorrection(const IndexVector &channels, const AdcChannelDataMap &acds, const FloatMap &wts) const
unsigned int Index
std::string string
Definition: nybbler.cc:12
NameVector m_Options
std::vector< float > FloatVector
std::map< Name, IndexVector > ChannelGroups
static constexpr double ps
Definition: Units.h:99
ChannelGroups m_chg
void getWeights(const IndexVector &channels, const AdcChannelDataMap &acds, FloatMap &wts) const
CnrGroupWeighted(fhicl::ParameterSet const &ps)
DataMap updateMap(AdcChannelDataMap &acds) const override
std::map< Index, float > FloatMap
std::vector< Index > IndexVector
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
~CnrGroupWeighted() override=default