LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
LArFFT.cc
Go to the documentation of this file.
1 //
3 // \file LArFFT_plugin
4 //
5 // This class simplifies implementation of Fourier transforms.
6 // Because all data inputs and outputs are purely real, the
7 // transforms implemented in this way get a substantial performance
8 // increase ~2x.
9 //
10 // \author pagebri3@msu.edu
11 //
13 
16 
17 //-----------------------------------------------
19  : fSize(pset.get<int>("FFTSize", 0))
20  , fOption(pset.get<std::string>("FFTOption"))
21  , fFitBins(pset.get<int>("FitBins"))
22 {
23  // Default to the readout window size if the user didn't input
24  // a specific size
25  if (fSize <= 0) {
26  // Creating a service handle to DetectorPropertiesService not only
27  // creates the service if it doesn't exist, it also guarantees
28  // that its callbacks are invoked before any of LArFFT's callbacks
29  // are invoked.
31  ->DataForJob()
32  .ReadOutWindowSize();
34  }
35  InitializeFFT();
36 }
37 
38 //-----------------------------------------------
40 {
42  ->DataForJob()
43  .ReadOutWindowSize();
45 }
46 
47 //-----------------------------------------------
49 {
50  int i;
51  for (i = 1; i < fSize; i *= 2) {}
52  fSize = i;
53  fFreqSize = fSize / 2 + 1;
54 
55  // allocate and setup Transform objects
56  fFFT = new TFFTRealComplex(fSize, false);
57  fInverseFFT = new TFFTComplexReal(fSize, false);
58 
59  int dummy[1] = {0};
60  // appears to be dummy argument from root page
61  fFFT->Init(fOption.c_str(), -1, dummy);
62  fInverseFFT->Init(fOption.c_str(), 1, dummy);
63 
64  fPeakFit = new TF1("fPeakFit", "gaus"); //allocate function used for peak fitting
65  fConvHist = new TH1D("fConvHist",
66  "Convolution Peak Data",
67  fFitBins,
68  0,
69  fFitBins); //allocate histogram for peak fitting
70  //allocate other data vectors
71  fCompTemp.resize(fFreqSize);
72  fKern.resize(fFreqSize);
73 }
74 
75 //------------------------------------------------
77 {
78  delete fFFT;
79  delete fInverseFFT;
80  delete fPeakFit;
81  delete fConvHist;
82 }
83 
84 //------------------------------------------------
85 void util::LArFFT::ReinitializeFFT(int size, std::string option, int fitbins)
86 {
87  //delete these, which will be remade
88  delete fFFT;
89  delete fInverseFFT;
90  delete fPeakFit;
91  delete fConvHist;
92 
93  //set members
94  fSize = size;
95  fOption = option;
96  fFitBins = fitbins;
97 
98  //now initialize
99  InitializeFFT();
100 }
101 
102 //-------------------------------------------------
103 // For the sake of efficiency, as all transforms should
104 // be of the same size, all functions expect vectors
105 // to be of the desired size.
106 // Note that because the transforms are real to real
107 // there is a redundancy in the information in the
108 // complex part in the positive and negative
109 // components of the FFT, thus the size of the
110 // frequency vectors are input_fFreqSize
111 // --see the FFTW3 or Root docmentation for details
112 
113 //According to the Fourier transform identity
114 //f(x-a) = Inverse Transform(exp(-2*Pi*i*a*w)F(w))
115 //--------------------------------------------------
116 void util::LArFFT::ShiftData(std::vector<TComplex>& input, double shift)
117 {
118  double factor = -2.0 * TMath::Pi() * shift / (double)fSize;
119 
120  for (int i = 0; i < fFreqSize; i++)
121  input[i] *= TComplex::Exp(TComplex(0, factor * (double)i));
122 
123  return;
124 }
void resetSizePerRun(art::Run const &)
Definition: LArFFT.cc:39
void ShiftData(std::vector< TComplex > &input, double shift)
Definition: LArFFT.cc:116
int fSize
Definition: LArFFT.h:73
std::vector< TComplex > fKern
Definition: LArFFT.h:80
STL namespace.
Definition: Run.h:37
TFFTRealComplex * fFFT
object to do FFT
Definition: LArFFT.h:82
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
LArFFT(fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
Definition: LArFFT.cc:18
GlobalSignal< detail::SignalResponseType::FIFO, void(Run const &)> sPreBeginRun
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120
TF1 * fPeakFit
Definition: LArFFT.h:77
std::vector< TComplex > fCompTemp
Definition: LArFFT.h:79
std::string fOption
Definition: LArFFT.h:75
TFFTComplexReal * fInverseFFT
object to do Inverse FF
Definition: LArFFT.h:83
TH1D * fConvHist
Definition: LArFFT.h:78
int fFitBins
Definition: LArFFT.h:76
void InitializeFFT()
Definition: LArFFT.cc:48
void ReinitializeFFT(int, std::string, int)
Definition: LArFFT.cc:85
int fFreqSize
Definition: LArFFT.h:74