NCFS-Pack
A generic (astro)particle physics analysis framework
 
Loading...
Searching...
No Matches
NcTransform Class Reference

Various transformations of (sequential) data samples. More...

#include "NcTransform.h"

Inheritance diagram for NcTransform:

Detailed Description

Various transformations of (sequential) data samples.


Copyright(c) 2021 NCFS/IIHE, All Rights Reserved. *
*
Authors: The Netherlands Center for Fundamental Studies (NCFS). *
The Inter-university Institute for High Energies (IIHE). *
Website : http://www.iihe.ac.be *
Contact : Nick van Eijndhoven (nickve.nl@gmail.com) *
*
Contributors are mentioned in the code where appropriate. *
*
No part of this software may be used, copied, modified or distributed *
by any means nor transmitted or translated into machine language for *
commercial purposes without written permission by the IIHE representative. *
Permission to use the software strictly for non-commercial purposes *
is hereby granted without fee, provided that the above copyright notice *
appears in all copies and that both the copyright notice and this *
permission notice appear in the supporting documentation. *
This software is provided "as is" without express or implied warranty. *
The authors make no claims that this software is free of error, or is *
consistent with any particular standard of merchantability, or that it *
will meet your requirements for any particular application, other than *
indicated in the corresponding documentation. *
This software should not be relied on for solving a problem whose *
incorrect solution could result in injury to a person or loss of property. *
If you do use this software in such a manner, it is at your own risk. *
The authors disclaim all liability for direct or consequential damage *
resulting from your use of this software. *

// Class NcTransform
// Class to perform various discrete transformations of (sequential) data samples.
//
// ********************************************************************************
// *** This class has become obsolete. ***
// *** Please use the class NcDSP instead, which offers extended functionality. ***
// *** This class NcTransform is only kept for backward compatibility. ***
// ********************************************************************************
//
//
// The following discrete transformations (using the FFTW algorithms) are supported :
// Fourier (DFT), Hartley (DHT), Sine (DST) and Cosine (DCT).
//
// All transformation results have been normalized, such that
// the inverse transformation provides the original input spectrum.
//
// For details about the transformations and their options, please refer
// to the documentation in the corresponding member functions.
//
// Usage example for a discrete Fourier transform (DFT) :
// ------------------------------------------------------
//
// Int_t N=2048; // Number of samples
// Float_t fsample=3.2e9; // Sampling rate in Hz
// Float_t nu=3e8; // Signal frequency in Hz
//
// Float_t pi=acos(-1.);
// Float_t omega=2.*pi*nu; // Signal frequency in rad/sec
// Float_t step=1./fsample; // The time step of each sample
//
// // Fill the time domain sampled data
// Double_t tdata[N];
// Float_t t=0;
// Float_t y=0;
// for (Int_t i=0; i<N; i++)
// {
// y=cos(omega*t)+5.*sin(3.*omega*t);
// tdata[i]=y;
// t+=step;
// }
//
// NcTransform q;
// q.SetSamplingFrequency(fsample);
// q.Load(N,tdata);
//
// // Obtain the amplitudes in an array
// q.Fourier("R2C");
// TArrayD arr=q.GetData("AMP out");
//
// // Obtain the amplitudes in a histogram
// TH1F hist;
// q.Fourier("R2C",&hist,"AMP Hz");
//
// // Illustration of forward followed by inverse transformation
//
// // The original time domain input spectrum
// TH1F hist1;
// q.Fourier("R2C",&hist1,"t");
//
// // The forward transformation
// TH1F hist2;
// q.Fourier("R2C",&hist2,"AMP Hz");
//
// // Load the obtained frequency domain data as new input to obtain
// // the original time domain spectrum via the inverse transformation
// q.LoadResult();
//
// // The frequency domain input spectrum
// TH1F hist3;
// q.Fourier("C2R",&hist3,"AMP Hz");
//
// // Obtain the original time domain spectrum via the inverse transformation
// TH1F hist4;
// q.Fourier("C2R",&hist4,"t");
//
// TCanvas c1("c1","Forward");
// c1.Divide(1,2);
// c1.cd(1);
// hist1.Draw();
// c1.cd(2);
// hist2.Draw();
//
// TCanvas c2("c2","Inverse");
// c2.Divide(1,2);
// c2.cd(1);
// hist3.Draw();
// c2.cd(2);
// hist4.Draw();
//
//--- Author: Nick van Eijndhoven, IIHE-VUB, Brussel, October 19, 2021 09:42Z
//- Modified: Nick van Eijndhoven, IIHE-VUB, Brussel, December 11, 2021 01:51Z

