Public Types | Public Member Functions | List of all members
FFTtools::SineSubtract Class Reference

#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)
 
double * subtractCW (int N, const double *y, double dt, double *y_out=NULL, 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 SineSubtractResultgetResult () 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
 
SineFittersineFitter ()
 

Detailed Description

The SineSubtract class handles the number of iterations and initialization of the fitter.

Definition at line 391 of file SineSubtract.h.

Member Enumeration Documentation

Enumerator
ENV_HILBERT 

No envelope is used.

Definition at line 584 of file SineSubtract.h.

The parameters for PowerSpectrumEstimator FFT

Enumerator
FFT_NPARAMS 

default =0

Definition at line 514 of file SineSubtract.h.

The parameters for PowerSpectrumEstimator LOMBSCARGLE

Enumerator
LS_NPARAMS 

default =2

Definition at line 521 of file SineSubtract.h.

Enumerator
NF_NPARAMS 

default = 0.15

Definition at line 553 of file SineSubtract.h.

These are the algorithms for finding the peak of the power spectrum.

Enumerator
NEIGHBORFACTOR 

Just uses the global maximum (you probably don't want this) . No params.

TSPECTRUM 

(default) requires being at least neighbor_factor bigger than one of the neighbors. See NEIGHBORFACTOR_Params for parametser

SAVGOLSUB 

Use TSpectrum (probably super slow). See TSPECTRUM_Params for parameters.

Subtract baseline computed with Savitzky Golay filter first. See SAVGOLSUB_Params for parameters.

Definition at line 544 of file SineSubtract.h.

These are the algorithms for estimating the power spectrum, used to help estimate the starting parameters.

Enumerator
LOMBSCARGLE 

(default) Compute power spectrum using magnigude of FFT, see FFT_Param enum for parameter names and defaults

Compute power spectrum using LombScargle Periodogram, see below for parameter names

Definition at line 506 of file SineSubtract.h.

Enumerator
SGS_WIDTH 

default = 3 (treated as int)

SGS_NPARAMS 

default = 5 , really halfwidth, (treated as int)

Definition at line 571 of file SineSubtract.h.

Enumerator
TS_THRESHOLD 

default = 2

TS_NDECONV_ITERATIONS 

default = 0.05

Definition at line 562 of file SineSubtract.h.

Constructor & Destructor Documentation

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.

Parameters
max_iter_without_reductionSet the maximum number of failed iterations before giving up. An iteration fails if the subtraction does not produce the required power reduction.
min_power_reductionSet the minimum power reduction necessary to keep an iteration. Default is 5 percent.
storeIf true, intermediate steps will be saved. This incurs some overhead, so is mostly useful for making pretty plots and diagnostics.

Definition at line 858 of file SineSubtract.cxx.

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.

Parameters
freq_dependent_min_power_reductionmin_power_reductionSet the minimum power reduction necessary to keep an iteration, varying with frequency (freq in GHz).
max_iter_without_reductionSet the maximum number of failed iterations before giving up. An iteration fails if the subtraction does not produce the required power reduction.
storeIf true, intermediate steps will be saved. This incurs some overhead, so is mostly useful for making pretty plots and diagnostics.

Definition at line 833 of file SineSubtract.cxx.

FFTtools::SineSubtract::~SineSubtract ( )
virtual

Deallocate everything

Definition at line 1536 of file SineSubtract.cxx.

Member Function Documentation

const double* FFTtools::SineSubtract::getAmpErrs ( int  g) const
inline

Get array of fit amplitude errors for the ith trace

Definition at line 666 of file SineSubtract.h.

const double* FFTtools::SineSubtract::getAmps ( int  g) const
inline

Get array of fit amplitudes for the ith trace

Definition at line 657 of file SineSubtract.h.

const double* FFTtools::SineSubtract::getFreqErrs ( ) const
inline

Get array of fit frequnecy errors

Definition at line 663 of file SineSubtract.h.

const double* FFTtools::SineSubtract::getFreqs ( ) const
inline

Get array of fit frequencies

Definition at line 654 of file SineSubtract.h.

int FFTtools::SineSubtract::getNSines ( ) const

Return the number of sines fit

Definition at line 1385 of file SineSubtract.cxx.

const double* FFTtools::SineSubtract::getPhaseErrs ( int  g) const
inline

Get array of fit phase errors for the ith trace

Definition at line 660 of file SineSubtract.h.

const double* FFTtools::SineSubtract::getPhases ( int  g) const
inline

Get array of fit phases for the ith trace

Definition at line 651 of file SineSubtract.h.

const std::vector<double>* FFTtools::SineSubtract::getPowerSequence ( ) const
inline

Returns a pointer to a vector of the sequence of powers vs. iteration

Definition at line 619 of file SineSubtract.h.

const SineSubtractResult* FFTtools::SineSubtract::getResult ( ) const
inline

Get a pointer to the SineSubtract result

Definition at line 669 of file SineSubtract.h.

const std::vector<std::vector<TGraph*> >* FFTtools::SineSubtract::getStoredGraphs ( ) const
inline

If storage of graphs is enabled, returns a pointer to a nested vector of stored graphs

Definition at line 622 of file SineSubtract.h.

const std::vector<TGraph*>* FFTtools::SineSubtract::getStoredSpectra ( ) const
inline

If storage of graphs is enabled, returns a pointer to a nested vector of stored power spectra

Definition at line 625 of file SineSubtract.h.

void FFTtools::SineSubtract::makePlots ( TCanvas *  cpower = 0,
TCanvas *  cspectra = 0,
int  ncols = 4 
) const

Generate plots of traces and spectra.

Parameters
cpowerPointer to canvas to put traces + fits on. If NULL, new one is created.
cspectraPointer to canvas to put spectra on. If NULL, new one is created.
ncolsThe number of columns per canvas

Definition at line 1500 of file SineSubtract.cxx.

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.

Parameters
titleUsed in the frame title
prefixUsed for naming files (e.g. sinsub will produce sinsub_0, sinsub_1, etc )
outdirOutput directory
formatThe format of the plots (e.g. png, pdf)
standaloneIf true, makes a self contained presentation, otherwise, can be copied and pasted in.

Definition at line 1390 of file SineSubtract.cxx.

size_t FFTtools::SineSubtract::nChannels ( ) const
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.

Definition at line 632 of file SineSubtract.h.

size_t FFTtools::SineSubtract::nStoredGraphsInChannel ( ) const
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.

Definition at line 629 of file SineSubtract.h.

size_t FFTtools::SineSubtract::nStoredSpectra ( ) const
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.

Definition at line 639 of file SineSubtract.h.

void FFTtools::SineSubtract::setAbsoluteMaxIterations ( int  max)
inline

Sets the maximum absolute number of iterations, even if power reduction is still happening. If max <= 0, there is no max

Definition at line 675 of file SineSubtract.h.

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).

Definition at line 1756 of file SineSubtract.cxx.

void FFTtools::SineSubtract::setFitterLimitOptions ( const SineFitterLimits lims)
inline

Makes the fitter use this SineFitterLimits

Definition at line 691 of file SineSubtract.h.

void FFTtools::SineSubtract::setFreqLimits ( double  min,
double  max 
)
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.

Parameters
minThe minimum frequency to try to remove
maxThe maximum frequency to try to remove

Definition at line 465 of file SineSubtract.h.

void FFTtools::SineSubtract::setFreqLimits ( int  nbands,
const double *  min,
const double *  max 
)
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.

Parameters
nbandsThe number of frequency bands
minArray of minima of each band
maxArray of maxima of each band

Definition at line 473 of file SineSubtract.h.

void FFTtools::SineSubtract::setMaxSuccessfulIterations ( int  max)
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

Definition at line 678 of file SineSubtract.h.

void FFTtools::SineSubtract::setMinPowerReduction ( double  min)
inline

Set the threshold for considering an iteration successful. This is a percentage of power reduction.

Definition at line 681 of file SineSubtract.h.

void FFTtools::SineSubtract::setNFailsExponent ( double  exp = 0.5)
inline

Each time an iteration fails, the power spectrum bin is weighted by 1./(1+nfails)^exp to discourage further usage

Definition at line 530 of file SineSubtract.h.

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).

