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 }
49
53 template <bool IsEnabled = true, typename std::enable_if<(IsEnabled && (std::is_same<Type, IDCFourierTransformBaseEPN>::value)), int>::type = 0>
54 IDCFourierTransform(const unsigned int rangeIDC = 200, const unsigned int nFourierCoefficientsStore = 200 + 2) : IDCFourierTransformEPN(rangeIDC), mFourierCoefficients{1, nFourierCoefficientsStore}, mVal1DIDCs(sNThreads), mCoefficients(sNThreads)
55 {
56 }
57
58 // Destructor
60
63 static void setFFT(const bool fft) { sFftw = fft; }
64
67 template <bool IsEnabled = true, typename std::enable_if<(IsEnabled && (std::is_same<Type, IDCFourierTransformBaseAggregator>::value)), int>::type = 0>
68 static void setNThreads(const int nThreads)
69 {
70 sNThreads = nThreads;
71 }
72
74 void initFFTW3Members();
75
77 template <bool IsEnabled = true, typename std::enable_if<(IsEnabled && (std::is_same<Type, IDCFourierTransformBaseAggregator>::value)), int>::type = 0>
78 void calcFourierCoefficients(const unsigned int timeFrames = 2000)
79 {
80 mFourierCoefficients.resize(timeFrames);
81 sFftw ? calcFourierCoefficientsFFTW3() : calcFourierCoefficientsNaive();
82 }
83
85 template <bool IsEnabled = true, typename std::enable_if<(IsEnabled && (std::is_same<Type, IDCFourierTransformBaseEPN>::value)), int>::type = 0>
87 {
88 sFftw ? calcFourierCoefficientsFFTW3() : calcFourierCoefficientsNaive();
89 }
90
92 std::vector<std::vector<float>> inverseFourierTransform() const { return sFftw ? inverseFourierTransformFFTW3() : inverseFourierTransformNaive(); }
93
95 unsigned int getrangeIDC() const { return this->mRangeIDC; }
96
98 const auto& getFourierCoefficients() const { return mFourierCoefficients; }
99
101 static bool getFFT() { return sFftw; }
102
104 static int getNThreads() { return sNThreads; }
105
109 void dumpToFile(const char* outFileName = "Fourier.root", const char* outName = "FourierCoefficients") const;
110
113 void dumpToTree(const char* outFileName = "FourierTree.root") const;
114
116 void printFFTWPlan() const;
117
120 std::vector<std::pair<float, float>> getFrequencies(const float samplingFrequency = getSamplingFrequencyIDCHz()) const { return getFrequencies(mFourierCoefficients, samplingFrequency); }
121
125 static std::vector<std::pair<float, float>> getFrequencies(const FourierCoeff& coeff, const float samplingFrequency = getSamplingFrequencyIDCHz());
126
128 static float getSamplingFrequencyIDCHz() { return 1e6 / (12 * o2::constants::lhc::LHCOrbitMUS); }
129
130 private:
131 FourierCoeff mFourierCoefficients;
132 inline static int sFftw{1};
133 inline static int sNThreads{1};
134 fftwf_plan mFFTWPlan{nullptr};
135 std::vector<float*> mVal1DIDCs;
136 std::vector<fftwf_complex*> mCoefficients;
137
139 void calcFourierCoefficientsNaive();
140
142 void calcFourierCoefficientsFFTW3();
143
145 std::vector<std::vector<float>> inverseFourierTransformNaive() const;
146
148 std::vector<std::vector<float>> inverseFourierTransformFFTW3() const;
149
151 void normalizeCoefficients()
152 {
153 std::transform(mFourierCoefficients.mFourierCoefficients.begin(), mFourierCoefficients.mFourierCoefficients.end(), mFourierCoefficients.mFourierCoefficients.begin(), [norm = this->mRangeIDC](auto& val) { return val / norm; });
154 };
155
157 unsigned int getNMaxCoefficients() const { return this->mRangeIDC / 2 + 1; }
158
160 void fftwLoop(const std::vector<float>& idcOneExpanded, const std::vector<unsigned int>& offsetIndex, const unsigned int interval, const unsigned int thread);
161
162 ClassDefNV(IDCFourierTransform, 1)
163};
164
165} // namespace o2::tpc
166
167#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
void initFFTW3Members()
initalizing fftw members, e.g. when changing sNThreads via setNThreads after first initialization
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:168
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)