ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtPadFFT.cxx
Go to the documentation of this file.
1 #include "AtPadFFT.h"
2 
3 #include <TComplex.h>
4 #include <TVirtualFFT.h>
5 
6 #include <cassert>
7 #include <cmath>
8 
9 std::unique_ptr<AtPadBase> AtPadFFT::Clone() const
10 {
11  return std::make_unique<AtPadFFT>(*this);
12 }
13 
17 Double_t AtPadFFT::GetPointRe(int i) const
18 {
19 
20  if (i < fRe.size())
21  return fRe[i];
22  else
23  return fRe.at(512 - i);
24 }
25 
29 Double_t AtPadFFT::GetPointIm(int i) const
30 {
31  if (i < fIm.size())
32  return fIm[i];
33  else
34  return -fIm.at(512 - i);
35 }
39 Double_t AtPadFFT::GetPointMag(int i) const
40 {
41  return std::sqrt(GetPointRe(i) * GetPointRe(i) + GetPointIm(i) * GetPointIm(i));
42 }
46 Double_t AtPadFFT::GetPointPhase(int i) const
47 {
48  return std::atan2(GetPointIm(i), GetPointRe(i));
49 }
53 void AtPadFFT::SetPointRe(int i, Double_t val)
54 {
55  if (i < fRe.size())
56  fRe[i] = val;
57  else
58  fRe.at(512 - i) = val;
59 }
63 void AtPadFFT::SetPointIm(int i, Double_t val)
64 {
65  if (i < fIm.size())
66  fIm[i] = val;
67  else
68  fIm.at(512 - i) = -val;
69 }
70 
75 {
76  fRe = std::move(re);
77  fIm = std::move(im);
78 }
79 
84 void AtPadFFT::GetDataFromFFT(const TVirtualFFT *fft)
85 {
86  assert(fft->GetN()[0] / 2 + 1 == fRe.size());
87 
88  for (int i = 0; i < fRe.size(); ++i)
89  fft->GetPointComplex(i, fRe.at(i), fIm.at(i));
90  /*
91  for (auto &re : fRe)
92  re /= fft->GetN()[0];
93  for (auto &im : fIm)
94  im /= fft->GetN()[0];
95  */
96 }
100 void AtPadFFT::SetFFTData(TVirtualFFT *fft)
101 {
102  assert(fft->GetN()[0] / 2 + 1 == fRe.size());
103  fft->SetPointsComplex(fRe.data(), fIm.data());
104 }
105 void AtPadFFT::SetPoint(int i, TComplex val)
106 {
107  assert(i < fRe.size());
108  SetPointIm(i, val.Im());
109  SetPointRe(i, val.Re());
110 }
111 
112 std::unique_ptr<AtPadFFT> AtPadFFT::CreateFromFFT(const TVirtualFFT *fft)
113 {
114  auto ret = std::make_unique<AtPadFFT>();
115  ret->GetDataFromFFT(fft);
116  return ret;
117 }
118 
AtPadFFT::Clone
virtual std::unique_ptr< AtPadBase > Clone() const override
Definition: AtPadFFT.cxx:9
AtPadFFT::SetData
void SetData(TraceTrans re, TraceTrans im)
Sets the real and imaginary parts of all frequency components.
Definition: AtPadFFT.cxx:74
AtPadFFT::CreateFromFFT
static std::unique_ptr< AtPadFFT > CreateFromFFT(const TVirtualFFT *fft)
Definition: AtPadFFT.cxx:112
AtPadFFT::SetPoint
void SetPoint(int i, TComplex val)
Definition: AtPadFFT.cxx:105
AtPadFFT::SetPointIm
void SetPointIm(int i, Double_t val)
Sets the imaginary value of the ith frequency component.
Definition: AtPadFFT.cxx:63
ClassImp
ClassImp(AtPadFFT)
AtPadFFT::fIm
TraceTrans fIm
Definition: AtPadFFT.h:26
AtPadFFT::SetPointRe
void SetPointRe(int i, Double_t val)
Sets the real value of the ith frequency component.
Definition: AtPadFFT.cxx:53
AtPadFFT::GetPointRe
Double_t GetPointRe(int i) const
Returns the real part of the ith frequency compnent.
Definition: AtPadFFT.cxx:17
AtPadFFT
Definition: AtPadFFT.h:19
AtPadFFT::GetPointIm
Double_t GetPointIm(int i) const
Returns the imaginary part of the ith frequency compnent.
Definition: AtPadFFT.cxx:29
AtPadFFT::GetPointPhase
Double_t GetPointPhase(int i) const
Returns the phase of the ith frequency compnent (-pi,pi].
Definition: AtPadFFT.cxx:46
AtPadFFT::TraceTrans
std::array< Double_t, 512/2+1 > TraceTrans
Definition: AtPadFFT.h:21
AtPadFFT::fRe
TraceTrans fRe
Definition: AtPadFFT.h:25
AtPadFFT.h
AtPadFFT::GetDataFromFFT
void GetDataFromFFT(const TVirtualFFT *fft)
Sets the real and imaginary parts of all frequency components from the TVirtualFFT.
Definition: AtPadFFT.cxx:84
AtPadFFT::GetPointMag
Double_t GetPointMag(int i) const
Returns the magnitude of the ith frequency compnent.
Definition: AtPadFFT.cxx:39
AtPadFFT::SetFFTData
void SetFFTData(TVirtualFFT *fft)
Sets the real and imaginary parts of all frequency components in a TVirtualFFT.
Definition: AtPadFFT.cxx:100