AdcChannelFFT.h
Go to the documentation of this file.
1 // AdcChannelFFT.h
2 
3 // David Adams
4 // April 2018
5 //
6 // Tool to perform FFT of the prepared data in an ADC channel data map.
7 //
8 // For AdcChannelData acd, the waveform (WF) is held in acd.samples, the DFT magnitudes
9 // in acd.dftmags and DFT phases in acd.fftphases. For a WF of length N, the length of the
10 // magnitudes vector is (N+2)/2 and the length of the phases is (N+1)/2, i.e. the same for
11 // N odd and one less for N even. I.e. N = N_mag + N_phase - 1. The first entry in the phase
12 // vector is always zero or pi. The magnitudes are all positive except, when N is even, there
13 // the last (Nyquist) magnitude is signed because there is no corresponding phase.
14 //
15 // The DFT magnitudes are stored in a float vector of lenght NMag normalized
16 // so that the relative power for each term is the square of its value.
17 // I.e. the DFT magnitudes only extend up to the Nyquist frequency and are normalized to
18 // include the power for all alias (e.g. folded) frequencies. To convert to a complex array
19 // of nsam terms all but the first and Nyquist (last only for even # samples) must be scaled
20 // by 1/sqrt(2).
21 //
22 // This is the Consistent-Power normalization described in DuneCommon/Utility/RealDftData.h.
23 //
24 // The DFT phases
25 //
26 // Configuration:
27 // LogLevel - 0=silent, 1=init, 2=each event, >2=more
28 // FirstTick - First tick used in transform.
29 // NTick - # ticks to use in transform. To end if 0.
30 // Action - 0 - Use existing DFT
31 // 1 - Evaluate DFT from WF. Do not save result.
32 // 2 - Evaluate DFT if it is not already present. Do not save result.
33 // 3 - Evaluate DFT and save result
34 // 4 - Evaluate DFT if it is not already present and save result.
35 // 10 - Use existing WF.
36 // 11 - Evaluate WF from DFT. Do not save result.
37 // 12 - Evaluate WF if it is not already present. Do not save result.
38 // 13 - Evaluate WF and save result
39 // 14 - Evaluate WF if it is not already present and save result.
40 // ReturnOpt - Controls how much data is written to the returned data map (see below)
41 // DataView - Action is taken for each entry on this view. Blank means the top.
42 //
43 // Only consistent results can be saved. I.e. FirstTick must be zero and Ntick zero
44 // or the same size as samples.
45 //
46 // In addition to the status, the returned data map includes:
47 // For forward transforms (Action = 0-4):
48 // if ReturnOpt%10 >= 1:
49 // fftTick0 - First tick used to evaluate the DFT.
50 // fftNTick - # ticks used to evaluate the DFT.
51 // fftNMag - # DFT magnitudes
52 // fftNPhase - # DFT phases (first is zero)
53 // fftNSample- # samples = fftNMag + fftNPhase - 1
54 // if ReturnOpt%10 >= 2:
55 // fftMags - FFT magnitudes
56 // fftPhases - FFT phases
57 // if ReturnOpt%10 >= 3:
58 // fftReals - Real part of each term (NTick entries)
59 // fftImags - Imaginary part of each term (NTick entries)
60 // if ReturnOpt = 10-13:
61 // fftSamples - Waveform
62 // If DatView is not blank, then the data map instead holds
63 // fftNproc - # AdcChannelData objects processed
64 // fftNfail - # objects for which the processing failed
65 
66 #ifndef AdcChannelFFT_H
67 #define AdcChannelFFT_H
68 
70 #include "fhiclcpp/ParameterSet.h"
73 
75 
76 public:
77 
78  using Index = unsigned int;
80  using DFT = DuneFFT::DFT;
81  using Name = std::string;
82 
84 
85  ~AdcChannelFFT() override =default;
86 
87  // AdcChannelTool methods.
88  DataMap view(const AdcChannelData& acd) const override;
89  DataMap update(AdcChannelData& acd) const override;
90 
91 private:
92 
93  // AdcChannelTool that act on the top of the data view.
94  DataMap viewTop(const AdcChannelData& acd) const;
95  DataMap updateTop(AdcChannelData& acd) const;
96 
97  // This does all the work of view:
98  // deciding what action to take
99  // calling one of the above to carry out the action
100  // constructing the result
101  void internalView(const AdcChannelData& acd, FloatVector& sams, FloatVector& amps, FloatVector& phas, DataMap& ret) const;
102 
103 private:
104 
105  // Configuration data.
112 
113 };
114 
115 
116 #endif
unsigned int Index
std::string string
Definition: nybbler.cc:12
CompactRealDftData< float > DFT
Definition: DuneFFT.h:28
AdcChannelFFT(fhicl::ParameterSet const &ps)
std::string Name
Definition: AdcChannelFFT.h:81
static constexpr double ps
Definition: Units.h:99
DataMap updateTop(AdcChannelData &acd) const
~AdcChannelFFT() override=default
DataMap viewTop(const AdcChannelData &acd) const
std::vector< AdcSignal > AdcSignalVector
Definition: AdcTypes.h:22
AdcSignalVector FloatVector
Definition: AdcChannelFFT.h:79
DataMap view(const AdcChannelData &acd) const override
DataMap update(AdcChannelData &acd) const override
void internalView(const AdcChannelData &acd, FloatVector &sams, FloatVector &amps, FloatVector &phas, DataMap &ret) const