On the basis of the RHESSI results it has been suggested that terrestrial gamma flashes (TGFs) are produced at very low altitudes. On the other hand some of the Burst and Transient Source Experiment (BATSE) spectra show unabsorbed fluxes of X rays in the 25–50 keV energy range, indicating a higher production altitude. To investigate this, we have developed a Monte Carlo code for X-ray propagation through the atmosphere. The most important features seen in the modeled spectra are (1) a low-energy cutoff which moves to lower energies as TGFs are produced at higher altitudes, (2) a high-energy cutoff which moves to lower energies as TGFs are observed at larger zenith angles, and (3) time delays are observed for TGFs produced at ≤20 km (and some at 30 km) altitude when observed at larger zenith angle than the half-angle defining the initial isotropic X-ray beam. This is a pure Compton effect. The model results and an optimization procedure are used to estimate production altitudes of the BATSE TGFs. The main findings are (1) half or more of the BATSE TGFs are produced at low altitudes, ≤20 km, (2) a significant portion of the BATSE TGFs are produced at higher altitudes, 30 km to 40 km, (3) for the TGFs produced at ≤20 km (and some at 30 km) altitudes the dispersion signatures can be explained as a pure Compton effect, and (4) the softening of the BATSE spectra for increasing zenith angles and the time dispersions both indicate that the initial TGF distribution is beamed.
 Following the discovery of the terrestrial gamma flashes (TGF) [Fishman et al., 1994] by the Burst and Transient Source Experiment (BATSE) on the Compton Gamma Ray Observatory (CGRO), there has been a debate about their production mechanism. Despite many unresolved questions there seems to be a consensus that these very short lived flashes (∼1 ms) of photon energies up to 20 MeV [Smith et al., 2005] are in fact bremsstrahlung produced by a beam of relativistic runaway electrons (RRE) produced above large thunderstorm systems. The controversy, however, is whether the electrons are accelerated by the quasi-static electric field (QES) following large positive cloud-to-ground lightening strokes [e.g., Gurevich and Zybin, 2001] or other mechanisms like the electromagnetic impulses (EMP) suggested by Inan and Lehtinen . When TGFs were first discovered, the QES theory was considered as the most likely production mechanism [Fishman et al., 1994]. However, the shape of measured spectra did not give a consistent picture for such an interpretation. While the QES mechanism is thought to be most important closer to cloud top at 10–20 km, many of the spectra did not show the expected absorption signatures at low photon energies. Consequently, many BATSE spectra indicate a higher production altitude. This argument was repeated by Nemiroff et al.  who performed a more detailed analysis of the spectral and temporal behavior of the BATSE measurements. They based their conclusion on the statement that the atmosphere is not very transparent for X-rays produced below 40 km. This mismatch of altitudes resulting from QES theory and observations were further modeled by Lehtinen et al. [1997, 1999, 2001] who found that QES mechanism could only be efficient up to 20 km at most. These findings motivated the EMP theory [Inan and Lehtinen, 2005] which allows for a production altitude of 50 km to 60 km. On the other hand the model results presented by Roussel-Dupré and Gurevich  indicate that the electric field above thundercloud after an intracloud strike can exceed the threshold electric field for runaway process at two altitudes, one just above the thundercloud and the other at 40–60 km. New observational evidence of the TGFs have been provided by the Reuven Ramaty High Energy Solar Spectroscopic Imager (RHESSI). Owing to a more effective trigger algorithm, RHESSI has been able to observe 10–20 TGF per month, while BATSE reported about 70 over a 9-year period. On the other hand, BATSE measured typically 100 counts/TGF [Nemiroff et al., 1997] due to larger detector area and provided spectral information about the individual TGF while the typical RHESSI event only have 20–30 counts/TGF. Thus in order to study the spectral shape of the RHESSI observations, all observed TGFs were superposed and, based on a Monte Carlo simulation, Dwyer and Smith  found that the superposed spectrum was indicative of a production altitude of 15 km to 21 km. However, to obtain this result, they had to make assumptions about the spatial distribution of TGFs within the field of view of RHESSI, that is, the distribution of entering angles, which depends on production altitude, X-ray propagation, and instrument sensitivity. Discussing the missing attenuation signatures at low energies in many of the BATSE spectra, they also considered the possibility that there might be two types of TGFs, a low-altitude TGF and a high-altitude TGF. If the latter is true, the superposition of all the RHESSI spectra will mix the two types of spectra. A similar approach, that is, adding all RHESSI spectra and averaging over all BATSE entering angles, was used by Carlson et al. , who found the most likely production altitude to be 15 km to 20 km and that the X-ray beam most likely was initially isotropic within a half-angle of 45° in contrast to the highly beamed initial X-ray distribution suggested by Cummer et al.  and Stanley et al. .
 To avoid the mixing of two possible types of TGFs and take advantage of the higher sensitivity as well as directional information from the BATSE measurements, we have revisited the BATSE spectra and performed a careful Monte Carlo (MC) simulation of the available individual spectra and their dispersion signatures. It will be shown that the information about entering angles is important and can help us understand the temporal behavior of TGF. Furthermore, information about entering angles has implications for the spectral shape and consequently the inferred production altitude. This study is also motivated by the upcoming experiment, Atmosphere-Space Interaction Monitor (ASIM), that will carry an X-ray detector to the International Space Station to monitor the low-energy part of the TGFs. Our study does not model the production of TGF by the relativistic electrons, but examine how a given X-ray energy spectrum with a power law ≥1 produced at some altitude or distribution of altitudes propagate through the atmosphere and what the output spectrum will be observed at different escaping angles at the top of the atmosphere. All effects that affect the propagation are taken into account, that is, absorption, Compton scattering and energy degradation, pair production, and new X rays produced by positrons and electrons.
