LALPulsar  6.1.0.1-b72065a
TransientCW_utils.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Reinhard Prix
3  * Copyright (C) 2017-2020 David Keitel
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with with program; see the file COPYING. If not, write to the
17  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18  * MA 02110-1301 USA
19  */
20 
21 #ifndef _TRANSIENTCW_UTILS_H
22 #define _TRANSIENTCW_UTILS_H
23 
24 /* C++ protection. */
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 /* ---------- System includes ---------- */
30 /* gsl-includes */
31 #include <gsl/gsl_vector.h>
32 #include <gsl/gsl_matrix.h>
33 
34 /* LAL-includes */
35 #include <lal/AVFactories.h>
36 #include <lal/LogPrintf.h>
37 #include <lal/SFTfileIO.h>
38 #include <lal/PulsarDataTypes.h>
39 #include <lal/ComputeFstat.h>
40 #include <lal/SinCosLUT.h> /* for XLALFastNegExp() */
41 #include <lal/FileIO.h>
42 #include <lal/ProbabilityDensity.h>
43 
44 ///
45 /// \defgroup TransientCW_utils_h Header TransientCW_utils.h
46 /// \ingroup lalpulsar_coh
47 /// \authors Reinhard Prix, David Keitel
48 ///
49 /// \brief Some helper functions useful for "transient CWs",
50 /// mostly applying transient window functions.
51 ///
52 /// The approach is described by Prix, Giampanis & Messenger
53 /// in https://arxiv.org/abs/1104.1704
54 
55 /// @{
56 
57 /* ---------- exported API defines ---------- */
58 
59 /**
60  * standard 24h day = 86400 seconds
61  * ==> this is what's used in the definition of 'tauDays'
62  */
63 #define DAY24 (24 * 3600)
64 
65 /**
66  * e-folding parameter for exponential window,
67  * after which we truncate the window for efficiency.
68  * 3 e-foldings means we lose only about e^(-2x3) ~1e-8 of signal power!
69  */
70 #define TRANSIENT_EXP_EFOLDING 3.0
71 
72 /* ---------- exported API types ---------- */
73 
74 /** Struct defining a range of transient windows */
75 typedef struct tagtransientWindowRange_t {
76  transientWindowType_t type; /**< window-type: none, rectangular, exponential, .... */
77  UINT4 t0; /**< earliest GPS start-time 't0' in seconds */
78  UINT4 t0Band; /**< range of start-times 't0' to search, in seconds */
79  UINT4 dt0; /**< stepsize to search t0-range with, in seconds */
80  UINT4 tau; /**< shortest transient timescale tau in seconds */
81  UINT4 tauBand; /**< range of transient timescales tau to search, in seconds */
82  UINT4 dtau; /**< stepsize to search tau-range with, in seconds */
84 
85 /**
86  * Struct holding a transient-window "F-statistic map" over start-time and timescale {t0, tau}.
87  * This contains a 2D matrix F_mn, with m = index over start-times t0, and n = index over timescales tau,
88  * in steps of dt0 in [t0, t0+t0Band], and dtau in [tau, tau+tauBand] as defined in transientWindowRange.
89  *
90  */
91 typedef struct tagtransientFstatMap_t {
92  gsl_matrix *F_mn; /**< "payload" F-map: F_mn for t0_m = t0 + m*dt0, and tau_n = tau + n*dtau */
93  REAL8 maxF; /**< maximal F-value obtained over transientWindowRange */
94  UINT4 t0_ML; /**< maximum-likelihood estimator for start-time t0 of max{2F} over transientWindowRange (in GPS seconds) */
95  UINT4 tau_ML; /**< maximum-likelihood estimator for duration Tcoh of max{2F} over the transientWindowRange (in seconds) */
97 
98 
99 /** Struct holding a transient CW candidate */
100 typedef struct tagtransientCandidate_t {
101  PulsarDopplerParams doppler; /**< Doppler params of this 'candidate' */
102  transientWindowRange_t windowRange; /**< type and parameters specifying the transient window range in {t0, tau} covered */
103  transientFstatMap_t *FstatMap; /**< F-statistic over transient-window range {t0, tau} AND ML-estimators { Fmax, t0_Fmax, tau_Fmax } */
104  REAL8 logBstat; /**< log of Bayes-factor, marginalized over transientWindowRange */
105  REAL8 t0_MP; /**< maximum-posterior estimate for t0 */
106  REAL8 tau_MP; /**< maximum-posterior estimate for tau */
108 
109 /* ---------- exported API prototypes ---------- */
110 int XLALParseTransientWindowName( const char *windowName );
111 
112 int XLALGetTransientWindowTimespan( UINT4 *t0, UINT4 *t1, transientWindow_t transientWindow );
113 
114 int XLALApplyTransientWindow( REAL4TimeSeries *series, transientWindow_t TransientWindowParams );
115 
118  transientWindow_t TransientWindowParams );
119 
120 int write_transientCandidate_to_fp( LALFILE *fp, const transientCandidate_t *thisTransCand, const char timeUnit );
121 
122 int write_transientFstatMap_to_fp( LALFILE *fp, const transientFstatMap_t *FstatMap, const transientWindowRange_t *windowRange, const PulsarDopplerParams *doppler );
123 
124 int write_transientCandidateAll_to_fp( LALFILE *fp, const transientCandidate_t *thisTransCand );
125 
126 
128  transientWindowRange_t windowRange,
129  BOOLEAN useFReg );
130 
132 pdf1D_t *XLALComputeTransientPosterior_t0( transientWindowRange_t windowRange, const transientFstatMap_t *FstatMap );
133 pdf1D_t *XLALComputeTransientPosterior_tau( transientWindowRange_t windowRange, const transientFstatMap_t *FstatMap );
134 
135 
138 
140 void XLALDestroyExpLUT( void );
141 
142 /* ---------- Fstat-atoms related functions ----------*/
143 int write_MultiFstatAtoms_to_fp( LALFILE *fp, const MultiFstatAtomVector *multiAtoms );
145 
147 
148 
149 /* ---------- INLINE function definitions ---------- */
150 
151 /**
152  * Function to compute the value of a rectangular transient-window at a given timestamp.
153  * This is the central function defining the rectangular window properties.
154  */
155 static inline REAL8
156 XLALGetRectangularTransientWindowValue( UINT4 timestamp, /**< timestamp for which to compute window-value */
157  UINT4 t0, /**< start-time of rectangular window */
158  UINT4 t1 /**< end-time of rectangular window */
159  )
160 {
161  if ( timestamp < t0 || timestamp > t1 ) {
162  return 0.0;
163  } else {
164  return 1.0;
165  }
166 
167 } /* XLALGetRectangularTransientWindowValue() */
168 
169 /**
170  * Function to compute the value of an exponential transient-window at a given timestamp.
171  *
172  * This is the central function defining the exponential window properties.
173  */
174 static inline REAL8
175 XLALGetExponentialTransientWindowValue( UINT4 timestamp, /**< timestamp for which to compute window-value */
176  UINT4 t0, /**< start-time of exponential window */
177  UINT4 t1, /**< end-time of exponential window */
178  UINT4 tau /**< characteristic time of the exponential window */
179  )
180 {
181  REAL8 ret;
182 
183  if ( timestamp < t0 || timestamp > t1 ) {
184  ret = 0.0;
185  } else {
186  REAL8 x = 1.0 * ( timestamp - t0 ) / tau;
187  ret = XLALFastNegExp( x ); // computes e^(-x)
188  }
189 
190  return ret;
191 
192 } /* XLALGetExponentialTransientWindowValue() */
193 
194 /**
195  * Function to compute the value of a given transient-window function at a given timestamp.
196  *
197  * This is a simple wrapper to the actual window-defining functions
198  */
199 static inline REAL8
200 XLALGetTransientWindowValue( UINT4 timestamp, /**< timestamp for which to compute window-value */
201  UINT4 t0, /**< start-time of window */
202  UINT4 t1, /**< end-time of window */
203  UINT4 tau, /**< characteristic time of window */
204  transientWindowType_t type /**< window type */
205  )
206 {
207  REAL8 val;
208 
209  switch ( type ) {
210  case TRANSIENT_NONE:
211  val = 1.0;
212  break;
213 
215  val = XLALGetRectangularTransientWindowValue( timestamp, t0, t1 );
216  break;
217 
219  val = XLALGetExponentialTransientWindowValue( timestamp, t0, t1, tau );
220  break;
221 
222  default:
223  XLALPrintError( "invalid transient window type %d not in [%d, %d].\n",
225  return -1; /* cop out because we're in an inline function */
226 
227  } /* switch window-type */
228 
229  /* return result */
230  return val;
231 
232 } /* XLALGetTransientWindowValue() */
233 
234 /// @}
235 
236 
237 #ifdef __cplusplus
238 }
239 #endif
240 /* C++ protection. */
241 
242 #endif /* Double-include protection. */
unsigned char BOOLEAN
double REAL8
char CHAR
uint32_t UINT4
transientWindowType_t
Struct to define parameters of a 'transient window' to be applied to obtain transient signals.
@ TRANSIENT_RECTANGULAR
standard rectangular window covering [t0, t0+tau]
@ TRANSIENT_LAST
@ TRANSIENT_NONE
Note: in this case the window-parameters will be ignored, and treated as rect={data},...
@ TRANSIENT_EXPONENTIAL
exponentially decaying window e^{-t0/tau} starting at t0.
transientFstatMap_t * XLALComputeTransientFstatMap(const MultiFstatAtomVector *multiFstatAtoms, transientWindowRange_t windowRange, BOOLEAN useFReg)
Function to compute transient-window "F-statistic map" over start-time and timescale {t0,...
void XLALDestroyTransientFstatMap(transientFstatMap_t *FstatMap)
Standard destructor for transientFstatMap_t Fully NULL-robust as usual.
int XLALParseTransientWindowName(const char *windowName)
Parse a transient window name string into the corresponding transientWindowType.
int XLALApplyTransientWindow2NoiseWeights(MultiNoiseWeights *multiNoiseWeights, const MultiLIGOTimeGPSVector *multiTS, transientWindow_t transientWindow)
apply transient window to give multi noise-weights, associated with given multi timestamps
int write_transientCandidate_to_fp(LALFILE *fp, const transientCandidate_t *thisCand, const char timeUnit)
Write one line for given transient CW candidate into output file.
int XLALGetTransientWindowTimespan(UINT4 *t0, UINT4 *t1, transientWindow_t transientWindow)
Helper-function to determine the total timespan of a transient CW window, ie.
FstatAtomVector * XLALmergeMultiFstatAtomsBinned(const MultiFstatAtomVector *multiAtoms, UINT4 deltaT)
Combine N Fstat-atoms vectors into a single 'canonical' binned and ordered atoms-vector.
void XLALDestroyExpLUT(void)
Destructor function for expLUT_t lookup table.
REAL8 XLALFastNegExp(REAL8 mx)
Fast exponential function e^-x using lookup-table (LUT).
int write_MultiFstatAtoms_to_fp(LALFILE *fp, const MultiFstatAtomVector *multiAtoms)
Write multi-IFO F-stat atoms 'multiAtoms' into output stream 'fstat'.
CHAR * XLALPulsarDopplerParams2String(const PulsarDopplerParams *par)
Turn pulsar doppler-params into a single string that can be used for filenames The format is tRefNNNN...
int write_transientCandidateAll_to_fp(LALFILE *fp, const transientCandidate_t *thisCand)
Write full set of t0 and tau grid points for given transient CW candidate into output file.
static REAL8 XLALGetTransientWindowValue(UINT4 timestamp, UINT4 t0, UINT4 t1, UINT4 tau, transientWindowType_t type)
Function to compute the value of a given transient-window function at a given timestamp.
int XLALApplyTransientWindow(REAL4TimeSeries *series, transientWindow_t transientWindow)
apply a "transient CW window" described by TransientWindowParams to the given timeseries
pdf1D_t * XLALComputeTransientPosterior_t0(transientWindowRange_t windowRange, const transientFstatMap_t *FstatMap)
Compute transient-CW posterior (normalized) on start-time t0, using given type and parameters of tran...
static REAL8 XLALGetExponentialTransientWindowValue(UINT4 timestamp, UINT4 t0, UINT4 t1, UINT4 tau)
Function to compute the value of an exponential transient-window at a given timestamp.
static REAL8 XLALGetRectangularTransientWindowValue(UINT4 timestamp, UINT4 t0, UINT4 t1)
Function to compute the value of a rectangular transient-window at a given timestamp.
pdf1D_t * XLALComputeTransientPosterior_tau(transientWindowRange_t windowRange, const transientFstatMap_t *FstatMap)
Compute transient-CW posterior (normalized) on timescale tau, using given type and parameters of tran...
REAL8 XLALComputeTransientBstat(transientWindowRange_t windowRange, const transientFstatMap_t *FstatMap)
Compute transient-CW Bayes-factor B_SG = P(x|HypS)/P(x|HypG) (where HypG = Gaussian noise hypothesis)...
void XLALDestroyTransientCandidate(transientCandidate_t *cand)
Standard destructor for transientCandidate_t Fully NULL-robust as usual.
int write_transientFstatMap_to_fp(LALFILE *fp, const transientFstatMap_t *FstatMap, const transientWindowRange_t *windowRange, const PulsarDopplerParams *doppler)
Write full set of t0 and tau grid points (assumed at fixed Doppler parameters) into output file.
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
double t0
A vector of -statistic 'atoms', i.e.
Definition: ComputeFstat.h:174
A multi-detector vector of FstatAtomVector.
Definition: ComputeFstat.h:186
A collection of (multi-IFO) LIGOTimeGPSVector time-stamps vectors.
Definition: SFTfileIO.h:198
One noise-weight (number) per SFT (therefore indexed over IFOs and SFTs.
Definition: PSDutils.h:71
Type containing the 'Doppler-parameters' affecting the time-evolution of the phase.
Struct holding a transient CW candidate.
transientFstatMap_t * FstatMap
F-statistic over transient-window range {t0, tau} AND ML-estimators { Fmax, t0_Fmax,...
REAL8 t0_MP
maximum-posterior estimate for t0
PulsarDopplerParams doppler
Doppler params of this 'candidate'.
REAL8 tau_MP
maximum-posterior estimate for tau
REAL8 logBstat
log of Bayes-factor, marginalized over transientWindowRange
transientWindowRange_t windowRange
type and parameters specifying the transient window range in {t0, tau} covered
Struct holding a transient-window "F-statistic map" over start-time and timescale {t0,...
gsl_matrix * F_mn
"payload" F-map: F_mn for t0_m = t0 + m*dt0, and tau_n = tau + n*dtau
UINT4 tau_ML
maximum-likelihood estimator for duration Tcoh of max{2F} over the transientWindowRange (in seconds)
UINT4 t0_ML
maximum-likelihood estimator for start-time t0 of max{2F} over transientWindowRange (in GPS seconds)
REAL8 maxF
maximal F-value obtained over transientWindowRange
Struct defining one transient window instance.
Struct defining a range of transient windows.
UINT4 tauBand
range of transient timescales tau to search, in seconds
UINT4 dtau
stepsize to search tau-range with, in seconds
UINT4 tau
shortest transient timescale tau in seconds
UINT4 t0
earliest GPS start-time 't0' in seconds
UINT4 dt0
stepsize to search t0-range with, in seconds
transientWindowType_t type
window-type: none, rectangular, exponential, ....
UINT4 t0Band
range of start-times 't0' to search, in seconds