LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
LArFFT_service.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 
14 // Framework includes
15 
16 extern "C" {
17 #include <sys/types.h>
18 #include <sys/stat.h>
19 }
23 
24 //-----------------------------------------------
26  : fSize (pset.get< int > ("FFTSize", 0))
27  , fOption (pset.get< std::string >("FFTOption"))
28  , fFitBins (pset.get< int >("FitBins"))
29 {
30 
31  // Default to the readout window size if the user didn't input
32  // a specific size
33  if(fSize <= 0)
34  fSize = art::ServiceHandle<detinfo::DetectorPropertiesService>()->provider()->ReadOutWindowSize();
35 
36  InitializeFFT();
37 }
38 
39 //-----------------------------------------------
41 
42  int i;
43  for(i = 1; i < fSize; i *= 2){ }
44  // mf::LogInfo("LArFFt") << "Requested size: " << fSize << " FFT size: " << i ;
45 
46  fSize=i;
47  fFreqSize = fSize/2+1;
48 
49  // allocate and setup Transform objects
50  fFFT = new TFFTRealComplex(fSize, false);
51  fInverseFFT = new TFFTComplexReal(fSize, false);
52 
53  int dummy[1] = {0};
54  // appears to be dummy argument from root page
55  fFFT->Init(fOption.c_str(),-1,dummy);
56  fInverseFFT->Init(fOption.c_str(),1,dummy);
57 
58  fPeakFit = new TF1("fPeakFit","gaus"); //allocate function used for peak fitting
59  fConvHist = new TH1D("fConvHist","Convolution Peak Data",fFitBins,0,fFitBins); //allocate histogram for peak fitting
60  //allocate other data vectors
61  fCompTemp.resize(fFreqSize);
62  fKern.resize(fFreqSize);
63 }
64 
65 //------------------------------------------------
67 {
68  delete fFFT;
69  delete fInverseFFT;
70  delete fPeakFit;
71  delete fConvHist;
72 }
73 
74 //------------------------------------------------
75 void util::LArFFT::ReinitializeFFT(int size, std::string option, int fitbins){
76 
77  //delete these, which will be remade
78  delete fFFT;
79  delete fInverseFFT;
80  delete fPeakFit;
81  delete fConvHist;
82 
83  //set members
84  fSize = size;
85  fOption = option;
86  fFitBins = fitbins;
87 
88  //now initialize
89  InitializeFFT();
90 }
91 
92 //-------------------------------------------------
93 // For the sake of efficiency, as all transforms should
94 // be of the same size, all functions expect vectors
95 // to be of the desired size.
96 // Note that because the transforms are real to real
97 // there is a redundancy in the information in the
98 // complex part in the positive and negative
99 // components of the FFT, thus the size of the
100 // frequency vectors are input_fFreqSize
101 // --see the FFTW3 or Root docmentation for details
102 
103 
104 //According to the Fourier transform identity
105 //f(x-a) = Inverse Transform(exp(-2*Pi*i*a*w)F(w))
106 //--------------------------------------------------
107 void util::LArFFT::ShiftData(std::vector<TComplex> & input,
108  double shift)
109 {
110  double factor = -2.0*TMath::Pi()*shift/(double)fSize;
111 
112  for(int i = 0; i < fFreqSize; i++)
113  input[i] *= TComplex::Exp(TComplex(0,factor*(double)i));
114 
115  return;
116 }
117 
118 namespace util{
119 
121 
122 }
Namespace for general, non-LArSoft-specific utilities.
Definition: PIDAAlg.h:17
void ShiftData(std::vector< TComplex > &input, double shift)
#define DEFINE_ART_SERVICE(svc)
Definition: ServiceMacros.h:93
int fSize
Definition: LArFFT.h:77
std::vector< TComplex > fKern
Definition: LArFFT.h:84
STL namespace.
TFFTRealComplex * fFFT
object to do FFT
Definition: LArFFT.h:86
LArFFT(fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
TF1 * fPeakFit
Definition: LArFFT.h:81
std::vector< TComplex > fCompTemp
Definition: LArFFT.h:83
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()
void ReinitializeFFT(int, std::string, int)
int fFreqSize
Definition: LArFFT.h:78