Definition at line 14 of file NcTransform.h.

Public Member Functions

 NcTransform (const char *name="", const char *title="")
 
 NcTransform (const NcTransform &q)
 
virtual ~NcTransform ()
 
virtual TObject * Clone (const char *name="") const
 
void Cosine (Int_t type, TH1 *hist=0, TString sel="none")
 
void Fourier (TString mode, TH1 *hist=0, TString sel="none")
 
TArrayD GetData (TString mode) const
 
Int_t GetN () const
 
Float_t GetSamplingFrequency () const
 
void Hartley (Int_t mode, TH1 *hist=0, TString sel="none")
 
void Load (Int_t n, Double_t *re, Double_t *im=0, Float_t f=-1)
 
void Load (NcSample *s, Int_t i, Float_t f=-1)
 
void Load (NcSample *s, TString name, Float_t f=-1)
 
void Load (TArray *re, TArray *im=0, Float_t f=-1)
 
void Load (TGraph *gr, Float_t f=-1)
 
void Load (TH1 *h, Float_t f=-1)
 
void LoadResult ()
 
void SetSamplingFrequency (Float_t f)
 
void Sine (Int_t type, TH1 *hist=0, TString sel="none")
 

Protected Member Functions

void Reset ()
 

Protected Attributes

TArrayD fImIn
 
TArrayD fImOut
 
Int_t fN
 
TVirtualFFT * fProc
 
TArrayD fReIn
 
TArrayD fReOut
 
Float_t fSample
 

Constructor & Destructor Documentation

◆ NcTransform() [1/2]

NcTransform::NcTransform ( const char * name = "",
const char * title = "" )
// Default constructor.

Definition at line 136 of file NcTransform.cxx.

◆ ~NcTransform()

NcTransform::~NcTransform ( )
virtual
// Default destructor.

Definition at line 148 of file NcTransform.cxx.

◆ NcTransform() [2/2]

NcTransform::NcTransform ( const NcTransform & q)
// Copy constructor.

Definition at line 163 of file NcTransform.cxx.

Member Function Documentation

◆ Clone()

TObject * NcTransform::Clone ( const char * name = "") const
virtual
// Make a deep copy of the current object and provide the pointer to the copy.
// This memberfunction enables automatic creation of new objects of the
// correct type depending on the object type, a feature which may be very useful
// for containers like NcEvent when adding objects in case the
// container owns the objects.

Definition at line 1591 of file NcTransform.cxx.

◆ Cosine()

