AnalysisWaveform.h
1 #ifndef ANALYSIS_WAVEFORM_HH
2 #define ANALYSIS_WAVEFORM_HH
3 
4 class FFTWComplex;
5 #include "TGraphAligned.h"
6 #include "Math/Interpolator.h"
7 #include "FFTWindow.h"
8 
48 {
49 
50 
51  public:
52 
54  static void enableDebug(bool enable);
55 
59  static void allowEvenToUnevenConversion(bool allow);
60 
63  {
64  AKIMA,
65  SPARSE_YEN,
66  REGULARIZED_SPARSE_YEN
67  };
68 
71  {
72  EVAL_LINEAR,
73  EVAL_AKIMA
74  };
75 
78 
81  {
82 
84  : max_distance(8), regularization_order(0), mu(1e-3) {; }
85 
86  int max_distance;
87  int regularization_order;
88  double mu;
89  };
90 
91 
94  {
95  public:
97  : method(FFT), window_size(64) { type = &FFTtools::GAUSSIAN_WINDOW; }
98 
99  enum method
100  {
101  FFT,
102  BARTLETT,
103  WELCH
104  } method;
105 
106 
107  int window_size;
108  const FFTtools::FFTWindowType *type;
109  };
110 
113 
114  /* Constructors */
115 
125  AnalysisWaveform(int Nt, const double * x, const double * y, double nominal_dt = 1./2.6, InterpolationType type = defaultInterpolationType, InterpolationOptions * opt = &defaultInterpolationOptions);
126 
128  AnalysisWaveform(int Nt, const double * y, double dt, double t0);
129 
131  static AnalysisWaveform * makeWf(const TGraph * g, bool even = true, AnalysisWaveform * replace = 0);
132 
133 
135  AnalysisWaveform(int Nt, const FFTWComplex * f, double df, double t0);
136 
138  AnalysisWaveform(int Nt = 260, double dt=1./2.6, double t0=0);
139 
141  AnalysisWaveform(const AnalysisWaveform & other);
142 
143  /* Computes the RMS, either in time or frequency domain to avoid an FFT*/
144  double getRMS() const;
145 
146  AnalysisWaveform & operator=(const AnalysisWaveform & other);
147 
148 
159  static AnalysisWaveform * correlation(const AnalysisWaveform * A, const AnalysisWaveform * B, int npadfreq = 0, double scale =1 , int window_normalize = 0);
160 
161  static AnalysisWaveform * convolution(const AnalysisWaveform * A, const AnalysisWaveform * B, int npadfreq = 0, double scale =1 );
162 
163  /* Enables or disables (check) and nagging on attemptoin correlation
164  * without zero padding. Useful if you actually want to do a circular
165  * correlation or if the check is too expensive for your tastes.
166  *
167  * Note that this only affects the current thread.
168  **/
169  static void setCorrelationNag(bool nag);
170 
171 
179  AnalysisWaveform * autoCorrelation(int npadtime =1, int npadfreq = 0, double scale = 1);
180 
182  bool checkIfPaddedInTime() const;
183 
184  virtual ~AnalysisWaveform();
185 
186  /* Constant accessors. If you coerce the compiler into allowing modification, coupled waveforms won't be updated */
187 
189  const TGraphAligned * uneven() const ;
190 
192  const TGraphAligned * even() const;
193 
195  const FFTWComplex * freq() const;
196 
198  const TGraphAligned * power() const;
199 
201  const TGraphAligned * powerdB() const;
202 
204  const TGraphAligned * phase() const;
205 
207  const TGraphAligned * groupDelay() const;
208 
210  const TGraphAligned * hilbertEnvelope() const;
211 
213  const AnalysisWaveform * hilbertTransform() const;
214 
216  int Nfreq() const;
217 
219  int Neven() const { return even()->GetN(); }
220 
222  int Nuneven() const { return uneven()->GetN(); }
223 
225  double deltaT() const { return dt ; }
226 
228  double deltaF() const { return df ; }
229 
233  void forceEvenSize(int size);
234 
235  // drawers since drawing is non-const (and we don't care about silly things like axes for constness)
236 
238  void drawEven(const char * opt = "", int color=-1) const;
239 
241  void drawHilbertEnvelope(const char * opt = "", int color=-1) const;
242 
244  void drawUneven(const char * opt = "", int color=-1) const;
245 
247  void drawPower(const char * opt = "", int color=-1) const;
248 
249 
251  void drawPowerdB(const char * opt = "", int color=-1) const;
252 
254  void drawPhase(const char * opt = "", int color=-1) const;
255 
257  double evalEven(double t, EvenEvaluationType = EVAL_LINEAR) const; //TODO: add additional evaluation methods other than linear interpolation. indeed, would be best to eval multiple points at same time
258 
260  void evalEven(int N, const double * __restrict t , double * __restrict v, EvenEvaluationType = EVAL_LINEAR) const;
261 
262 
264  FFTWComplex * updateFreq();
266  void updateFreq(int new_N, const FFTWComplex * new_freq, double new_df = 0) ;
267 
270 
272  void updateEven(const TGraph * replace_even);
273 
276 
278  void updateUneven(const TGraph * replace_uneven);
279 
280 
289  void padEven(int factor, int where = 1);
290 
292  void padFreq(int factor);
293 
294 
296  void padFreqAdd(int npad);
297 
298 
300  void setPowerCalculationOptions(PowerCalculationOptions & opt);
301 
302 
306  static void basisChange(AnalysisWaveform * __restrict hpol_or_lcp, AnalysisWaveform * __restrict vpol_or_rcp);
307 
310  static void sumDifference(AnalysisWaveform * __restrict a, AnalysisWaveform * __restrict b);
311 
312 
314  void zeroMeanEven();
315 
316  void setTitle(const char * title);
317  /* Sets the line and marker color */
318  void setColor(int c);
319  /* Sets the line width */
320  void setWidth(int w);
321 
322  /* Sets range user for x axis of frequency plots */
323  void setFreqDisplayRange(double low, double high);
324 
325  /* Sets range user for x axis of time plots */
326  void setTimeDisplayRange(double low, double high);
327 
328  private:
329  void calculateEvenFromUneven() const;
330  void calculateEvenFromFreq() const;
331  void calculateFreqFromEven() const;
332  void calculateUnevenFromEven() const;
333 
334  /* Storage vars */
335  mutable TGraphAligned g_uneven;
336  mutable TGraphAligned g_hilbert_envelope;
337  mutable TGraphAligned g_even;
338  mutable TGraphAligned g_power;
339  mutable TGraphAligned g_power_db;
340  mutable TGraphAligned g_phase;
341  mutable TGraphAligned g_group_delay;
342 
343 
344  mutable double dt;
345  mutable double df;
346  mutable int fft_len;
347  mutable FFTWComplex * fft;
348 
349  mutable ROOT::Math::Interpolator theEvenAkimaInterpolator;
350  const ROOT::Math::Interpolator * evenAkimaInterpolator() const;
351 
352  InterpolationType interpolation_type;
353  InterpolationOptions interpolation_options;
354  PowerCalculationOptions power_options;
355 
356  /* State vars */
357  mutable bool just_padded;
358  mutable bool must_update_uneven;
359  mutable bool must_update_freq;
360  mutable bool must_update_even;
361  mutable bool uneven_equals_even;
362  mutable bool power_dirty;
363  mutable bool power_db_dirty;
364  mutable bool phase_dirty;
365  mutable bool group_delay_dirty;
366  mutable bool hilbert_envelope_dirty;
367  mutable bool hilbert_dirty;
368  mutable bool even_akima_interpolator_dirty;
369  mutable AnalysisWaveform * hilbert_transform;
370  mutable int force_even_size;
371  unsigned uid;
372  void nameGraphs();
373 };
374 
375 
376 
377 #endif
double evalEven(double t, EvenEvaluationType=EVAL_LINEAR) const
const TGraphAligned * power() const
const AnalysisWaveform * hilbertTransform() const
void drawHilbertEnvelope(const char *opt="", int color=-1) const
void forceEvenSize(int size)
const TGraphAligned * powerdB() const
const TGraphAligned * phase() const
bool checkIfPaddedInTime() const
static AnalysisWaveform * makeWf(const TGraph *g, bool even=true, AnalysisWaveform *replace=0)
TGraphAligned * updateEven()
void drawPowerdB(const char *opt="", int color=-1) const
static void basisChange(AnalysisWaveform *__restrict hpol_or_lcp, AnalysisWaveform *__restrict vpol_or_rcp)
static void enableDebug(bool enable)
static InterpolationType defaultInterpolationType
const FFTWComplex * freq() const
const TGraphAligned * uneven() const
AnalysisWaveform(int Nt, const double *x, const double *y, double nominal_dt=1./2.6, InterpolationType type=defaultInterpolationType, InterpolationOptions *opt=&defaultInterpolationOptions)
void drawPower(const char *opt="", int color=-1) const
This is a wrapper class for a complex number.
Definition: FFTWComplex.h:12
void drawEven(const char *opt="", int color=-1) const
void padEven(int factor, int where=1)
void padFreq(int factor)
double deltaT() const
static InterpolationOptions defaultInterpolationOptions
const TGraphAligned * groupDelay() const
double deltaF() const
const TGraphAligned * hilbertEnvelope() const
static void allowEvenToUnevenConversion(bool allow)
TGraphAligned * updateUneven()
void drawPhase(const char *opt="", int color=-1) const
void setPowerCalculationOptions(PowerCalculationOptions &opt)
static void sumDifference(AnalysisWaveform *__restrict a, AnalysisWaveform *__restrict b)
static AnalysisWaveform * correlation(const AnalysisWaveform *A, const AnalysisWaveform *B, int npadfreq=0, double scale=1, int window_normalize=0)
const TGraphAligned * even() const
FFTWComplex * updateFreq()
void padFreqAdd(int npad)
This class is intended to be the main storage vessel for ANITA waveforms. It is similar in principle ...
AnalysisWaveform * autoCorrelation(int npadtime=1, int npadfreq=0, double scale=1)
void drawUneven(const char *opt="", int color=-1) const