Definition at line 1725 of file SineSubtract.cxx.

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).

Definition at line 1697 of file SineSubtract.cxx.

void FFTtools::SineSubtract::setStore ( bool  s)
inline

Togggle storage of intermediate traces

Definition at line 688 of file SineSubtract.h.

void FFTtools::SineSubtract::setTraceLimits ( int  min,
int  max 
)
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.

Parameters
minThe minimum sample of the trace to use
maxThe maximum sample of the trace to use

Definition at line 496 of file SineSubtract.h.

void FFTtools::SineSubtract::setVerbose ( bool  v)
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.

Definition at line 482 of file SineSubtract.h.

TGraph* FFTtools::SineSubtract::storedGraph ( int  i,
int  c 
)
inline

Returns the ith graph in the cth trace

Definition at line 635 of file SineSubtract.h.

TGraph* FFTtools::SineSubtract::storedSpectra ( int  i)
inline

Returns the power spectra of the ith iteration

Definition at line 642 of file SineSubtract.h.

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.

Parameters
ngthe number of graphs
gThe graphs. Will be modified.
dtThe nominal sample rate for uneven waveforms. If <=0, then the graphs are assumed to be even and dt is computed from first time step.
wScales 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)

Definition at line 959 of file SineSubtract.cxx.

void FFTtools::SineSubtract::unsetFreqLimits ( )
inline

Clear all frequency limits

Definition at line 476 of file SineSubtract.h.


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