%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
This is the README file for the Example folder of PRIMAT.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1 Octobre 2024
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-The main code of PRIMAT is the file PRIMAT-Main.nb. When saving this files, Mathematica automatically generates a file with the same name but with an extension *.m. This .m file can then be loaded in other notebook, or in the terminal version of Mathematica. If you find that your version of Mathematica does not generate a new .m file each time you save the .nb file. There are two possibilities
1) You to "Save As" and then you select Mathematica Package (.m) format when saving
2) Or you activate permanently the automatic creation of .m, by going into Format->Option Inspector. Then you select on top left "Global Preferences", and browse into the category "Notebook Options->File Options" and you set the "AutoGeneratePackage" to 'Automatic'.

Once you have the .m file associated with PRIMAT-Main.nb, you can then use the Examples (and modify them), as they start by loading the .m file.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Here is the list of examples of usage of PRIMAT:



**** Basic examples ****

01_Abundances-and-Plots.nb is a simple notebook which can be used to plot the time evolution of abundances. This is a duplicated of the plots which can already be found inside PRIMAT.nb, but it allows to manipulate a smaller notebook.

02_Final-Abundances.nb explains how to call PRIMAT and then perform plots of results, get the final abundances and even output the results in external TSV files.

03_PRIMAT-Custom-Plots.nb is the notebook which was used to generate plots of abundances in the Physics Reports article (Pitrou et. al 2018) associated with the code.

**** Advanced examples ****

These examples can take a long time to run, either because PRIMAT is called on large grids, or because Monte-Carlo estimation of errors is performed, or both ! However the results which have been previously obtained with these examples can be downloaded on PRIMAT webpage, hence the long computation can be skipped and the user can proceed by loading the stored data.

04_Abundances-Eta.nb computes the abundances as a function of the baryon-to-photon ration eta. It uses a Monte-Carlo on nuclear rates (and neutron lifetime) to estimate the errors. It is also used to perform the classical plots of abundances in function of eta (with the observational bounds superimposed). 

05_Posterior-Baryons.nb is used to compute the posterior distribution of the baryons abundance (Omega_b h^2), given the observational constraints on D/H (deuterium measurement) and Y_p (He4 measurement). In order to take into account the uncertainty on nuclear rates, it runs a MonteCarlo for each value of the baryons abundances, where it varies the rates according to the uncertainties provided. 

06_MonteCarlo-Rates.nb computes the uncertainty on abundances from nuclear rates uncertainty only. It uses a huge Monte-Carlo from which the various quantiles can be inferred (at CMB values of baryons). It was used to provide Table VII of the Physics Reports.

07_AbundanceFit.nb is performing a fit in the three dimensional space of parameters of (Omega_b h^2) N_eff and tau_neutron. The result is provided in Table VI of the Physics Reports (Pitrou et. al. 2018).

08_Omegab-Neff-For-CAMB.nb performs a two dimensional exploration in (Omega_b h^2) N_eff, with errors estimated from Monte-Carlo. The resulting table has been provided to the CAMB distribution and is also available for download on PRIMAT webpage

09_Abundances-Nrelat.nb computes the abundances as a function of Nrelat, the number of decoupled relativistic degrees of freedom. ration eta. It uses a Monte-Carlo on nuclear rates (and neutron lifetime) to estimate the errors. 

10_Abundances-Xi.nb computes the abundances as a function of xi, the reduced chemical potential of neutrinos. It assumes that all neutrino species have the same reduced chemical potential, and ignores the effects of incomplete neutrino decoupling. It uses a Monte-Carlo on nuclear rates (and neutron lifetime) to estimate the errors. 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Since these notebooks require a large series of runs (either because PRIMAT is run on a grid, or because MCMC are used to estimate the uncertainty from nuclear rates), they save the lengthy computation in a file. In order to avoid running them in the GUI of Mathematica, one can also run the *.m file of these examples which performs these long computations and dumps the necessary in a file (usually a *.mx file).
Then when evaluating the *.nb, one can then evaluate cell by cell and avoid the cell which performs the long run (or comment it), and then proceed with loading the stored results from the *.mx file.

If the command line kernel is available under the name 'math' (sometimes it is Mathematica, sometimes WolframKernel, you have to find out) then you can for instance run an example as

nohup math < 04_Abundances-Eta.m > output_messages &

Do not forget to modify the variable which sets up the number of available Kernels ($DefaultParallelKernels).
If you do not want to wait for the results, the results already obtained in the advances notebooks are available for download on PRIMAT webpage.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
PRIMAT webpage : http://www2.iap.fr/users/pitrou/primat.htm




