# Add module for updating p_astro using PE samples

It is possible to update GW source classification reported by the search pipelines using the more accurate mass-estimates of online PE. Such a framework is already implemented by the Rapid-PE-RIFT pipeline. A similar framework can be developed for online bilby in the following way.

As derived G2301521 we can use the following expression to update the category-specific probability of astrophysical origin reported by the search pipelines:

`P(H_{\alpha}|d)=(1-P_{\text{Terr}}^{pipeline})\frac{R_{\alpha}Z_{\alpha}}{\sum_{\beta}R_{\beta}Z_{\beta}}`

`Z_{\alpha}=\int d\theta p(d|\theta)p(\theta|H_{\alpha})`

- Unlike in the case of Rapid-PE-RIFT pipeline which evaluates the evidence integral by interpolating and integrating the marginalized likelihood across a grid of intrinsic parameters, we just sum the population prior over posterior samples yielded by bilby.
- Unlike the search pipelines and Rapid-PE-RIFT pipeline's current implementation, we apply the population prior in source frame since bilby provides samples of luminosity distance.

`Z_{\alpha}=\frac{Z_{PE}}{N_{samp}}\sum_{i\sim\text{posterior}}^{N_{samp}}\frac{p(m_{1s,i},m_{2s,i},z_i|\alpha)}{p(m_{1d,i}m_{2d,i},d_{L,i})\times \frac{dd_L}{dz}\frac{1}{(1+z_i)^2}}`

We use the following straw-person population prior for classifying the sources into different astrophysical categories.

`p(m_{1s},m_{2s},z|\alpha) \propto \frac{m_{1s}^{\alpha}m_{2s}^{\beta}}{\text{min}(m_{1s},m_{2s,max})^{\beta+1}-m_{2s,min}^{\beta+1}}\frac{dV_c}{dz}\frac{1}{1+z}`

### Preliminary results for O4 events:

### Things to do:

- Test on MDC
- Possible to incorporate tidal deformability measurements and marginalize over the EoS?

Edited by Anarya Ray