LALSimulation  5.4.0.1-fe68b98
LALSimIMRPhenomTHM_internals.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Hector Estelles
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with with program; see the file COPYING. If not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17  * MA 02110-1301 USA
18  */
19 
20 
21 /**
22  * \author Hector Estelles
23  */
24 
25 #include <math.h>
26 
29 
30 /* LAL Header Files */
31 #include <lal/LALSimIMR.h>
32 #include <lal/LALConstants.h>
33 #include <lal/Date.h>
34 #include <lal/Units.h>
35 
36 /* GSL Header Files */
37 #include <gsl/gsl_linalg.h>
38 #include <gsl/gsl_complex.h>
39 #include <gsl/gsl_complex_math.h>
40 #include <gsl/gsl_roots.h>
41 
42 /* ************************************* */
43 /* ******* STRUCTS INITIALIZATION ****** */
44 /* ************************************* */
45 
46 /* Function for populating the IMRPhenomTWaveformStruct.
47  This will compute and store the needed parameters for evaluating the fits and phase/amplitude related quantities. */
48 
50  IMRPhenomTWaveformStruct *wf, /* Waveform struct */
51  const REAL8 m1_SI, /* Mass of companion 1 (kg) */
52  const REAL8 m2_SI, /* Mass of companion 2 (kg) */
53  const REAL8 chi1L_In, /* Dimensionless aligned spin of companion 1 */
54  const REAL8 chi2L_In, /* Dimensionless aligned spin of companion 2 */
55  const REAL8 distance, /* Luminosity distance (m) */
56  const REAL8 deltaT, /* sampling interval (s) */
57  const REAL8 fmin, /* starting GW frequency (Hz) */
58  const REAL8 fRef, /* reference GW frequency (Hz) */
59  const REAL8 phiRef, /* reference orbital phase (rad) */
60  LALDict *lalParams /* Dictionary with LAL parameters */
61 )
62 {
63  /* Rescale to mass in solar masses */
64  REAL8 m1_In = m1_SI / LAL_MSUN_SI; // Mass 1 in solar masses
65  REAL8 m2_In = m2_SI / LAL_MSUN_SI; // Mass 2 in solar masses
66 
67  REAL8 m1, m2, chi1L, chi2L;
68 
69  /* Check if m1 >= m2, if not then swap masses/spins */
70  if(m1_In >= m2_In)
71  {
72  chi1L = chi1L_In;
73  chi2L = chi2L_In;
74  m1 = m1_In;
75  m2 = m2_In;
76  }
77  else
78  {
79  XLAL_PRINT_WARNING("Warning: m1 < m2, swapping the masses and spins.\n");
80  chi1L = chi2L_In;
81  chi2L = chi1L_In;
82  m1 = m2_In;
83  m2 = m1_In;
84  }
85 
86  // Symmetric mass ratio
87  REAL8 delta = fabs((m1 - m2) / (m1+m2));
88  REAL8 eta = fabs(0.25 * (1.0 - delta*delta) ); // Symmetric mass ratio, use fabs to prevent negative sign due to roundoff
89  REAL8 q = ((m1 > m2) ? (m1 / m2) : (m2 / m1));
90 
91  /* If eta > 0.25, e.g. roundoff, then set to 0.25 */
92  if(eta > 0.25)
93  {
94  eta = 0.25;
95  }
96  if(eta == 0.25) q = 1.;
97 
98  /* Masses definitions. Note that m1 and m2 are the component masses in solar masses. */
99  wf->m1_SI = m1 * LAL_MSUN_SI; // Mass 1 (larger) in SI units
100  wf->m2_SI = m2 * LAL_MSUN_SI; // Mass 2 (smaller) in SI units
101  wf->q = q; // mass ratio q>1
102  wf->eta = eta; // Symmetric mass ratio
103  wf->Mtot_SI = wf->m1_SI + wf->m2_SI; // Total mass in SI units
104  wf->Mtot = m1 + m2; // Total mass in solar masses
105  wf->m1 = m1 / (wf->Mtot); // Mass 1 (larger), dimensionless (i.e. m1 \in [0,1])
106  wf->m2 = m2 / (wf->Mtot); // Mass 2 (smaller), dimensionless
107  wf->M_sec = wf->Mtot * LAL_MTSUN_SI; // Conversion factor Hz to geometric frequency, total mass in seconds
108  wf->delta = delta; // PN symmetry coefficient
109  wf->dist_sec = distance * (LAL_MTSUN_SI/LAL_MRSUN_SI); // distance in seconds
110  wf->phiRef = phiRef; // Reference orbital phase
111 
112  /* Spins */
113  wf->chi1L = chi1L;
114  wf->chi2L = chi2L;
115 
116  /* Spin parameterisations for calling the calibrated fits*/
117  wf->Shat = ((wf->m1)*(wf->m1)*chi1L + (wf->m2)*(wf->m2)*chi2L)/((wf->m1)*(wf->m1) + (wf->m2)*(wf->m2));
118  wf->dchi = chi1L - chi2L;
119 
120  /* Final Mass and Spin (we employ the XLAL functions of PhenomX) */
123 
125 
126  /* Distance*/
127  wf->distance = distance;
128 
129  /* Impose fRef=fmin if fRef=0 */
130  wf->fRef = fRef;
131  if(fRef==0.0){wf->fRef = fmin;}
132  wf->fmin = fmin;
133 
134  /*Dimensionless minimum and reference frequency */
135  wf->MfRef = wf->M_sec*wf->fRef;
136  wf->Mfmin = wf->M_sec*wf->fmin;
137 
138  wf->deltaT = deltaT;
139  wf->dtM = deltaT/wf->M_sec; // Dimensionless sampling rate
140 
141  wf->ampfac = (wf->M_sec/wf->dist_sec); // Amplitude conversion factor from NR to physical units
142 
143  wf->inspVersion = XLALSimInspiralWaveformParamsLookupPhenomTHMInspiralVersion(lalParams); // This will select if (2,2) inspiral phase/frequency are reconstructed with 3 or 4 regions
144 
145  return XLAL_SUCCESS;
146 }
147 
148 /* Function for populating the IMRPhenomTPhase22Struct.
149  This will solve the linear systems for obtaining ansatz coefficients from 22 frequency collocation points.
150  PN Coefficients of TaylorT3 approximant employed in the inspiral ansatz are defined here.
151  Minimum and reference time, as well as waveform length, will be computed here. */
152 
154 
155  /* ***** Initialize parameters and variables ****** */
156 
157  REAL8 eta = wf->eta; // Symmetric mass ratio
158  REAL8 chi1L = wf->chi1L; // Dimensionless aligned spin of companion 1
159  REAL8 chi2L = wf->chi2L; // Dimensionless aligned spin of companion 2
160  REAL8 S = wf->Shat; // Effective dimensionless spin parameter
161  REAL8 dchi = wf->dchi; // Dimensionless spin difference chi1L - chi2L
162  REAL8 delta = wf->delta; // Asymmetry parameter
163  pPhase->dtM = wf->dtM; // Dimensionless sampling rate
164 
165  /* Calibrated value of TaylorT3 t0 parameter for matching frequency at TaylorT3 theta=0.33.
166  If 4 regions are selected for reconstruction, first inspiral region will be employ TaylorT3 with this value of t0.
167  With this, it is ensured that the early inspiral is described by the proper TaylorT3 PN description.
168  If 3 regions are selected, this will be still employed for computing the value of TaylorT3 at theta=0.33 for setting the first collocation point.*/
169  REAL8 tt0 = IMRPhenomT_Inspiral_TaylorT3_t0(eta, S, dchi, delta);
170  pPhase->tt0 = tt0;
171 
172  /* Ringdown and damping frequency of final BH for the 22 mode (defined on LALSimIMRPhenomTHM_fits.c) */
173  REAL8 fRING = evaluate_QNMfit_fring22(wf->afinal) / (wf->Mfinal); // 22 mode ringdown frequency
174  REAL8 fDAMP = evaluate_QNMfit_fdamp22(wf->afinal) / (wf->Mfinal); // 22 mode damping frequency of ground state (n=1) QNM
175 
176  /* Angular ringdown and damping frequencies (omega =2*pi*f) */
177  REAL8 alpha1RD = 2*LAL_PI*fDAMP;
178  REAL8 omegaRING = 2*LAL_PI*fRING;
179 
180  pPhase->omegaRING = omegaRING;
181  pPhase->alpha1RD = alpha1RD;
182 
185 
186  pPhase->EulerRDslope = 2*LAL_PI*(evaluate_QNMfit_fring22(wf->afinal_prec) / (wf->Mfinal) - evaluate_QNMfit_fring21(wf->afinal_prec) / (wf->Mfinal)); // FIXME:
187  if(wf->afinal<0)
188  {
189  pPhase->EulerRDslope = -pPhase->EulerRDslope;
190  }
191 
192  /* Dimensionless minimum and reference frequencies */
193  pPhase->MfRef = wf->MfRef;
194  pPhase->Mfmin = wf->Mfmin;
195 
196  /* GSL objects for solving system of equations via LU decomposition */
197  gsl_vector *b, *x;
198  gsl_matrix *A;
199  gsl_permutation *p;
200  int s; /* Sign of permutation */
201 
202  /* ********************************** */
203  /* *** RINGDOWN COEFFICIENTS ******** */
204  /* ********************************** */
205 
206  /* For phase and frequency ringdown ansatz, coefficients are obtained from ringdown and damping frequencies, frequency at peak amplitude
207  and phenomenological fits of two free coefficients. No linear system solving is needed.
208  Coefficient c1 is defined in Eq. [9] of Damour&Nagar 2014 (10.1103/PhysRevD.90.024054, https://arxiv.org/abs/1406.0401).
209  Coefficients c2 and c3 are calibrated to NR/Teukolsky data.
210  Coefficient c4 is set to zero.
211  Explained also in Sec II.C, eq. 26 of https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf */
212 
213  pPhase->omegaPeak = IMRPhenomT_PeakFrequency_22(eta, S, dchi, delta); // 22 Frequency at the peak 22 amplitude time (t=0 by definition)
214 
215  pPhase->c3 = IMRPhenomT_RD_Freq_D3_22(eta, S, dchi, delta);
216  pPhase->c2 = IMRPhenomT_RD_Freq_D2_22(eta, S, dchi, delta);
217  pPhase->c4 = 0.0;
218  pPhase->c1 = (1 + pPhase->c3 + pPhase->c4)*(pPhase->omegaRING - pPhase->omegaPeak)/pPhase->c2/(pPhase->c3 + 2*pPhase->c4);
219  pPhase->c1_prec = (1 + pPhase->c3 + pPhase->c4)*(pPhase->omegaRING_prec - pPhase->omegaPeak)/pPhase->c2/(pPhase->c3 + 2*pPhase->c4);
220 
221  /* ********************************** */
222  /* *** INSPIRAL COEFFICIENTS ******** */
223  /* ********************************** */
224 
225  /* PN coefficients of the TaylorT3 approximant employed in the inspiral ansatz are defined here.
226  Unknown coefficients for the higher order extension in the inspiral ansatz are obtained through fitted collocation points
227  solving a linear system of equations. */
228 
229 
230  /*PN coefficients corresponding to the TaylorT3 implementation of the model,
231  as defined in Appendix A1 of Estelles et al 2020 (https://arxiv.org/pdf/2004.08302.pdf) */
232 
233  pPhase->omega1PN = 0.27641369047619047 + (11*eta)/32.;
234 
235  pPhase->omega1halfPN = (-19*(chi1L + chi2L)*eta)/80. + (-113*(chi2L*(-1 + delta) - chi1L*(1 + delta)) - 96*LAL_PI)/320.;
236 
237  pPhase->omega2PN = (1855099 + 1714608*chi2L*chi2L*(-1 + delta) - 1714608*chi1L*chi1L*(1 + delta))/1.4450688e7 + ((56975 + 61236*chi1L*chi1L - 119448*chi1L*chi2L + 61236*chi2L*chi2L)*eta)/258048. + \
238  (371*eta*eta)/2048.;
239 
240  pPhase->omega2halfPN = (-17*(chi1L + chi2L)*eta*eta)/128. + (-146597*(chi2L*(-1 + delta) - chi1L*(1 + delta)) - 46374*LAL_PI)/129024. + (eta*(-2*(chi1L*(1213 - 63*delta) + chi2L*(1213 + 63*delta)) + \
241  117*LAL_PI))/2304.;
242 
243  pPhase->omega3PN = -2.499258364444952 - (16928263*chi1L*chi1L)/1.376256e8 - (16928263*chi2L*chi2L)/1.376256e8 - (16928263*chi1L*chi1L*delta)/1.376256e8 + (16928263*chi2L*chi2L*delta)/1.376256e8 + \
244  ((-2318475 + 18767224*chi1L*chi1L - 54663952*chi1L*chi2L + 18767224*chi2L*chi2L)*eta*eta)/1.376256e8 + (235925*eta*eta*eta)/1.769472e6 + (107*LAL_GAMMA)/280. - (6127*chi1L*LAL_PI)/12800. - \
245  (6127*chi2L*LAL_PI)/12800. - (6127*chi1L*delta*LAL_PI)/12800. + (6127*chi2L*delta*LAL_PI)/12800. + (53*LAL_PI*LAL_PI)/200. + \
246  (eta*(632550449425 + 35200873512*chi1L*chi1L - 28527282000*chi1L*chi2L + 9605339856*chi1L*chi1L*delta - 1512*chi2L*chi2L*(-23281001 + 6352738*delta) + 34172264448*(chi1L + chi2L)*LAL_PI - \
247  22912243200*LAL_PI*LAL_PI))/1.040449536e11 + (107*log(2))/280.;
248 
249  pPhase->omega3halfPN = (-12029*(chi1L + chi2L)*eta*eta*eta)/92160. + (eta*eta*(507654*chi1L*chi2L*chi2L - 838782*chi2L*chi2L*chi2L + chi2L*(-840149 + 507654*chi1L*chi1L - 870576*delta) +
250  chi1L*(-840149 - 838782*chi1L*chi1L + 870576*delta) + 1701228*LAL_PI))/1.548288e7 +
251  (eta*(218532006*chi1L*chi2L*chi2L*(-1 + delta) - 1134*chi2L*chi2L*chi2L*(-206917 + 71931*delta) - chi2L*(1496368361 - 429508815*delta + 218532006*chi1L*chi1L*(1 + delta)) +
252  chi1L*(-1496368361 - 429508815*delta + 1134*chi1L*chi1L*(206917 + 71931*delta)) - 144*(488825 + 923076*chi1L*chi1L - 1782648*chi1L*chi2L + 923076*chi2L*chi2L)*LAL_PI))/1.8579456e8 +
253  (-6579635551*chi2L*(-1 + delta) + 535759434*chi2L*chi2L*chi2L*(-1 + delta) - chi1L*(-6579635551 + 535759434*chi1L*chi1L)*(1 + delta) +
254  (-565550067 - 465230304*chi2L*chi2L*(-1 + delta) + 465230304*chi1L*chi1L*(1 + delta))*LAL_PI)/1.30056192e9;
255 
256 
257  /* Solve inspiral coefficients */
258 
259  /* Inspiral reconstruction is based on the TaylorT3 approximant at 3.5PN with spin-orbit and spin-spin contributions, whose coefficients are defined above.
260  TaylorT3 is parameterised in terms of a 'PN time parameter' theta=pow(eta*(tt0 - tEarly)/5,-1./8), which depends on an integration constant tt0 (coming from the TaylorT2 derivation) which has to be fixed
261  in order to impose a determined frequency at a determined time. TaylorT3 will diverge when t=tt0, so this parameter can be understood as the merger time prediction of TaylorT3, which in general will not be
262  the actual merger time. In order to overcome the divergence issue in cases where this occurs too early, we originally decided to set tt0 to the peak time of the 22. This produces a small frequency shift that
263  over many cycles can reduce the accuracy of the model for long waveforms. To overcome this, an early collocation point at theta=0.33 is set to the actual value of TaylorT3 (through a tt0 fit) to impose
264  the low frequency regime to follow the correct description. Along with this, the early inspiral region with theta<0.33 was selected to be modeled with pure TaylorT3 with the tt0 fit value.
265  However, several tests suggest that actually imposing the theta=0.33 value is enough and two regions are not needed. We let as an option in the model to select the inspiral reconstruction with or without this split.
266  Depending on the value of the LAL parameter 'PhenomTHMInspiralVersion' reconstruction of the inspiral phase can be splitted into two different regions. For default value (0) this will not be done.
267  In default reconstruction, TaylorT3 with t0=0 will be employed, plus 6 additional higher order terms to be solved with the value of 5 fitted collocation points at fixed theta positions {0.45, 0.55, 0.65, 0.75, 0.82}
268  + and early collocation point at theta=0.33 whose value will be the value of TaylorT3 with t0 computed from a fit.
269  In non-default reconstruction, region with theta<0.33 will be modelled by TaylorT3 with the tt0 fit value and without extra coefficients.*/
270 
271  /* Initialize higher order extension coefficients to 0. In this way, when calling the ansatz IMRPhenomTInspiralOmegaAnsatz22 it will return PN TaylorT3 value. */
272  pPhase->omegaInspC1 = 0.0;
273  pPhase->omegaInspC2 = 0.0;
274  pPhase->omegaInspC3 = 0.0;
275  pPhase->omegaInspC4 = 0.0;
276  pPhase->omegaInspC5 = 0.0;
277  pPhase->omegaInspC6 = 0.0;
278 
279  /* Set collocation points */
280 
281  REAL8 thetapoints[6] = {0.33,0.45,0.55,0.65,0.75,0.82}; // Collocation point times as defined in Eq. 11 of PhenomTHM paper https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf */
282 
283  REAL8 omegainsppoints[6];
284 
285  /* Boundary time between early and late inspiral regions (only needed if non-default 4 region reconstruction is selected). Boundary is fixed at theta=0.33 for all cases. Inverting the definition of theta, the boundary time is obtained.
286  Each inspiral region (if non-default reconstruction is selected) has a different parameterization. For the early inspiral region, theta is defined employing the calibrated quantity t0 (tt0 in the code),
287  while in the late inspiral region t0 is set to 0 for avoiding singularities. */
288  REAL8 tEarly = -5.0/(eta*pow(thetapoints[0],8));
289  pPhase->tEarly = tEarly;
290  REAL8 thetaini = pow(eta*(tt0 - tEarly)/5,-1./8); // This thetaini is the reparameterization of theta=0.33 for the early inspiral region theta definition.
291 
292  /* initialize collocation point values for solving inspiral coefficient system */
293  omegainsppoints[0] = IMRPhenomTTaylorT3(thetaini, pPhase);
294  omegainsppoints[1] = IMRPhenomT_Inspiral_Freq_CP1_22(eta, S, dchi, delta);
295  omegainsppoints[2] = IMRPhenomT_Inspiral_Freq_CP2_22(eta, S, dchi, delta);
296  omegainsppoints[3] = IMRPhenomT_Inspiral_Freq_CP3_22(eta, S, dchi, delta);
297  omegainsppoints[4] = IMRPhenomT_Inspiral_Freq_CP4_22(eta, S, dchi, delta);
298  omegainsppoints[5] = IMRPhenomT_Inspiral_Freq_CP5_22(eta, S, dchi, delta);
299 
300  /*Set linear system, which is rank 6 */
301  p = gsl_permutation_alloc(6);
302  b = gsl_vector_alloc(6);
303  x = gsl_vector_alloc(6);
304  A = gsl_matrix_alloc(6,6);
305 
306  /*Set A matrix and b vector*/
307 
308  REAL8 theta, theta8, theta9, theta10, theta11, theta12, theta13, T3offset; // Initialize theta powers the diagonal A matrix
309  /* theta is a weighted dimensionless time parameter defined in Eq. 315 of Blanchet 2014 (https://arxiv.org/abs/1310.1528).
310  Notice however that here is defined at the (-1/8) power, in order to represent the Post-Newtonian order (1/c). */
311 
312  /* Set up inspiral coefficient system.
313  This system of equations is explained in eq. 10 of THM paper https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf */
314  for (UINT4 idx=0; idx<6; idx++)
315  {
316  /* Needed powers of theta */
317  theta = thetapoints[idx];
318  theta8 = pow(theta,8);
319  theta9 = theta*theta8;
320  theta10 = theta*theta9;
321  theta11 = theta*theta10;
322  theta12 = theta*theta11;
323  theta13 = theta*theta12;
324 
325  T3offset = IMRPhenomTTaylorT3(theta, pPhase); // TaylorT3 value at the specific collocation point time */
326 
327  gsl_vector_set(b,idx,(4/theta/theta/theta)*(omegainsppoints[idx] - T3offset));
328 
329  gsl_matrix_set(A,idx,0,theta8);
330  gsl_matrix_set(A,idx,1,theta9);
331  gsl_matrix_set(A,idx,2,theta10);
332  gsl_matrix_set(A,idx,3,theta11);
333  gsl_matrix_set(A,idx,4,theta12);
334  gsl_matrix_set(A,idx,5,theta13);
335 
336  }
337 
338  /* We now solve the system A x = b via an LU decomposition */
339  gsl_linalg_LU_decomp(A,p,&s);
340  gsl_linalg_LU_solve(A,p,b,x);
341 
342  /* Set inspiral phenomenological coefficients from solution to A x = b */
343  pPhase->omegaInspC1 = gsl_vector_get(x,0);
344  pPhase->omegaInspC2 = gsl_vector_get(x,1);
345  pPhase->omegaInspC3 = gsl_vector_get(x,2);
346  pPhase->omegaInspC4 = gsl_vector_get(x,3);
347  pPhase->omegaInspC5 = gsl_vector_get(x,4);
348  pPhase->omegaInspC6 = gsl_vector_get(x,5);
349 
350  /* Boundary time between late inspiral and merger regions.
351  This is selected to correspond to theta=0.81, earlier than the last collocation point at theta=0.82, because in this way
352  the derivative at the boundary with the merger region, needed for the merger reconstruction, is less forced. */
353  REAL8 tCut = -5.0/(eta*pow(0.81,8));
354  pPhase->tCut22 = tCut;
355  REAL8 omegaCut = IMRPhenomTInspiralOmegaAnsatz22(0.81, pPhase);// 22 frequency value at tCut
356 
357  /* Tidy up in preparation for next GSL solve ... */
358  gsl_vector_free(b);
359  gsl_vector_free(x);
360  gsl_matrix_free(A);
361  gsl_permutation_free(p);
362 
363  /*Set linear system for solving merger coefficients*/
364  p = gsl_permutation_alloc(3);
365  b = gsl_vector_alloc(3);
366  x = gsl_vector_alloc(3);
367  A = gsl_matrix_alloc(3,3);
368 
369  /* ********************************** */
370  /* *** MERGER COEFFICIENTS ********** */
371  /* ********************************** */
372 
373  /* In order to obtain the value of the 3 free coefficients of the ansatz defined in IMRPhenomTMergerOmegaAnsatz22, we need to solve a linear system
374  where the ansatz is imposed to match a collocation point value at theta(t)=0.95 and to satisfy continuity with the inspiral ansatz and differentiability with the ringdown ansatz.
375  Notice that the ansatz definition IMRPhenomTMergerOmegaAnsatz22 differs from eq [27-26] of PhenomTHM paper (https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf)
376  in that here 2 of the coefficients are analytically solved for imposing continuity with the ringdown ansatz and differentiability with the inspiral ansatz.
377 
378  Reminder: the ansatz described in IMRPhenomTMergerOmegaAnsatz22 corresponds to the rescaled frequency \bar{\omega}=1 - (\omega / \omega_ring) (eq. 27 of https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf),
379  so the system is solved for the rescaled frequency. For the analytical phase of IMRPhenomTMergerPhaseAnsatz22, which is the quantity employed
380  in the waveform construction, the factors are already included to produce the correct phase. */
381 
382 
383  REAL8 tMerger22 = -5.0/(eta*pow(0.95,8)); // Collocation point time of the merger region. This is placed at a fixed position theta=0.95.
384  REAL8 omegaMergerCP = 1. - IMRPhenomT_Merger_Freq_CP1_22(eta, S, dchi, delta)/pPhase->omegaRING; // Collocation point.
385  REAL8 omegaCutBar = 1. - omegaCut/pPhase->omegaRING; // Boundary frequency between inspiral and merger ringdown, rescaled.
386 
387  /* Now we need the derivative values at the boundaries.
388  Being the inspiral and ringdown ansatz differentiable analytical functions, the analytical derivative could be computed.
389  However, for code saving, it is enough to compute a numerical derivative at the boundary. Since the expressions are differentiable,
390  the numerical derivative is clean from any noise, and using a first order finite difference scheme is enough to obtain the derivative
391  at sufficient precission. */
392 
393  REAL8 theta2 = pow(-eta*tCut/5.,-1./8);
394  REAL8 theta1 = pow(-eta*(tCut-0.0000001)/5,-1./8);
395  REAL8 domegaCut = -(IMRPhenomTInspiralOmegaAnsatz22(theta2, pPhase) - IMRPhenomTInspiralOmegaAnsatz22(theta1, pPhase))/(0.0000001)/pPhase->omegaRING; // Derivative of rescale frequency at the inspiral boundary
396  REAL8 domegaPeak = -(IMRPhenomTRDOmegaAnsatz22(0.0000001, pPhase) - IMRPhenomTRDOmegaAnsatz22(0., pPhase))/(0.0000001)/pPhase->omegaRING; // Derivative of rescale frequency at the ringdown boundary
397  pPhase->domegaPeak = domegaPeak;
398 
399  /* Now we set the linear system for solving merger ansatz coefficients of IMRPhenomTMergerOmegaAnsatz22,
400  as explained in eq. 30 of PhenomTHM paper (https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf)
401  Reminder: Here two coefficients are already analytically solved, so the system contains only three equations for the three remaining coefficients. */
402 
403  /* A_{0,i} and b_{0}. Here we impose continuity with the inspiral region.
404  The value of the solution vector coefficient b_{0} is the rescaled frequency at the inspiral boundary, minus the terms of the ansatz which are already fixed analytically.
405  The value of the first row of basis matrix are the arcsinh powers of the ansatz evaluated at the boundary time tCut. */
406 
407  gsl_complex phi = gsl_complex_rect(pPhase->alpha1RD*tCut,0);
408  gsl_complex arcsinhphi = gsl_complex_arcsinh(phi);
409  REAL8 ascut = GSL_REAL(arcsinhphi);
410  REAL8 ascut2 = ascut*ascut;
411  REAL8 ascut3 = ascut*ascut2;
412  REAL8 ascut4 = ascut*ascut3;
413 
414  gsl_vector_set(b,0,omegaCutBar - (1. - pPhase->omegaPeak/pPhase->omegaRING) - (pPhase->domegaPeak/pPhase->alpha1RD)*ascut);
415 
416  gsl_matrix_set(A,0,0,ascut2);
417  gsl_matrix_set(A,0,1,ascut3);
418  gsl_matrix_set(A,0,2,ascut4);
419 
420  /* A_{1,i} and b_{1}. Here we impose the collocation point at theta=0.95.
421  The value of the solution vector coefficient b_{1} is the rescaled value of the collocation point, minus the terms of the ansatz which are already fixed analytically.
422  The value of the second row of basis matrix are the arcsinh powers of the ansatz evaluated at the collocation point time tMerger22 (determined from theta(t)=0.95). */
423 
424  phi = gsl_complex_rect(pPhase->alpha1RD*tMerger22,0);
425  arcsinhphi = gsl_complex_arcsinh(phi);
426  REAL8 as025cut = GSL_REAL(arcsinhphi);
427  REAL8 as025cut2 = as025cut*as025cut;
428  REAL8 as025cut3 = as025cut*as025cut2;
429  REAL8 as025cut4 = as025cut*as025cut3;
430 
431  gsl_vector_set(b,1,omegaMergerCP - (1. - pPhase->omegaPeak/pPhase->omegaRING) - (pPhase->domegaPeak/pPhase->alpha1RD)*as025cut);
432 
433  gsl_matrix_set(A,1,0,as025cut2);
434  gsl_matrix_set(A,1,1,as025cut3);
435  gsl_matrix_set(A,1,2,as025cut4);
436 
437  /* A_{2,i} and b_{2}. Here we impose differentiability with the ringdown region.
438  The value of the solution vector coefficient b_{2} is the rescaled frequency derivative at the ringdown boundary, minus the terms of the ansatz derivative which are already fixed analytically.
439  The value of the third row of basis matrix are the arcsinh powers of the ansatz evaluated at the boundary time tCut. */
440 
441  REAL8 dencut = sqrt(1.0 + tCut*tCut*pPhase->alpha1RD*pPhase->alpha1RD); // Factor that appears from the derivative of the ansatz
442 
443  gsl_matrix_set(A,2,0,2.0*pPhase->alpha1RD*ascut/dencut);
444  gsl_matrix_set(A,2,1,3.0*pPhase->alpha1RD*ascut2/dencut);
445  gsl_matrix_set(A,2,2,4.0*pPhase->alpha1RD*ascut3/dencut);
446 
447  gsl_vector_set(b,2,domegaCut - pPhase->domegaPeak/dencut);
448 
449  /* We now solve the system A x = b via an LU decomposition */
450  gsl_linalg_LU_decomp(A,p,&s);
451  gsl_linalg_LU_solve(A,p,b,x);
452 
453  /* Set merger phenomenological coefficients from solution to A x = b */
454  pPhase->omegaMergerC1 = gsl_vector_get(x,0);
455  pPhase->omegaMergerC2 = gsl_vector_get(x,1);
456  pPhase->omegaMergerC3 = gsl_vector_get(x,2);
457 
458  // Free the gsl objects employed in solving the coefficient system
459  gsl_vector_free(b);
460  gsl_vector_free(x);
461  gsl_matrix_free(A);
462  gsl_permutation_free(p);
463 
464  /* *********************************************** */
465  /* *** PHASE CONTINUITY BETWEEN REGIONS ********** */
466  /* *********************************************** */
467 
468  /* Phase of the different regions correspond to the analytical integration of the frequency ansatz.
469  Here we adapt the corresponding offsets for each phase ansatz in order to obtain continuity between regions */
470 
471  /* First we set the offsets to zero in order to call the phase ansatzs without the offsets */
472  pPhase->phOffInsp = 0.;
473  pPhase->phOffMerger = 0.;
474  pPhase->phOffRD = 0.;
475 
476  /* phOffInsp contains the difference between the early and late inspiral regions at the early inspiral boundary defined by tEarly (theta=0.33).
477  This is only needed if reconstruction is non-default (4 regions) but it is harmless if reconstruction employs 3 regions */
478  REAL8 thetabarini = pow(eta*(tt0 - tEarly),-1./8);
479  REAL8 thetabarini2 = pow(-eta*(tEarly),-1./8);
480  pPhase->phOffInsp = IMRPhenomTInspiralPhaseTaylorT3(thetabarini, wf, pPhase) - IMRPhenomTInspiralPhaseAnsatz22(tEarly, thetabarini2, wf, pPhase);
481 
482  REAL8 thetabarCut = pow(-eta*tCut,-1./8);
483  REAL8 phMECOinsp = IMRPhenomTInspiralPhaseAnsatz22(tCut, thetabarCut, wf, pPhase); //Value of inspiral phase at inspiral-merger boundary
484  REAL8 phMECOmerger = IMRPhenomTMergerPhaseAnsatz22(tCut, pPhase); //Value of merger phase at merger-ringdown boundary
485 
486  pPhase->phOffMerger = phMECOinsp - phMECOmerger; // Needed offset for merger ansatz in order to match inspiral phase value at the boundary
487  pPhase->phOffRD = IMRPhenomTMergerPhaseAnsatz22(0, pPhase); //Neded offset for ringdown ansatz in order to match merger phase value at the boundary
488 
489 
490  /* *********************************************** */
491  /* *** EPOCH AND WAVEFORM LENGHT ***************** */
492  /* *********************************************** */
493 
494 
495  /* Waveform lenght is determined by the time spent from the starting frequency to the peak amplitude time of the 22 mode, with the addition of 500M after that time for
496  having a sufficient ringdown window for sane Fourier tranforms */
497 
498  /* Starting time is determined as the time at which starting frequency occurs, and it is determined by root finding employing the frequency function */
499 
500 
501  /* First we set the gsl objects needed for root finding the minimum time */
502  const gsl_root_fsolver_type *solver_type;
503  gsl_root_fsolver *solver;
504  gsl_function F;
505 
506  /* Populate an auxiliary struct needed for gsl root finder */
507  struct FindRootParams frparams;
508  frparams.f0 = pPhase->Mfmin;
509  frparams.pPhase = pPhase;
510  frparams.wf = wf;
511 
512  /* Populate the gsl function needed for the root finder */
513  F.function = &GetTimeOfFreq;
514  F.params = &frparams;
515 
516  /* Allocate a brent solver and set it to use F */
517  /* Left boundary of the solver is set at a sufficient early time such that above one solar mass, it exists a solution. */
518  solver_type = gsl_root_fsolver_brent;
519  gsl_set_error_handler_off();
520 
521  int status;
522  int status_solver = GSL_CONTINUE;
523  solver = gsl_root_fsolver_alloc(solver_type);
524  status = gsl_root_fsolver_set(solver, &F, -1000000000.0,tEnd);
525 
526  double r = 0.0;
527  for (UINT4 i = 1; i <= 1000 && status_solver == GSL_CONTINUE; ++i) {
528  /* iterate one step of the solver */
529  status_solver = gsl_root_fsolver_iterate(solver);
530  if (status_solver != GSL_SUCCESS)
531  break;
532 
533  /* get the solver's current best solution and bounds */
534  r = gsl_root_fsolver_root(solver);
535  double x_lo = gsl_root_fsolver_x_lower(solver);
536  double x_hi = gsl_root_fsolver_x_upper(solver);
537 
538  /* Check to see if the solution is within 0.0001 */
539  status_solver = gsl_root_test_interval(x_lo, x_hi, 0, 0.0001);
540  }
541  XLAL_CHECK(GSL_SUCCESS == status, XLAL_EFUNC, "Error: Root finder unable to solve minimum time. Minimum frequency may be too high for these parameters. Try reducing fmin below the peak frequency: %.8f Hz. \n", pPhase->omegaPeak/(LAL_TWOPI*wf->M_sec));
542 
543  pPhase->tmin = r; // Minimum time is selected as the solution of the above root finding operation
544  gsl_root_fsolver_free(solver); // Free the gsl solver
545 
546  /* Now we repeat the same procedure for determining the time at which the specified reference frequency occurs. This is needed to set the reference phase */
547 
548  /* First we check if fmin and fref coincide, to save the computation */
549  if(wf->fRef == wf->fmin)
550  {
551  pPhase->tRef = pPhase->tmin;
552  }
553  /* If not, we repeat the same operation to obtain the reference time */
554  else
555  {
556  frparams.f0 = pPhase->MfRef;
557  frparams.pPhase = pPhase;
558  frparams.wf = wf;
559 
560  F.function = &GetTimeOfFreq;
561  F.params = &frparams;
562 
563  /* Allocate a brent solver and set it to use F */
564  solver_type = gsl_root_fsolver_brent;
565  solver = gsl_root_fsolver_alloc(solver_type);
566  status = gsl_root_fsolver_set(solver, &F, -1000000000.0,tEnd);
567  status_solver = GSL_CONTINUE;
568 
569  for (UINT4 i = 1; i <= 1000 && status_solver == GSL_CONTINUE; ++i) {
570  /* iterate one step of the solver */
571  status_solver = gsl_root_fsolver_iterate(solver);
572  if (status_solver != GSL_SUCCESS)
573  break;
574 
575  /* get the solver's current best solution and bounds */
576  r = gsl_root_fsolver_root(solver);
577  double x_lo = gsl_root_fsolver_x_lower(solver);
578  double x_hi = gsl_root_fsolver_x_upper(solver);
579 
580  /* Check to see if the solution is within 0.001 */
581  status_solver = gsl_root_test_interval(x_lo, x_hi, 0, 0.0001);
582  }
583  XLAL_CHECK(GSL_SUCCESS == status, XLAL_EFUNC, "Error: Root finder unable to solve reference time. Reference frequency may be too high for these parameters. Try reducing fRef below the peak frequency: %.8f Hz. \n", pPhase->omegaPeak/(LAL_TWOPI*wf->M_sec));
584 
585  pPhase->tRef = r;
586  gsl_root_fsolver_free(solver);
587  }
588 
590 
591  /* Required waveform length. We select maximum time of 500M since it is enough to contain the non-negligible ringdown content of the modes up to m=5.
592  Length of early and late inspiral regions are computed since in the case of non-default reconstruction (4 regions) this is needed to compute frequencies
593  in both regimes with the two different TaylorT3 implementations. If default reconstruction, it is harmless. */
594 
595  pPhase->wflength = floor((tEnd - pPhase->tmin)/wf->dtM);
596  if(tEarly<=pPhase->tmin && tCut>pPhase->tmin)
597  {
598  pPhase->wflength_insp_late = floor((tCut - pPhase->tmin + wf->dtM)/wf->dtM);
600  }
601  else if(tCut<=pPhase->tmin)
602  {
605  }
606  else{
607  pPhase->wflength_insp_late = floor((tCut - tEarly + wf->dtM)/wf->dtM);
608  pPhase->wflength_insp_early = floor((tEarly - pPhase->tmin + wf->dtM)/wf->dtM);
609  }
610 
611 
612 
613  return XLAL_SUCCESS;
614 }
615 
616 /* ---------------------------------------------------------------------------------------------------- */
617 
618 /* **************************************************** */
619 /* ******* HIGHER MODES STRUCTURE INITIALIZATION ****** */
620 /* **************************************************** */
621 
622 /* Function for populating the IMRPhenomTHMAmpStruct.
623  This will solve the linear systems for obtaining ansatz coefficients from lm amplitude collocation points.
624  PN Coefficients of the mode amplitude are defined and stored for each mode.
625  Inspiral PN amplitude is a complex quantity, with its argument contributing to the mode's phase. Since amplitude collocation points are taken from the absolute value,
626  some preprocessing of the fits is needed, in particular to obtain the real projection once known the argument angle. */
627 
629 {
630  REAL8 eta = wf->eta; // Symmetric mass ratio
631  REAL8 chi1 = wf->chi1L; // Dimensionless aligned spin of companion 1
632  REAL8 chi2 = wf->chi2L; // Dimensionless aligned spin of companion 2
633  REAL8 S = wf->Shat; // Dimensionless effective spin parameters employed for fit evaluation
634  REAL8 dchi = wf->dchi; // Dimensionless spin difference chi1 - chi2
635  REAL8 delta = wf->delta; // Mass asymmetry parameter
636  REAL8 tCut = tCUT_Amp; // tCUT_Amp = -150
637 
638  pAmp->fac0 = 2*eta*sqrt(16*LAL_PI/5); // Precomputed amplitude global factor (see eq. 12-14 of PhenomTHM paper https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf)
639 
640  /* GSL objects for solving system of equations via LU decomposition */
641  gsl_vector *b, *x;
642  gsl_matrix *A;
643  gsl_permutation *p;
644  int s;
645 
646  /* For the selected mode, all needed fit values, PN coefficients and ringdown coefficients to fully determine the amplitude ansatz are computed. */
647 
648  REAL8 ampInspCP[3]; // Inspiral collocation point values.
649  REAL8 ampMergerCP1, ampPeak; // Merger collocation point value and peak amplitude
650  REAL8 ampRDC3, fDAMP, fDAMPn2, fDAMP_prec, fDAMPn2_prec, coshc3, tanhc3; // Ringdown ansatz c3 free coefficient, damping frequencies and needed quantities to compute ringdown ansatz coefficients.
651  /* Ringdown ansatz coefficients c_{1,2,3,4} as defined in eq. [6-8] of Damour&Nagar 2014 (https://arxiv.org/pdf/1406.0401.pdf), also explained in eq.26 of THM paper (https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf)
652  and alpha_1, alpha_2, alpha_21 as defined in Sec IV of the same reference are stored in the amplitude struct since they are directly passed to the ringdown ansatz.
653  tshift, also passed to the amplitude struct, corresponds to the peak amplitude time of the (l,m) mode (0 for the 22 by construction). */
654  gsl_complex phi; // Argument for the gsl hyperbolic functions. It is a real quantity but gsl functions expect a complex number, so it is constructed as (phi,0).
655 
656  /* The PN amplitude coefficients of the inspiral ansatz are defined in Appendix A of PhenomTHM paper (https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf).
657  They are constructed from:
658  - 3PN expressions from Blanchet et al. 2008 (Class.Quant.Grav.25:165003,2008, https://arxiv.org/abs/0802.1249)
659  - 2PN spin corrections from Buonanno et al. 2013 (Phys. Rev D87, 044009, 2013, https://arxiv.org/abs/1209.6349)
660  - 1.5PN contributions from Arun et al. 2008 (Phys.Rev.D79:104023,2009; Erratum-ibid.D84:049901,2011, https://arxiv.org/abs/0810.5336) */
661 
662  if (l==2 && m==2)
663  {
664  /* Needed fits for collocation points and ringdown coefficient */
665  ampInspCP[0] = IMRPhenomT_Inspiral_Amp_CP1_22(eta, S, dchi, delta);
666  ampInspCP[1] = IMRPhenomT_Inspiral_Amp_CP2_22(eta, S, dchi, delta);
667  ampInspCP[2] = IMRPhenomT_Inspiral_Amp_CP3_22(eta, S, dchi, delta);
668  ampMergerCP1 = IMRPhenomT_Merger_Amp_CP1_22(eta, S, dchi, delta);
669  ampPeak = IMRPhenomT_PeakAmp_22(eta, S, dchi, delta);
670  ampRDC3 = IMRPhenomT_RD_Amp_C3_22(eta, S);
671 
672  fDAMP = evaluate_QNMfit_fdamp22(wf->afinal) / (wf->Mfinal); //damping frequency of 122 QNM
673  fDAMPn2 = evaluate_QNMfit_fdamp22n2(wf->afinal) / (wf->Mfinal); //damping frequency of 222 QNM
674 
675  fDAMP_prec = evaluate_QNMfit_fdamp22(wf->afinal_prec) / (wf->Mfinal);
676  fDAMPn2_prec = evaluate_QNMfit_fdamp22n2(wf->afinal_prec) / (wf->Mfinal);
677 
678  pAmp->tshift = 0.0; //Peak time, by construction 0 for l=2, m=2
679 
680  /* PN Amplitude coefficients, defined in eq.A1 of https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf (before global rotation applied, see eq.13 of https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf) */
681 
682  pAmp->ampN = 1.0;
683  pAmp->amp0halfPNreal = 0.0;
684  pAmp->amp0halfPNimag = 0.0;
685 
686  pAmp->amp1PNreal = -2.5476190476190474 + (55*eta)/42.;
687  pAmp->amp1PNimag = 0.0;
688 
689  pAmp->amp1halfPNreal = (-2*chi1)/3. - (2*chi2)/3. - (2*chi1*delta)/(3.*((1 - delta)/2. + (1 + delta)/2.)) + (2*chi2*delta)/(3.*((1 - delta)/2. + (1 + delta)/2.)) + (2*chi1*eta)/3. + (2*chi2*eta)/3. + 2*LAL_PI;
690  pAmp->amp1halfPNimag = 0.0;
691 
692  pAmp->amp2PNreal = -1.437169312169312 + pow(chi1,2)/2. + pow(chi2,2)/2. + (pow(chi1,2)*delta)/2. - (pow(chi2,2)*delta)/2. - (1069*eta)/216. - pow(chi1,2)*eta + 2*chi1*chi2*eta - pow(chi2,2)*eta + (2047*pow(eta,2))/1512.;
693  pAmp->amp2PNimag = 0.0;
694 
695  pAmp->amp2halfPNreal = - (107*LAL_PI)/21. + (34*eta*LAL_PI)/21.;
696  pAmp->amp2halfPNimag = -24.*eta;
697 
698  pAmp->amp3PNreal = 41.78634662956092 - (278185*eta)/33264. - (20261*pow(eta,2))/2772. + (114635*pow(eta,3))/99792. - (856*LAL_GAMMA)/105. + (2*pow(LAL_PI,2))/3. + (41*eta*pow(LAL_PI,2))/96.;
699  pAmp->amp3PNimag = (428./105)*LAL_PI;
700 
701  pAmp->amp3halfPNreal = (-2173*LAL_PI)/756. - (2495*eta*LAL_PI)/378. + (40*pow(eta,2)*LAL_PI)/27.;
702  pAmp->amp3halfPNimag = (14333*eta)/162. - (4066*pow(eta,2))/945.;
703 
704  pAmp->amplog = -428/105.;
705  }
706 
707  else if (l==2 && m==1)
708  {
709  /* Needed fits for collocation points and ringdown coefficient */
710  ampInspCP[0] = IMRPhenomT_Inspiral_Amp_CP1_21(eta, S, dchi, delta);
711  ampInspCP[1] = IMRPhenomT_Inspiral_Amp_CP2_21(eta, S, dchi, delta);
712  ampInspCP[2] = IMRPhenomT_Inspiral_Amp_CP3_21(eta, S, dchi, delta);
713  ampMergerCP1 = IMRPhenomT_Merger_Amp_CP1_21(eta, S, dchi, delta);
714  ampPeak = IMRPhenomT_PeakAmp_21(eta, S, dchi, delta);
715  ampRDC3 = IMRPhenomT_RD_Amp_C3_21(eta, S, dchi);
716 
717  fDAMP = evaluate_QNMfit_fdamp21(wf->afinal) / (wf->Mfinal); //damping frequency of 121 QNM
718  fDAMPn2 = evaluate_QNMfit_fdamp21n2(wf->afinal) / (wf->Mfinal); //damping frequency of 221 QNM
719 
720  fDAMP_prec = evaluate_QNMfit_fdamp21(wf->afinal_prec) / (wf->Mfinal);
721  fDAMPn2_prec = evaluate_QNMfit_fdamp21n2(wf->afinal_prec) / (wf->Mfinal);
722 
723  pAmp->tshift = IMRPhenomT_tshift_21(eta, S, dchi); //Peak time of l=2, m=1 mode
724 
725  /* PN Amplitude coefficients, defined in eq.A2 of https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf (before global rotation applied, see eq.13 of https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf) */
726 
727  pAmp->ampN = 0.0;
728  pAmp->amp0halfPNreal = delta/3.;
729  pAmp->amp0halfPNimag = 0.0;
730 
731  pAmp->amp1PNreal = -chi1/4. + chi2/4. - (chi1*delta)/(4.*((1 - delta)/2. + (1 + delta)/2.)) - (chi2*delta)/(4.*((1 - delta)/2. + (1 + delta)/2.));
732  pAmp->amp1PNimag = 0.0;
733 
734  pAmp->amp1halfPNreal = -17*delta/84. + (5*delta*eta)/21.;
735  pAmp->amp1halfPNimag = 0.0;
736 
737  pAmp->amp2PNimag = -delta/6. - (2*delta*log(2))/3.;
738  pAmp->amp2PNreal = (79*chi1)/84. - (79*chi2)/84. + (79*chi1*delta)/84. + (79*chi2*delta)/84. - (43*chi1)/(42.*((1 - delta)/2. + (1 + delta)/2.)) + (43*chi2)/(42.*((1 - delta)/2. + (1 + delta)/2.)) - (43*chi1*delta)/(42.*((1 - delta)/2. + (1 + delta)/2.)) - (43*chi2*delta)/(42.*((1 - delta)/2. + (1 + delta)/2.)) - (139*chi1*eta)/84. + (139*chi2*eta)/84. - (139*chi1*delta*eta)/84. - (139*chi2*delta*eta)/84. + (86*chi1*eta)/(21.*((1 - delta)/2. + (1 + delta)/2.)) - (86*chi2*eta)/(21.*((1 - delta)/2. + (1 + delta)/2.)) + (43*chi1*delta*eta)/(21.*((1 - delta)/2. + (1 + delta)/2.)) + (43*chi2*delta*eta)/(21.*((1 - delta)/2. + (1 + delta)/2.)) + (delta*LAL_PI)/3.;
739 
740  pAmp->amp2halfPNimag = 0.0;
741  pAmp->amp2halfPNreal = (-43*delta)/378. - (509*delta*eta)/378. + (79*delta*pow(eta,2))/504.;
742 
743  pAmp->amp3PNimag = -((-17*delta)/168. + (353*delta*eta)/84. - (17*delta*log(2))/42. + (delta*eta*log(2))/7.);
744  pAmp->amp3PNreal = (-17*delta*LAL_PI)/84. + (delta*eta*LAL_PI)/14.;
745 
746  pAmp->amp3halfPNreal = 0.0;
747  pAmp->amp3halfPNimag = 0.0;
748 
749  pAmp->amplog = 0.0;
750  }
751 
752  else if (l==3 && m==3)
753  {
754  /* Needed fits for collocation points and ringdown coefficient */
755  ampInspCP[0] = IMRPhenomT_Inspiral_Amp_CP1_33(eta, S, dchi, delta);
756  ampInspCP[1] = IMRPhenomT_Inspiral_Amp_CP2_33(eta, S, dchi, delta);
757  ampInspCP[2] = IMRPhenomT_Inspiral_Amp_CP3_33(eta, S, dchi, delta);
758  ampMergerCP1 = IMRPhenomT_Merger_Amp_CP1_33(eta, S, dchi, delta);
759  ampPeak = IMRPhenomT_PeakAmp_33(eta, S, dchi, delta);
760  ampRDC3 = IMRPhenomT_RD_Amp_C3_33(eta, S);
761 
762  fDAMP = evaluate_QNMfit_fdamp33(wf->afinal) / (wf->Mfinal); //damping frequency of 133 QNM
763  fDAMPn2 = evaluate_QNMfit_fdamp33n2(wf->afinal) / (wf->Mfinal); //damping frequency of 233 QNM
764 
765  fDAMP_prec = evaluate_QNMfit_fdamp33(wf->afinal_prec) / (wf->Mfinal);
766  fDAMPn2_prec = evaluate_QNMfit_fdamp33n2(wf->afinal_prec) / (wf->Mfinal);
767 
768  pAmp->tshift = IMRPhenomT_tshift_33(eta, S);
769 
770  /* PN Amplitude coefficients, defined in eq.A3 of https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf (before global rotation applied, see eq.13 of https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf) */
771 
772  pAmp->ampN = 0.0;
773  pAmp->amp0halfPNimag = 0.0;
774  pAmp->amp0halfPNreal = 0.7763237542601484*delta;
775 
776  pAmp->amp1PNreal = 0.0;
777  pAmp->amp1PNimag = 0.0;
778 
779  pAmp->amp1halfPNimag = 0.0;
780  pAmp->amp1halfPNreal = -3.1052950170405937*delta + 1.5526475085202969*delta*eta;
781 
782  pAmp->amp2PNimag = -1.371926598204461*delta;
783  pAmp->amp2PNreal = -(-0.5822428156951114*chi1 + 0.5822428156951114*chi2 - 7.316679009572791*delta - 0.5822428156951114*chi1*delta - 0.5822428156951114*chi2*delta + (1.3585665699552598*chi1)/((1 - delta)/2. + (1 + delta)/2.) - (1.3585665699552598*chi2)/((1 - delta)/2. + (1 + delta)/2.) + (1.3585665699552598*chi1*delta)/((1 - delta)/2. + (1 + delta)/2.) + (1.3585665699552598*chi2*delta)/((1 - delta)/2. + (1 + delta)/2.) + 1.7467284470853341*chi1*eta - 1.7467284470853341*chi2*eta + 1.7467284470853341*chi1*delta*eta + 1.7467284470853341*chi2*delta*eta - (5.434266279821039*chi1*eta)/((1 - delta)/2. + (1 + delta)/2.) + (5.434266279821039*chi2*eta)/((1 - delta)/2. + (1 + delta)/2.) - (2.7171331399105196*chi1*delta*eta)/((1 - delta)/2. + (1 + delta)/2.) - (2.7171331399105196*chi2*delta*eta)/((1 - delta)/2. + (1 + delta)/2.));
784 
785  pAmp->amp2halfPNimag = 0.0;
786  pAmp->amp2halfPNreal = -(-0.08680711070363478*delta + 8.647776123213047*delta*eta - 2.0866641516022777*delta*pow(eta,2));
787 
788  pAmp->amp3PNreal = 0.0;
789  pAmp->amp3PNimag = 0.0;
790 
791  pAmp->amp3halfPNreal = 0.0;
792  pAmp->amp3halfPNimag = 0.0;
793 
794  pAmp->amplog = 0.0;
795  }
796 
797  else if (l==4 && m==4)
798  {
799  /* Needed fits for collocation points and ringdown coefficient */
800  ampInspCP[0] = IMRPhenomT_Inspiral_Amp_CP1_44(eta, S, dchi, delta);
801  ampInspCP[1] = IMRPhenomT_Inspiral_Amp_CP2_44(eta, S, dchi, delta);
802  ampInspCP[2] = IMRPhenomT_Inspiral_Amp_CP3_44(eta, S, dchi, delta);
803  ampMergerCP1 = IMRPhenomT_Merger_Amp_CP1_44(eta, S, dchi, delta);
804  ampPeak = IMRPhenomT_PeakAmp_44(eta, S, dchi, delta);
805  ampRDC3 = IMRPhenomT_RD_Amp_C3_44(eta, S);
806 
807  fDAMP = evaluate_QNMfit_fdamp44(wf->afinal) / (wf->Mfinal); //damping frequency of 144 QNM
808  fDAMPn2 = evaluate_QNMfit_fdamp44n2(wf->afinal) / (wf->Mfinal); //damping frequency of 244 QNM
809 
810  fDAMP_prec = evaluate_QNMfit_fdamp44(wf->afinal_prec) / (wf->Mfinal);
811  fDAMPn2_prec = evaluate_QNMfit_fdamp44n2(wf->afinal_prec) / (wf->Mfinal);
812 
813  pAmp->tshift = IMRPhenomT_tshift_44(eta, S); //Peak time of l=4, m=4 mode
814 
815  /* PN Amplitude coefficients, defined in eq.A4 of https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf (before global rotation applied, see eq.13 of https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf) */
816 
817  pAmp->ampN = 0.0;
818  pAmp->amp0halfPNreal = 0.0;
819  pAmp->amp0halfPNimag = 0.0;
820 
821  pAmp->amp1PNreal = 0.751248226425348*(1 - 3*eta);
822  pAmp->amp1PNimag = 0.0;
823 
824  pAmp->amp1halfPNreal = 0.0;
825  pAmp->amp1halfPNimag = 0.0;
826 
827  pAmp->amp2PNreal = -4.049910893365739 + 14.489984730901032*eta - 5.9758381647470875*pow(eta,2);
828  pAmp->amp2PNimag = 0.0;
829 
830  pAmp->amp2halfPNreal = 0.751248226425348*(4*LAL_PI - 12*eta*LAL_PI);
831  pAmp->amp2halfPNimag = 0.751248226425348*(-2.854822555520438 + 13.189467666561313*eta);
832 
833  pAmp->amp3PNreal = -(-8*pow(0.7142857142857143,0.5)*(5.338016983016983 - (1088119*eta)/28600. + (146879*pow(eta,2))/2340. - (226097*pow(eta,3))/17160.))/9.;
834  pAmp->amp3PNimag = 0.0;
835 
836  pAmp->amp3halfPNreal = 0.0;
837  pAmp->amp3halfPNimag = 0.0;
838 
839  pAmp->amplog = 0.0;
840  }
841 
842  else if (l==5 && m==5)
843  {
844  /* Needed fits for collocation points and ringdown coefficient */
845  ampInspCP[0] = IMRPhenomT_Inspiral_Amp_CP1_55(eta, S, dchi, delta);
846  ampInspCP[1] = IMRPhenomT_Inspiral_Amp_CP2_55(eta, S, dchi, delta);
847  ampInspCP[2] = IMRPhenomT_Inspiral_Amp_CP3_55(eta, S, dchi, delta);
848  ampMergerCP1 = IMRPhenomT_Merger_Amp_CP1_55(eta, S, dchi, delta);
849  ampPeak = IMRPhenomT_PeakAmp_55(eta, S, dchi, delta);
850  ampRDC3 = IMRPhenomT_RD_Amp_C3_55(eta, S, dchi);
851 
852  fDAMP = evaluate_QNMfit_fdamp55(wf->afinal) / (wf->Mfinal); //damping frequency of 155 QNM
853  fDAMPn2 = evaluate_QNMfit_fdamp55n2(wf->afinal) / (wf->Mfinal); //damping frequency of 255 QNM
854 
855  fDAMP_prec = evaluate_QNMfit_fdamp55(wf->afinal_prec) / (wf->Mfinal);
856  fDAMPn2_prec = evaluate_QNMfit_fdamp55n2(wf->afinal_prec) / (wf->Mfinal);
857 
858  pAmp->tshift = IMRPhenomT_tshift_55(eta, S); //Peak time of l=5, m=5 mode
859 
860  /* PN Amplitude coefficients, defined in eq.A5 of https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf (before global rotation applied, see eq.13 of https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf) */
861 
862  pAmp->ampN = 0.0;
863  pAmp->amp0halfPNreal = 0.0;
864  pAmp->amp0halfPNimag = 0.0;
865 
866  pAmp->amp1PNreal = 0.0;
867  pAmp->amp1PNimag = 0.0;
868 
869  pAmp->amp1halfPNimag = 0.0;
870  pAmp->amp1halfPNreal = 0.8013768943966973*delta*(1 - 2*eta);
871 
872  pAmp->amp2PNreal = 0.0;
873  pAmp->amp2PNimag = 0.0;
874 
875  pAmp->amp2halfPNimag = 0.0;
876  pAmp->amp2halfPNreal = 0.8013768943966973*delta*(-6.743589743589744 + (688*eta)/39. - (256*pow(eta,2))/39.);
877 
878  pAmp->amp3PNimag = -3.0177162096765713*delta + 12.454250695829877*delta*eta;
879  pAmp->amp3PNreal = 12.58799882096634*delta - 25.175997641932675*delta*eta;
880 
881  pAmp->amp3halfPNreal = 0.0;
882  pAmp->amp3halfPNimag = 0.0;
883 
884  pAmp->amplog = 0.0;
885  }
886 
887  else
888  {
889  XLAL_ERROR(XLAL_EFUNC, "Mode not implemented in PhenomTHM. Modes available: [2,2], [2,1], [3,3], [4,4], [5,5].");
890  }
891 
892  /***********************************************************/
893  /************** RINGDOWN ANSATZ COEFFICIENTS ***************/
894  /***********************************************************/
895 
896  /* Ringdown ansatz coefficients as defined in in eq. [6-8] of Damour&Nagar 2014 (https://arxiv.org/pdf/1406.0401.pdf).
897  See also eq.26c-e of THM paper: https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf
898  Essentially, c3 is the only calibrated coefficient. c2 accounts for the effect of the first overtone in the early ringdown, and c1 and c4 fix the peak amplitude and null derivative at peak */
899 
900  pAmp->alpha1RD = 2*LAL_PI*fDAMP;
901  pAmp->alpha2RD = 2*LAL_PI*fDAMPn2;
902  pAmp->alpha21RD = 0.5*(pAmp->alpha2RD - pAmp->alpha1RD); //Coefficient c_2 of ringdown amplitude ansatz as defined in equation 7 of Damour&Nagar 2014 (https://arxiv.org/pdf/1406.0401.pdf) and eq.26d of https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf
903 
904  pAmp->alpha1RD_prec = 2*LAL_PI*fDAMP_prec;
905  pAmp->alpha2RD_prec = 2*LAL_PI*fDAMPn2_prec;
906  pAmp->alpha21RD_prec = 0.5*(pAmp->alpha2RD_prec - pAmp->alpha1RD_prec);
907 
908  pAmp->c3 = ampRDC3;
909  pAmp->c2 = 0.5*(pAmp->alpha2RD - pAmp->alpha1RD);
910  pAmp->c2_prec = 0.5*(pAmp->alpha2RD_prec - pAmp->alpha1RD_prec);
911 
912  phi = gsl_complex_rect(pAmp->c3,0); // Needed complex parameter for gsl hyperbolic functions
913  gsl_complex coshphi = gsl_complex_cosh(phi);
914  coshc3 = GSL_REAL(coshphi);
915  gsl_complex tanhphi = gsl_complex_tanh(phi);
916  tanhc3 = GSL_REAL(tanhphi);
917 
918  /* This condition ensures that the second derivative of the amplitude at the mode peak is always zero or negative, not producing then a second peak in the ringdown */
919  if(fabs(pAmp->c2) > fabs(0.5*pAmp->alpha1RD/tanhc3))
920  {
921  pAmp->c2 = -0.5*pAmp->alpha1RD/tanhc3;
922  }
923  if(fabs(pAmp->c2_prec) > fabs(0.5*pAmp->alpha1RD_prec/tanhc3))
924  {
925  pAmp->c2_prec = -0.5*pAmp->alpha1RD_prec/tanhc3;
926  }
927 
928 
929  pAmp->c1 = ampPeak*pAmp->alpha1RD*coshc3*coshc3/pAmp->c2;
930  pAmp->c1_prec = ampPeak*pAmp->alpha1RD_prec*coshc3*coshc3/pAmp->c2_prec;
931  pAmp->c4 = ampPeak - pAmp->c1*tanhc3;
932  pAmp->c4_prec = ampPeak - pAmp->c1_prec*tanhc3;
933 
934  /***********************************************************/
935  /************** INSPIRAL COEFFICIENTS SOLUTION *************/
936  /***********************************************************/
937 
938  /* In order to obtain the value of the 3 unknown extra coefficients of the inspiral amplitude ansatz, we need to solve a linear system
939  where the ansatz is imposed to match collocation point values at the corresponding collocation point times.
940  See equation 15 of THM paper: https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf */
941 
942  /* Initialise the extra coefficients to zero, so calls to the amplitude ansatz function returns pure PN */
943  pAmp->inspC1 = 0.0;
944  pAmp->inspC2 = 0.0;
945  pAmp->inspC3 = 0.0;
946 
947  REAL8 tinsppoints[3] = {-2000., -250., -150.0}; // Collocation point times as defined in Eq. 16 of PhenomTHM paper (https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf)
948 
949  /* We allocate a rank three linear system to solve the coefficients */
950  p = gsl_permutation_alloc(3);
951  b = gsl_vector_alloc(3);
952  x = gsl_vector_alloc(3);
953  A = gsl_matrix_alloc(3,3);
954 
955  REAL8 theta, omega, xx, x4, x4half, x5; // Needed powers of PN parameter x=v^2=(\omega_orb)^(2/3)=(0.5\omega_22)^(2/3)
956  REAL8 ampoffset; // Known PN part of the amplitude
957  REAL8 bi; // CP value - known PN amplitude vector
958 
959  /* In this loop over collocation points, the components of the solution vector b and the basis matrix A are established.
960  See equation 15 of THM paper: https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf */
961  for (UINT4 idx=0; idx<3; idx++)
962  {
963  theta = pow(-eta*tinsppoints[idx]/5,-1./8);
964  omega = IMRPhenomTomega22(tinsppoints[idx],theta, wf, pPhase); // Twice the orbital frequency at the collocation point time
965  xx = pow(0.5*omega,2./3); // PN expansion parameter of the amplitude
966  x4 = xx*xx*xx*xx; // Needed powers
967  x4half = x4*sqrt(xx);
968  x5 = x4*xx;
969 
970  ampoffset = creal(IMRPhenomTInspiralAmpAnsatzHM(xx, pAmp)); // Real part of the known PN contribution
971  bi = (1./pAmp->fac0/xx)*(ampInspCP[idx] - ampoffset); // Solution vector: collocation point value minus the know PN part of the ansatz, factored by the amplitude factor to not include it in each basis function (the powers of x)
972 
973  gsl_vector_set(b,idx,bi); // Set b vector
974 
975  /*Set basis matrix elements, Basis functions are the higher order powers of x that we add to the PN ansatz */
976  gsl_matrix_set(A,idx,0,x4);
977  gsl_matrix_set(A,idx,1,x4half);
978  gsl_matrix_set(A,idx,2,x5);
979  }
980 
981  /* We now solve the system A x = b via an LU decomposition */
982  gsl_linalg_LU_decomp(A,p,&s);
983  gsl_linalg_LU_solve(A,p,b,x);
984 
985  /* Set the extra pseudo-PN coefficients with the solutions of the system */
986  pAmp->inspC1 = gsl_vector_get(x,0);
987  pAmp->inspC2 = gsl_vector_get(x,1);
988  pAmp->inspC3 = gsl_vector_get(x,2);
989 
990  /* Free the gsl solver */
991  gsl_vector_free(b);
992  gsl_vector_free(x);
993  gsl_matrix_free(A);
994  gsl_permutation_free(p);
995 
996  /***********************************************************/
997  /************** MERGER COEFFICIENTS SOLUTION ***************/
998  /***********************************************************/
999 
1000 
1001  /* We need to solve for 4 unknown coefficients of the ansatz defined in IMRPhenomTMergerAmpAnsatzHM.
1002  Three of them are obtained by imposing continuity and differentiability at the boundary with the inspiral
1003  region (i.e in t = tCUT_Amp) and continuity with the ringdown region (i.e imposing amp(t_peak)=AmpPeak).
1004  Differentiability at the ringdown boundary is satisfied by default since both the merger and the ringdown
1005  ansatz describe a peak (derivative zero) at t_peak.
1006  4th coefficient is obtained by imposing the ansatz to match a collocation point at t=-25M.
1007  See equation 31 of THM paper: https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf */
1008 
1009  /* Reallocate gsl linear system, this time rank 4*/
1010  p = gsl_permutation_alloc(4);
1011  b = gsl_vector_alloc(4);
1012  x = gsl_vector_alloc(4);
1013  A = gsl_matrix_alloc(4,4);
1014 
1015  /* Set A_{0,i} and b_{0}: here we impose continuity with the inspiral region, essentially equating the value of the merger ansatz at the inspiral boundary time tCut
1016  with the value of the inspiral amplitude at that time. */
1017 
1018  theta = pow(-eta*tCut/5,-1./8);
1019  xx = pow(0.5*IMRPhenomTomega22(tCut,theta, wf, pPhase),2./3); // PN expansion parameter at tCut
1020  REAL8 ampinsp = copysign(1.0,creal(IMRPhenomTInspiralAmpAnsatzHM(xx, pAmp)))*cabs(IMRPhenomTInspiralAmpAnsatzHM(xx, pAmp)); // Value of the absolute inspiral amplitude, carrying the sign
1021  gsl_vector_set(b,0,ampinsp); // Set solution vector: Continuity with the inspiral region
1022 
1023  /* Here we compute the needed hyperbolic secant functions for the merger ansatz basis matrix */
1024  /* Time parameterisation of merger ansatz is in tau=t-tshift, so peak occurs at tau=0 */
1025  phi = gsl_complex_rect(pAmp->alpha1RD*(tCut-pAmp->tshift),0);
1026  gsl_complex sechphi = gsl_complex_sech(phi);
1027  REAL8 sech1 = GSL_REAL(sechphi);
1028  phi = gsl_complex_rect(2*pAmp->alpha1RD*(tCut-pAmp->tshift),0);
1029  sechphi = gsl_complex_sech(phi);
1030  REAL8 sech2 = GSL_REAL(sechphi);
1031 
1032  /* Set the first row of the basis matrix. Just the functions that multiply each unknown coefficient of the ansatz */
1033  gsl_matrix_set(A,0,0,1.0);
1034  gsl_matrix_set(A,0,1,sech1);
1035  gsl_matrix_set(A,0,2,pow(sech2,1./7));
1036  gsl_matrix_set(A,0,3,(tCut-pAmp->tshift)*(tCut-pAmp->tshift));
1037 
1038 
1039  /* Set A_{1,i} and b_{1}: here we impose a collocation point value, essentially equating the value of the merger ansatz at the collocation point time
1040  with the value of the collocation point. */
1041 
1042  gsl_vector_set(b,1,ampMergerCP1); // Imposing collocation point value
1043 
1044  /* Here we compute the needed hyperbolic secant functions for the merger ansatz basis matrix */
1045  phi = gsl_complex_rect(pAmp->alpha1RD*(tcpMerger-pAmp->tshift),0);
1046  sechphi = gsl_complex_sech(phi);
1047  sech1 = GSL_REAL(sechphi);
1048  phi = gsl_complex_rect(2*pAmp->alpha1RD*(tcpMerger-pAmp->tshift),0);
1049  sechphi = gsl_complex_sech(phi);
1050  sech2 = GSL_REAL(sechphi);
1051 
1052  /* Set the second row of the basis matrix. Just the functions that multiply each unknown coefficient of the ansatz */
1053  gsl_matrix_set(A,1,0,1.0);
1054  gsl_matrix_set(A,1,1,sech1);
1055  gsl_matrix_set(A,1,2,pow(sech2,1./7));
1056  gsl_matrix_set(A,1,3,(tcpMerger-pAmp->tshift)*(tcpMerger-pAmp->tshift));
1057 
1058  /* Set A_{2,i} and b_{2}: here we impose the peak amplitude value, essentially equating the value of the merger ansatz at the peak time tshift with
1059  with the value of the peak amplitude. */
1060 
1061  gsl_vector_set(b,2,ampPeak); // Imposing peak amplitude, that guarantees continuity with ringdown region.
1062 
1063  /* Set the second row of the basis matrix. Just the functions that multiply each unknown coefficient of the ansatz, once evaluated in the peak time */
1064  gsl_matrix_set(A,2,0,1.0);
1065  gsl_matrix_set(A,2,1,1.0); // sech(tau=0)=1
1066  gsl_matrix_set(A,2,2,1.0); // sech(tau=0)=1
1067  gsl_matrix_set(A,2,3,0.0); // tau*tau = 0 in tau=0
1068 
1069  /* Set A_{3,i} and b_{3}: here we impose the differentiability at the inspiral merger boundary, essentially by equating the value of the merger ansatz derivative at the
1070  boundary time tCut with the value of the inspiral amplitude derivative at that time. */
1071 
1072  /* First we compute the numerical derivatives with inspiral region for imposing differentiability at boundary.
1073  For this, first we compute the values of theta at two differentially close points in the boundary, from that we compute twice the orbital frequency at those points
1074  and then the value of the PN expansion parameter x at those points. Derivative is the amplitude difference between these two points weighted by the differential step.
1075  We carry the sign of the inspiral amplitude derivative. */
1076  REAL8 theta2 = pow(-eta*tCut/5.,-1./8);
1077  REAL8 theta1 = pow(-eta*(tCut-0.000001)/5,-1./8);
1078  REAL8 omega2 = IMRPhenomTomega22(tCut, theta2, wf, pPhase);
1079  REAL8 omega1 = IMRPhenomTomega22(tCut-0.000001, theta1, wf, pPhase);
1080  REAL8 x1 = pow(0.5*omega1,2./3);
1081  REAL8 x2 = pow(0.5*omega2,2./3);
1082  REAL8 dampMECO = copysign(1.0,creal(IMRPhenomTInspiralAmpAnsatzHM(x2, pAmp)))*(cabs(IMRPhenomTInspiralAmpAnsatzHM(x2, pAmp)) - cabs(IMRPhenomTInspiralAmpAnsatzHM(x1, pAmp)))/0.000001; // Value of inspiral derivative at boundary time.
1083 
1084  gsl_vector_set(b,3,dampMECO); // We set this value to the solution vector
1085 
1086  /* Here we compute the needed hyperbolic functions for the merger ansatz derivative basis matrix */
1087  phi = gsl_complex_rect(pAmp->alpha1RD*(tCut-pAmp->tshift),0);
1088  sechphi = gsl_complex_sech(phi);
1089  sech1 = GSL_REAL(sechphi);
1090  gsl_complex phi2 = gsl_complex_rect(2*pAmp->alpha1RD*(tCut-pAmp->tshift),0);
1091  sechphi = gsl_complex_sech(phi2);
1092  sech2 = GSL_REAL(sechphi);
1093  tanhphi = gsl_complex_tanh(phi);
1094  REAL8 tanh = GSL_REAL(tanhphi);
1095  gsl_complex sinhphi = gsl_complex_sinh(phi2);
1096  REAL8 sinh = GSL_REAL(sinhphi);
1097 
1098  /* Basis functions of the analytical time derivative of the merger ansatz */
1099  REAL8 aux1 = -pAmp->alpha1RD*sech1*tanh;
1100  REAL8 aux2 = (-2./7)*pAmp->alpha1RD*sinh*pow(sech2,8./7);
1101  REAL8 aux3 = 2*(tCut-pAmp->tshift);
1102 
1103  /*We set the value of the basis matrix with the previous elements */
1104  gsl_matrix_set(A,3,0,0.0);
1105  gsl_matrix_set(A,3,1,aux1);
1106  gsl_matrix_set(A,3,2,aux2);
1107  gsl_matrix_set(A,3,3,aux3);
1108 
1109  /* Once we have set up the system, we now solve the system A x = b via an LU decomposition */
1110  gsl_linalg_LU_decomp(A,p,&s);
1111  gsl_linalg_LU_solve(A,p,b,x);
1112 
1113  /* Initialize the unkown merger ansatz coefficients with the solution of the linear system */
1114  pAmp->mergerC1 = gsl_vector_get(x,0);
1115  pAmp->mergerC2 = gsl_vector_get(x,1);
1116  pAmp->mergerC3 = gsl_vector_get(x,2);
1117  pAmp->mergerC4 = gsl_vector_get(x,3);
1118 
1119  /* Deallocate the gsl linear system objects */
1120  gsl_vector_free(b);
1121  gsl_vector_free(x);
1122  gsl_matrix_free(A);
1123  gsl_permutation_free(p);
1124 
1125 
1126  /************************************************************/
1127  /*** COMPLEX AMPLITUDE PHASING AT INSPIRAL MERGER BOUNDARY **/
1128  /************************************************************/
1129 
1130  /* Inspiral amplitude is a complex quantity, and then its argument contributes to the phase and frequency
1131  of the modes. In order to not have a phase/frequency discontinuity between inspiral and merger regions,
1132  we need to store the value of this phase contribution at the boundary, so it can be added
1133  to the merger phase/frequency ansatz later. See discussion on Sec. IID of THM paper: https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf*/
1134 
1135 
1136  pAmp->omegaCutPNAMP = -(ComplexAmpOrientation(x2, pAmp) - ComplexAmpOrientation(x1, pAmp))/0.000001; // Derivative of the phase contribution at boundary. Needed for frequency continuity
1137  pAmp->phiCutPNAMP = atan2(cimag(IMRPhenomTInspiralAmpAnsatzHM(x2, pAmp)),creal(IMRPhenomTInspiralAmpAnsatzHM(x2, pAmp))); // Phase contribution at boundary. Needed for phase continuity
1138 
1139  /* We need to compute an extra Pi factor for adding to the merger phase if the inspiral amplitude real part is negative */
1140  if(copysign(1.0,creal(IMRPhenomTInspiralAmpAnsatzHM(x2, pAmp)))==-1.0)
1141  {
1142  pAmp->phiCutPNAMP += LAL_PI;
1143  }
1144 
1145  return XLAL_SUCCESS;
1146 }
1147 
1148 /* Function for populating the IMRPhenomTHMPhaseStruct.
1149  This will solve the linear systems for obtaining lm phase ansatz coefficients from lm frequency collocation points.
1150  Inspiral is not present here since for (l,m)!=(2,2) the inspiral phase is rescaled from the (2,2) phase.
1151  For each mode, ringdown quantities are defined and stored and the merger linear system of free coefficients is solved.
1152  Essentially, the code is the same than for the 22 merger-ringdown, but with the right quantities for each mode. */
1153 
1155 {
1156 
1157  REAL8 eta = wf->eta; // Symmetric mass ratio
1158  REAL8 S = wf->Shat; // Dimensionless effective spin parameters employed for fit evaluation
1159  REAL8 dchi = wf->dchi; // Dimensionless spin difference chi1L - chi2L
1160  REAL8 delta = wf->delta; // PN Asymmetry parameter
1161  REAL8 tCut = tCUT_Freq; // Inspiral ending time (t=-150M)
1162 
1163  /*Store twice orbital frequency at t=-150, for higher mode reconstruction*/
1164  REAL8 thetaCut = pow(-eta*tCut/5,-1./8);
1165  REAL8 omegaCut = IMRPhenomTomega22(tCut, thetaCut, wf, pPhase);
1166 
1167  REAL8 omegaCutPNAMP = pAmplm->omegaCutPNAMP; // Value of the phase derivative coming from complex inspiral amplitude at the boundary time.
1168 
1169  pPhaseHM->emm = m; // Magnetic number of the mode
1170 
1171  /* GSL objects for solving system of equations via LU decomposition */
1172  gsl_vector *b, *x;
1173  gsl_matrix *A;
1174  gsl_permutation *p;
1175  int s;
1176 
1177  REAL8 fRING, fDAMP, fDAMPn2; // Ringdown and damping frequencies of each mode
1178  REAL8 omegaCutBar, omegaMergerCP; // Rescaled frequencies at the inspiral boundary time tCut and collocation point time.
1179  REAL8 domegaPeak; // Rescaled frequency derivative at the ringdown boundary
1180 
1181  REAL8 theta2 = pow(-eta*tCut/5.,-1./8);
1182  REAL8 theta1 = pow(-eta*(tCut-0.0000001)/5,-1./8);
1183  REAL8 domegaCut = (IMRPhenomTomega22(tCut, theta2, wf, pPhase) - IMRPhenomTomega22(tCut-0.0000001, theta1, wf, pPhase))/(0.0000001); // Insoiral frequency derivative at the boundary time.
1184 
1185  /* Set quantities for each mode.
1186  Essentially, we compute the needed ringdown and damping frequencies of each mode for the ringdown ansatz:
1187  -Coefficient c1 is defined in Eq. [9] of Damour&Nagar 2014 (10.1103/PhysRevD.90.024054, https://arxiv.org/abs/1406.0401).
1188  -Coefficients c2 and c3 are calibrated to NR/Teukolsky data.
1189  -Coefficient c4 is set to zero.
1190  We also store the value of the rescaled frequencies and frequency derivatives at the boundaries, and the collocation point value. */
1191 
1192 
1193  if (l==2 && m==2)
1194  {
1195  /* Ringdown and damping frequencies*/
1196  fRING = evaluate_QNMfit_fring22(wf->afinal) / (wf->Mfinal);
1197  fDAMP = evaluate_QNMfit_fdamp22(wf->afinal) / (wf->Mfinal);
1198  fDAMPn2 = evaluate_QNMfit_fdamp22n2(wf->afinal) / (wf->Mfinal);
1199 
1200  pPhaseHM->omegaRING = 2*LAL_PI*fRING;
1201  pPhaseHM->alpha1RD = 2*LAL_PI*fDAMP;
1202  pPhaseHM->alpha2RD = 2*LAL_PI*fDAMPn2;
1203  pPhaseHM->alpha21RD = 0.5*(pPhaseHM->alpha2RD - pPhaseHM->alpha1RD);
1204 
1207 
1208 
1209  omegaCutBar = 1. - (omegaCut + omegaCutPNAMP)/pPhaseHM->omegaRING; // Value of the rescaled inspiral frequency at the boundary time. Notice that it includes the contribution from the complex amplitude.
1210  omegaMergerCP = 1. - IMRPhenomT_Merger_Freq_CP1_22(eta, S, dchi, delta)/pPhaseHM->omegaRING; // Value of the rescaled collocation point.
1211  pPhaseHM->omegaPeak = IMRPhenomT_PeakFrequency_22(eta, S, dchi, delta); // Value of the frequency at the merger-ringdown boundary.
1212 
1213  domegaCut = -domegaCut/pPhaseHM->omegaRING; //Rescaled frequency derivative at the inspiral boundary
1214  domegaPeak = -(IMRPhenomTRDOmegaAnsatzHM(0.0000001, pPhaseHM) - IMRPhenomTRDOmegaAnsatzHM(0., pPhaseHM))/(0.0000001)/pPhaseHM->omegaRING; //Rescaled numerical frequency derivative at the ringdown boundary
1215  pPhaseHM->domegaPeak = domegaPeak;
1216 
1217  /* Ringdown ansatz coefficients, as defined Damour&Nagar 2014 (10.1103/PhysRevD.90.024054, https://arxiv.org/abs/1406.0401), with the difference that we set c4=0 and we free c2 to acomodate a fit. */
1218  pPhaseHM->c3 = IMRPhenomT_RD_Freq_D3_22(eta, S, dchi, delta);
1219  pPhaseHM->c2 = IMRPhenomT_RD_Freq_D2_22(eta, S, dchi, delta);
1220  pPhaseHM->c4 = 0.0;
1221  pPhaseHM->c1 = (1 + pPhaseHM->c3 + pPhaseHM->c4)*(pPhaseHM->omegaRING - pPhaseHM->omegaPeak)/pPhaseHM->c2/(pPhaseHM->c3 + 2*pPhaseHM->c4);
1222  pPhaseHM->c1_prec = (1 + pPhaseHM->c3 + pPhaseHM->c4)*(pPhaseHM->omegaRING_prec - pPhaseHM->omegaPeak)/pPhaseHM->c2/(pPhaseHM->c3 + 2*pPhaseHM->c4);
1223 
1224  }
1225 
1226  else if (l==2 && m==1)
1227  {
1228  /* Ringdown and damping frequencies*/
1229  fRING = evaluate_QNMfit_fring21(wf->afinal) / (wf->Mfinal);
1230  fDAMP = evaluate_QNMfit_fdamp21(wf->afinal) / (wf->Mfinal);
1231  fDAMPn2 = evaluate_QNMfit_fdamp21n2(wf->afinal) / (wf->Mfinal);
1232 
1233  pPhaseHM->omegaRING = 2*LAL_PI*fRING;
1234  pPhaseHM->alpha1RD = 2*LAL_PI*fDAMP;
1235  pPhaseHM->alpha2RD = 2*LAL_PI*fDAMPn2;
1236  pPhaseHM->alpha21RD = 0.5*(pPhaseHM->alpha2RD - pPhaseHM->alpha1RD);
1237 
1240 
1241  omegaCut = 0.5*omegaCut; // Frequency at the inspiral boundary coming from the 2,2 rescaling
1242  omegaCutBar = 1. - (omegaCut + omegaCutPNAMP)/pPhaseHM->omegaRING; // Value of the rescaled inspiral frequency at the boundary time. Notice that it includes the contribution from the complex amplitude.
1243  omegaMergerCP = 1. - IMRPhenomT_Merger_Freq_CP1_21(eta, S, dchi, delta)/pPhaseHM->omegaRING; // Value of the rescaled collocation point.
1244  pPhaseHM->omegaPeak = IMRPhenomT_PeakFrequency_21(eta, S, dchi, delta); // Value of the frequency at the merger-ringdown boundary.
1245 
1246  /* Ringdown ansatz coefficients, as defined Damour&Nagar 2014 (10.1103/PhysRevD.90.024054, https://arxiv.org/abs/1406.0401), with the difference that we set c4=0 and we free c2 to acomodate a fit. */
1247  pPhaseHM->c3 = IMRPhenomT_RD_Freq_D3_21(eta, S, dchi, delta);
1248  pPhaseHM->c2 = IMRPhenomT_RD_Freq_D2_21(eta, S, dchi, delta);
1249  pPhaseHM->c4 = 0.0;
1250  pPhaseHM->c1 = (1 + pPhaseHM->c3 + pPhaseHM->c4)*(pPhaseHM->omegaRING - pPhaseHM->omegaPeak)/pPhaseHM->c2/(pPhaseHM->c3 + 2*pPhaseHM->c4);
1251  pPhaseHM->c1_prec = (1 + pPhaseHM->c3 + pPhaseHM->c4)*(pPhaseHM->omegaRING_prec - pPhaseHM->omegaPeak)/pPhaseHM->c2/(pPhaseHM->c3 + 2*pPhaseHM->c4);
1252 
1253  domegaCut = -0.5*domegaCut/pPhaseHM->omegaRING; //Rescaled frequency derivative at the inspiral boundary
1254  domegaPeak = -(IMRPhenomTRDOmegaAnsatzHM(0.00001, pPhaseHM) - IMRPhenomTRDOmegaAnsatzHM(0., pPhaseHM))/(0.00001)/pPhaseHM->omegaRING; //Rescaled numerical frequency derivative at the ringdown boundary
1255  pPhaseHM->domegaPeak = domegaPeak;
1256 
1257  }
1258 
1259  else if (l==3 && m==3)
1260  {
1261  /* Ringdown and damping frequencies*/
1262  fRING = evaluate_QNMfit_fring33(wf->afinal) / (wf->Mfinal);
1263  fDAMP = evaluate_QNMfit_fdamp33(wf->afinal) / (wf->Mfinal);
1264  fDAMPn2 = evaluate_QNMfit_fdamp33n2(wf->afinal) / (wf->Mfinal);
1265 
1266  pPhaseHM->omegaRING = 2*LAL_PI*fRING;
1267  pPhaseHM->alpha1RD = 2*LAL_PI*fDAMP;
1268  pPhaseHM->alpha2RD = 2*LAL_PI*fDAMPn2;
1269  pPhaseHM->alpha21RD = 0.5*(pPhaseHM->alpha2RD - pPhaseHM->alpha1RD);
1270 
1273 
1274  omegaCut = 1.5*omegaCut; // Frequency at the inspiral boundary coming from the 2,2 rescaling
1275  omegaCutBar = 1. - (omegaCut + omegaCutPNAMP)/pPhaseHM->omegaRING; // Value of the rescaled inspiral frequency at the boundary time. Notice that it includes the contribution from the complex amplitude.
1276  omegaMergerCP = 1. - IMRPhenomT_Merger_Freq_CP1_33(eta, S, dchi, delta)/pPhaseHM->omegaRING; // Value of the rescaled collocation point.
1277  pPhaseHM->omegaPeak = IMRPhenomT_PeakFrequency_33(eta, S, dchi); // Value of the frequency at the merger-ringdown boundary.
1278 
1279  /* Ringdown ansatz coefficients, as defined Damour&Nagar 2014 (10.1103/PhysRevD.90.024054, https://arxiv.org/abs/1406.0401), with the difference that we set c4=0 and we free c2 to acomodate a fit. */
1280  pPhaseHM->c3 = IMRPhenomT_RD_Freq_D3_33(eta, S, dchi, delta);
1281  pPhaseHM->c2 = IMRPhenomT_RD_Freq_D2_33(eta, S, dchi, delta);
1282  pPhaseHM->c4 = 0.0;
1283  pPhaseHM->c1 = (1 + pPhaseHM->c3 + pPhaseHM->c4)*(pPhaseHM->omegaRING - pPhaseHM->omegaPeak)/pPhaseHM->c2/(pPhaseHM->c3 + 2*pPhaseHM->c4);
1284  pPhaseHM->c1_prec = (1 + pPhaseHM->c3 + pPhaseHM->c4)*(pPhaseHM->omegaRING_prec - pPhaseHM->omegaPeak)/pPhaseHM->c2/(pPhaseHM->c3 + 2*pPhaseHM->c4);
1285 
1286  domegaCut = -1.5*domegaCut/pPhaseHM->omegaRING; //Rescaled frequency derivative at the inspiral boundary
1287  domegaPeak = -(IMRPhenomTRDOmegaAnsatzHM(0.00001, pPhaseHM) - IMRPhenomTRDOmegaAnsatzHM(0., pPhaseHM))/(0.00001)/pPhaseHM->omegaRING; //Rescaled numerical frequency derivative at the ringdown boundary
1288  pPhaseHM->domegaPeak = domegaPeak;
1289 
1290  }
1291 
1292  else if (l==4 && m==4)
1293  {
1294  /* Ringdown and damping frequencies*/
1295  fRING = evaluate_QNMfit_fring44(wf->afinal) / (wf->Mfinal);
1296  fDAMP = evaluate_QNMfit_fdamp44(wf->afinal) / (wf->Mfinal);
1297  fDAMPn2 = evaluate_QNMfit_fdamp44n2(wf->afinal) / (wf->Mfinal);
1298 
1299  pPhaseHM->omegaRING = 2*LAL_PI*fRING;
1300  pPhaseHM->alpha1RD = 2*LAL_PI*fDAMP;
1301  pPhaseHM->alpha2RD = 2*LAL_PI*fDAMPn2;
1302  pPhaseHM->alpha21RD = 0.5*(pPhaseHM->alpha2RD - pPhaseHM->alpha1RD);
1303 
1306 
1307  omegaCut = 2*omegaCut; // Frequency at the inspiral boundary coming from the 2,2 rescaling
1308  omegaCutBar = 1. - (omegaCut + omegaCutPNAMP)/pPhaseHM->omegaRING; // Value of the rescaled inspiral frequency at the boundary time. Notice that it includes the contribution from the complex amplitude.
1309  omegaMergerCP = 1. - IMRPhenomT_Merger_Freq_CP1_44(eta, S, dchi, delta)/pPhaseHM->omegaRING; // Value of the rescaled collocation point.
1310  pPhaseHM->omegaPeak = IMRPhenomT_PeakFrequency_44(eta, S, dchi, delta); // Value of the frequency at the merger-ringdown boundary.
1311 
1312  /* Ringdown ansatz coefficients, as defined Damour&Nagar 2014 (10.1103/PhysRevD.90.024054, https://arxiv.org/abs/1406.0401), with the difference that we set c4=0 and we free c2 to acomodate a fit. */
1313  pPhaseHM->c3 = IMRPhenomT_RD_Freq_D3_44(eta, S, dchi, delta);
1314  pPhaseHM->c2 = IMRPhenomT_RD_Freq_D2_44(eta, S, dchi, delta);
1315  pPhaseHM->c4 = 0.0;
1316  pPhaseHM->c1 = (1 + pPhaseHM->c3 + pPhaseHM->c4)*(pPhaseHM->omegaRING - pPhaseHM->omegaPeak)/pPhaseHM->c2/(pPhaseHM->c3 + 2*pPhaseHM->c4);
1317  pPhaseHM->c1_prec = (1 + pPhaseHM->c3 + pPhaseHM->c4)*(pPhaseHM->omegaRING_prec - pPhaseHM->omegaPeak)/pPhaseHM->c2/(pPhaseHM->c3 + 2*pPhaseHM->c4);
1318 
1319  domegaCut = -2.0*domegaCut/pPhaseHM->omegaRING; //Rescaled frequency derivative at the inspiral boundary
1320  domegaPeak = -(IMRPhenomTRDOmegaAnsatzHM(0.0000001, pPhaseHM) - IMRPhenomTRDOmegaAnsatzHM(0., pPhaseHM))/(0.0000001)/pPhaseHM->omegaRING; //Rescaled numerical frequency derivative at the ringdown boundary
1321  pPhaseHM->domegaPeak = domegaPeak;
1322 
1323  }
1324 
1325  else if (l==5 && m==5)
1326  {
1327  /* Ringdown and damping frequencies*/
1328  fRING = evaluate_QNMfit_fring55(wf->afinal) / (wf->Mfinal);
1329  fDAMP = evaluate_QNMfit_fdamp55(wf->afinal) / (wf->Mfinal);
1330  fDAMPn2 = evaluate_QNMfit_fdamp55n2(wf->afinal) / (wf->Mfinal);
1331 
1332  pPhaseHM->omegaRING = 2*LAL_PI*fRING;
1333  pPhaseHM->alpha1RD = 2*LAL_PI*fDAMP;
1334  pPhaseHM->alpha2RD = 2*LAL_PI*fDAMPn2;
1335  pPhaseHM->alpha21RD = 0.5*(pPhaseHM->alpha2RD - pPhaseHM->alpha1RD);
1336 
1339 
1340  omegaCut = 2.5*omegaCut; // Frequency at the inspiral boundary coming from the 2,2 rescaling
1341  omegaCutBar = 1. - (omegaCut + omegaCutPNAMP)/pPhaseHM->omegaRING; // Value of the rescaled inspiral frequency at the boundary time. Notice that it includes the contribution from the complex amplitude.
1342  omegaMergerCP = 1. - IMRPhenomT_Merger_Freq_CP1_55(eta, S, dchi, delta)/pPhaseHM->omegaRING; // Value of the rescaled collocation point.
1343  pPhaseHM->omegaPeak = IMRPhenomT_PeakFrequency_55(eta, S, dchi, delta); // Value of the frequency at the merger-ringdown boundary.
1344 
1345  /* Ringdown ansatz coefficients, as defined Damour&Nagar 2014 (10.1103/PhysRevD.90.024054, https://arxiv.org/abs/1406.0401), with the difference that we set c4=0 and we free c2 to acomodate a fit. */
1346  pPhaseHM->c3 = IMRPhenomT_RD_Freq_D3_55(eta, S, dchi, delta);
1347  pPhaseHM->c2 = IMRPhenomT_RD_Freq_D2_55(eta, S, dchi, delta);
1348  pPhaseHM->c4 = 0.0;
1349  pPhaseHM->c1 = (1 + pPhaseHM->c3 + pPhaseHM->c4)*(pPhaseHM->omegaRING - pPhaseHM->omegaPeak)/pPhaseHM->c2/(pPhaseHM->c3 + 2*pPhaseHM->c4);
1350  pPhaseHM->c1_prec = (1 + pPhaseHM->c3 + pPhaseHM->c4)*(pPhaseHM->omegaRING_prec - pPhaseHM->omegaPeak)/pPhaseHM->c2/(pPhaseHM->c3 + 2*pPhaseHM->c4);
1351 
1352  domegaCut = -2.5*domegaCut/pPhaseHM->omegaRING; //Rescaled frequency derivative at the inspiral boundary
1353  domegaPeak = -(IMRPhenomTRDOmegaAnsatzHM(0.0000001, pPhaseHM) - IMRPhenomTRDOmegaAnsatzHM(0., pPhaseHM))/(0.0000001)/pPhaseHM->omegaRING; //Rescaled numerical frequency derivative at the ringdown boundary
1354  pPhaseHM->domegaPeak = domegaPeak;
1355 
1356  }
1357 
1358  else
1359  {
1360  XLAL_ERROR(XLAL_EFUNC, "Mode not implemented in PhenomTHM. Modes available: [2,2], [2,1], [3,3], [4,4], [5,5].");
1361  }
1362 
1363  /* In order to obtain the value of the 3 free coefficients of the ansatz defined in IMRPhenomTMergerOmegaAnsatzHM, we need to solve a linear system
1364  where the ansatz is imposed to match a collocation point value at t=-25M and to satisfy continuity with the inspiral ansatz and differentiability with the ringdown ansatz.
1365  Notice that the ansatz definition IMRPhenomTMergerOmegaAnsatzHM differs from eq [27-28] of PhenomTHM paper (https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf)
1366  in that here 2 of the coefficients are analytically solved for imposing continuity with the ringdown ansatz and differentiability with the inspiral ansatz.
1367 
1368  Reminder: the ansatz described in IMRPhenomTMergerOmegaAnsatzHM corresponds to the rescaled frequency \bar{\omega}=1 - (\omega / \omega_ring) (eq. 27 of https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf),
1369  so the system is solved for the rescaled frequency. For the analytical phase of IMRPhenomTMergerPhaseAnsatzHM, which is the quantity employed
1370  in the waveform construction, the factors are already included to produce the correct phase. */
1371 
1372  p = gsl_permutation_alloc(3);
1373  b = gsl_vector_alloc(3);
1374  x = gsl_vector_alloc(3);
1375  A = gsl_matrix_alloc(3,3);
1376 
1377  /* This is essentially the same procedure as in IMRPhenomTSetPhase22Coefficients */
1378 
1379  /* Set linear system */
1380 
1381  /* A_{0,i}, imposing continuity at the inspiral boundary. */
1382 
1383  gsl_complex phi = gsl_complex_rect(pPhaseHM->alpha1RD*tCut,0);
1384  gsl_complex arcsinhphi = gsl_complex_arcsinh(phi);
1385  REAL8 ascut = GSL_REAL(arcsinhphi);
1386  REAL8 ascut2 = ascut*ascut;
1387  REAL8 ascut3 = ascut*ascut2;
1388  REAL8 ascut4 = ascut*ascut3;
1389 
1390  gsl_vector_set(b,0,omegaCutBar - (1. - pPhaseHM->omegaPeak/pPhaseHM->omegaRING) - (pPhaseHM->domegaPeak/pPhaseHM->alpha1RD)*ascut);
1391 
1392  gsl_matrix_set(A,0,0,ascut2);
1393  gsl_matrix_set(A,0,1,ascut3);
1394  gsl_matrix_set(A,0,2,ascut4);
1395 
1396  /* A_{1,i}, imposing collocation point. */
1397 
1398  phi = gsl_complex_rect(pPhaseHM->alpha1RD*tcpMerger,0);
1399  arcsinhphi = gsl_complex_arcsinh(phi);
1400  REAL8 as025cut = GSL_REAL(arcsinhphi);
1401  REAL8 as025cut2 = as025cut*as025cut;
1402  REAL8 as025cut3 = as025cut*as025cut2;
1403  REAL8 as025cut4 = as025cut*as025cut3;
1404 
1405  gsl_vector_set(b,1,omegaMergerCP - (1. - pPhaseHM->omegaPeak/pPhaseHM->omegaRING) - (pPhaseHM->domegaPeak/pPhaseHM->alpha1RD)*as025cut);
1406 
1407  gsl_matrix_set(A,1,0,as025cut2);
1408  gsl_matrix_set(A,1,1,as025cut3);
1409  gsl_matrix_set(A,1,2,as025cut4);
1410 
1411  /* A_{2,i}, imposing differentiability at the ringdown boundary. */
1412 
1413  REAL8 dencut = sqrt(1.0 + tCut*tCut*pPhaseHM->alpha1RD*pPhaseHM->alpha1RD);
1414 
1415  gsl_matrix_set(A,2,0,2.0*pPhaseHM->alpha1RD*ascut/dencut);
1416  gsl_matrix_set(A,2,1,3.0*pPhaseHM->alpha1RD*ascut2/dencut);
1417  gsl_matrix_set(A,2,2,4.0*pPhaseHM->alpha1RD*ascut3/dencut);
1418 
1419  gsl_vector_set(b,2,domegaCut - pPhaseHM->domegaPeak/dencut);
1420 
1421  /* We now solve the system A x = b via an LU decomposition */
1422  gsl_linalg_LU_decomp(A,p,&s);
1423  gsl_linalg_LU_solve(A,p,b,x);
1424 
1425  /* Set merger phenomenological coefficients from solution to A x = b */
1426 
1427  pPhaseHM->omegaMergerC1 = gsl_vector_get(x,0);
1428  pPhaseHM->omegaMergerC2 = gsl_vector_get(x,1);
1429  pPhaseHM->omegaMergerC3 = gsl_vector_get(x,2);
1430 
1431  gsl_vector_free(b);
1432  gsl_vector_free(x);
1433  gsl_matrix_free(A);
1434  gsl_permutation_free(p);
1435 
1436  /* Solve phase offsets */
1437 
1438  pPhaseHM->phOffMerger = 0.;
1439  pPhaseHM->phOffRD = 0.;
1440 
1441  REAL8 thetabarCut = pow(-eta*tCut,-1./8);
1442  REAL8 phMECOinsp = (m/2.)*IMRPhenomTPhase22(tCut, thetabarCut, wf, pPhase);
1443  REAL8 phMECOmerger = IMRPhenomTMergerPhaseAnsatzHM(tCut, pPhaseHM);
1444 
1445  pPhaseHM->phOffMerger = phMECOinsp - phMECOmerger;
1446 
1447  pPhaseHM->phOffRD = IMRPhenomTMergerPhaseAnsatzHM(0, pPhaseHM);
1448 
1449  return XLAL_SUCCESS;
1450 }
1451 
1452 /* ---------------------------------------------------------------------------------------------------- */
1453 
1454 /* ************************************* */
1455 /* ******* ANSATZ DEFINITION ****** */
1456 /* ************************************* */
1457 
1458 /* ******* 22 ANSATZ ****** */
1459 /* Ansatz for inspiral-merger-ringdown regions of frequency and phase of the (2,2) mode.
1460  Amplitude ansatz for the (2,2) is included in the general (l,m) amplitude ansatz. */
1461 
1462 /* ******* FREQUENCY ANSATZ ****** */
1463 
1464 /* 22 inspiral frequency ansatz is contructed with a higher order extension of TaylorT3, as described in equation 9 of PhenomTHM paper (https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf) */
1466 
1467  REAL8 theta2 = theta*theta;
1468  REAL8 theta3 = theta2*theta;
1469  REAL8 theta4 = theta2*theta2;
1470  REAL8 theta5 = theta3*theta2;
1471  REAL8 theta6 = theta3*theta3;
1472  REAL8 theta7 = theta4*theta3;
1473 
1474  REAL8 fac = theta3/8;
1475  REAL8 logterm = (107*log(theta))/280.;
1476 
1477  REAL8 out = (1 + pPhase->omega1PN*theta2 + pPhase->omega1halfPN*theta3 + pPhase->omega2PN*theta4 + pPhase->omega2halfPN*theta5 + pPhase->omega3PN*theta6 + logterm*theta6 + pPhase->omega3halfPN*theta7);
1478 
1479  return 2*fac*out;
1480 }
1481 
1483 
1484  REAL8 theta8 = pow(theta,8);
1485  REAL8 theta9 = theta8*theta;
1486  REAL8 theta10 = theta9*theta;
1487  REAL8 theta11 = theta10*theta;
1488  REAL8 theta12 = theta11*theta;
1489  REAL8 theta13 = theta12*theta;
1490 
1491  REAL8 fac = theta*theta*theta/8;
1492 
1493  REAL8 taylort3 = IMRPhenomTTaylorT3(theta, pPhase);
1494 
1495  REAL8 out = pPhase->omegaInspC1*theta8 + pPhase->omegaInspC2*theta9 + pPhase->omegaInspC3*theta10 + pPhase->omegaInspC4*theta11 + pPhase->omegaInspC5*theta12 + pPhase->omegaInspC6*theta13;
1496 
1497  return taylort3 + 2*fac*out;
1498 }
1499 
1500 /* 22 merger frequency ansatz is a phenomenological expression described in equation [27-28] of PhenomTHM paper (https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf)
1501  The ansatz described here corresponds to the rescaled frequency \bar{\omega}=1 - (\omega / \omega_ring) of equation 27. */
1503 
1504  gsl_complex phi = gsl_complex_rect(pPhase->alpha1RD*t,0);
1505  gsl_complex arcsinhphi = gsl_complex_arcsinh(phi);
1506  REAL8 x = GSL_REAL(arcsinhphi);
1507  REAL8 x2 = x*x;
1508  REAL8 x3 = x2*x;
1509  REAL8 x4 = x2*x2;
1510 
1512 
1513  return out;
1514 }
1515 
1516 /* 22 ringdown frequency ansatz is the analytical derivate of the expression in IMRPhenomTRDPhaseAnsatz22, described in equation 24 of PhenomTHM paper (https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf) */
1518 
1519  REAL8 c3 = pPhase->c3;
1520  REAL8 c4 = pPhase->c4;
1521  REAL8 c2 = pPhase->c2;
1522  REAL8 c1 = pPhase->c1;
1523 
1524 
1525  REAL8 expC = exp(-1*c2*t);
1526  REAL8 expC2 = expC*expC;
1527 
1528 
1529 
1530  REAL8 num = c1*(-2*c2*c4*expC2 - c2*c3*expC);
1531  REAL8 den = 1 + c4*expC2 + c3*expC;
1532 
1533  return (num/den + pPhase->omegaRING);
1534 }
1535 
1536 /* ******** PHASE ANSATZ ********* */
1537 
1539 
1540  REAL8 eta = wf->eta;
1541 
1542  REAL8 aux = (pow(5,-0.625)*pow(eta,-1)*pow(thetabar,-5)*(-168 - 280*pPhase->omega1PN*pow(5,0.25)*pow(thetabar,2) - 420*pPhase->omega1halfPN*pow(5,0.375)*pow(thetabar,3) -
1543  840*pPhase->omega2PN*pow(5,0.5)*pow(thetabar,4) + 840*pPhase->omega2halfPN*log(thetabar)*pow(5,0.625)*pow(thetabar,5) - 321*pow(5,0.75)*pow(thetabar,6) +
1544  840*pPhase->omega3PN*pow(5,0.75)*pow(thetabar,6) + 321*log(thetabar*pow(5,0.125))*pow(5,0.75)*pow(thetabar,6) + 420*pPhase->omega3halfPN*pow(5,0.875)*pow(thetabar,7)))/84.;
1545 
1546  return aux;
1547 }
1548 
1549 /* 22 inspiral phase is obtained from analytical integral of the frequency ansatz, which containts TaylorT3 + the extra calibrated terms.
1550  Then, it depends on the omega{N}PN coefficients of TaylorT3 and on the solution to the extra coefficients omegaInspCi. */
1552 
1553  REAL8 eta = wf->eta;
1554 
1555  REAL8 aux = -(pow(5,-0.625)*pow(eta,-2)*pow(t,-1)*pow(thetabar,-7)*(3*(-107 + 280*pPhase->omega3PN)*pow(5,0.75) + 321*log(thetabar*pow(5,0.125))*pow(5,0.75) + 420*pPhase->omega3halfPN*thetabar*pow(5,0.875) +
1556  56*(25*pPhase->omegaInspC1 + 3*eta*t)*pow(thetabar,2) + 1050*pPhase->omegaInspC2*pow(5,0.125)*pow(thetabar,3) + 280*(3*pPhase->omegaInspC3 + eta*pPhase->omega1PN*t)*pow(5,0.25)*pow(thetabar,4) +
1557  140*(5*pPhase->omegaInspC4 + 3*eta*pPhase->omega1halfPN*t)*pow(5,0.375)*pow(thetabar,5) + 120*(5*pPhase->omegaInspC5 + 7*eta*pPhase->omega2PN*t)*pow(5,0.5)*pow(thetabar,6) +
1558  525*pPhase->omegaInspC6*pow(5,0.625)*pow(thetabar,7) + 105*eta*pPhase->omega2halfPN*t*log(-t)*pow(5,0.625)*pow(thetabar,7)))/84.;
1559 
1560  return aux + pPhase->phOffInsp;
1561 }
1562 
1563 /* 22 merger phase ansatz is an analytical integral of the 22 frequency ansatz of IMRPhenomTMergerOmegaAnsatz22 */
1565 
1566  gsl_complex phi = gsl_complex_rect(pPhase->alpha1RD*t,0);
1567  gsl_complex arcsinhphi = gsl_complex_arcsinh(phi);
1568  REAL8 x = GSL_REAL(arcsinhphi);
1569 
1570  REAL8 alpha1RD = pPhase->alpha1RD;
1571  REAL8 omegaPeak = pPhase->omegaPeak;
1572  REAL8 domegaPeak = pPhase->domegaPeak;
1573  REAL8 omegaRING = pPhase->omegaRING;
1574 
1575  REAL8 cc = pPhase->omegaMergerC1;
1576  REAL8 dd = pPhase->omegaMergerC2;
1577  REAL8 ee = pPhase->omegaMergerC3;
1578 
1579  REAL8 aux = omegaRING*t - omegaRING*(2*cc*t + 24*ee*t + 6*dd*t*x + domegaPeak*t*x*pow(alpha1RD,-1) + t*(1 - omegaPeak*pow(omegaRING,-1)) + cc*t*pow(x,2) + 12*ee*t*pow(x,2) + dd*t*pow(x,3) +
1580  ee*t*pow(x,4) - domegaPeak*pow(alpha1RD,-2)*pow(1 + pow(alpha1RD,2)*pow(t,2),0.5) - 6*dd*pow(alpha1RD,-1)*pow(1 + pow(alpha1RD,2)*pow(t,2),0.5) -
1581  2*cc*x*pow(alpha1RD,-1)*pow(1 + pow(alpha1RD,2)*pow(t,2),0.5) - 24*ee*x*pow(alpha1RD,-1)*pow(1 + pow(alpha1RD,2)*pow(t,2),0.5) -
1582  3*dd*pow(alpha1RD,-1)*pow(x,2)*pow(1 + pow(alpha1RD,2)*pow(t,2),0.5) - 4*ee*pow(alpha1RD,-1)*pow(x,3)*pow(1 + pow(alpha1RD,2)*pow(t,2),0.5));
1583 
1584  return (aux + pPhase->phOffMerger);
1585 }
1586 
1587 /* 22 ringdown phase ansatz is taken from equation 5 in Damour&Nagar 2014 (https://arxiv.org/pdf/1406.0401.pdf).
1588  By construction is the analytical integral of the ansatz in IMRPhenomTRDOmegaAnsatz22. */
1590 
1591  REAL8 c3 = pPhase->c3;
1592  REAL8 c4 = pPhase->c4;
1593  REAL8 c2 = pPhase->c2;
1594  REAL8 c1 = pPhase->c1_prec;
1595 
1596 
1597  REAL8 expC = exp(-c2*t);
1598  REAL8 expC2 = expC*expC;
1599 
1600  REAL8 num = 1 + c3*expC + c4*expC2;
1601  REAL8 den = 1 + c3 + c4;
1602  REAL8 aux = log(num/den);
1603 
1604  return (c1*aux + pPhase->omegaRING_prec*t + pPhase->phOffRD);
1605 }
1606 
1607 /* ---------------------------------------------------------------------------------------------------- */
1608 
1609 /* ******************* HIGHER MODES ANSATZ ******************* */
1610 
1611 /* Ansatz for inspiral-merger-ringdown regions of amplitude of (l,m) modes,
1612  and ansatz for merger-ringdown regions of frequency and phase of (l,m) modes.
1613  (inspiral region for frequency and phase is rescaled from the 22 result). */
1614 
1615 
1616 /* ***** FREQUENCY ANSATZ ********* */
1617 /* Same ansatz presented in IMRPhenomTMergerOmegaAnsatz22 and IMRPhenomTRDOmegaAnsatz22,
1618  but with ringdown quantities and coefficient fits for the particular (l,m) mode,
1619  passed through the IMRPhenomTHMPhaseStruct */
1620 
1622 
1623  gsl_complex phi = gsl_complex_rect(pPhase->alpha1RD*t,0);
1624  gsl_complex sinhphi = gsl_complex_arcsinh(phi);
1625  REAL8 x = GSL_REAL(sinhphi);
1626  REAL8 x2 = x*x;
1627  REAL8 x3 = x2*x;
1628  REAL8 x4 = x2*x2;
1629 
1631 
1632  return out;
1633 }
1634 
1636 
1637  REAL8 c3 = pPhase->c3;
1638  REAL8 c4 = pPhase->c4;
1639  REAL8 c2 = pPhase->c2;
1640  REAL8 c1 = pPhase->c1;
1641 
1642 
1643  REAL8 expC = exp(-c2*t);
1644  REAL8 expC2 = expC*expC;
1645 
1646 
1647 
1648  REAL8 num = c1*(-2*c2*c4*expC2 - c2*c3*expC);
1649  REAL8 den = 1 + c4*expC2 + c3*expC;
1650 
1651  return (num/den + pPhase->omegaRING);
1652 }
1653 
1654 /* ***** PHASE ANSATZ ********* */
1655 /* Same ansatz presented in IMRPhenomTMergerPhaseAnsatz22 and IMRPhenomTRDPhaseAnsatz22,
1656  but with ringdown quantities and coefficient fits for the particular (l,m) mode,
1657  passed through the IMRPhenomTHMPhaseStruct */
1658 
1660 
1661  gsl_complex phi = gsl_complex_rect(pPhase->alpha1RD*t,0);
1662  gsl_complex sinhphi = gsl_complex_arcsinh(phi);
1663  REAL8 x = GSL_REAL(sinhphi);
1664 
1665  REAL8 alpha1RD = pPhase->alpha1RD;
1666  REAL8 omegaPeak = pPhase->omegaPeak;
1667  REAL8 domegaPeak = pPhase->domegaPeak;
1668  REAL8 omegaRING = pPhase->omegaRING;
1669 
1670  REAL8 cc = pPhase->omegaMergerC1;
1671  REAL8 dd = pPhase->omegaMergerC2;
1672  REAL8 ee = pPhase->omegaMergerC3;
1673 
1674  REAL8 aux = omegaRING*t - omegaRING*(2*cc*t + 24*ee*t + 6*dd*t*x + domegaPeak*t*x*pow(alpha1RD,-1) + t*(1 - omegaPeak*pow(omegaRING,-1)) + cc*t*pow(x,2) + 12*ee*t*pow(x,2) + dd*t*pow(x,3) +
1675  ee*t*pow(x,4) - domegaPeak*pow(alpha1RD,-2)*pow(1 + pow(alpha1RD,2)*pow(t,2),0.5) - 6*dd*pow(alpha1RD,-1)*pow(1 + pow(alpha1RD,2)*pow(t,2),0.5) -
1676  2*cc*x*pow(alpha1RD,-1)*pow(1 + pow(alpha1RD,2)*pow(t,2),0.5) - 24*ee*x*pow(alpha1RD,-1)*pow(1 + pow(alpha1RD,2)*pow(t,2),0.5) -
1677  3*dd*pow(alpha1RD,-1)*pow(x,2)*pow(1 + pow(alpha1RD,2)*pow(t,2),0.5) - 4*ee*pow(alpha1RD,-1)*pow(x,3)*pow(1 + pow(alpha1RD,2)*pow(t,2),0.5));
1678 
1679  return (aux + pPhase->phOffMerger);
1680 }
1681 
1683 
1684  REAL8 c3 = pPhase->c3;
1685  REAL8 c4 = pPhase->c4;
1686  REAL8 c2 = pPhase->c2;
1687  REAL8 c1 = pPhase->c1_prec;
1688 
1689 
1690  REAL8 expC = exp(-1*c2*t);
1691  REAL8 expC2 = expC*expC;
1692 
1693  REAL8 num = 1 + c3*expC + c4*expC2;
1694  REAL8 den = 1 + c3 + c4;
1695  REAL8 aux = log(num/den);
1696 
1697  return (c1*aux + pPhase->omegaRING_prec*t + pPhase->phOffRD);
1698 }
1699 
1700 /* *********** AMPLITUDE ANSATZ ************** */
1701 
1702 /* Ansatz for the inspiral amplitude of a general (l,m) mode. PN amplitude coefficients for each mode are defined in IMRPhenomTSetHMAmplitudeCoefficients
1703  and are passed through the IMRPhenomTHMAmpStruct defined for the partucular mode. Expression is extended to higher order through the addition of three extra terms
1704  whose coefficients inspCi are solved in IMRPhenomTSetHMAmplitudeCoefficients.
1705  General form of the expression is described in eq [14] of PhenomTHM paper (https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf).*/
1707 {
1708  REAL8 fac = pAmp->fac0*x;
1709 
1710  REAL8 xhalf = sqrt(x);
1711  REAL8 x1half = x*xhalf;
1712  REAL8 x2 = x*x;
1713  REAL8 x2half = x2*xhalf;
1714  REAL8 x3 = x2*x;
1715  REAL8 x3half = x3*xhalf;
1716  REAL8 x4 = x2*x2;
1717  REAL8 x4half = x4*xhalf;
1718  REAL8 x5 = x3*x2;
1719 
1720  REAL8 ampreal = pAmp->ampN + pAmp->amp0halfPNreal*xhalf + pAmp->amp1PNreal*x + pAmp->amp1halfPNreal*x1half + pAmp->amp2PNreal*x2 + pAmp->amp2halfPNreal*x2half + pAmp->amp3PNreal*x3 + pAmp->amp3halfPNreal*x3half + pAmp->amplog*log(16*x)*x3;
1721  REAL8 ampimag = pAmp->amp0halfPNimag*xhalf + pAmp->amp1PNimag*x + pAmp->amp1halfPNimag*x1half + pAmp->amp2PNimag*x2 + pAmp->amp2halfPNimag*x2half + pAmp->amp3PNimag*x3 + pAmp->amp3halfPNimag*x3half;
1722  COMPLEX16 amp = crect(ampreal + pAmp->inspC1*x4 + pAmp->inspC2*x4half + pAmp->inspC3*x5, ampimag);
1723 
1724  return fac*amp;
1725 }
1726 
1727 /* Wrapper to compute directly the phase contribution of the complex inspiral amplitude at a specific value of the PN expansion parameter x.
1728 See equation 18 of PhenomTHM paper: https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf */
1730 {
1731  REAL8 xhalf = sqrt(xref);
1732  REAL8 x1half = xref*xhalf;
1733  REAL8 x2 = xref*xref;
1734  REAL8 x2half = x2*xhalf;
1735  REAL8 x3 = x2*xref;
1736  REAL8 x3half = x3*xhalf;
1737  REAL8 x4 = x2*x2;
1738  REAL8 x4half = x4*xhalf;
1739  REAL8 x5 = x3*x2;
1740 
1741  REAL8 ampreal = pAmp->ampN + pAmp->amp0halfPNreal*xhalf + pAmp->amp1PNreal*xref + pAmp->amp1halfPNreal*x1half + pAmp->amp2PNreal*x2 + pAmp->amp2halfPNreal*x2half + pAmp->amp3PNreal*x3 + pAmp->amp3halfPNreal*x3half + pAmp->amplog*log(16*xref)*x3;
1742  REAL8 ampimag = pAmp->amp0halfPNimag*xhalf + pAmp->amp1PNimag*xref + pAmp->amp1halfPNimag*x1half + pAmp->amp2PNimag*x2 + pAmp->amp2halfPNimag*x2half + pAmp->amp3PNimag*x3 + pAmp->amp3halfPNimag*x3half;
1743 
1744  return atan2(ampimag,ampreal + pAmp->inspC1*x4 + pAmp->inspC2*x4half + pAmp->inspC3*x5);
1745 }
1746 
1747 /* Ansatz for the merger amplitude of a general (l,m) mode. A phenomenological expression in terms of hyperbolic functions is employed,
1748  as described in eq 29 of PhenomTHM paper (https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf) */
1750 {
1751  double tpeak = pAmp->tshift;
1752 
1753  gsl_complex phi = gsl_complex_rect(pAmp->alpha1RD*(t-tpeak),0);
1754  gsl_complex phi2 = gsl_complex_rect(2*pAmp->alpha1RD*(t-tpeak),0);
1755  gsl_complex secphi = gsl_complex_sech(phi);
1756  gsl_complex secphi2 = gsl_complex_sech(phi2);
1757 
1758  REAL8 sech1 = GSL_REAL(secphi);
1759  REAL8 sech2 = GSL_REAL(secphi2);
1760 
1761  REAL8 aux = pAmp->mergerC1 + pAmp->mergerC2*sech1 + pAmp->mergerC3*pow(sech2,1./7) + pAmp->mergerC4*(t-tpeak)*(t-tpeak);
1762  return aux;
1763 }
1764 
1765 /* Ansatz for the ringdown amplitude of a general (l,m) mode. Equivalent to eq 4 of Damour&Nagar 2014 (https://arxiv.org/pdf/1406.0401.pdf).
1766  Also described in eq 25 of PhenomTHM paper (https://dcc.ligo.org/DocDB/0172/P2000524/001/PhenomTHM_SH-3.pdf). */
1768 {
1769  double tpeak = pAmp->tshift;
1770  REAL8 c3 = pAmp->c3;
1771  REAL8 c4 = pAmp->c4_prec;
1772  REAL8 c2 = pAmp->c2_prec;
1773  REAL8 c1 = pAmp->c1_prec;
1774 
1775  gsl_complex phi = gsl_complex_rect(c2*(t-tpeak) + c3,0);
1776  gsl_complex tanhphi = gsl_complex_tanh(phi);
1777  REAL8 tanh = GSL_REAL(tanhphi);
1778 
1779  REAL8 expAlpha = exp(-pAmp->alpha1RD_prec*(t-tpeak));
1780 
1781  return expAlpha*(c1*tanh + c4);
1782 }
1783 
1784 /* ---------------------------------------------------------------------------------------------------- */
1785 
1786 /* ****************************************** */
1787 /* ******* PIECEWISE EXPRESSIONS ************ */
1788 /* ****************************************** */
1789 
1790 /* ***** Functions for obtaining 22 phase and frequency for the whole time series **** */
1791 /* These are needed as separate functions from the general (l,m) piecewise functions because
1792  22 phase and frequency need to be precomputed before each mode structure is invoked. */
1793 
1795  REAL8 t,
1796  REAL8 theta,
1799 )
1800 {
1801  REAL8 w;
1802 
1803  if(t < pPhase->tEarly && pWF->inspVersion!=0) // If non-default recounstruction (4 regions) computes early inspiral region with pure TaylorT3
1804  {
1806  }
1807  else if(t < pPhase->tCut22 - pPhase->dtM) // For times earlier than the inspiral-merger boundary, computes inspiral frequency
1808  {
1810  }
1811  else if(t > 0) // For times later than the 22 peak amplitude time, computes ringdown frequencies
1812  {
1814  }
1815  else // Remaining thing is to compute merger frequency
1816  {
1818  w = pPhase->omegaRING*(1. - w); // This is done for correcting the rescaling in the merger, as explained in IMRPhenomTMergerOmegaAnsatz22
1819  }
1820 
1821  return w;
1822 }
1823 
1825  REAL8 t,
1826  REAL8 thetabar,
1829 )
1830 {
1831  REAL8 ph;
1832 
1833  if(t < pPhase->tEarly && pWF->inspVersion!=0) // If non-default recounstruction (4 regions) computes early inspiral region with pure TaylorT3
1834  {
1835  ph = IMRPhenomTInspiralPhaseTaylorT3(thetabar, pWF, pPhase);
1836  }
1837  else if(t < pPhase->tCut22 - pPhase->dtM) // For times earlier than the inspiral-merger boundary, computes inspiral phase
1838  {
1839  ph = IMRPhenomTInspiralPhaseAnsatz22(t, thetabar, pWF, pPhase);
1840  }
1841  else if(t > 0)
1842  {
1843  ph = IMRPhenomTRDPhaseAnsatz22(t, pPhase); // For times later than the 22 peak amplitude time, computes ringdown phase
1844  }
1845  else
1846  {
1847  ph = IMRPhenomTMergerPhaseAnsatz22(t, pPhase); // Remaining thing is to compute merger phase
1848  }
1849 
1850  return ph;
1851 }
1852 
1853 /* ***** Functions for obtaining (l,m) phase and amplitude for the whole time series.
1854 Explanation of the piece-wise function is the same as above, but now boundary times are different and there are only 3 regions for each mode. **** */
1855 
1857  REAL8 t,
1858  REAL8 phiInsp,
1859  IMRPhenomTHMPhaseStruct *pPhaseHM,
1860  UNUSED IMRPhenomTHMAmpStruct *pAmpHM
1861 )
1862 {
1863  REAL8 ph;
1864 
1865  if(t < tCUT_Freq)
1866  {
1867  ph = (pPhaseHM->emm/2.)*phiInsp;
1868  }
1869  else if(t > 0)
1870  {
1871  ph = IMRPhenomTRDPhaseAnsatzHM(t, pPhaseHM) - pAmpHM->phiCutPNAMP;
1872  }
1873  else
1874  {
1875  ph = IMRPhenomTMergerPhaseAnsatzHM(t, pPhaseHM) - pAmpHM->phiCutPNAMP;
1876  }
1877 
1878  return ph;
1879 }
1880 
1882  REAL8 t,
1883  UNUSED REAL8 x,
1884  IMRPhenomTHMAmpStruct *pAmp
1885 )
1886 {
1887  COMPLEX16 amp;
1888 
1889  if(t < tCUT_Amp)
1890  {
1891  amp = IMRPhenomTInspiralAmpAnsatzHM(x, pAmp);
1892  }
1893  else if(t > pAmp->tshift)
1894  {
1895  amp = IMRPhenomTRDAmpAnsatzHM(t, pAmp);
1896  }
1897  else
1898  {
1899  amp = IMRPhenomTMergerAmpAnsatzHM(t, pAmp);
1900  }
1901 
1902  return amp;
1903 }
1904 
1905 /* ---------------------------------------------------------------------------------------------------- */
1906 
1907 /******** Wrapper function for GSL root finder *****/
1908 
1909 double GetTimeOfFreq(double t, void *params)
1910 {
1911  struct FindRootParams *p;
1912 
1913  p = (struct FindRootParams *)params;
1914 
1915  REAL8 theta;
1916 
1917  if(t < p->pPhase->tEarly)
1918  {
1919  theta = pow(p->wf->eta*(p->pPhase->tt0-t)/5,-1./8);
1920  }
1921  else
1922  {
1923  theta = pow(p->wf->eta*(-t)/5,-1./8);
1924  }
1925 
1926  return(LAL_TWOPI*p->f0 - IMRPhenomTomega22(t, theta, p->wf, p->pPhase));
1927 }
1928 
1930 {
1931  REAL8 EulerRDslope = 2*LAL_PI*(evaluate_QNMfit_fring22(af) / (mf) - evaluate_QNMfit_fring21(af) / (mf)); // FIXME:
1932  if(af<0)
1933  {
1934  EulerRDslope = -EulerRDslope;
1935  }
1936 
1937  return EulerRDslope;
1938 }
const double c1
const double c2
static double IMRPhenomT_Inspiral_Amp_CP1_33(double eta, double S, double dchi, double delta)
static double IMRPhenomT_Inspiral_Freq_CP4_22(double eta, double S, double dchi, double delta)
static double IMRPhenomT_Inspiral_Amp_CP2_55(double eta, double S, double dchi, double delta)
static double IMRPhenomT_Inspiral_Amp_CP3_33(double eta, double S, double dchi, double delta)
static double evaluate_QNMfit_fdamp55(double finalDimlessSpin)
static double IMRPhenomT_Inspiral_Amp_CP2_22(double eta, double S, double dchi, double delta)
static double IMRPhenomT_RD_Amp_C3_33(double eta, double S)
static double IMRPhenomT_PeakFrequency_22(double eta, double S, double dchi, double delta)
static double IMRPhenomT_tshift_21(double eta, double S, double dchi)
static double IMRPhenomT_PeakFrequency_44(double eta, double S, double dchi, double delta)
static double IMRPhenomT_PeakAmp_22(double eta, double S, double dchi, double delta)
static double IMRPhenomT_Inspiral_Amp_CP3_22(double eta, double S, double dchi, double delta)
static double IMRPhenomT_RD_Amp_C3_21(double eta, double S, double dchi)
static double IMRPhenomT_RD_Freq_D3_55(double eta, double S, double dchi, double delta)
static double IMRPhenomT_PeakFrequency_21(double eta, double S, double dchi, double delta)
static double evaluate_QNMfit_fdamp22n2(double finalDimlessSpin)
static double evaluate_QNMfit_fdamp22(double finalDimlessSpin)
static double IMRPhenomT_Inspiral_Amp_CP3_44(double eta, double S, double dchi, double delta)
static double evaluate_QNMfit_fdamp21n2(double finalDimlessSpin)
static double evaluate_QNMfit_fdamp44n2(double finalDimlessSpin)
static double IMRPhenomT_Merger_Amp_CP1_44(double eta, double S, double dchi, double delta)
static double IMRPhenomT_Merger_Amp_CP1_22(double eta, double S, double dchi, double delta)
static double evaluate_QNMfit_fring33(double finalDimlessSpin)
static double IMRPhenomT_tshift_55(double eta, double S)
static double IMRPhenomT_Inspiral_Amp_CP1_44(double eta, double S, double dchi, double delta)
static double IMRPhenomT_RD_Freq_D2_21(double eta, double S, double dchi, double delta)
static double IMRPhenomT_Inspiral_Amp_CP2_21(double eta, double S, double dchi, double delta)
static double IMRPhenomT_RD_Freq_D2_33(double eta, double S, double dchi, double delta)
static double evaluate_QNMfit_fdamp33(double finalDimlessSpin)
static double IMRPhenomT_Merger_Freq_CP1_55(double eta, double S, double dchi, double delta)
static double evaluate_QNMfit_fdamp33n2(double finalDimlessSpin)
static double IMRPhenomT_RD_Amp_C3_44(double eta, double S)
static double evaluate_QNMfit_fdamp44(double finalDimlessSpin)
static double IMRPhenomT_Merger_Amp_CP1_33(double eta, double S, double dchi, double delta)
static double IMRPhenomT_RD_Freq_D3_22(double eta, double S, double dchi, double delta)
static double IMRPhenomT_Merger_Freq_CP1_22(double eta, double S, double dchi, double delta)
static double IMRPhenomT_PeakFrequency_33(double eta, double S, double dchi)
static double IMRPhenomT_Inspiral_Freq_CP3_22(double eta, double S, double dchi, double delta)
static double evaluate_QNMfit_fring22(double finalDimlessSpin)
static double IMRPhenomT_Inspiral_Amp_CP2_44(double eta, double S, double dchi, double delta)
static double IMRPhenomT_Inspiral_Amp_CP3_55(double eta, double S, double dchi, double delta)
static double IMRPhenomT_RD_Freq_D2_22(double eta, double S, double dchi, double delta)
static double IMRPhenomT_Merger_Freq_CP1_21(double eta, double S, double dchi, double delta)
static double IMRPhenomT_Inspiral_Freq_CP2_22(double eta, double S, double dchi, double delta)
static double IMRPhenomT_RD_Freq_D3_21(double eta, double S, double dchi, double delta)
static double IMRPhenomT_RD_Amp_C3_55(double eta, double S, double dchi)
static double IMRPhenomT_Merger_Amp_CP1_21(double eta, double S, double dchi, double delta)
static double IMRPhenomT_PeakAmp_55(double eta, double S, double dchi, double delta)
static double IMRPhenomT_RD_Freq_D3_33(double eta, double S, double dchi, double delta)
static double IMRPhenomT_PeakAmp_44(double eta, double S, double dchi, double delta)
static double IMRPhenomT_tshift_44(double eta, double S)
static double evaluate_QNMfit_fdamp21(double finalDimlessSpin)
static double evaluate_QNMfit_fring55(double finalDimlessSpin)
static double IMRPhenomT_PeakAmp_21(double eta, double S, double dchi, double delta)
static double IMRPhenomT_Inspiral_Freq_CP5_22(double eta, double S, double dchi, double delta)
static double evaluate_QNMfit_fring21(double finalDimlessSpin)
static double IMRPhenomT_Merger_Freq_CP1_44(double eta, double S, double dchi, double delta)
static double IMRPhenomT_PeakAmp_33(double eta, double S, double dchi, double delta)
static double IMRPhenomT_Inspiral_Amp_CP1_21(double eta, double S, double dchi, double delta)
static double IMRPhenomT_Merger_Freq_CP1_33(double eta, double S, double dchi, double delta)
static double IMRPhenomT_RD_Freq_D2_55(double eta, double S, double dchi, double delta)
static double IMRPhenomT_RD_Freq_D2_44(double eta, double S, double dchi, double delta)
static double IMRPhenomT_PeakFrequency_55(double eta, double S, double dchi, double delta)
static double IMRPhenomT_tshift_33(double eta, double S)
static double IMRPhenomT_RD_Freq_D3_44(double eta, double S, double dchi, double delta)
static double IMRPhenomT_Inspiral_Freq_CP1_22(double eta, double S, double dchi, double delta)
static double IMRPhenomT_Inspiral_Amp_CP1_22(double eta, double S, double dchi, double delta)
static double IMRPhenomT_RD_Amp_C3_22(double eta, double S)
static double evaluate_QNMfit_fring44(double finalDimlessSpin)
static double evaluate_QNMfit_fdamp55n2(double finalDimlessSpin)
static double IMRPhenomT_Inspiral_Amp_CP2_33(double eta, double S, double dchi, double delta)
static double IMRPhenomT_Merger_Amp_CP1_55(double eta, double S, double dchi, double delta)
static double IMRPhenomT_Inspiral_TaylorT3_t0(double eta, double S, double dchi, double delta)
Inspiral 22 frequency collocation points.
static double IMRPhenomT_Inspiral_Amp_CP3_21(double eta, double S, double dchi, double delta)
static double IMRPhenomT_Inspiral_Amp_CP1_55(double eta, double S, double dchi, double delta)
static double double delta
double IMRPhenomTRDPhaseAnsatz22(REAL8 t, IMRPhenomTPhase22Struct *pPhase)
double IMRPhenomTMergerOmegaAnsatz22(REAL8 t, IMRPhenomTPhase22Struct *pPhase)
COMPLEX16 IMRPhenomTInspiralAmpAnsatzHM(REAL8 x, IMRPhenomTHMAmpStruct *pAmp)
double IMRPhenomTInspiralOmegaAnsatz22(REAL8 theta, IMRPhenomTPhase22Struct *pPhase)
double IMRPhenomTomega22(REAL8 t, REAL8 theta, IMRPhenomTWaveformStruct *pWF, IMRPhenomTPhase22Struct *pPhase)
double IMRPhenomTInspiralPhaseAnsatz22(REAL8 t, REAL8 thetabar, IMRPhenomTWaveformStruct *wf, IMRPhenomTPhase22Struct *pPhase)
double IMRPhenomTRDOmegaAnsatzHM(REAL8 t, IMRPhenomTHMPhaseStruct *pPhase)
int IMRPhenomTSetHMAmplitudeCoefficients(int l, int m, IMRPhenomTHMAmpStruct *pAmp, IMRPhenomTPhase22Struct *pPhase, IMRPhenomTWaveformStruct *wf)
REAL8 GetEulerSlope(REAL8 af, REAL8 mf)
double GetTimeOfFreq(double t, void *params)
double IMRPhenomTMergerPhaseAnsatz22(REAL8 t, IMRPhenomTPhase22Struct *pPhase)
double IMRPhenomTMergerAmpAnsatzHM(REAL8 t, IMRPhenomTHMAmpStruct *pAmp)
double IMRPhenomTRDOmegaAnsatz22(REAL8 t, IMRPhenomTPhase22Struct *pPhase)
double ComplexAmpOrientation(REAL8 xref, IMRPhenomTHMAmpStruct *pAmp)
COMPLEX16 IMRPhenomTHMAmp(REAL8 t, UNUSED REAL8 x, IMRPhenomTHMAmpStruct *pAmp)
double IMRPhenomTMergerOmegaAnsatzHM(REAL8 t, IMRPhenomTHMPhaseStruct *pPhase)
double IMRPhenomTRDAmpAnsatzHM(REAL8 t, IMRPhenomTHMAmpStruct *pAmp)
int IMRPhenomTSetPhase22Coefficients(IMRPhenomTPhase22Struct *pPhase, IMRPhenomTWaveformStruct *wf)
double IMRPhenomTHMPhase(REAL8 t, REAL8 phiInsp, IMRPhenomTHMPhaseStruct *pPhaseHM, UNUSED IMRPhenomTHMAmpStruct *pAmpHM)
double IMRPhenomTTaylorT3(REAL8 theta, IMRPhenomTPhase22Struct *pPhase)
double IMRPhenomTMergerPhaseAnsatzHM(REAL8 t, IMRPhenomTHMPhaseStruct *pPhase)
int IMRPhenomTSetWaveformVariables(IMRPhenomTWaveformStruct *wf, const REAL8 m1_SI, const REAL8 m2_SI, const REAL8 chi1L_In, const REAL8 chi2L_In, const REAL8 distance, const REAL8 deltaT, const REAL8 fmin, const REAL8 fRef, const REAL8 phiRef, LALDict *lalParams)
int IMRPhenomTSetHMPhaseCoefficients(int l, int m, IMRPhenomTHMPhaseStruct *pPhaseHM, IMRPhenomTPhase22Struct *pPhase, IMRPhenomTHMAmpStruct *pAmplm, IMRPhenomTWaveformStruct *wf)
double IMRPhenomTPhase22(REAL8 t, REAL8 thetabar, IMRPhenomTWaveformStruct *pWF, IMRPhenomTPhase22Struct *pPhase)
double IMRPhenomTRDPhaseAnsatzHM(REAL8 t, IMRPhenomTHMPhaseStruct *pPhase)
double IMRPhenomTInspiralPhaseTaylorT3(REAL8 thetabar, IMRPhenomTWaveformStruct *wf, IMRPhenomTPhase22Struct *pPhase)
#define tCUT_Freq
#define tCUT_Amp
#define tcpMerger
REAL8 XLALSimIMRPhenomXFinalMass2017(REAL8 eta, REAL8 chi1L, REAL8 chi2L)
Final Mass = 1 - Energy Radiated, X Jimenez-Forteza et al, PRD, 95, 064024, (2017),...
REAL8 XLALSimIMRPhenomXFinalSpin2017(REAL8 eta, REAL8 chi1L, REAL8 chi2L)
Final Dimensionless Spin, X Jimenez-Forteza et al, PRD, 95, 064024, (2017), arXiv:1611....
INT4 XLALSimInspiralWaveformParamsLookupPhenomTHMInspiralVersion(LALDict *params)
int s
Definition: bh_qnmode.c:137
int l
Definition: bh_qnmode.c:135
double i
Definition: bh_ringdown.c:118
double theta
Definition: bh_sphwf.c:118
const double w
#define LAL_MSUN_SI
#define LAL_PI
#define LAL_TWOPI
#define LAL_MTSUN_SI
#define LAL_GAMMA
#define LAL_MRSUN_SI
#define crect(re, im)
double complex COMPLEX16
double REAL8
uint32_t UINT4
static const INT4 r
static const INT4 m
static const INT4 q
#define XLAL_ERROR(...)
#define XLAL_CHECK(assertion,...)
#define XLAL_PRINT_WARNING(...)
XLAL_SUCCESS
XLAL_EFUNC
list x
list p
string status
IMRPhenomTPhase22Struct * pPhase
IMRPhenomTWaveformStruct * wf
Definition: burst.c:245
double deltaT
Definition: unicorn.c:24