void NcTransform::Cosine ( Int_t type,
TH1 * hist = 0,
TString sel = "none" )
// Perform a normalized 1-dimensional Discrete Cosine Transformation (DCT).
// Actually, this is just a regular Discrete Fourier Transformation (DFT)
// with only real input values which contain an even symmetry.
// Consequently, the resulting transformed array is also only real with even symmetry.
//
// Conventions :
// -------------
// N = The number of data elements
// Time domain array : X[]=X[0],...,X[N-1]
// Frequency domain array : Q[]=Q[0],...,Q[N-1]
//
// Cosine transform type 1 : Q[k]=(1/sqrt(2*(N-1)))*[X[0]+pow(-1,k)*X[N-1]+2*sum(n=1,n=N-2){X[n]*cos(pi*n*k/(N-1))}]
//
// Cosine transform type 2 : Q[k]=(1/sqrt(2N))*2*sum(n=0,n=N-1){X[n]*cos(pi*(n+1)*k/N)}]
//
// Cosine transform type 3 : Q[k]=(1/sqrt(2N))[X[0]+2*sum(n=0,n=N-1){X[n]*cos(pi*n*(k+0.5)/N)}]
//
// Cosine transform type 4 : Q[k]=(1/sqrt(2N))*2*sum(n=0,n=N-1){X[n]*cos(pi*(n+0.5)*(k+0.5)/N)}
//
// Notes :
// -------
// 1) The type 1 transformation is only defined for N>1 and is its own inverse.
// 2) The type 4 transformation is its own inverse.
// 3) The type 3 transformation is the inverse of type 2 (and vice versa).
// 4) The type 2 transformation is often called "the" DCT.
// 5) The type 3 transformation id often called "the" inverse DCT (IDCT).
//
// Input arguments :
// -----------------
// type : The type of transformation (i.e. 1,2,3 or 4) to be performed
// The inverse transformations are specified with the corresponding negative type value
// hist : (optional) Histogram with selected results
// sel : String to specify the representation of the result histogram
// "k" --> X-axis represents the index k in the frequency domain
// "f" --> X-axis represents the fraction f of the sampling rate in the frequency domain
// "Hz" --> X-axis represents the actual frequency in Hz in the frequency domain
// "n" --> X-axis represents the index n in the time domain
// "t" --> X-axis represents the actual time in seconds in the time domain
// "2" --> X-axis spans the full number of data points, instead of the usual (N/2)+1
//
// Note : The options "Hz" and "t" can only be used if the actual data acquisition sampling rate
// has been provided via the Load() memberfunction.
//
// Examples :
// ----------
// sel="f" will show the (N/2)+1 amplitudes as a function of the fractional sampling rate.
// sel="k 2" will show all N amplitudes as a function of the index k in the frequency domain.
//
// The default values are hist=0 and sel="none"

Definition at line 1079 of file NcTransform.cxx.

◆ Fourier()

void NcTransform::Fourier ( TString mode,
TH1 * hist = 0,
TString sel = "none" )
// Perform a normalized 1-dimensional Discrete Fourier Transformation (DFT).
//
// Conventions :
// -------------
// N = The number of data elements
// Time domain array : X[]=X[0],...,X[N-1]
// Frequency domain array : Q[]=Q[0],...,Q[N-1]
//
// Fourier transform : Q[k]=(1/sqrt(N))*sum(n=0,n=N-1){X[n]*exp(-i*2pi*(k/N)*n)}
//
// Inverse Fourier transform : X[n]=(1/sqrt(N))*sum(k=0,k=N-1){Q[k]*exp(i*2pi*(n/N)*k)}
//
// Input arguments :
// -----------------
// mode : "R2C" --> Perform a real-input to complex-output discrete Fourier transformation
// "C2R" --> Perform the inverse transformation of "R2C"
// "C2C" --> Perform a complex-input to complex-output discrete Fourier transformation
// "C2CI" --> Perform the inverse of "C2C"
// hist : (optional) Histogram with selected results
// sel : String to specify the contents and representation of the result histogram
// "RE" --> Y-axis shows the values of the real (re) components
// "IM" --> Y-axis shows the values of the imaginary (im) components
// "AMP" --> Y-axis shows the values of the amplitudes, i.e. sqrt(re*re+im*im)
// "PHIR" --> Y-axis shows the values of the phases, i.e. arctan(im/re), in radians
// "PHID" --> Y-axis shows the values of the phases, i.e. arctan(im/re), in degrees
// "k" --> X-axis represents the index k in the frequency domain
// "f" --> X-axis represents the fraction f of the sampling rate in the frequency domain
// "Hz" --> X-axis represents the actual frequency in Hz in the frequency domain
// "n" --> X-axis represents the index n in the time domain
// "t" --> X-axis represents the actual time in seconds in the time domain
// "2" --> X-axis spans the full number of data points, instead of the usual (N/2)+1
//
// Note : The options "Hz" and "t" can only be used if the actual data acquisition sampling rate
// has been provided via the Load() memberfunction.
//
// Examples :
// ----------
// sel="AMP f" will show the (N/2)+1 amplitudes as a function of the fractional sampling rate.
// sel="RE k 2" will show all N real components as a function of the index k in the frequency domain.
//
// The default values are hist=0 and sel="none"

