<commit_before>.. _tutorial:

Tutorial
========

This tutorial will walk you through the steps to repeat the analysis
of the AGN PG1553+113 done in the official `Fermi collaboration python tutorial
<http://fermi.gsfc.nasa.gov/ssc/data/analysis/scitools/python_tutorial.html>`__
and results published here.

We strongly recommend that you run this analysis once, so that you
can be sure to produce correct results before analyzing your source.


Make a new directory now where you want all of your intermediate
and final analysis results to be placed and go there. 
For illustration purposes we will assume in this tutorial this
directory is `~/myanalysis`:

.. code-block:: bash

   mkdir ~/myanalysis`~/myanalysis`
   cd ~/myanalysis

First get the data as explain the the offical page. You should have this when typing `ls`

.. code-block:: bash

   L110728114426E0D2F37E85_PH00.fits
   L110728114426E0D2F37E85_PH01.fits
   L110728114426E0D2F37E85_SC00.fits

Make an ascii will with the 'entire' path of the FT1 (PH) fits files. Let's assume this file is called  `data.list` .


The analysis can be performed on disjoint time bins. An ascii file must be provided in the [Time]/file option. The file must be a 2 columns file with T_start and T_stop (in MJD, MET or JD). Each line is a time bin.

.. code-block:: bash

   239557418 239657418 
   239667418 239757410
   239957418 239967418

Folder management
-----------------

Once you have decided where the results will be placed (here `~/myanalysis`), enrico will create some subfolders to store results and files. 

 * fits files (livetime cube, selected events, etc...) will be placed in the main folder (here `~/myanalysis`)
 * The spectrum results (ascii files, plots) will be stored in a folder named Spectrum (here `~/myanalysis/Spectrum`)
 * Data (fits files) and results from the generation of energy bin will be stored in a subfolder `Ebin#` where # is the number of bins you ask for (here `~/myanalysis/Ebin#`).
 * Data (fits files) and results  generated for the light curve will be placed in `Lightcurve#`  where # is the number of bins you ask for (here `~/myanalysis/Lightcurve#`).
 * TSmap data will be placed in a TSmap subfolder  (here `~/myanalysis/TSmap`).


Make a config file
------------------

enrico uses configuration file to run analysis. The way it has been thought, you
need only one configuration file per analysis. The drawback is that such file
can be complicated to generated by hand or to understand (for a description see :ref:`configfile`).

You can use the `enrico_config` tool to quickly make a config file
called `myanalysis.conf`. It will ask you for the required options
and copy the rest from a default config file `enrico/data/config/default.conf`:

Statement enclosed in [] are default, being there to help you.

.. code-block:: bash

   $ enrico_config myanalysis.conf
   Please provide the following required options [default] :
   Output directory [~/myanalysis] :
   Target Name : PG155+113
   Right Ascension: 238.92935
   Declination: 11.190102
   Options are : PowerLaw, PowerLaw2, LogParabola, PLExpCutoff
   Spectral Model [PowerLaw] : PowerLaw2
   ROI Size [15] : 10
   FT2 file [~/myanalysis/spacecraft.fits] : ~/myanalysis/L110728114426E0D2F37E85_SC00.fits
   FT1 list of files [~/myanalysis/events.lis] : ~/myanalysis/data.list
   tag [LAT_Analysis] : TestOfPG1553
   Start time [239557418] : 239557417
   End time [334165418] : 256970880
   Emin [100] : 200
   Emax [300000] : 

Note :

* Always give the full path for the files
* We used the PowerLaw2 model as in the Fermi tutorial.
* Time is give in MET
* Energy is given in MeV
* ROI size is given in degrees<commit_msg>* Updated doc/source/tutorial.rst adding:     - Added the redshift, EBL model and last parameters of "enrico_config myanalysis.conf" example.<commit_after>.. _tutorial:

Tutorial
========

This tutorial will walk you through the steps to repeat the analysis
of the AGN PG1553+113 done in the official `Fermi collaboration python tutorial
<http://fermi.gsfc.nasa.gov/ssc/data/analysis/scitools/python_tutorial.html>`__
and results published here.