2. BATSE Spectra and Time Profile
2.1. BATSE Measurements
 The BATSE spectra from the Large Area Detector are sampled in four bins with energy bins 24–60 keV, 60–110 keV, 110–320 keV, and 320–22,206 keV. Although the energy resolution of the BATSE spectra is not very good, this instrument was sensitive to X rays down to about 25 keV. As the absorption effects on X rays at low energies is assumed to be a strong indicator of production altitude, these measurements are the only ones, to date, where the expected fall-off at low energies can be used for altitude production estimates. Whereas Nemiroff et al.  analyzed 13 spectra, we have found 21 spectra from the BATSE data base that had statistics good enough for the analysis presented in this paper. Furthermore, based on difference in counting rates in the eight various Large Area Detector of BATSE combined with the respond matrix for the instrument, the entering angle of the TGFs can be estimated. Our procedure will be described in section 4.
 Two BATSE spectra are shown in Figures 1a and 1b to illustrate the two types of spectra. The spectrum for trigger 2465 has a distinct fall-off at lower energies, indicating a production altitude deep in the atmosphere, whereas the spectrum for trigger 2144 does not resemble any signature of low energy absorption, even when the statistical error (vertical lines) are considered. One would assume that these two TGFs are produced at very different altitudes. This will be discussed later.
 Another significant result reported by Nemiroff et al.  is the dispersion signatures which were present in most of the TGFs. In Figures 1c and 1d one can see the dispersion signatures for the same two trigger events. Dispersion signatures are seen for TGFs both with and without the low-energy cutoff. Figure 23 shows the distribution of time delays for the first three energy bins relative to the highest energy bin in 200 μs time bins for all the TGFs. While eight TGFs are in the ±100 μs bin, 15 TGFs show a distinct dispersion signature of 100–300 μs, with an average of 240 μs. Nemiroff et al.  reported time delays between 100 μs and 200 μs based on their 13 events.