Definition at line 590 of file NcTransform.cxx.

◆ GetData()

TArrayD NcTransform::GetData ( TString mode) const
// Provide a selected set of data.
//
// Input argument :
// ----------------
// sel : String to specify the contents of the provided data array
// "RE" --> The values of the real (re) components
// "IM" --> The values of the imaginary (im) components
// "AMP" --> The amplitudes, i.e. sqrt(re*re+im*im)
// "PHIR" --> The phases, i.e. arctan(im/re), in radians
// "PHID" --> The phases, i.e. arctan(im/re), in degrees
// "in" --> The values of the input data are provided
// "out" --> The values of the output data are provided
//
// Examples :
// ----------
// sel="AMP out" will provide all the N amplitudes of the resulting data after transformation.
// sel="RE in" will provide all the N real components of the input data.

Definition at line 531 of file NcTransform.cxx.

◆ GetN()

Int_t NcTransform::GetN ( ) const
// Provide the number of data elements (to be) processed.

Definition at line 520 of file NcTransform.cxx.

◆ GetSamplingFrequency()

Float_t NcTransform::GetSamplingFrequency ( ) const
// Provide the current value of the DAQ sampling frequency in Hz.

Definition at line 210 of file NcTransform.cxx.

◆ Hartley()

void NcTransform::Hartley ( Int_t mode,
TH1 * hist = 0,
TString sel = "none" )
// Perform a normalized 1-dimensional Discrete Hartley Transformation (DHT).
// Actually, a DHT is closely related to a Discrete Fourier Transformation (DFT)
// with only real input values.
// Consequently, the resulting transformed array is also only real.
//
// Indicating in the frequency domain the DHT data elements by H[k] and the
// DFT data elements by F[k], we have the following relations :
//
// 1) Re(F[k])=(H[k]+H[N-k])/2 and Im(F[k])=(H[N-k]-H[k])/2
// 2) H[k]=Re((1+i)*F[k])
//
// Conventions :
// -------------
// N = The number of data elements
// Time domain array : X[]=X[0],...,X[N-1]
// Frequency domain array : Q[]=Q[0],...,Q[N-1]
//
// Hartley transform : Q[k]=(1/sqrt(N))*sum(n=0,n=N-1){X[n]*[cos(2pi*(k/N)*n)+sin(2pi*(k/N)*n)]}
//
// Inverse Hartley transform : X[n]=(1/sqrt(N))*sum(n=0,k=N-1){Q[k]*[cos(2pi*(n/N)*k)+sin(2pi*(n/N)*k)]}
//
// So, it is seen that the Hartley transform is its own inverse.
//
// Input arguments :
// -----------------
// mode : >0 --> Perform the forward X[n]->Q[k] Hartley transformation
// <0 --> Perform the backward Q[k]->X[n] Hartley transformation
// hist : (optional) Histogram with selected results
// sel : String to specify the representation of the result histogram
// "k" --> X-axis represents the index k in the frequency domain
// "f" --> X-axis represents the fraction f of the sampling rate in the frequency domain
// "Hz" --> X-axis represents the actual frequency in Hz in the frequency domain
// "n" --> X-axis represents the index n in the time domain
// "t" --> X-axis represents the actual time in seconds in the time domain
// "2" --> X-axis spans the full number of data points, instead of the usual (N/2)+1
//
// Note : The options "Hz" and "t" can only be used if the actual data acquisition sampling rate
// has been provided via the Load() memberfunction.
//
// Examples :
// ----------
// sel="f" will show the (N/2)+1 amplitudes as a function of the fractional sampling rate.
// sel="k 2" will show all N amplitudes as a function of the index k in the frequency domain.
//
// The default values are hist=0 and sel="none"

