All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LArFFT.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
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 //
12 ////////////////////////////////////////////////////////////////////////
13 
16 
17 //-----------------------------------------------
18 util::LArFFT::LArFFT(fhicl::ParameterSet const& pset, art::ActivityRegistry& reg)
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.
30  fSize = art::ServiceHandle<detinfo::DetectorPropertiesService const>()
31  ->DataForJob()
32  .ReadOutWindowSize();
33  reg.sPreBeginRun.watch(this, &util::LArFFT::resetSizePerRun);
34  }
35  InitializeFFT();
36 }
37 
38 //-----------------------------------------------
39 void
41 {
42  fSize = art::ServiceHandle<detinfo::DetectorPropertiesService const>()
43  ->DataForJob()
44  .ReadOutWindowSize();
45  ReinitializeFFT(fSize, fOption, fFitBins);
46 }
47 
48 //-----------------------------------------------
49 void
51 {
52  int i;
53  for (i = 1; i < fSize; i *= 2) {}
54  fSize = i;
55  fFreqSize = fSize / 2 + 1;
56 
57  // allocate and setup Transform objects
58  fFFT = new TFFTRealComplex(fSize, false);
59  fInverseFFT = new TFFTComplexReal(fSize, false);
60 
61  int dummy[1] = {0};
62  // appears to be dummy argument from root page
63  fFFT->Init(fOption.c_str(), -1, dummy);
64  fInverseFFT->Init(fOption.c_str(), 1, dummy);
65 
66  fPeakFit = new TF1("fPeakFit", "gaus"); //allocate function used for peak fitting
67  fConvHist = new TH1D("fConvHist",
68  "Convolution Peak Data",
69  fFitBins,
70  0,
71  fFitBins); //allocate histogram for peak fitting
72  //allocate other data vectors
73  fCompTemp.resize(fFreqSize);
74  fKern.resize(fFreqSize);
75 }
76 
77 //------------------------------------------------
79 {
80  delete fFFT;
81  delete fInverseFFT;
82  delete fPeakFit;
83  delete fConvHist;
84 }
85 
86 //------------------------------------------------
87 void
88 util::LArFFT::ReinitializeFFT(int size, std::string option, int fitbins)
89 {
90  //delete these, which will be remade
91  delete fFFT;
92  delete fInverseFFT;
93  delete fPeakFit;
94  delete fConvHist;
95 
96  //set members
97  fSize = size;
98  fOption = option;
99  fFitBins = fitbins;
100 
101  //now initialize
102  InitializeFFT();
103 }
104 
105 //-------------------------------------------------
106 // For the sake of efficiency, as all transforms should
107 // be of the same size, all functions expect vectors
108 // to be of the desired size.
109 // Note that because the transforms are real to real
110 // there is a redundancy in the information in the
111 // complex part in the positive and negative
112 // components of the FFT, thus the size of the
113 // frequency vectors are input_fFreqSize
114 // --see the FFTW3 or Root docmentation for details
115 
116 //According to the Fourier transform identity
117 //f(x-a) = Inverse Transform(exp(-2*Pi*i*a*w)F(w))
118 //--------------------------------------------------
119 void
120 util::LArFFT::ShiftData(std::vector<TComplex>& input, double shift)
121 {
122  double factor = -2.0 * TMath::Pi() * shift / (double)fSize;
123 
124  for (int i = 0; i < fFreqSize; i++)
125  input[i] *= TComplex::Exp(TComplex(0, factor * (double)i));
126 
127  return;
128 }
129 
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
void resetSizePerRun(art::Run const &)
Definition: LArFFT.cc:40
void ShiftData(std::vector< TComplex > &input, double shift)
Definition: LArFFT.cc:120
int fSize
Definition: LArFFT.h:77
shift
Definition: fcl_checks.sh:26
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
LArFFT(fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
Definition: LArFFT.cc:18
echo Invalid option
Definition: TrainMVA.sh:17
void InitializeFFT()
Definition: LArFFT.cc:50
void ReinitializeFFT(int, std::string, int)
Definition: LArFFT.cc:88