Part of the MCMC example - run minuit first

based on demo_JPAC_fit.ipynb

Create results directory

Read processed data

pre-processed by process_data.py

Define Waves for Fit (and input initial values of minuit and fitted parameters).

Fit real and imaginary parts

Fit amplitude and phase

Binning of the data/monte-carlo and define amplitude (function) to fit

Here the user defines number of bins, variable to be binned and range

Plot events per bin for visualisation and to make sure there are enough events per bin

Fitting with Minuit and Extended LogLikelihood

Look at other possibilities through pypwa (use the ?pwa command\ or see https://pypwa.jlab.org or https://github.com/JeffersonLab/PyPWA)

Looking at the results of fitting

Checking the waves used (and filling waves variable for later use)

Filling strings with wave names (for plotting)

Getting the bin mass values and number of events in datasample for those bins

Calculating the expected number of events in a mass bin

Plot expected number of events vs mass and data vs mass (both should agree if fitting worked)

Calculate initial intensities (in case we need to check them)

Calculate the expected number of events for each wave (vs mass)

Plot expected number of events vs mass for each wave

Expected number of events vs mass for each wave in a same plot

Calculate Moments

Calculate PhaseMotion between two waves

In this example between 2nd and 3rd waves in amp list

Plot PhaseMotion

Write fitted values (of production amplitudes) to disk