The Medium Energy Gamma-ray Astronomy library (MEGAlib) is a set of software tools which are designed to simulate and analyze data of gamma-ray detectors, with a specialization on Compton telescopes. While MEGAlib was originally developed for astrophysics, it has been expanded and used for ground based applications such as medical imaging and homeland security. The library comprises all necessary data analysis steps from simulation/measurements via event reconstruction to image reconstruction.

MEGAlib contains a geometry and detector description tool for the detailed modeling of different detector types and characteristics, and provides an easy to use simulation program based on Geant4. For different Compton telescope detector types (electron tracking, multiple Compton or time of flight based) specialized Compton event reconstruction algorithms are implemented in different approaches (Chi-square and Bayesian). The high level data analysis tools allow to calculate response matrices, perform image deconvolution (specialized in list-mode-likelihood-based Compton image reconstruction), determine detector resolutions and sensitivities, retrieve spectra, determine polarization modulations, etc.

The highly modular and completely object-oriented library is written in C++ and utilizes ROOT and Geant4. While it has been originally developed for the Compton scattering and pair creation telescope MEGA, it also has been successfully applied to a wide variety of hard X-ray/gamma-ray telescopes in space and on ground, such as COMPTEL, NCT, ACT, NuSTAR, GRI, GRIPS, and HEMI.

For a general overview of MEGAlib consider reading MEGAlib's key reference Andreas Zoglauer et al., "MEGAlib - Medium Energy Gamma-ray Astronomy Library", NewAR 50 (7-8), 2006.