ROOT FFTW Wrapper
|
#include <SineSubtract.h>
Public Types | |
enum | PowerSpectrumEstimator { FFT, LOMBSCARGLE } |
enum | FFT_Params { FFT_NPAD, FFT_NPARAMS } |
enum | LOMBSCARGLE_Params { LS_OVERSAMPLE_FACTOR, LS_NPARAMS } |
enum | PeakFindingOption { GLOBALMAX, NEIGHBORFACTOR, TSPECTRUM, SAVGOLSUB } |
enum | NEIGHBORFACTOR_Params { NF_NEIGHBOR_FACTOR, NF_NPARAMS } |
enum | TSPECTRUM_Params { TS_SIGMA, TS_THRESHOLD, TS_NDECONV_ITERATIONS, TS_AVERAGE_WINDOW, TS_NPARAMS } |
enum | SAVGOLSUB_Params { SGS_ORDER, SGS_WIDTH, SGS_NPARAMS } |
enum | EnvelopeOption { ENV_NONE, ENV_HILBERT, ENV_RMS, ENV_PEAK } |
enum | ENV_HILBERT_Params { ENV_HILBERT_FIT_ORDER, ENV_HILBERT_NPARAMS } |
enum | ENV_RMS_Params { ENV_RMS_FIT_ORDER, ENV_RMS_WINDOW, ENV_RMS_NPARAMS } |
enum | ENV_PEAK_Params { ENV_PEAK_FIT_ORDER, ENV_PEAK_MINDISTANCE, ENV_PEAK_NPARAMS } |
Public Member Functions | |
SineSubtract (int max_iter_without_reduction=3, double min_power_reduction=0.05, bool store=false) | |
SineSubtract (const TGraph *freq_dependent_min_power_reduction, int max_iter_without_reduction=3, bool store=false) | |
virtual | ~SineSubtract () |
TGraph * | subtractCW (const TGraph *g, double dt, const SineSubtractResult *result=NULL) |
void | subtractCW (int ng, TGraph **g, double dt, const double *w=0, const SineSubtractResult *result=NULL) |
void | setFreqLimits (double min, double max) |
void | setFreqLimits (int nbands, const double *min, const double *max) |
void | unsetFreqLimits () |
void | setVerbose (bool v) |
void | setTraceLimits (int min, int max) |
void | setNFailsExponent (double exp=0.5) |
void | setPowerSpectrumEstimator (PowerSpectrumEstimator estimator, const double *params=0) |
void | setPeakFindingOption (PeakFindingOption peak, const double *params=0) |
void | setEnvelopeOption (EnvelopeOption env, const double *params=0) |
const std::vector< double > * | getPowerSequence () const |
const std::vector< std::vector< TGraph * > > * | getStoredGraphs () const |
const std::vector< TGraph * > * | getStoredSpectra () const |
size_t | nStoredGraphsInChannel () const |
size_t | nChannels () const |
TGraph * | storedGraph (int i, int c) |
TGraph * | storedEnvelope (int i, int c) |
size_t | nStoredSpectra () const |
TGraph * | storedSpectra (int i) |
int | getNSines () const |
int | getNGraphs () const |
const double * | getPhases (int g) const |
const double * | getFreqs () const |
const double * | getAmps (int g) const |
const double * | getPhaseErrs (int g) const |
const double * | getFreqErrs () const |
const double * | getAmpErrs (int g) const |
const SineSubtractResult * | getResult () const |
void | setMaxIterationsWithoutReduction (int max) |
void | setAbsoluteMaxIterations (int max) |
void | setMaxSuccessfulIterations (int max) |
void | setMinPowerReduction (double min) |
void | setMinPowerReduction (const TGraph *g) |
void | setStore (bool s) |
void | setFitterLimitOptions (const SineFitterLimits *lims) |
void | makePlots (TCanvas *cpower=0, TCanvas *cspectra=0, int ncols=4) const |
void | makeSlides (const char *title="SineSubtract", const char *prefix="sinsub", const char *outdir=".", const char *format="png", bool standalone=true) const |
SineFitter * | sineFitter () |
The SineSubtract class handles the number of iterations and initialization of the fitter.
These are the algorithms for finding the peak of the power spectrum.
These are the algorithms for estimating the power spectrum, used to help estimate the starting parameters.
FFTtools::SineSubtract::SineSubtract | ( | int | max_iter_without_reduction = 3 , |
double | min_power_reduction = 0.05 , |
||
bool | store = false |
||
) |
Create a new SineSubtract. A few options may be set here, although they can all be changed by setters later too (and there are other options that can only be set by setters.
max_iter_without_reduction | Set the maximum number of failed iterations before giving up. An iteration fails if the subtraction does not produce the required power reduction. |
min_power_reduction | Set the minimum power reduction necessary to keep an iteration. Default is 5 percent. |
store | If true, intermediate steps will be saved. This incurs some overhead, so is mostly useful for making pretty plots and diagnostics. |
FFTtools::SineSubtract::SineSubtract | ( | const TGraph * | freq_dependent_min_power_reduction, |
int | max_iter_without_reduction = 3 , |
||
bool | store = false |
||
) |
Create a new SineSubtract. A few options may be set here, although they can all be changed by setters later too (and there are other options that can only be set by setters.
freq_dependent_min_power_reductionmin_power_reduction | Set the minimum power reduction necessary to keep an iteration, varying with frequency (freq in GHz). |
max_iter_without_reduction | Set the maximum number of failed iterations before giving up. An iteration fails if the subtraction does not produce the required power reduction. |
store | If true, intermediate steps will be saved. This incurs some overhead, so is mostly useful for making pretty plots and diagnostics. |
|
virtual |
Deallocate everything
|
inline |
Get array of fit amplitude errors for the ith trace
|
inline |
Get array of fit amplitudes for the ith trace
|
inline |
Get array of fit frequnecy errors
|
inline |
Get array of fit frequencies
int FFTtools::SineSubtract::getNSines | ( | ) | const |
Return the number of sines fit
|
inline |
Get array of fit phase errors for the ith trace
|
inline |
Get array of fit phases for the ith trace
|
inline |
Returns a pointer to a vector of the sequence of powers vs. iteration
|
inline |
Get a pointer to the SineSubtract result
|
inline |
If storage of graphs is enabled, returns a pointer to a nested vector of stored graphs
|
inline |
If storage of graphs is enabled, returns a pointer to a nested vector of stored power spectra
void FFTtools::SineSubtract::makePlots | ( | TCanvas * | cpower = 0 , |
TCanvas * | cspectra = 0 , |
||
int | ncols = 4 |
||
) | const |
Generate plots of traces and spectra.
cpower | Pointer to canvas to put traces + fits on. If NULL, new one is created. |
cspectra | Pointer to canvas to put spectra on. If NULL, new one is created. |
ncols | The number of columns per canvas |
void FFTtools::SineSubtract::makeSlides | ( | const char * | title = "SineSubtract" , |
const char * | prefix = "sinsub" , |
||
const char * | outdir = "." , |
||
const char * | format = "png" , |
||
bool | standalone = true |
||
) | const |
Make Beamer slides showing all iterations, for those moments when you desperately need slides to show.
title | Used in the frame title |
prefix | Used for naming files (e.g. sinsub will produce sinsub_0, sinsub_1, etc ) |
outdir | Output directory |
format | The format of the plots (e.g. png, pdf) |
standalone | If true, makes a self contained presentation, otherwise, can be copied and pasted in. |
|
inline |
If storage of graphs is enabled, returns the number of channels stored (the number of traces that are being simultaneously fit for. Will be 0 if storage disabled.
|
inline |
If storage of graphs is enabled, returns the number of stored graphs per channel (basically the number of iterations+1). Will be 0 if storage disabled.
|
inline |
If storage of graphs is enabled, returns the number of stored spectra. (Basically the number of iterations+1). Will be 0 if storage disabled.
|
inline |
Sets the maximum absolute number of iterations, even if power reduction is still happening. If max <= 0, there is no max
void FFTtools::SineSubtract::setEnvelopeOption | ( | EnvelopeOption | env, |
const double * | params = 0 |
||
) |
Set the envelope option used to estimate an envelope to modify the sinusoids. See EnvelopeOption for possibilities. params depends on the particular envelope option you want (or pass 0 for defaults).
|
inline |
Makes the fitter use this SineFitterLimits
|
inline |
Set limits on the frequencies to try to subtract. If the units of the graph are in ns, the frequencies should be in GHz.
min | The minimum frequency to try to remove |
max | The maximum frequency to try to remove |
|
inline |
Set multiple allowed bands of frequencies to try to subtract. If the units of the graph are in ns, the frequencies should be in GHz.
nbands | The number of frequency bands |
min | Array of minima of each band |
max | Array of maxima of each band |
|
inline |
Sets the maximum number of successful iterations, useful if you're trying to subtract a particular sinusoid. If max <=0, there is no max
|
inline |
Set the threshold for considering an iteration successful. This is a percentage of power reduction.
|
inline |
Each time an iteration fails, the power spectrum bin is weighted by 1./(1+nfails)^exp to discourage further usage
void FFTtools::SineSubtract::setPeakFindingOption | ( | PeakFindingOption | peak, |
const double * | params = 0 |
||
) |
Set the peak finding option used to seed the sinusoid fitter. See PeakFindingOption for possibilities. params depends on the particular peak finder you want (or pass 0 for defaults).
void FFTtools::SineSubtract::setPowerSpectrumEstimator | ( | PowerSpectrumEstimator | estimator, |
const double * | params = 0 |
||
) |
Set the power spectrum estimator used to initialize the SineSubtractFilter. See documentation for PowerSpectrumEstimator for what the types mean (or pass 0 to use the defaults).
|
inline |
Togggle storage of intermediate traces
|
inline |
In some cases, it may make sense to use only part of the trace for subtraction. For example, one may want to avoid using the part near the trigger to avoid subtracting off a pulse. If trace limits are enabled, only the portion of the trace within limits is used for estimating the spectrum and finding sinusoids that reduce the power, however, once those sinusoids are found, the entire trace has them subtracted.
While in principle, these could be different for each each waveform when subtracting multiple, right now they are all the same.
min | The minimum sample of the trace to use |
max | The maximum sample of the trace to use |
|
inline |
Toggle voluminous verbosity. It is a well-known fact that additional lines of text scrolling with great alacrity on your terminal have myriad benefits that this comment is far too brief to expound.
|
inline |
Returns the ith graph in the cth trace
|
inline |
Returns the power spectra of the ith iteration
void FFTtools::SineSubtract::subtractCW | ( | int | ng, |
TGraph ** | g, | ||
double | dt, | ||
const double * | w = 0 , |
||
const SineSubtractResult * | result = NULL |
||
) |
Subtract CW from one or more traces. Sine Subtraction can handle both evenly-spaced and unevenly-spaced waveforms. For evenly spaced waveforms, you should pass dt<-0, otherwise you should pass the nominal average. Right now, all graphs are assumed to have the same sampling, although this limitation could be removed with some work.
The input graphs are touched, you should make a copy if you want to preserve the originals.
ng | the number of graphs |
g | The graphs. Will be modified. |
dt | The nominal sample rate for uneven waveforms. If <=0, then the graphs are assumed to be even and dt is computed from first time step. |
w | Scales for the input values. If the y-axis have different scales (different gains or units) you should pass an array here. If 0, everything is equally-weighted. |
We need padded copies of traces if they don't all have the same length so that the spectrum has the same bins (or if we want to pad for extra resolution)
|
inline |
Clear all frequency limits