================================================
Simulated signal from xml file
================================================

:code:`BayesWave` can inject simulated signals from an XML file in the LIGO-specific :code:`LIGO_LW` format.


Example 1: Making an XML file and injecting into simulated noise 
---------------------------------------------------------------------------
This example shows how to make an XML file using LALApps tools,
and how run :code:`BayesWave` on the simulated signals in the XML file using simulated detector noise.

Making an XML file
~~~~~~~~~~~~~~~~~~~~

Here we show one example of how to make an XML file that contains parameters for simulated binary black hole signals.
This example uses the :code:`inspinj` tool from LALApps. For more information, see `LALApps documentation here <https://lscsoft.docs.ligo.org/lalsuite/lalapps/inspinj_8c.html>`_.

The following example bash script will produce a file called :code:`equalMass35Msun-injections.xml`,
which contains paramters for 10 injections of binary black holes with equal component masses of :math:`35M_\odot`.
There is no spin, and the waveform approximant used is :code:`IMRPhenomDtwoPointFivePN`.
The exact SNRs of the injections depends on the noise realisation used, but it should be somewhere in the neighborhood of 10-35.

.. literalinclude:: test_suite/xml_injections/make_xml.sh
    :language: bash

:download:`Download bash script <test_suite/xml_injections/make_xml.sh>`


Config file
~~~~~~~~~~~~~~~

This :code:`.ini` file is for a run into gaussian detector noise using a simulated Advanced LIGO PSD.
This example analyses data from the H1 and L1 detectors, will run in the signal, glitch, and noise models,
and does not used :code:`BayesLine` PSD estimation (assumes the PSD is known).

.. literalinclude:: test_suite/xml_injections/xml_simNoise.ini
    :language: cfg

:download:`Download .ini file <test_suite/xml_injections/xml_simNoise.ini>`

Call to :code:`bayeswave_pipe`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This bash script contains the call to :code:`bayeswave_pipe` to setup the injection runs.
For xml injections into simulated data, you will need to include the path to the xml file, and the :code:`--sim-data` flag.

.. literalinclude:: test_suite/xml_injections/runpipe_simNoise.sh
    :language: bash

:download:`Download bash script <test_suite/xml_injections/runpipe_simNoise.sh>`


Option 2: Injecting into real data
-------------------------------------------

In this example, we will look at running the off-source injections for the event 
GW200311_115853 from the third Gravitational-Wave Transient Catalog (`Abbott et al. 2023 <https://arxiv.org/abs/2111.03606>`_).

The XML contains 200 injections, and can be downloaded at the link here:  
:download:`Download xml file <test_suite/xml_injections/GW200311_115853_offsource.xml>`

Config file
~~~~~~~~~~~~~~~

This example will use data from Hanford, Livingston, and Virgo.
This example will also use the BayesLine option to do on-source PSD estimation, 
and will only run the signal model (skipping the glitch and Gaussian noise only models).

.. literalinclude:: test_suite/xml_injections/xml_realNoise.ini
    :language: cfg

:download:`Download .ini file <test_suite/xml_injections/xml_realNoise.ini>`

Call to :code:`bayeswave_pipe`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This bash script contains the call to :code:`bayeswave_pipe` to setup the injection runs.
Because this is a large batch of injections, we will use the :code:`--skip-megapy` flag
which will skip the call to the plotting script :code:`megaplot` 
since we probably don't need to look at every single output page.

.. literalinclude:: test_suite/xml_injections/runpipe_realNoise.sh
    :language: bash

:download:`Download bash script <test_suite/xml_injections/runpipe_realNoise.sh>`