Definition at line 879 of file NcTransform.cxx.

◆ Load() [1/6]

void NcTransform::Load ( Int_t n,
Double_t * re,
Double_t * im = 0,
Float_t f = -1 )
// Provide new input data to be transformed and reset the processor.
//
// Input arguments :
// -----------------
// n : The number of data elements
// re : Array with real data elements
// im : Array with imaginary data elements
// f : (optional) Actual data acquisition sampling frequency in Hz
// In case f<0 the current sampling frequency is not modified.
//
// If provided, the array size must be at least of dimension "n".
//
// The defaults are im=0 and f=-1.

Definition at line 221 of file NcTransform.cxx.

◆ Load() [2/6]

void NcTransform::Load ( NcSample * s,
Int_t i,
Float_t f = -1 )
// Provide new input data from the NcSample "s" to be transformed and reset the processor.
//
// Input arguments :
// -----------------
// i : The data of the i-th variable (1=first) of the NcSample are used
// f : (optional) Actual data acquisition sampling frequency in Hz
// In case f<0 the current sampling frequency is not modified.
//
// Note : The Store Mode of the NcSample must be activated.
//
// The default value is f=-1.

Definition at line 315 of file NcTransform.cxx.

◆ Load() [3/6]

void NcTransform::Load ( NcSample * s,
TString name,
Float_t f = -1 )
// Provide new input data from the NcSample "s" to be transformed and reset the processor.
//
// Input arguments :
// -----------------
// name : Name of the NcSample variable of which the data are used
// f : (optional) Actual data acquisition sampling frequency in Hz
// In case f<0 the current sampling frequency is not modified.
//
// Note : The Store Mode of the NcSample must be activated.
//
// The default value is f=-1.

Definition at line 365 of file NcTransform.cxx.

◆ Load() [4/6]

void NcTransform::Load ( TArray * re,
TArray * im = 0,
Float_t f = -1 )
// Provide new input data to be transformed and reset the processor.
//
// Input arguments :
// -----------------
// re : Array with real data elements
// im : Array with imaginary data elements
// f : (optional) Actual data acquisition sampling frequency in Hz
// In case f<0 the current sampling frequency is not modified.
//
// If both arrays are provided, the size of the smallest non-empty array
// will be used to compose the input data.
//
// The defaults are im=0 and f=-1.

Definition at line 258 of file NcTransform.cxx.

◆ Load() [5/6]

void NcTransform::Load ( TGraph * gr,
Float_t f = -1 )
// Provide new input data from a TGraph object to be transformed and reset the processor.
//
// Input arguments :
// -----------------
// gr : Pointer to the TGraph object of which the bin contents are used
// f : (optional) Actual data acquisition sampling frequency in Hz
// In case f<0 the current sampling frequency is not modified.
//
// The default value is f=-1.

Definition at line 456 of file NcTransform.cxx.

◆ Load() [6/6]

void NcTransform::Load ( TH1 * h,
Float_t f = -1 )
// Provide new input data from a 1-Dimensional histogram to be transformed and reset the processor.
//
// Input arguments :
// -----------------
// h : Pointer to the 1-D histogram of which the bin contents are used
// f : (optional) Actual data acquisition sampling frequency in Hz
// In case f<0 the current sampling frequency is not modified.
//
// The default value is f=-1.

Definition at line 409 of file NcTransform.cxx.

◆ LoadResult()

void NcTransform::LoadResult ( )
// Load the transformation result as new input data in order to enable
// inverse transformations acting on previous transformation results.

Definition at line 505 of file NcTransform.cxx.

◆ Reset()

void NcTransform::Reset ( )
protected
// Internal member function to reset all data and the processor.

Definition at line 180 of file NcTransform.cxx.

