Commit 2a7cdabb7f062c23dc11263aebfdad4ad1a0de1c
1 parent
92c51561
Complement User Manual
Showing
7 changed files
with
223 additions
and
24 deletions
doc/source/users/tutorial/index.rst
doc/source/users/tutorial/sky/index.rst
doc/source/users/user_manual/internals.rst
| ... | ... | @@ -6,4 +6,54 @@ Under the hood |
| 6 | 6 | Registry classes |
| 7 | 7 | ---------------- |
| 8 | 8 | |
| 9 | -To be written (describe what a registry class is) ... | |
| 9 | +Registry classes statically hold instances of derived classes, and can be | |
| 10 | +used to allocate a derived class dependent on some text string. | |
| 11 | +The code thread below illustrates how the :doxy:`GModels::read()` method | |
| 12 | +extracts models from an XML file, allocates the requested model through the | |
| 13 | +:doxy:`GModelRegistry::alloc()` method, and appends the model to the model | |
| 14 | +container. | |
| 15 | + | |
| 16 | +**C++** | |
| 17 | + | |
| 18 | +.. code-block:: cpp | |
| 19 | + :linenos: | |
| 20 | + | |
| 21 | + int n = lib->elements("source"); // Get number of sources | |
| 22 | + for (int i = 0; i < n; ++i) { // Loop over sources | |
| 23 | + const GXmlElement* src = lib->element("source", i); // Get pointer on source | |
| 24 | + std::string type = src->attribute("type"); // Get source model type | |
| 25 | + GModelRegistry registry; // Get model registry | |
| 26 | + GModel* ptr = registry.alloc(type); // Allocate model of specific type | |
| 27 | + if (ptr != NULL) { // If model is valid: | |
| 28 | + ptr->read(*src); // - read model | |
| 29 | + append(*ptr); // - append it to container | |
| 30 | + delete ptr; // - free model | |
| 31 | + } | |
| 32 | + } | |
| 33 | + | |
| 34 | +To access the registry information it is sufficient to create an instance of | |
| 35 | +the registry. To illustrate how the registry is filled the | |
| 36 | +``src/model/GModelSky.cpp`` file can be examined: | |
| 37 | + | |
| 38 | +**C++** | |
| 39 | + | |
| 40 | +.. code-block:: cpp | |
| 41 | + :linenos: | |
| 42 | + | |
| 43 | + const GModelSky g_pointsource_seed("PointSource"); | |
| 44 | + const GModelSky g_extendedsource_seed("ExtendedSource"); | |
| 45 | + const GModelSky g_diffusesource_seed("DiffuseSource"); | |
| 46 | + const GModelSky g_compositesource_seed("CompositeSource"); | |
| 47 | + const GModelRegistry g_pointsource_registry(&g_pointsource_seed); | |
| 48 | + const GModelRegistry g_extendedsource_registry(&g_extendedsource_seed); | |
| 49 | + const GModelRegistry g_diffusesource_registry(&g_diffusesource_seed); | |
| 50 | + const GModelRegistry g_compositesource_registry(&g_compositesource_seed); | |
| 51 | + | |
| 52 | +Here four instances of :doxy:`GModelSky` are created as global variables which | |
| 53 | +are appended to the :doxy:`GModelRegistry` registry by creating an instance | |
| 54 | +of the registry which takes the address of the :doxy:`GModelSky` instance | |
| 55 | +as argument. | |
| 56 | + | |
| 57 | +Registries are widely used throughout GammaLib for the handling of models and | |
| 58 | +its components, and the handling of the observations of the different supported | |
| 59 | +instruments. | ... | ... |
doc/source/users/user_manual/modules/model/par.rst
| 1 | 1 | Model parameters |
| 2 | 2 | ================ |
| 3 | 3 | |
| 4 | -To be written | |
| 4 | +Model parameters are implemented by :doxy:`GModelPar` which derives from | |
| 5 | +the abstract :doxy:`GOptimizerPar` base class. Each model parameter is | |
| 6 | +factorised into a value and a scale part according to | |
| 7 | + | |
| 8 | +.. math:: | |
| 9 | + p = v \times s | |
| 10 | + | |
| 11 | +where | |
| 12 | +:math:`p` is the model parameter, | |
| 13 | +:math:`v` is the model value factor, and | |
| 14 | +:math:`s` is the model scale factor. | |
| 15 | +All three components can be accessed or set via the | |
| 16 | +:doxy:`GModelPar::value()`, | |
| 17 | +:doxy:`GModelPar::factor_value()`, and | |
| 18 | +:doxy:`GModelPar::scale()` methods. | |
| 19 | + | |
| 20 | +In addition, the class handles parameter errors and gradients as well | |
| 21 | +as parameter minima or maxima. | |
| 22 | +Parameter errors can be accessed or set via the | |
| 23 | +:doxy:`GModelPar::error()` and :doxy:`GModelPar::factor_error()`, | |
| 24 | +where the former concerns the error on :math:`p` while the latter concerns | |
| 25 | +the error on :math:`v`. | |
| 26 | +Equivalent methods exist for | |
| 27 | +the gradient | |
| 28 | +(:doxy:`GModelPar::gradient()` and :doxy:`GModelPar::factor_gradient()`), | |
| 29 | +the minimum | |
| 30 | +(:doxy:`GModelPar::min()` and :doxy:`GModelPar::factor_min()`), and | |
| 31 | +the maximum | |
| 32 | +(:doxy:`GModelPar::max()` and :doxy:`GModelPar::factor_max()`). | |
| 33 | + | |
| 34 | +Finally, :doxy:`GModelPar::fix()` and :doxy:`GModelPar::free()` methods | |
| 35 | +allow to fix or to free a model parameter, and the :doxy:`GModelPar::is_free()` | |
| 36 | +and :doxy:`GModelPar::is_fix()` methods allow to check whether a parameter is | |
| 37 | +free or fixed. | |
| 38 | + | |
| 39 | + | ... | ... |
doc/source/users/user_manual/modules/obs/caldb.rst
| 1 | 1 | .. _um_obs_caldb: |
| 2 | 2 | |
| 3 | -Setting up and using a calibration database | |
| 4 | -=========================================== | |
| 3 | +Using a calibration database | |
| 4 | +============================ | |
| 5 | 5 | |
| 6 | -To be written (describe how to setup and how to use a calibration | |
| 7 | -database) ... | |
| 6 | +The class :doxy:`GCaldb` implements the interface to a calibration database | |
| 7 | +that is compliant with the HEASARC format. | |
| 8 | +To use a calibration database, make sure that the environment variable | |
| 9 | +``CALDB`` is set to a valid calibration database. | |
| 10 | +The database is the open by specifying a mission and an instrument name. | |
| 11 | +The examples below show two variants of opening the ``prod2`` database for | |
| 12 | +``CTA``. | |
| 13 | + | |
| 14 | +**Python** | |
| 15 | + | |
| 16 | +.. code-block:: python | |
| 17 | + :linenos: | |
| 18 | + | |
| 19 | + import gammalib # Make GammaLib available | |
| 20 | + caldb1 = gammalib.GCaldb('cta','prod2') # Using opening constructor | |
| 21 | + caldb2 = gammalib.GCaldb() | |
| 22 | + caldb2.open('cta','prod2') # Using open method | |
| 23 | + | |
| 24 | +**C++** | |
| 25 | + | |
| 26 | +.. code-block:: cpp | |
| 27 | + :linenos: | |
| 28 | + | |
| 29 | + #include "GammaLib.hpp" // Make GammaLib available | |
| 30 | + GCaldb caldb1("cta","prod2"); // Using opening constructor | |
| 31 | + GCaldb caldb2; | |
| 32 | + caldb2.open("cta","prod2"); // Using open method | |
| 33 | + | |
| 34 | +Once opened, the database can be used to locate for example the filename | |
| 35 | +of a response component. The examples below show how the effective area | |
| 36 | +filename for the response ``South_5h`` is accessed via the calibration | |
| 37 | +database. | |
| 38 | + | |
| 39 | +**Python** | |
| 40 | + | |
| 41 | +.. code-block:: python | |
| 42 | + :linenos: | |
| 43 | + | |
| 44 | + filename = caldb1.filename('','','EFF_AREA','','','NAME(South_5h)') | |
| 45 | + | |
| 46 | +**C++** | |
| 47 | + | |
| 48 | +.. code-block:: cpp | |
| 49 | + :linenos: | |
| 50 | + | |
| 51 | + GFilename filename = caldb1.filename("","","EFF_AREA","","","NAME(South_5h)"); | ... | ... |
doc/source/users/user_manual/modules/obs/energy.rst
| ... | ... | @@ -3,6 +3,76 @@ |
| 3 | 3 | Energies in GammaLib |
| 4 | 4 | ==================== |
| 5 | 5 | |
| 6 | -To be written (describe how energies are implemented in GammaLib; mention | |
| 7 | -that the internal energy is MeV; this section should also handle EBOUNDS) | |
| 8 | -... | |
| 6 | +Energies are implemented by the :doxy:`GEnergy` class that transparently | |
| 7 | +handles energies with different units. The energy is stored internally in | |
| 8 | +MeV, but energies can also be provided in erg, keV, GeV, TeV, as well as | |
| 9 | +the equivalent wavelength in Angstrom. | |
| 10 | + | |
| 11 | +The code threads below illustrate how an energy of 511 keV can be set using | |
| 12 | +the energy constructor or a dedicated method, and how that energy can be | |
| 13 | +retrieved in units of MeV. | |
| 14 | + | |
| 15 | +**Python** | |
| 16 | + | |
| 17 | +.. code-block:: python | |
| 18 | + :linenos: | |
| 19 | + | |
| 20 | + import gammalib # Make GammaLib available | |
| 21 | + energy1 = gammalib.GEnergy(511.0,'keV') # Using energy constructor | |
| 22 | + energy2 = gammalib.GEnergy() | |
| 23 | + energy2.keV(511.0) # Using keV method | |
| 24 | + E_MeV1 = energy2('MeV') # Get energy in MeV | |
| 25 | + E_MeV2 = energy2.MeV() # Another variant to get energy in MeV | |
| 26 | + | |
| 27 | +**C++** | |
| 28 | + | |
| 29 | +.. code-block:: cpp | |
| 30 | + :linenos: | |
| 31 | + | |
| 32 | + #include "GammaLib.hpp" // Make GammaLib available | |
| 33 | + GEnergy energy1(511.0,"keV"); // Using energy constructor | |
| 34 | + GEnergy energy2; | |
| 35 | + energy2.keV(511.0); // Using keV method | |
| 36 | + double E_MeV1 = energy2("MeV"); // Get energy in MeV | |
| 37 | + double E_MeV2 = energy2.MeV(); // Another variant to get energy in MeV | |
| 38 | + | |
| 39 | +Energies can be added and subtracted, or multiplied or divided by a floating | |
| 40 | +point value. | |
| 41 | +In addition, two energies can be divided, resulting in a floating point value. | |
| 42 | +Energies can also be compared using the usual operators. | |
| 43 | + | |
| 44 | +Energies can be collected by the :doxy:`GEnergies` container class. The threads | |
| 45 | +below illustrate how energies can be appended or inserted into the | |
| 46 | +:doxy:`GEnergies` container class. | |
| 47 | + | |
| 48 | +**Python** | |
| 49 | + | |
| 50 | +.. code-block:: python | |
| 51 | + :linenos: | |
| 52 | + | |
| 53 | + import gammalib # Make GammaLib available | |
| 54 | + energy1 = gammalib.GEnergy(511.0,'keV') # Set first energy | |
| 55 | + energy2 = gammalib.GEnergy(1024.0,'keV') # Set second energy | |
| 56 | + energies = gammalib.GEnergies() # Create energy container instance | |
| 57 | + energies.append(energy1) # Append first energy | |
| 58 | + energies.insert(0,energy2) # Insert second energy before first energy | |
| 59 | + | |
| 60 | +**C++** | |
| 61 | + | |
| 62 | +.. code-block:: cpp | |
| 63 | + :linenos: | |
| 64 | + | |
| 65 | + #include "GammaLib.hpp" // Make GammaLib available | |
| 66 | + GEnergy energy1(511.0,"keV"); // Set first energy | |
| 67 | + GEnergy energy2(1024.0,"keV"); // Set second energy | |
| 68 | + GEnergies energies; // Create energy container instance | |
| 69 | + energies.append(energy1); // Append first energy | |
| 70 | + energies.insert(0,energy2); // Insert second energy before first energy | |
| 71 | + | |
| 72 | +The energy container can be saved into a file using the :doxy:`GEnergies::save()` | |
| 73 | +method, and loaded from a file using either the load constructor or the | |
| 74 | +:doxy:`GEnergies::load()` method. | |
| 75 | + | |
| 76 | +Another energy container class is :doxy:`GEbounds` which stores the energy | |
| 77 | +boundaries for an arbitrary number of energy bins. | |
| 78 | + | ... | ... |
doc/source/users/user_manual/modules/support/constants.rst
| ... | ... | @@ -9,18 +9,18 @@ Constants |
| 9 | 9 | |
| 10 | 10 | The following constants are available: |
| 11 | 11 | |
| 12 | -========================== ===== | |
| 13 | -Constant Value | |
| 14 | -========================== ===== | |
| 15 | -``gammalib::MeV2erg`` :math:`1.6021765 \times 10^{-6}` (converts MeV to erg) | |
| 16 | -``gammalib::erg2MeV`` :math:`624150.96` (converts erg to MeV) | |
| 17 | -``gammalib::MeV2Angstrom`` :math:`1.239841875e-2` (converts MeV to Angstrom) | |
| 18 | -``gammalib::pc2cm`` :math:`3.08568025 \times 10^{18}` (converts pc to cm) | |
| 19 | -``gammalib::sec_in_day`` :math:`86400.0` (number of seconds in one day) | |
| 20 | -``gammalib::sec2day`` :math:`1/86400` (converts seconds to days) | |
| 21 | -``gammalib::tai2tt`` :math:`32.184` (converts TAI to TT system) | |
| 22 | -``gammalib::mec2`` :math:`0.5109989461` (electron rest mass in MeV) | |
| 23 | -========================== ===== | |
| 12 | +========================== ================================= ======= | |
| 13 | +Constant Value Purpose | |
| 14 | +========================== ================================= ======= | |
| 15 | +``gammalib::MeV2erg`` :math:`1.6021765 \times 10^{-6}` Converts MeV to erg | |
| 16 | +``gammalib::erg2MeV`` :math:`624150.96` Converts erg to MeV | |
| 17 | +``gammalib::MeV2Angstrom`` :math:`1.239841875\times 10^{-2}` Converts MeV to Angstrom | |
| 18 | +``gammalib::pc2cm`` :math:`3.08568025 \times 10^{18}` Converts pc to cm | |
| 19 | +``gammalib::sec_in_day`` :math:`86400.0` Number of seconds in one day | |
| 20 | +``gammalib::sec2day`` :math:`1/86400` Converts seconds to days | |
| 21 | +``gammalib::tai2tt`` :math:`32.184` Converts TAI to TT system | |
| 22 | +``gammalib::mec2`` :math:`0.5109989461` Electron rest mass in MeV | |
| 23 | +========================== ================================= ======= | |
| 24 | 24 | |
| 25 | 25 | |
| 26 | 26 | Functions | ... | ... |