## 7 Characterisation Simulations
### MEGALib  
The Medium-Energy Gamma-ray Astronomy library (MEGALib) v4.0 is a collection of programs for simulating gamma-ray instrumentation [43]). The software library was initially developed for the telescope MEGA [47]), which combined Compton scattering and pair production instrumentation; therefore, the higher-level data analysis tools concentrate on Compton telescope processes. However, the flexible design of the tools makes it applicable to many detector types, including scintillation-based instruments like GMOD on EIRSAT-1. The simulations performed with MEGALib for EIRSAT-1 used the following three MEGALib packages [48]:  
1. Geometry for MEGAlib (Geomega);
2. A Cosmic Simulator for MEGAlib (Cosima);
3. Real Event Analyser (Revan). The geometry of the detector and the satellite were first defined using Geomega, as seen in Figure 16; then, the gamma-ray source(s) were defined and, using Cosima and Revan tools, the response of GMOD in EIRSAT-1 to the sources was simulated. The main input file of Geomega includes the list of materials, the volumes of all the components of the spacecraft, the characteristics of the detector and any trigger criteria. In MEGAlib, the lengths of all objects are defined in half lengths and, throughout the programme, all the units are in cm, keV, g and deg. The materials that comprise the different components of the detector and the satellite, their densities and chemical compositions are defined in a separate file in Geomega and included in the main input file. The volumes can be a variety of different shapes including boxes, spheres, tubes and trapezoids. The gamma-ray detector also needs to be defined in the geometry file in MEGAlib. Various properties of the detector are defined in the geometry file including trigger thresholds, noise thresholds and energy resolution in the case of scintillation-based detectors. The definition of the detector identifies which volume(s) in the model in which the positions and energies of interactions should be recorded. The second tool used in MEGAlib is Cosima. Cosima is a Geant-4-based [49] simulator of the detection of gamma rays in the keV to a few hundreds of GeV range via photo-electric absorption, Compton scattering and pair production by gamma-ray telescopes. The Cosima simulation is directed by an input \"source\" file. The first input into the source file is the Geomega geometry definition of the satellite and the detector, as shown in the sample  
Figure 16: Updated EIRSAT-1 MEGAlib mass model including the GTRB with one solar panel cut out to view the internal components. code below. The second section of the source file describes the electromagnetic interactions package that will be used to describe the interactions in the simulation. The Livermore low-energy EM package describes gamma-ray interactions in the 250 eV to 100 GeV range [50]. The output format of the simulated data is then defined (e.g., storage of simulation history and ionisation information) and the final section describes a simulated run. One source file can define multiple simulation runs that will be performed in succession. Each run must have a defined output file name, stop criterion (time), definition of the radioactive source including the particle type, beam type and position, source spectrum and the average total flux integrated over beam and spectrum. The flux (particles/s) is calculated by multiplying the activity of the source (Bq) by the transition probability. The output of the Cosima simulation contains the interaction history of all the primary and secondary particles and all of the hits in the detector. Along with each hit, the associated position in world coordinates and energy are recorded. Revan is the final MEGAlib package used in this chapter, to combine the Cosima simulation results and the Geomega geometry together to generate a simulated detector response. Revan is used to generate the spectrum recorded by the simulated detector of the gamma-ray source.