NCFS-Pack
A generic (astro)particle physics analysis framework
 
Loading...
Searching...
No Matches
NcDSP.h
Go to the documentation of this file.
1#ifndef NcDSP_h
2#define NcDSP_h
3
4// Copyright(c) 2021 NCFS/IIHE, All Rights Reserved.
5// See cxx source for full Copyright notice.
6
7#include "TArrayD.h"
8#include "TArrayL64.h"
9#include "TVirtualFFT.h"
10#include "TList.h"
11#include "TLine.h"
12
13#include "NcSample.h"
14#include "NcMath.h"
15#include "NcSignal.h"
16#include "NcDevice.h"
17
19
20class NcDSP : public TNamed
21{
22 public:
23 NcDSP(const char* name="",const char* title=""); // Default constructor
24 virtual ~NcDSP(); // Default destructor
25 NcDSP(const NcDSP& q); // Copy constructor
26 virtual TObject* Clone(const char* name="") const; // Make a deep copy and provide its pointer
27 void SetSamplingFrequency(Float_t f); // Set the actual DAQ sampling frequency in Hz
28 Float_t GetSamplingFrequency() const; // Provide the current DAQ sampling frequency in Hz
29 void Load(Int_t n,Double_t* re,Double_t* im=0,Float_t f=-1); // Provide new input data to be processed
30 void Load(TArray* re,TArray* im=0,Float_t f=-1); // Provide new input data to be processed
31 void Load(NcSample* s,Int_t i,Float_t f=-1); // Provide new input data to be processed
32 void Load(NcSample* s,TString name,Float_t f=-1); // Provide new input data to be processed
33 void Load(TH1* h,Float_t f=-1); // Provide new input data to be processed
34 void Load(TGraph* gr,Float_t f=-1); // Provide new input data to be processed
35 void LoadResult(); // Load the transformation result as new input data
36 void SetWaveform(Int_t n,Double_t* h,Float_t f=-1); // Set the (system response) waveform for Convolution, Correlation etc.
37 void SetWaveform(TArray* h,Float_t f=-1); // Set the (system response) waveform for Convolution, Correlation etc.
38 void SetWaveform(NcSample* s,Int_t i,Float_t f=-1); // Set the (system response) waveform for Convolution, Correlation etc.
39 void SetWaveform(NcSample* s,TString name,Float_t f=-1); // Set the (system response) waveform for Convolution, Correlation etc.
40 void SetWaveform(TH1* h,Float_t f=-1); // Set the (system response) waveform for Convolution, Correlation etc.
41 void SetWaveform(TGraph* gr,Float_t f=-1); // Set the (system response) waveform for Convolution, Correlation etc.
42 void Fourier(TString mode,TH1* hist=0,TString sel="none"); // Perform a 1-dimensional Discrete Fourier Transform (DFT)
43 void Hartley(Int_t mode,TH1* hist=0,TString sel="none"); // Perform a 1-dimensional Discrete Hartley Transform (DHT)
44 void Cosine(Int_t type,TH1* hist=0,TString sel="none"); // Perform a 1-dimensional Discrete Cosine Transform (DCT)
45 void Sine(Int_t type,TH1* hist=0,TString sel="none"); // Perform a 1-dimensional Discrete Sine Transform (DST)
46 void Hilbert(Int_t mode,TH1* hist=0,TString sel="none"); // Perform a 1-dimensional Discrete Hilbert Transform (HT)
47 TArrayD Convolve(TH1* hist=0,Int_t* i1=0,Int_t* i2=0,Int_t shift=0); // Convolve the loaded data with the stored waveform data
48 TArrayD Correlate(TH1* hist=0,Int_t* i1=0,Int_t* i2=0,Double_t* peak=0,TString norm="NONE"); // Correlate the stored waveform data with the loaded data
49 TArrayD Digitize(Int_t nbits,Double_t vcal,Int_t mode,TH1* hist=0,Double_t* stp=0,Double_t* scale=0) const; // Digitize values according to an "nbits" ADC.
50 TArrayL64 ADC(Int_t nbits,Double_t range,Double_t Vbias=0,TArray* Vsig=0,TH1* hist=0,Int_t B=0,Int_t C=3) const; // Provide the quantized data of an "nbits" ADC.
51 TArrayD DAC(Int_t nbits,Double_t range,Double_t Vbias=0,TArray* adcs=0,TArray* peds=0,TH1* hist=0,Int_t B=0,Int_t C=3) const; // Reconstruct the analog signals from an "nbits" ADC.
52 TArrayD Transmit(Int_t nbits,Double_t range,Double_t Vbias=0,TArray* Vsig=0,TArray* peds=0,TH1* hist=0,Int_t B=0,Int_t C=3) const; // Transmit signals according to an "bits" ADC-DAC chain
53
54 TArrayD SampleAndHold(TF1 f,Double_t step,Double_t vmin,Double_t vmax,TH1* hist=0,Int_t loc=-1) const; // Perform a Sample-And-Hold operation on function "f"
55 TArrayD SampleAndHold(Int_t ns,TH1* hist=0,Int_t loc=-1,Int_t jmin=0,Int_t jmax=-1) const; // Perform a Sample-And-Hold operation on the stored waveform data
56 TArrayD SampleAndSum(TF1 f,Double_t step,Double_t vmin,Double_t vmax,TH1* hist=0) const; // Perform a Sample-And-Sum operation on function "f"
57 TArrayD SampleAndSum(Int_t ns,TH1* hist,Int_t jmin=0,Int_t jmax=-1) const; // Perform a Sample-And-Sum operation on the stored waveform data
58 TArrayD FilterMovingAverage(Int_t n,TString mode,TH1* hist=0,Int_t* i1=0,Int_t* i2=0,TH1* hisf=0,Bool_t dB=kTRUE); // Perform a Moving Average filter on the loaded data
59 TArrayD FilterLowPass(Double_t fcut,Int_t n,TH1* hisf=0,Bool_t dB=kTRUE,TH1* hist=0,Int_t* i1=0,Int_t* i2=0,Bool_t adaptn=kTRUE); // Perform a Low Pass filter on the loaded data
60 TArrayD FilterHighPass(Double_t fcut,Int_t n,TH1* hisf=0,Bool_t dB=kTRUE,TH1* hist=0,Int_t* i1=0,Int_t* i2=0,Bool_t adaptn=kTRUE); // Perform a High Pass filter on the loaded data
61 TArrayD FilterBandPass(Double_t f1,Double_t f2,Int_t n,TH1* hisf=0,Bool_t dB=kTRUE,TH1* hist=0,Int_t* i1=0,Int_t* i2=0,Bool_t adaptn=kTRUE); // Perform a Band Pass filter on the loaded data
62 TArrayD FilterBandReject(Double_t f1,Double_t f2,Int_t n,TH1* hisf=0,Bool_t dB=kTRUE,TH1* hist=0,Int_t* i1=0,Int_t* i2=0,Bool_t adaptn=kTRUE); // Perform a Band Reject filter on the loaded data
63 TArrayD FilterMultiBand(TArray& freqs,Int_t n,TH1* hisf=0,Bool_t dB=kTRUE,TH1* hist=0,Int_t* i1=0,Int_t* i2=0,Bool_t adaptn=kTRUE); // Perform a Multi Band filter on the loaded data
64 TArrayD GetMovingAverageKernel(Int_t n,TH1* hisf=0,Bool_t dB=kTRUE,TH1* hist=0); // Provide a time domain Moving Average Filter kernel
65 TArrayD GetLowPassKernel(Double_t fcut,Int_t n,TH1* hisf=0,Bool_t dB=kTRUE,TH1* hist=0,Bool_t adaptn=kTRUE); // Provide a time domain Low Pass Filter kernel
66 TArrayD GetHighPassKernel(Double_t fcut,Int_t n,TH1* hisf=0,Bool_t dB=kTRUE,TH1* hist=0,Bool_t adaptn=kTRUE); // Provide a time domain High Pass Filter kernel
67 TArrayD GetBandPassKernel(Double_t f1,Double_t f2,Int_t n,TH1* hisf=0,Bool_t dB=kTRUE,TH1* hist=0,Bool_t adaptn=kTRUE); // Provide a time domain Band Pass Filter kernel
68 TArrayD GetBandRejectKernel(Double_t f1,Double_t f2,Int_t n,TH1* hisf=0,Bool_t dB=kTRUE,TH1* hist=0,Bool_t adaptn=kTRUE); // Provide a time domain Band Reject Filter kernel
69 TArrayD GetMultiBandKernel(TArray& freqs,Int_t n,TH1* hisf=0,Bool_t dB=kTRUE,TH1* hist=0,Bool_t adaptn=kTRUE); // Provide a time domain Multi Band Filter kernel
70 Int_t GetN(Int_t mode=0) const; // Provide the number of data elements (to be) processed.
71 TArrayD GetData(TString mode) const; // Provide a selected set of data
72
73 TGraph Periodogram(TString tu,Double_t Tmin,Double_t Tmax,Int_t n,TArray& t,TArray& y,TArray* dy=0,TF1* Z=0, NcDevice* results=0) const; // Provide a periodogram for the specified data
74 TGraph Periodogram(TString tu,Double_t Tmin,Double_t Tmax,Int_t n,NcSample s,Int_t it,Int_t iy,Int_t idy=0,TF1* Z=0, NcDevice* results=0) const; // Provide a periodogram for the specified data
75 TGraph Periodogram(TString tu,Double_t Tmin,Double_t Tmax,Int_t n,NcSample s,TString namet,TString namey,TString namedy="-",TF1* Z=0, NcDevice* results=0) const; // Provide a periodogram for the specified data
76 TGraph Periodogram(TString tu,Double_t Tmin,Double_t Tmax,Int_t n,TH1& h,Bool_t err=kFALSE,TF1* Z=0, NcDevice* results=0) const; // Provide a periodogram for the specified data
77 TGraph Periodogram(TString tu,Double_t Tmin,Double_t Tmax,Int_t n,TGraph& g,Bool_t err=kFALSE,TF1* Z=0, NcDevice* results=0) const; // Provide a periodogram for the specified data
78
79 protected:
80 TVirtualFFT* fProc; // The FFTW processor
81 Int_t fN; // The number of data elements to be processed as entered via Load()
82 Int_t fNwf; // The number of data elements to be processed as entered via SetWaveform();
83 TArrayD fReIn; // Input array for real components
84 TArrayD fImIn; // Input array for imaginary components
85 TArrayD fReOut; // Output array for real components
86 TArrayD fImOut; // Output array for imaginary components
87 TArrayD fHisto; // Array containing the contents of the selected transformation histogram
88 TArrayD fWaveform; // (System response) waveform for Convolution, Correlation etc.
89 TString fNorm; // Parameter to invoke normalization in the convolution for correlation studies
90 Float_t fSample; // The actual data acquisition sampling frequency in Hz
91 Bool_t fKeepOutput; // Internal flag to enable preventing the resetting of the output data
92
93 // Internal member functions
94 void Reset(); // Reset all data and the FFTW processor for the various transformations
95 void HistogramFilterFFT(TArray* h,TH1* hisf,Bool_t dB,Bool_t kernel,TH1* hist=0); // Provide filter kernel or result histograms
96 void HistogramTrafoResult(TString name,Int_t mode,TH1* hist,TString sel); // Provide a histogram of the requested transformation result
97
98 ClassDef(NcDSP,11) // Various Digital Signal Processing (DSP) operations for (sequential) data samples
99};
100#endif
void LoadResult()
Definition NcDSP.cxx:691
Int_t GetN(Int_t mode=0) const
Definition NcDSP.cxx:1008
TArrayD FilterMultiBand(TArray &freqs, Int_t n, TH1 *hisf=0, Bool_t dB=kTRUE, TH1 *hist=0, Int_t *i1=0, Int_t *i2=0, Bool_t adaptn=kTRUE)
Definition NcDSP.cxx:4533
void SetSamplingFrequency(Float_t f)
Definition NcDSP.cxx:370
TArrayD FilterLowPass(Double_t fcut, Int_t n, TH1 *hisf=0, Bool_t dB=kTRUE, TH1 *hist=0, Int_t *i1=0, Int_t *i2=0, Bool_t adaptn=kTRUE)
Definition NcDSP.cxx:3946
TArrayD fImIn
Definition NcDSP.h:84
TArrayD Convolve(TH1 *hist=0, Int_t *i1=0, Int_t *i2=0, Int_t shift=0)
Definition NcDSP.cxx:2126
TGraph Periodogram(TString tu, Double_t Tmin, Double_t Tmax, Int_t n, TArray &t, TArray &y, TArray *dy=0, TF1 *Z=0, NcDevice *results=0) const
Definition NcDSP.cxx:5552
TArrayD GetMultiBandKernel(TArray &freqs, Int_t n, TH1 *hisf=0, Bool_t dB=kTRUE, TH1 *hist=0, Bool_t adaptn=kTRUE)
Definition NcDSP.cxx:5278
void HistogramTrafoResult(TString name, Int_t mode, TH1 *hist, TString sel)
Definition NcDSP.cxx:1768
TArrayD fWaveform
Definition NcDSP.h:88
void Hilbert(Int_t mode, TH1 *hist=0, TString sel="none")
Definition NcDSP.cxx:1568
Float_t fSample
Definition NcDSP.h:90
void Fourier(TString mode, TH1 *hist=0, TString sel="none")
Definition NcDSP.cxx:1092
void SetWaveform(Int_t n, Double_t *h, Float_t f=-1)
Definition NcDSP.cxx:716
TArrayD FilterHighPass(Double_t fcut, Int_t n, TH1 *hisf=0, Bool_t dB=kTRUE, TH1 *hist=0, Int_t *i1=0, Int_t *i2=0, Bool_t adaptn=kTRUE)
Definition NcDSP.cxx:4091
TArrayD GetBandRejectKernel(Double_t f1, Double_t f2, Int_t n, TH1 *hisf=0, Bool_t dB=kTRUE, TH1 *hist=0, Bool_t adaptn=kTRUE)
Definition NcDSP.cxx:5153
TArrayD fHisto
Definition NcDSP.h:87
TArrayD fImOut
Definition NcDSP.h:86
Int_t fN
Definition NcDSP.h:81
NcDSP(const char *name="", const char *title="")
Definition NcDSP.cxx:293
void Cosine(Int_t type, TH1 *hist=0, TString sel="none")
Definition NcDSP.cxx:1334
TArrayL64 ADC(Int_t nbits, Double_t range, Double_t Vbias=0, TArray *Vsig=0, TH1 *hist=0, Int_t B=0, Int_t C=3) const
Definition NcDSP.cxx:2798
TString fNorm
Definition NcDSP.h:89
TArrayD GetHighPassKernel(Double_t fcut, Int_t n, TH1 *hisf=0, Bool_t dB=kTRUE, TH1 *hist=0, Bool_t adaptn=kTRUE)
Definition NcDSP.cxx:4911
TArrayD FilterMovingAverage(Int_t n, TString mode, TH1 *hist=0, Int_t *i1=0, Int_t *i2=0, TH1 *hisf=0, Bool_t dB=kTRUE)
Definition NcDSP.cxx:3698
void Hartley(Int_t mode, TH1 *hist=0, TString sel="none")
Definition NcDSP.cxx:1240
TArrayD GetData(TString mode) const
Definition NcDSP.cxx:1028
TArrayD Digitize(Int_t nbits, Double_t vcal, Int_t mode, TH1 *hist=0, Double_t *stp=0, Double_t *scale=0) const
Definition NcDSP.cxx:2577
TArrayD fReOut
Definition NcDSP.h:85
TArrayD FilterBandReject(Double_t f1, Double_t f2, Int_t n, TH1 *hisf=0, Bool_t dB=kTRUE, TH1 *hist=0, Int_t *i1=0, Int_t *i2=0, Bool_t adaptn=kTRUE)
Definition NcDSP.cxx:4385
void HistogramFilterFFT(TArray *h, TH1 *hisf, Bool_t dB, Bool_t kernel, TH1 *hist=0)
Definition NcDSP.cxx:5420
TArrayD DAC(Int_t nbits, Double_t range, Double_t Vbias=0, TArray *adcs=0, TArray *peds=0, TH1 *hist=0, Int_t B=0, Int_t C=3) const
Definition NcDSP.cxx:3025
virtual ~NcDSP()
Definition NcDSP.cxx:307
TArrayD GetLowPassKernel(Double_t fcut, Int_t n, TH1 *hisf=0, Bool_t dB=kTRUE, TH1 *hist=0, Bool_t adaptn=kTRUE)
Definition NcDSP.cxx:4776
TVirtualFFT * fProc
Definition NcDSP.h:80
TArrayD GetMovingAverageKernel(Int_t n, TH1 *hisf=0, Bool_t dB=kTRUE, TH1 *hist=0)
Definition NcDSP.cxx:4688
TArrayD SampleAndHold(TF1 f, Double_t step, Double_t vmin, Double_t vmax, TH1 *hist=0, Int_t loc=-1) const
Definition NcDSP.cxx:3357
virtual TObject * Clone(const char *name="") const
Definition NcDSP.cxx:6194
Float_t GetSamplingFrequency() const
Definition NcDSP.cxx:384
Int_t fNwf
Definition NcDSP.h:82
TArrayD fReIn
Definition NcDSP.h:83
TArrayD Correlate(TH1 *hist=0, Int_t *i1=0, Int_t *i2=0, Double_t *peak=0, TString norm="NONE")
Definition NcDSP.cxx:2402
TArrayD SampleAndSum(TF1 f, Double_t step, Double_t vmin, Double_t vmax, TH1 *hist=0) const
Definition NcDSP.cxx:3534
void Sine(Int_t type, TH1 *hist=0, TString sel="none")
Definition NcDSP.cxx:1452
Bool_t fKeepOutput
Definition NcDSP.h:91
void Load(Int_t n, Double_t *re, Double_t *im=0, Float_t f=-1)
Definition NcDSP.cxx:395
TArrayD FilterBandPass(Double_t f1, Double_t f2, Int_t n, TH1 *hisf=0, Bool_t dB=kTRUE, TH1 *hist=0, Int_t *i1=0, Int_t *i2=0, Bool_t adaptn=kTRUE)
Definition NcDSP.cxx:4236
TArrayD GetBandPassKernel(Double_t f1, Double_t f2, Int_t n, TH1 *hisf=0, Bool_t dB=kTRUE, TH1 *hist=0, Bool_t adaptn=kTRUE)
Definition NcDSP.cxx:5030
void Reset()
Definition NcDSP.cxx:344
TArrayD Transmit(Int_t nbits, Double_t range, Double_t Vbias=0, TArray *Vsig=0, TArray *peds=0, TH1 *hist=0, Int_t B=0, Int_t C=3) const
Definition NcDSP.cxx:3265
Signal (Hit) handling of a generic device.
Definition NcDevice.h:14
Sampling and statistics tools for various multi-dimensional data samples.
Definition NcSample.h:28