ExpTailPedRemover.h
Go to the documentation of this file.
1 // ExpTailPedRemover.h
2 //
3 // David Adams
4 // September 2020
5 //
6 // Tool to remove an exponential tail and tim-dependent pedestal from
7 // AC-coupled front-end electronics. See DUNE-doc-20618.
8 //
9 // The measured charge vector is assumed to be a sum of signal and tail:
10 //
11 // Qdat = Qsig + Qtai + Qped + Qnoise
12 //
13 // where <Qnoise> = 0.
14 //
15 // This tool replaces the sample vector (assumed to be Qdat) in
16 // AdcChannelData with signal (pus noise), i.e. it removes the tail and pedestal.
17 //
18 // Any signal contribution is assumed to be accompanied by an exponential tail
19 // whose integral cancels that of the signal. The decay time of the exponential
20 // is a parameter of this tool. If 0, there is no tail.
21 //
22 // The data is fit with this model and Np + 1 varied parameters: the initial
23 // charge Qtail[0] and the Np parameters in the pedestal model and the initial charge of the tail csi.
24 //
25 // The fit is iterative using samples not flagged as signal to evaluate these
26 // parameters. Each iteration, the samples are updated and those values are used
27 // to evaluate the signal for the next iteration. Iterations stop when the signal
28 // evalaution does not change or the maximum # iterations is reached.
29 //
30 // The pedestal model is a polynomial in (tick-Pedtick0) with degree PedDgree
31 // plus a series of fixed frequncy terms for the frequncies listed in PedFreqs.
32 //
33 // Configuration:
34 // LogLevel - 0=silent, 1=init, 3=each event, >4=more
35 // DecayTime: Exponential decay time in ticks. If <= 0, the tail is not used.
36 // MaxTick: Maximum # ticks expected. Pedestal arrays are this size.
37 // PedDegree: Degree of the pedestal polynomial: <0=none, 1=flat, 2=linear, >=3=quadratic
38 // PedTick0: polynomial = SUM lambda_i (isam - PedTick0)^i
39 // PedFreqs: Frequency terms (sin and cos) added for each of these frequencies [1/tick]
40 // SignalFlag: Specifies how signal regions are identified in the samples.
41 // 0 - Use all samples.
42 // 1 - Use the input acd.signal. If not enough values, pad with
43 // false and log warning.
44 // 2 - Apply the signal finder on updated samples each iteration.
45 // 3 - Same as 2 plus the signal finder is applied on the final
46 // samples.
47 // SignalIterationLimit - Maximum nimber of fit iterations.
48 // SignalTool - Name of the tool used identify signals. The method called is
49 // AdcChannelTool::update, i.e. single-channel signal finding.
50 // NoWarnStatuses - Status flags for which warnings should not be logged.
51 // IncludeChannelRanges - List of channel ranges to correct. If empty, all channels
52 // Use empty or "all" for all channels or "none" for no channels.
53 // Tool channelRanges is used to map these names to channels.
54 // ExcludeChannelRanges - List of channel ranges whose channels are excluded from
55 // the list to process derived from IncludeChannelRanges.
56 // If "all", no channels are processed.
57 //
58 // The following metadata is added to each channel (i.e. to AdcChannelData):
59 // uscPedestal - fitted pedestal (w.r.t. input samples)
60 // uscTail - Fitted tail for the first bin (tau[0])
61 // uscNoise - Noise = RMS of (sample - pedestal) in the no-signal region
62 //
63 // The following are returned in the call toi view:
64 // uscPedestal - As above
65 // uscTail - As above.
66 // uscNsamFit - # non-signal samples
67 // uscNiteration - # fit iterations
68 
69 #ifndef ExpTailPedRemover_H
70 #define ExpTailPedRemover_H
71 
73 #include "fhiclcpp/ParameterSet.h"
75 #include <vector>
76 #include <set>
77 
79 
80 public:
81 
82  using Index = unsigned int;
83  using IndexVector = std::vector<Index>;
84  using IndexSet = std::set<Index>;
85  using Vector = std::vector<double>;
86  using Name = std::string;
87  using NameVector = std::vector<Name>;
88  using FloatVector = std::vector<float>;
89  using FloatVectorVector = std::vector<FloatVector>;
90 
92 
93  ~ExpTailPedRemover() override =default;
94 
95  DataMap update(AdcChannelData& acd) const override;
96 
97 private:
98 
99  // Configuration data.
104  double m_DecayTime;
112 
113  // Derived from configuration.
114  bool m_useChannelRanges; // If true, only channels in checkChannels are processed.
116  std::vector<bool> m_checkChannels;
119  NameVector m_fitNames; // Names for the fitted params: {Tail, Pedestal, Slope, Curvature, Cos, Sin, ...)
121 
122  // private methods
123 
124  // Return if tail is used.
125  bool useTail() const { return m_DecayTime > 0.0; }
126  bool usePolynomial() const { return m_PedDegree >= 0; }
127 
128  // Remove the pedestal and tail from a data vactor.
129  void getSignal(const Vector& qdats, double ped, double csi, Vector& qsigs) const;
130 
131  // Use the samples qdats to estimate the pedestal ped and initial tail charge csi.
132  // nsamFit is the # samples used in the fit, i.e. those not considered signal
133  void estimatepars(const Vector& qdats, double& ped, double& csi, Index& nsamFit) const;
134 
135  // Fit to line.
136  void wlinfit(const Vector& x, const Vector& y, const Vector& e,
137  double& slope, double& intercept) const;
138 
139 };
140 
141 
142 #endif
void getSignal(const Vector &qdats, double ped, double csi, Vector &qsigs) const
ExpTailPedRemover(fhicl::ParameterSet const &ps)
bool usePolynomial() const
std::vector< FloatVector > FloatVectorVector
unsigned int Index
IndexVector m_NoWarnStatuses
std::string string
Definition: nybbler.cc:12
void estimatepars(const Vector &qdats, double &ped, double &csi, Index &nsamFit) const
NameVector m_ExcludeChannelRanges
bool useTail() const
const double e
AdcChannelTool * m_pSignalTool
static constexpr double ps
Definition: Units.h:99
std::vector< Index > IndexVector
std::vector< double > Vector
std::vector< bool > m_checkChannels
FloatVectorVector m_pedVectors
~ExpTailPedRemover() override=default
std::vector< Name > NameVector
list x
Definition: train.py:276
std::set< Index > IndexSet
DataMap update(AdcChannelData &acd) const override
NameVector m_IncludeChannelRanges
void wlinfit(const Vector &x, const Vector &y, const Vector &e, double &slope, double &intercept) const
std::vector< float > FloatVector