◆ SetSamplingFrequency()

void NcTransform::SetSamplingFrequency ( Float_t f)
// Set the actual DAQ sampling frequency in Hz.
// This sampling frequency may be overwritten by invokation of
// one of the various Load() member functions.
// The sampling frequency is set to 0 in the constructor of this class.

Definition at line 196 of file NcTransform.cxx.

◆ Sine()

void NcTransform::Sine ( Int_t type,
TH1 * hist = 0,
TString sel = "none" )
// Perform a normalized 1-dimensional Discrete Sine Transformation (DST).
// Actually, this is just a regular Discrete Fourier Transformation (DFT)
// with only real input values which contain an odd symmetry.
// Consequently, the resulting transformed array is also only real with odd symmetry.
//
// Conventions :
// -------------
// N = The number of data elements
// Time domain array : X[]=X[0],...,X[N-1]
// Frequency domain array : Q[]=Q[0],...,Q[N-1]
//
// Sine transform type 1 : Q[k]=(1/sqrt(2N+1))*2*sum(n=0,n=N-1){X[n]*sin(pi*(n+1)*(k+1)/(N+1))}]
//
// Sine transform type 2 : Q[k]=(1/sqrt(2N))*2*sum(n=0,n=N-1){X[n]*sin(pi*(n+0.5)*(k+1)/N)}
//
// Sine transform type 3 : Q[k]=(1/sqrt(2N))*[pow(-1,k)*X[N-1]+2*sum(n=0,n=N-2){X[n]*sin(pi*(n+1)*(k+0.5)/N)}]
//
// Sine transform type 4 : Q[k]=(1/sqrt(2N))*2*sum(n=0,n=N-1){X[n]*sin(pi*(n+0.5)*(k+0.5)/N)}
//
// Notes :
// -------
// 1) The type 1 transformation is its own inverse.
// 2) The type 4 transformation is its own inverse.
// 3) The type 3 transformation is the inverse of type 2 (and vice versa).
//
// Input arguments :
// -----------------
// type : The type of transformation (i.e. 1,2,3 or 4) to be performed
// The inverse transformations are specified with the corresponding negative type value
// hist : (optional) Histogram with selected results
// sel : String to specify the representation of the result histogram
// "k" --> X-axis represents the index k in the frequency domain
// "f" --> X-axis represents the fraction f of the sampling rate in the frequency domain
// "Hz" --> X-axis represents the actual frequency in Hz in the frequency domain
// "n" --> X-axis represents the index n in the time domain
// "t" --> X-axis represents the actual time in seconds in the time domain
// "2" --> X-axis spans the full number of data points, instead of the usual (N/2)+1
//
// Note : The options "Hz" and "t" can only be used if the actual data acquisition sampling rate
// has been provided via the Load() memberfunction.
//
// Examples :
// ----------
// sel="f" will show the (N/2)+1 amplitudes as a function of the fractional sampling rate.
// sel="k 2" will show all N amplitudes as a function of the index k in the frequency domain.
//
// The default values are hist=0 and sel="none"

Definition at line 1336 of file NcTransform.cxx.

Member Data Documentation

◆ fImIn

TArrayD NcTransform::fImIn
protected

Definition at line 41 of file NcTransform.h.

◆ fImOut

TArrayD NcTransform::fImOut
protected

Definition at line 43 of file NcTransform.h.

◆ fN

Int_t NcTransform::fN
protected

Definition at line 39 of file NcTransform.h.

◆ fProc

TVirtualFFT* NcTransform::fProc
protected

Definition at line 38 of file NcTransform.h.

◆ fReIn

TArrayD NcTransform::fReIn
protected

Definition at line 40 of file NcTransform.h.

◆ fReOut

TArrayD NcTransform::fReOut
protected

Definition at line 42 of file NcTransform.h.

◆ fSample

Float_t NcTransform::fSample
protected

Definition at line 44 of file NcTransform.h.


The documentation for this class was generated from the following files: