LArFFT_service.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 
18 
19 //-----------------------------------------------
21  : fSize(pset.get<int>("FFTSize", 0))
22  , fOption(pset.get<std::string>("FFTOption"))
23  , fFitBins(pset.get<int>("FitBins"))
24 {
25  // Default to the readout window size if the user didn't input
26  // a specific size
27  if (fSize <= 0) {
28  // Creating a service handle to DetectorPropertiesService not only
29  // creates the service if it doesn't exist, it also guarantees
30  // that its callbacks are invoked before any of LArFFT's callbacks
31  // are invoked.
33  ->DataForJob()
34  .ReadOutWindowSize();
36  }
37  InitializeFFT();
38 }
39 
40 //-----------------------------------------------
41 void
43 {
45  ->DataForJob()
46  .ReadOutWindowSize();
48 }
49 
50 //-----------------------------------------------
51 void
53 {
54  int i;
55  for (i = 1; i < fSize; i *= 2) {}
56  fSize = i;
57  fFreqSize = fSize / 2 + 1;
58 
59  // allocate and setup Transform objects
60  fFFT = new TFFTRealComplex(fSize, false);
61  fInverseFFT = new TFFTComplexReal(fSize, false);
62 
63  int dummy[1] = {0};
64  // appears to be dummy argument from root page
65  fFFT->Init(fOption.c_str(), -1, dummy);
66  fInverseFFT->Init(fOption.c_str(), 1, dummy);
67 
68  fPeakFit = new TF1("fPeakFit", "gaus"); //allocate function used for peak fitting
69  fConvHist = new TH1D("fConvHist",
70  "Convolution Peak Data",
71  fFitBins,
72  0,
73  fFitBins); //allocate histogram for peak fitting
74  //allocate other data vectors
75  fCompTemp.resize(fFreqSize);
76  fKern.resize(fFreqSize);
77 }
78 
79 //------------------------------------------------
81 {
82  delete fFFT;
83  delete fInverseFFT;
84  delete fPeakFit;
85  delete fConvHist;
86 }
87 
88 //------------------------------------------------
89 void
91 {
92  //delete these, which will be remade
93  delete fFFT;
94  delete fInverseFFT;
95  delete fPeakFit;
96  delete fConvHist;
97 
98  //set members
99  fSize = size;
100  fOption = option;
101  fFitBins = fitbins;
102 
103  //now initialize
104  InitializeFFT();
105 }
106 
107 //-------------------------------------------------
108 // For the sake of efficiency, as all transforms should
109 // be of the same size, all functions expect vectors
110 // to be of the desired size.
111 // Note that because the transforms are real to real
112 // there is a redundancy in the information in the
113 // complex part in the positive and negative
114 // components of the FFT, thus the size of the
115 // frequency vectors are input_fFreqSize
116 // --see the FFTW3 or Root docmentation for details
117 
118 //According to the Fourier transform identity
119 //f(x-a) = Inverse Transform(exp(-2*Pi*i*a*w)F(w))
120 //--------------------------------------------------
121 void
122 util::LArFFT::ShiftData(std::vector<TComplex>& input, double shift)
123 {
124  double factor = -2.0 * TMath::Pi() * shift / (double)fSize;
125 
126  for (int i = 0; i < fFreqSize; i++)
127  input[i] *= TComplex::Exp(TComplex(0, factor * (double)i));
128 
129  return;
130 }
131 
void resetSizePerRun(art::Run const &)
void ShiftData(std::vector< TComplex > &input, double shift)
std::string string
Definition: nybbler.cc:12
int fSize
Definition: LArFFT.h:77
std::vector< TComplex > fKern
Definition: LArFFT.h:84
STL namespace.
Definition: Run.h:17
TFFTRealComplex * fFFT
object to do FFT
Definition: LArFFT.h:86
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
static int input(void)
Definition: code.cpp:15695
LArFFT(fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
#define DEFINE_ART_SERVICE(svc)
GlobalSignal< detail::SignalResponseType::FIFO, void(Run const &)> sPreBeginRun
TF1 * fPeakFit
Definition: LArFFT.h:81
std::vector< TComplex > fCompTemp
Definition: LArFFT.h:83
cet::LibraryManager dummy("noplugin")
std::string fOption
Definition: LArFFT.h:79
TFFTComplexReal * fInverseFFT
object to do Inverse FF
Definition: LArFFT.h:87
TH1D * fConvHist
Definition: LArFFT.h:82
int fFitBins
Definition: LArFFT.h:80
void InitializeFFT()
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
void ReinitializeFFT(int, std::string, int)
int fFreqSize
Definition: LArFFT.h:78