Energies in GammaLibΒΆ
Energies are implemented by the GEnergy class that transparently handles energies with different units. The energy is stored internally in MeV, but energies can also be provided in erg, keV, GeV, TeV, as well as the equivalent wavelength in Angstrom.
The code threads below illustrate how an energy of 511 keV can be set using the energy constructor or a dedicated method, and how that energy can be retrieved in units of MeV.
C++
1GEnergy energy1(511.0,"keV"); // Using energy constructor
2GEnergy energy2;
3energy2.keV(511.0); // Using keV method
4double E_MeV1 = energy2("MeV"); // Get energy in MeV
5double E_MeV2 = energy2.MeV(); // Another variant to get energy in MeV
Python
1energy1 = gammalib.GEnergy(511.0,'keV') # Using energy constructor
2energy2 = gammalib.GEnergy()
3energy2.keV(511.0) # Using keV method
4E_MeV1 = energy2('MeV') # Get energy in MeV
5E_MeV2 = energy2.MeV() # Another variant to get energy in MeV
Energies can be added and subtracted, or multiplied or divided by a floating point value. In addition, two energies can be divided, resulting in a floating point value. Energies can also be compared using the usual operators.
Energies can be collected by the GEnergies container class. The threads below illustrate how energies can be appended or inserted into the GEnergies container class.
C++
1GEnergy energy1(511.0,"keV"); // Set first energy
2GEnergy energy2(1024.0,"keV"); // Set second energy
3GEnergies energies; // Create energy container instance
4energies.append(energy1); // Append first energy
5energies.insert(0,energy2); // Insert second energy before first energy
Python
1energy1 = gammalib.GEnergy(511.0,'keV') # Set first energy
2energy2 = gammalib.GEnergy(1024.0,'keV') # Set second energy
3energies = gammalib.GEnergies() # Create energy container instance
4energies.append(energy1) # Append first energy
5energies.insert(0,energy2) # Insert second energy before first energy
The energy container can be saved into a file using the GEnergies::save() method, and loaded from a file using either the load constructor or the GEnergies::load() method.
Another energy container class is GEbounds which stores the energy boundaries for an arbitrary number of energy bins.