We strongly recommend that you run this analysis once, so that you
can be sure to produce correct results before analyzing your source.


Make a new directory now where you want all of your intermediate
and final analysis results to be placed and go there. 
For illustration purposes we will assume in this tutorial this
directory is `~/myanalysis`:

.. code-block:: bash

   mkdir ~/myanalysis`~/myanalysis`
   cd ~/myanalysis

First get the data as explain the the offical page. You should have this when typing `ls`

.. code-block:: bash

   L110728114426E0D2F37E85_PH00.fits
   L110728114426E0D2F37E85_PH01.fits
   L110728114426E0D2F37E85_SC00.fits

Make an ascii will with the 'entire' path of the FT1 (PH) fits files. Let's assume this file is called  `data.list` .


The analysis can be performed on disjoint time bins. An ascii file must be provided in the [Time]/file option. The file must be a 2 columns file with T_start and T_stop (in MJD, MET or JD). Each line is a time bin.

.. code-block:: bash

   239557418 239657418 
   239667418 239757410
   239957418 239967418

Folder management
-----------------

Once you have decided where the results will be placed (here `~/myanalysis`), enrico will create some subfolders to store results and files. 

 * fits files (livetime cube, selected events, etc...) will be placed in the main folder (here `~/myanalysis`)
 * The spectrum results (ascii files, plots) will be stored in a folder named Spectrum (here `~/myanalysis/Spectrum`)
 * Data (fits files) and results from the generation of energy bin will be stored in a subfolder `Ebin#` where # is the number of bins you ask for (here `~/myanalysis/Ebin#`).
 * Data (fits files) and results  generated for the light curve will be placed in `Lightcurve#`  where # is the number of bins you ask for (here `~/myanalysis/Lightcurve#`).
 * TSmap data will be placed in a TSmap subfolder  (here `~/myanalysis/TSmap`).


Make a config file
------------------

enrico uses configuration file to run analysis. The way it has been thought, you
need only one configuration file per analysis. The drawback is that such file
can be complicated to generated by hand or to understand (for a description see :ref:`configfile`).

You can use the `enrico_config` tool to quickly make a config file
called `myanalysis.conf`. It will ask you for the required options
and copy the rest from a default config file `enrico/data/config/default.conf`:

Statement enclosed in [] are default, being there to help you.

.. code-block:: bash

   $ enrico_config myanalysis.conf
   Please provide the following required options [default] :
   Output directory [~/myanalysis] :
   Target Name : PG155+113
   Right Ascension: 238.92935
   Declination: 11.190102
   redshift, no effect if null [0] : 0.49
   ebl model to used
   0=Kneiske, 1=Primack05, 2=Kneiske_HighUV, 3=Stecker05, 4=Franceschini, 5=Finke, 6=Gilmore : 4
   Options are : PowerLaw, PowerLaw2, LogParabola, PLExpCutoff
   Spectral Model [PowerLaw] : PowerLaw2
   ROI Size [15] : 10
   FT2 file [~/myanalysis/spacecraft.fits] : ~/myanalysis/L110728114426E0D2F37E85_SC00.fits
   FT1 list of files [~/myanalysis/events.lis] : ~/myanalysis/data.list
   tag [LAT_Analysis] : TestOfPG1553
   Start time [239557418] : 239557417
   End time [334165418] : 256970880
   Emin [100] : 200
   Emax [300000] : 
   IRFs [CALDB] : 
   evclass [128] : 
   evtype [3] : 
   Corresponding IRFs	=	('P8R2_SOURCE_V6', ['BACK', 'FRONT'])
   Is this ok? [y] : y
   Corresponding zmax =  95
   
Note :

* Always give the full path for the files
* We used the PowerLaw2 model as in the Fermi tutorial.
* Time is give in MET
* Energy is given in MeV
* ROI size is given in degrees
{'fraction_non_alphanumeric': 0.08392948390393459, 'fraction_numerical': 0.06093510475217169, 'mean_word_length': 3.773780487804878, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2323317', 'n_tokens_mistral': 2761, 'n_tokens_neox': 2327, 'n_words': 1044}