3. Monte Carlo Simulations
 To model the BATSE spectra and dispersion signatures, we have developed a MC code for X-ray propagation through the atmosphere. The code takes into account photoelectric absorption, Compton scattering and energy degradation, pair production and, the most important contribution of new X-rays produced by pair-produced positrons and electrons. A detailed description of the code is given in Appendix A, and here we just give a brief overview of input, output and main features of the MC code. In our MC runs we initiate 1 or 5 million photons with six different power law distributions with an upper cutoff energy at 18 MeV produced at seven different discrete altitudes or distributed altitudes. Five million photons are only used for the lowest production altitudes, 10 km, 15 km, and 20 km, in order to obtain sufficient statistics of photons escaping the atmosphere. We let the power laws vary from 1 to 1.5, as the hardest spectrum that can be produced in the bremsstrahlung process is a power of 1. However, as will be seen the spectrum measured at the top of the atmosphere can be much harder than 1/E. In addition we run the code for two different initial angular distribution, one that is beamed vertically along z-axis and one isotropic within 20° solid angle. We sample the photons at the top of the atmosphere in seven different 10°-intervals of escaping angles, that is, α = 0°–9°, 10°–19°, 20°–29°,30°–39°, 40°–49°, 50°–59° and 60°–69°, that is, these are solid angle intervals. As explained in Appendix A2, this gives four libraries of a total of 1176 different spectra escaping the atmosphere. For each photon we keep track of energy, altitude, azimuth, zenith, radius from origin in xy-plane and the accumulated path length.
3.1. Comparison With GEANT
 The MC code is optimized to run fast and is much simpler (and faster) than the more complex GEANT code [Agostinelli et al., 2003]. GEANT is a powerful Monte Carlo high-energy physics simulator used extensively in particle physics for detector design, radiation dosimetry, and predictive modeling. However, to verify our code, we have compared our results with GEANT for three different production altitudes. Both the GEANT runs and our MC runs are initiated with 1 million photons distributed as E−1 with cutoff at 10 keV and 10 MeV starting at three different discrete altitudes as a beam with α = 1°.
 Besides showing almost identical profiles, the comparison shows that the total numbers of photons escaping the atmosphere only vary +3%, −2%, and +1% (MC versus GEANT). Although the differences are negligible, they can be explained by the exponential fit we use for the density profile, which misses the real density increase around 50 km, which was used for the GEANT run. We should emphasize at this point that we only model the X-ray propagation and not the original production of bremsstrahlung by runaway electrons. Thus only the new bremsstrahlung produced by pair-produced electrons are added to the X-ray distribution. Consequently, there is no electric field in either models accelerating the electrons produced by the pair production process.
3.2. Beamed Distributions From MC
 In Figure 4 we present the results for initial distributions of photons beamed at α = 0° produced at discrete altitudes (Figure 4, first, second, and third columns) compared with a distributed production altitude profile (Figure 4, fourth and fifth columns). The distributed production altitude profiles are shown in Figure A3 in Appendix A. The initial spectral distribution is E−1. The photons are sampled at seven different escaping angle intervals (solid angle intervals due to the cylindric symmetry) at the top of the atmosphere.
 First, we want to focus on the spectra in the third and fourth columns. The spectrum in black is what we would see if we could sample all the photons escaping the atmosphere. The other lines are the spectra from escaping angles 0°–9° (light blue), 10°–19° (green), 20°–29° (light green), 30°–39° (orange), 40°–49° (red), 50°–59° (brown), and 60°–69° (blue).
 The following features in the spectra should be noticed.
 1. Spectra from all production altitudes have a high-energy cutoff at decreasing energy for increasing escaping angle. This is due to the fact that the high-energy photons that escape the atmosphere have not interacted with the air, while lower-energy photons will experience multiple Compton scattering decreasing their energy and changing their direction. Thus the highest X-ray energies will only be measured if the initial X rays are beamed directly toward the detector. This is true for both the discrete altitude and the distributed altitude. Given that TGFs are initially beamed and randomly distributed in the field of view of any detector on a satellite it is more likely to observe TGFs at 40° escaping angle than at 0°. This implies that a distinct high-energy cutoff should be observed if one had the energy resolution or at least as a softening of the spectrum. This will be discussed later when we compare with the BATSE measurements.
 2. For all escaping angles except 0°–9° the low-energy cutoff due to absorption gets steeper as the production occurs deeper in the atmosphere. The spectra from 60 km have a very broad energy peak compared to production at 15 km and 20 km.
 3. The low-energy cutoff does not seem to depend very much on the assumption of a discrete altitude or a distributed altitude profile. This is somewhat surprising because in the distributed case some photons propagate through less air than in the discrete case and would be less affected by absorption. The similarities in shape indicate that the differences in absorption are insignificant as long as the peak production dominates.
 4. If the TGFs are produced at very low discrete altitudes, for example, at 10 km or 15 km, there will be a minimum around 0.7–1 MeV, see Figures 4a and 4b, third column. This minimum is very distinct for small escaping angles. This minimum, which is at lower energies (∼500 keV) for the <90° curve they used, is what made Dwyer and Smith  conclude that the RHESSI superposed spectra are most likely produced at very low altitudes. For the distributed altitude profile for 15 km and 20 km (Figures 4a and 4b, fourth column) there is not a minimum but a flattening of the spectra above ∼500 keV.
 Now we turn to the predicted energy dispersion signatures. As we keep track of the accumulated path length before escaping the atmosphere at 100 km, the total time spent within the atmosphere is given for each photon as
where c is the speed of light and s is the accumulated path length. In the first, second, and fifth columns we show the time profiles for the photons in four different energy bins, which is the the same binning that was used for the BATSE measurements [Nemiroff et al., 1997]. Time resolution is 100 μs and zero is the time of the TGF initiation at the production altitude. The counts have been normalized, but both the error bars (which are small and can only be seen in some of the plots) as well as the normalizing factor (i.e., the number in upper left corner) are indicated.
 The following features in the time profiles should be noticed:
 1. Time delays of 100 μs can be seen for TGFs produced at 20 km and below when observed at the most likely zenith angles, 40°–49° (Figures 4a and 4b, third and fourth columns). For TGF produced at 30 km, only some escaping angles, that is, 30°–39°, show dispersion for all initial power indices, beamed and isotropic, while TGF produced at ≥40 km show no dispersion. The modeled dispersion signature is a pure Compton effect. The photons with low energies escaping the atmosphere are in fact initial high energy photons that have experienced multiple scattering and energy degradation. The high-energy photons escaping the atmosphere are the ones that propagated with only one or two interactions with air. Consequently, the low energy photons due to the multiple Compton scattering have a much longer accumulated path length than the high-energy photons.
 2. If TGFs are observed at the same angle as they are produced, i.e., the instrument zenith angle and X-ray initial α angle are the same (for plane atmosphere), the majority of photons detected have not experienced any interaction with air, even from 10 km. However, as mentioned above, it is not very likely to observe TGFs at small escaping angles.
 3. For TGFs produced at high altitudes (>30 km) and observed at large escaping angles, there are no peak in the time delay, but a tail can be seen at lower energies.
3.3. Isotropic Cone Distributions From MC
 Then we present (Figure 5) the results for photons with an initial isotropic angular distribution within a cone of α = 20°. The spectral distribution is again E−1 and a distributed altitude profile is used to make the results comparable with the two rightmost columns in Figure 4.
 Regarding both the spectra and time profiles the same features as pointed out for the beamed spectra can be seen. The only difference is that the high-energy cutoff now only appears for escaping angles larger than 20°. A detector sampling at angles smaller than the isotropy angle will see a mixture of directly escaping photons and photons that have experienced multiple Compton scattering. However, at sampling angles larger than the isotropy angle the Compton scattered photons will dominate and give rise to a high-energy cutoff. Time profiles for both 0°–9° and 10°–19° (not shown) are similar to the profiles in Figure 4, first column, that is, as for photons escaping vertically out of the atmosphere. However, as soon as we sample at angles larger than the isotropic boundary a clear time delay is seen for TGFs produced ≤20 km. The explanation is again that we sample only photons that have experienced Compton scattering and energy degradation or reproduced by pair production. For TGFs produced at 30 km and above there are no time delay for the peaks but a tail can be seen.
3.4. Beamed Distributions From MC: Spectrograms
 To further see the spectral differences versus altitude and escaping angles, we present spectrograms (Figure 6) for three different escaping angles for discrete altitude (left column) and distributed altitude (right column). The initial X-ray distribution was beamed and E−1. We want to point out the following: (1) The low-energy cutoff moves to lower energies as the TGFs are produced at higher altitudes. (2) The high-energy fall-off has a minimum for 10 km and 60 km with a maximum for 20 km. (3) The peak intensity (white line) are similar for 10 km to 30 km, but falls off for production altitudes above 30 km. (4) Production altitude of 15 km and 30 km gives very similar spectra which will be difficult to distinguish. (5) The similarities between a discrete altitude and a distributed altitude profile is striking except for TGFs produced at 10 km. To summarize so far, it should be possible to use the differences in low-energy and high-energy cutoffs as well as the peak energy to determine at what altitude the TGFs are produced.
4. Comparing With the BATSE Spectra and Time Profiles
 Now we describe how the library of all our modeled TGF spectra will be used to find the most likely production altitude and initial spectral index for each BATSE spectrum. The four different libraries of modeled spectra (the beamed-discrete, the beamed-distributed, the isotropic-cone-discrete, and the isotropic-cone-distributed) are used separately for each TGF. The production altitude and initial spectral index values are estimated by an optimization procedure which folds the modeled photon spectra through the BATSE Energy Response Matrix (ERM) to form a χ2 parameter from actual BATSE data counts. The parameters of TGF amplitude, altitude, index, and spatial location are then varied in a continuum parameter space to find a minimum χ2 value.
 For each BATSE TGF the procedure is carried out in three steps and the result for TGF trigger 106 is shown in Figure 7.
 1. An initial coarse location map is created by scanning an image field of view below BATSE from the nadir out to the earth horizon (∼70°). For each pixel a simple detector area vector (dot product) with the pixel direction vector is used to get a rough spectral amplitude and χ2 parameter. This is done with just the four of the eight BATSE detectors which will be facing the pixel TGF flux direction. The result is a map of regions of detector “quadruples” showing how the χ2 fitting parameter varies within them. This gives a sequence of coarse possible TGF locations which are then to be used as initial locations for a second finer search using some plausible spectral model.
 2. For each possible location a first TGF Location Spectrum (TLS) is used and folded through the BATSE ERM to form a χ2 optimization parameter with the BATSE count data (the black line in the Figure 7a). The TGF location and TLS parameters are varied to find a new location which is accurate to within about 5 degrees and close to the best TGF location estimate to be expected. The detector “quadruple” with the minimal χ2 then gives the selection TGF location.
 3. Using this finer location the procedure is then repeated to match with the MC modeled photon flux data and its altitude, spectral index, escape angle parameters to find a new optimal location and parameters. The resulting best fit for all four libraries are shown in Figure 7a as red, green, blue, and cyan lines. The beamed-discrete best fit is also shown as a red histogram after folded through the ERM with the Poisson uncertainties (red vertical lines). Black squares are the mean input count values for the four BATSE detectors facing the TGF.
 The results of the optimization for TGF trigger 106 can be seen in the altitude-index map (Figure 7b) showing the variation in the χ2 fitting parameter around some optimum (altitude, index) point. From the first contour at χ2 minimum +1.0, robust estimates in altitude and index can be obtained. Ideally, this contour should be a circle or ellipse but in some cases it is a long winding valley given a good estimate in altitude but a large error bar on the spectral index, perhaps so large that in some cases, the spectral index is not determinate.
 There are two criteria for including the TGFs in the final analysis. (1) The reduced χ2 (i.e., the χ2 divided by the degree of freedom) should be less than 1.5. (2) There is only one location, that is, zenith angle, that fulfills this criterion. Of the 25 BATSE TGFs we started with, a total 21 TGFs meet both these criteria. In Figure 8 the results of the optimization procedure described above for the four libraries are shown with error bars for both altitude determination and initial spectral index.
5.1. Production Altitude
 For all the four libraries the optimized production altitudes are found between 10 km to 40 km and in Figure 9 the distributions of altitudes are presented. Half or more of TGFs are produced at 20 km or below, and all libraries indicate that a significant portion of TGFs are produced at higher altitudes.
 The features that most significantly identify the altitude is the low-energy cutoff, the high-energy cutoff, and the bump in the spectrum around 1 MeV. All these features are highly dependent on what zenith angle the TGF comes from, emphasizing how important this information is. Although the energy bins of the BATSE spectra are large we are able to distinguish the differences for low-energy and high-energy cutoff. The low-altitude TGFs are consistent with the results reported by Dwyer and Smith  and Carlson et al.  as well as observations of sferics correlated in time with TGFs [Stanley et al., 2006]. Cummer et al.  also suggested a low-altitude source due to insufficient charge moment changes to produce large electric fields at high altitudes for all the TGF they analyzed. On the other hand our results clearly indicate that a large portion of TGFs are produced at higher altitudes. The distributions in Figure 9 may indicate that there is a peak below 20 km and another from 30 km to 40 km. This would give some support to the modeling results by Roussel-Dupré and Gurevich  showing that the electric field above thundercloud after an intracloud discharge can exceed the threshold electric field for runaway process at two altitudes, one just above the thundercloud and the other above 40 km.
5.2. Dispersion Signatures
 As shown in Figures 4a and 4b, second and fifth columns, the modeled X-ray distributions found from our library will give dispersion signatures of about 100μs for all TGFs produced ≤20 km (and even at 30 km for some escaping angles), in good agreement with the BATSE time delay distribution shown in Figure 2. In these cases the time delays can be explained as a pure Compton effect as explained earlier. No additional temporal behavior of the QES (or EMP) is then needed to explain this feature.
 For the two TGFs shown in Figure 1, when using the beamed-discrete library, we found that the trigger 2144 was most likely produced at 35 km while trigger 2465 was produced at 29 km, which is much closer in altitude than we would expect. Although our modeling result shows clear dispersion for TGFs produced ≤20 km, some escaping angles (i.e, at 30°–39°) also show dispersion from 30 km (not shown) and the dispersion signatures seen for both these TGFs can still be a Compton effect.
5.3. Beamed or Isotropic Initial X-Ray Distribution
 In section 3 we pointed out that there is a very clear high-energy cutoff that moves to lower energies as the TGFs are observed at larger zenith angles. However, this will only be seen when the zenith angle (of observation) is larger than the angle defining the initial isotropic X-ray distribution (for a plane atmosphere). Furthermore, we made the point that this distinct high-energy cutoff should be observed if one had the energy resolution. As BATSE does not have sufficient spectral resolution at high energies we will look for a softening of the spectrum.
 In Figure 10 the zenith angle is shown as function of power index. This power index is not the power index that defines the initial X-ray distribution of the TGF as it is produced in the atmosphere. The power index shown here is related to the TGF spectrum escaping the atmosphere and give a measure of softening due to the high-energy cutoff. There is a clear trend that the TGF spectra observed by BATSE is softer at larger zenith angle. Following our argument about high-energy cutoff for TGFs observed at zenith angles larger than the isotropy angle, this is an indication that the initial distribution of X-ray is fairly beamed. Using the altitudes estimates from the beamed-discrete library, we can also see that TGFs produced deep in the atmosphere (open circles) have a harder spectrum than the TGFs produced at higher altitudes (asterisk) in excellent agreement with the bump at 1 MeV or flattening seen in the modeled spectra in Figures 4a and 4b, third column.
 A second indicator of beamed distribution is the time dispersion that will not be seen if the angle of observation is within the isotropic cone angle. As dispersion signature is a common feature this indicates that the isotropic cone angle has to be small, probably ≤30°.
 Finally, we want to emphasize once again that there are no electric field in our model. This means that the pair-produced positrons and electrons are not accelerated, which may underestimate the refilling of low-energy X rays somewhat. Future modeling efforts will aim at resolving this.
 By modeling the X-ray propagation through the atmosphere, taking into account all the important interaction processes the X-ray photons experience, we have built four libraries of the expected X-ray distributions at the top of the atmosphere for different escaping angles.
 Important features seen in the modeled spectra can be summarized:
 1. A low-energy cutoff which moves to lower energies as TGFs are produced at higher altitudes.
 2. A high-energy cutoff which moves to lower energies as TGFs are observed at larger zenith angles.
 3. Time delays are observed for TGFs produced at ≤20 km (and some at 30 km) altitude when observed at larger zenith angle than the half-angle defining the initial isotropic X-ray beam. This is a pure Compton effect.
 Combined with an optimization procedure to determine the zenith angle from BATSE measurements and the most likely production altitude and initial power index of the TGF, we have reached the following conclusions: (1) Half or more of the BATSE TGFs are produced at low altitudes, ≤20 km. (2) A significant portion of the BATSE TGFs are produced at higher altitudes, 30 km to 40 km. (3) For the TGFs produced at ≤20 km (and some at 30 km) the dispersion signatures can be explained as a pure Compton effect. (4) The softening of the observed BATSE spectra for increasing zenith angles indicate that the initial TGF photon distribution produced at some altitude is highly beamed.
 As all four libraries give converging results, we believe that it is not crucial for these results whether we assume discrete or distributed altitude as long as the peak altitude is dominating. Furthermore, as long as the half-angle of initial isotropic X-ray distribution is kept smaller than the zenith angle of observation, the beamed and isotropic (within 20°) distribution give very similar results.
Appendix A:: Monte Carlo Code
A1. Basic Elements of the MC Code
 As input to the MC code we need the coefficients in air for absorption (μA), Compton scattering (μC) and pair production (μP). We have used the coefficients given by Storm and Israel  for different photon energies as shown in Figure A1a.
 In Figure A1b the MSIS-E-90 atmospheric density profile at 55° geographic latitude is shown for July (dotted) and January (solid). The dashed line is the exponential fit to the January profile, requiring that the column density below 100 km is identical for the MSIS January profile and the exponential fit. The exponential fit helps us solving the path length analytically (see below) on the expense of not getting the small increase in density between 50 km and 80 km. The column densities for the various discrete production altitudes used in this study is given in Table A1.
Table A1. Altitude and Atmospheric Column Density
Column Density, g/cm2
 As Compton scattering implies both scattering and energy decrease depending on scattering angle, we need information about the angular scattering probability. Noticing that incoherent scattering is only important at low X-ray energies where absorption is dominating anyway, the following expression for Compton scattering probability versus scattering angle [Storm and Israel, 1967] can be used
where r0 is the electron radius, Z is average atomic number for air (7.35) and αn = . E is the energy of the photon. The normalized probability distributions for X-ray energies (E) from 50 keV to 18 MeV are shown in Figure A1c. For high energy X rays the Compton scattering are strongly forward scattered (θ = 0 is forward). When the scattering angle is known the new energy of the X-ray photon is given by
We have not included bremsstrahlung from Compton accelerated electrons, see discussion below.
 Pair production is treated separately for positrons and electrons. We assume the positrons will lose their energy through multiple collisions and eventually annihilate with a cold electron and produce two photons with energy of 511 keV in arbitrary but opposite directions. Although many of these photons will be degraded in energy by Compton scattering the peak at 511 keV in the spectrum escaping the atmosphere is due to the contribution from X rays produced by positrons. We have not included bremsstrahlung production from the positrons, see discussion below. For pair-produced electrons we have included the bremsstrahlung production. The newly produced electrons will have energies given by
