Project
Loading...
Searching...
No Matches
IDCFourierTransform.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16
17#ifndef ALICEO2_IDCFOURIERTRANSFORM_H_
18#define ALICEO2_IDCFOURIERTRANSFORM_H_
19
20#include <vector>
21#include "Rtypes.h"
22#include "DataFormatsTPC/Defs.h"
26
27using fftwf_plan = struct fftwf_plan_s*;
28using fftwf_complex = float[2];
29
30namespace o2::tpc
31{
32
35
37template <class Type> // do not use enum class as type to avoid problems with ROOT dictionary generation!
39{
40 public:
45 template <bool IsEnabled = true, typename std::enable_if<(IsEnabled && (std::is_same<Type, IDCFourierTransformBaseAggregator>::value)), int>::type = 0>
46 IDCFourierTransform(const unsigned int rangeIDC = 200, const unsigned int nFourierCoefficientsStore = 200 + 2) : IDCFourierTransformAggregator(rangeIDC), mFourierCoefficients{1, nFourierCoefficientsStore}, mVal1DIDCs(sNThreads), mCoefficients(sNThreads)
47 {
48 initFFTW3Members();
49 };
50
54 template <bool IsEnabled = true, typename std::enable_if<(IsEnabled && (std::is_same<Type, IDCFourierTransformBaseEPN>::value)), int>::type = 0>
55 IDCFourierTransform(const unsigned int rangeIDC = 200, const unsigned int nFourierCoefficientsStore = 200 + 2) : IDCFourierTransformEPN(rangeIDC), mFourierCoefficients{1, nFourierCoefficientsStore}, mVal1DIDCs(sNThreads), mCoefficients(sNThreads)
56 {
57 initFFTW3Members();
58 };
59
60 // Destructor
62
65 static void setFFT(const bool fft) { sFftw = fft; }
66
69 template <bool IsEnabled = true, typename std::enable_if<(IsEnabled && (std::is_same<Type, IDCFourierTransformBaseAggregator>::value)), int>::type = 0>
70 static void setNThreads(const int nThreads)
71 {
72 sNThreads = nThreads;
73 }
74
76 template <bool IsEnabled = true, typename std::enable_if<(IsEnabled && (std::is_same<Type, IDCFourierTransformBaseAggregator>::value)), int>::type = 0>
77 void calcFourierCoefficients(const unsigned int timeFrames = 2000)
78 {
79 mFourierCoefficients.resize(timeFrames);
80 sFftw ? calcFourierCoefficientsFFTW3() : calcFourierCoefficientsNaive();
81 }
82
84 template <bool IsEnabled = true, typename std::enable_if<(IsEnabled && (std::is_same<Type, IDCFourierTransformBaseEPN>::value)), int>::type = 0>
86 {
87 sFftw ? calcFourierCoefficientsFFTW3() : calcFourierCoefficientsNaive();
88 }
89
91 std::vector<std::vector<float>> inverseFourierTransform() const { return sFftw ? inverseFourierTransformFFTW3() : inverseFourierTransformNaive(); }
92
94 unsigned int getrangeIDC() const { return this->mRangeIDC; }
95
97 const auto& getFourierCoefficients() const { return mFourierCoefficients; }
98
100 static bool getFFT() { return sFftw; }
101
103 static int getNThreads() { return sNThreads; }
104
108 void dumpToFile(const char* outFileName = "Fourier.root", const char* outName = "FourierCoefficients") const;
109
112 void dumpToTree(const char* outFileName = "FourierTree.root") const;
113
115 void printFFTWPlan() const;
116
119 std::vector<std::pair<float, float>> getFrequencies(const float samplingFrequency = getSamplingFrequencyIDCHz()) const { return getFrequencies(mFourierCoefficients, samplingFrequency); }
120
124 static std::vector<std::pair<float, float>> getFrequencies(const FourierCoeff& coeff, const float samplingFrequency = getSamplingFrequencyIDCHz());
125
127 static float getSamplingFrequencyIDCHz() { return 1e6 / (12 * o2::constants::lhc::LHCOrbitMUS); }
128
129 private:
130 FourierCoeff mFourierCoefficients;
131 inline static int sFftw{1};
132 inline static int sNThreads{1};
133 fftwf_plan mFFTWPlan{nullptr};
134 std::vector<float*> mVal1DIDCs;
135 std::vector<fftwf_complex*> mCoefficients;
136
138 void calcFourierCoefficientsNaive();
139
141 void calcFourierCoefficientsFFTW3();
142
144 std::vector<std::vector<float>> inverseFourierTransformNaive() const;
145
147 std::vector<std::vector<float>> inverseFourierTransformFFTW3() const;
148
150 void normalizeCoefficients()
151 {
152 std::transform(mFourierCoefficients.mFourierCoefficients.begin(), mFourierCoefficients.mFourierCoefficients.end(), mFourierCoefficients.mFourierCoefficients.begin(), [norm = this->mRangeIDC](auto& val) { return val / norm; });
153 };
154
156 unsigned int getNMaxCoefficients() const { return this->mRangeIDC / 2 + 1; }
157
159 void initFFTW3Members();
160
162 void fftwLoop(const std::vector<float>& idcOneExpanded, const std::vector<unsigned int>& offsetIndex, const unsigned int interval, const unsigned int thread);
163
164 ClassDefNV(IDCFourierTransform, 1)
165};
166
167} // namespace o2::tpc
168
169#endif
This file provides the structs for storing the factorized IDC values and fourier coefficients to be s...
fftwf_plan_s * fftwf_plan
float[2] fftwf_complex
Header to collect LHC related constants.
void dumpToFile(const char *outFileName="Fourier.root", const char *outName="FourierCoefficients") const
const auto & getFourierCoefficients() const
static int getNThreads()
get the number of threads used for calculation of the fourier coefficients
void printFFTWPlan() const
printing information about the algorithms which are used by FFTW for debugging e.g....
void dumpToTree(const char *outFileName="FourierTree.root") const
IDCFourierTransform(const unsigned int rangeIDC=200, const unsigned int nFourierCoefficientsStore=200+2)
std::vector< std::pair< float, float > > getFrequencies(const float samplingFrequency=getSamplingFrequencyIDCHz()) const
std::vector< std::vector< float > > inverseFourierTransform() const
get IDC0 values from the inverse fourier transform. Can be used for debugging. std::vector<std::vecto...
static void setFFT(const bool fft)
void calcFourierCoefficients()
calculate fourier coefficients for one TPC side
static void setNThreads(const int nThreads)
static bool getFFT()
get type of used fourier transform
void calcFourierCoefficients(const unsigned int timeFrames=2000)
calculate fourier coefficients for one TPC side
GLuint GLfloat * val
Definition glcorearb.h:1582
constexpr double LHCOrbitMUS
return * this
Global TPC definitions and constants.
Definition SimTraits.h:167
struct containing the fourier coefficients calculated from IDC0 for n timeframes
std::vector< float > mFourierCoefficients
fourier coefficients. coefficient real and complex parameters are stored alternating
void resize(const unsigned int nTimeFrames)