Example: :math:`\overline{p}p` data
===================================

.. note::

  See original Wiki page `here
  <https://panda-wiki.gsi.de/foswiki/bin/view/PWA/SamplePWA>`__.

For testing and benchmarking purposes, an example PWA of Monte Carlo toy data
is located in the directory :file:`Examples/benchmark/pbarp`. It is an analysis
of the antiproton-proton annihilation into :math:`\pi^0\pi^0\eta` with only the
:math:`f_2(1270)` and the :math:`a_2(1320)` as intermediate resonances.

This page is a step by step tutorial on running this example.

Relevant Files
--------------

The following files should be located in the :file:`benchmark` folder:

================================  =============================================
File                              Description
================================  =============================================
:file:`benchmark*runscript`       Shell scripts to run the PWA in different
                                  modes
:file:`defaultparams.dat`         A list of default start parameters for the fit
:file:`pbarpReactionDefault.cfg`  The configuration file. The fitted model is
                                  defined and all options set here
:file:`toyDataMC.dat`             The phase space distributed toy Monte Carlo
                                  data as an ASCII file containing four-vectors
:file:`toyDataModel.dat`          The "experimental" toy data as an ASCII file
                                  containing four-vectors
================================  =============================================

Setting the Environment
-----------------------

To run PAWIAN, some environment variables have to be set (see :doc:`/install`).
An example is given in the file :file:`SetEnv_rub` in the top directory of the
PAWIAN installation. On the Βochum site, you only have to :command:`cd` into
that directory and type:

.. code-block:: bash

  source SetEnv_rub

Otherwise, you'll have to set the relevant environment variables
:code:`ROOTSYS`, :code:`TOP_DIR`, :code:`LD_LIBRARY_PATH` and
:code:`BOOST_BUILD_PATH:code:` yourself. Additionally, :code:`${ROOTSYS}/bin`
has to appear in your :code:`PATH` variable.

Generating the default Parameter List
-------------------------------------

To start any PWA, a list of start parameters has to be given. A default list
can be generated by running

.. code-block:: bash

  $TOP_DIR/bin/singleChannelApp --pbarpFiles pbarpReactionDefault.cfg --mode dumpDefaultParams

Starting the Server and the Clients
-----------------------------------

This example PWA is performed using the client/server mode with two clients, each one using two threads. The relevant configuration file options are

.. code-block:: ini

  serverPort = 50001
  serverAddress = localhost
  noOfClients = 2
  noOfThreads = 2

To start the server run:

.. code-block:: bash

  $TOP_DIR/bin/singleChannelApp --pbarpFiles pbarpReactionDefault.cfg --mode server --paramFile defaultparams.dat

However, you may want to pipe the output into a log file, e.g.

.. code-block:: bash

  $TOP_DIR/bin/singleChannelApp --pbarpFiles pbarpReactionDefault.cfg --mode server --paramFile defaultparams.dat !>& server.log &

Wait some seconds and then start the two clients on the same machine:

.. code-block:: bash

  $TOP_DIR/bin/singleChannelApp --pbarpFiles pbarpReactionDefault.cfg --mode client --paramFile defaultparams.dat !>& client1.log &
  $TOP_DIR/bin/singleChannelApp --pbarpFiles pbarpReactionDefault.cfg --mode client --paramFile defaultparams.dat !>& client2.log &

In the :file:`server.log`, lines similar to the following should appear:

.. code-block:: none

  INFO: ********* Server mode ****************
  INFO: Listening on port 50001
  INFO: Number of clients for channel 0 : 2
  INFO: Waiting for 2 clients ...
  INFO: Client pc17 logged in (ID 0).
  INFO: Client pc17 logged in (ID 1).
  INFO: All clients ready.
  INFO: start migrad

During the minimization, the current values of the likelihood are printed

.. code-block:: none

  INFO: current LH = -2210.678789216901

while the current parameter values (with default errors) are frequently dumped
into a file named currentResult.dat. After the minimization has finished, the
log file should show:

.. code-block:: none

  **************** Minuit FunctionMinimum information ******************
  INFO: Function minimum is valid.
  INFO: Covariance matrix is valid.
  INFO: Final LH: -7163.214059
  INFO: # of function calls: 2868
  INFO: minimum edm: 4.96117168e-06

The file :file:`finalResult.dat` now holds the list of final fit parameters
with proper errors. Another file :file:`serializedOutput.dat` is created in
which (currently only) the covariance matrix is stored for later use.

Plotting the Result
-------------------

Start the QA mode by running

.. code-block:: bash

  $TOP_DIR/bin/singleChannelApp --pbarpFiles pbarpReactionDefault.cfg --mode qaMode --paramFile finalResult.dat !>& logQA.log &

A `ROOT <https://panda-wiki.gsi.de/foswiki/bin/view/PWA/ROOT>`_ file
pawianHists.root is created (this may take some time). This file holds:

* Two ROOT trees :code:`_dataFourvecs` and :code:`_fittedFourvecs`, where the
  latter are the Monte Carlo data but with an additional weight representing
  the fitted intensity for this event.

* Histograms of masses and angles, as chosen in the configuration file. The
  histograms have prefixes :code:`"Data"`, :code:`"MC"` and :code:`"Fit"`, so
  to quickly estimate the goodness of fit, you can plot the "Data" and the
  corresponding :code:`"Fit"` histogram on the same canvas.

Examples:

.. image:: /images/pbarp/invMassPi0Eta.png
  :alt: Invariant pi0 eta mass

.. image:: /images/pbarp/invMassPi0Pi0.png
  :alt: Invariant pi0 pi0 mass