These electrons will produce bremsstrahlung with energies ranging from 0 keV to EE. A test run with GEANT starting with 1 million X-ray photons from a discrete altitude of 15 km beamed inside a cone of 1° zenith angle (similar setup as shown in Figure 3a) was made with and without this bremsstrahlung produced by all electrons (pair-produced and Compton accelerated) and pair-produced positrons. The result can be seen in Figure A2.
 At the top of the atmosphere the contribution over all escaping angles is about 7% distributed in energies below ∼80 keV. For altitudes above 30 km the contribution is negligible. Although we do not think that this contribution will alter the results in this paper significantly, we have included the bremsstrahlung contribution from the pair-produced electrons in our MC code. The cross section for bremsstrahlung production for electrons is taken from Evans  and the angular distribution is for simplicity assumed to be in the direction of the parent electron.
 Although we have not included all the bremsstrahlung processes correctly, the validation by comparing our model with GEANT, which is shown in Figure 3, convinces us that our simplistic approach to estimate the bremsstrahlung contribution is not crucial for the results presented in this paper.
 In our MC simulations we start out with 1 (or 5) million photons. Each photon holds information about (1) altitude, z, (2) energy, E, (3) polar angle relative to z-axis, α, (4) azimuthal angle, β, (5) distant from origo, r in the xy plane, and (6) accumulated path length, s. The geometry is shown in Figure A3a.
 For each photon we calculate the path length before an interaction takes place based on general MC approach using the total interaction probability and random numbers. Using the exponential fit to the atmospheric density, this path length can be solved analytically by the following equation
where upward is a plus symbol and downward is a minus symbol, the angle α is defined in Figure A3a. The random number is rand and μT is given by
The density, at the starting altitude, z1 is given by equation (A6) where a is the coefficient in the exponential fit to the atmospheric density.
These analytic expressions are only valid for a planar atmosphere, which is used to speed up the code significantly. To find path lengths for a spherical atmosphere requires numerical integration. Our approach will underestimate the number of X-rays leaving the atmosphere and overestimate the accumulated path lengths slightly. As these effects are only significant for photons with α close to 90° we do not allow photons to have α angles between 85° and 95°. For angles <85° and >95° these effects are very small.
 The next step is to determine whether the interaction is absorption, Compton scattering or pair production by using their relative probabilities. For absorption the photon is lost. For Compton scattering, the angular probability function and energy formula (equation (A2)) gives us the new direction and energy. The new r and s are also calculated. For pair production the bremsstrahlung from electrons and the X rays produced from positron-electron annihilation are estimated. These X rays are added to the spectrum at this stage. This sequence is repeated until all photons have either reached the ground, escaped the atmosphere (>100 km), or been absorbed.
A2. Building the Library
 The 1 (or 5) million photons are initiated with a power law distribution, E−λ with a cutoff energy at 18 MeV (as shown in Figure A3b for λ = 1) at either a discrete altitude (z1) or a distributed altitude (as shown for z1 = 15 km and z1 = 30 km). We also run the code for two different initial angular distributions.
 First, we initiate the photons as a beam along the z-axis, with α = 0 for six different λs ranging from 1 to 1.5, starting at seven different altitudes, that is, 10, 15, 20, 30, 40, 50, and 60 km using two different profiles, a discrete altitude and a distributed profile. We sample each run at the top of the atmosphere in seven different 10°-intervals of escaping angles, that is, α = 0°–9°,10°–19°, 20°–29°, 30°–39°, 40°–49° 50°–59° and 60°–69°. For the beamed distribution from discrete altitude this gives 6 × 7 × 7 = 294 different spectra escaping the atmosphere.
 The same procedure is repeated with beamed distribution and distributed production altitude profile, an initial isotropic distribution within α = 20 from discrete altitude and an initial isotropic distribution within α = 20 from distributed production altitude profile, giving four libraries of spectra (294 × 4 = 1176).
 These four libraries, which are denoted “beamed-discrete,” “beamed-distributed,” “isotropic-cone-discrete,” and “isotropic-cone-distributed,” containing a total of 1176 spectra escaping the top of the atmosphere are then used for the fitting procedure for each measured BATSE spectrum.
 The authors would like to thank G. Fishman for the use of the BATSE data.
 Amitava Bhattacharjee thanks the reviewers for their assistance in evaluating this paper.