The determination of x-ray spectra near the maze entrance of linear accelerator (LINAC) rooms is challenging due to the pulsed nature of the LINAC source. Mathematical methods to account for pulse pileup have been examined. These methods utilize the highly periodic pulsing structure of the LINAC, differing from the effects of high-intensity radioactive sources. Methods: Sodium iodide (NaI) and plastic scintillation detectors were used to determine the energy spectra at different points near the maze entrance of a medical LINAC. Monte Carlo calculations of the energy distribution of scattered photons were used to simulate the energy spectrum at the maze entrance. The proposed algorithm uses the Monte Carlo code, FLUKA, to calculate a response function for both detectors. To determine the effects of the pileup in the spectra, the Poisson distribution was used, employing the average number of photons per pulse (l) interacting with the detector. The quantity, l, was obtained from the ratio of the number of events detected to the number of pulses delivered. The energy spectra at various distances from the maze entrance were measured using NaI and plastic scintillation detectors. From these measurements, the values of µ were calculated, and the pileup probability was determined. The FLUKA Monte Carlo code was used to calculate the spectrum at the maze entrance and the response matrices of the NaI and plastic scintillation detectors. The algorithm based on the Poisson distribution was applied to calculate the spectrum. Results: The agreement between the calculated and measured spectra was within the first standard deviation of the variance expected in µ. This agreement confirms that photons at the maze entrance have energies between 30 and 240 keV for a maze with three turns, with an average energy of around 85 keV. After pileup correction, the range of the pulse height distribution with the plastic scintillation detector, which has a low atomic number, was decreased (0 to 140 keV). In contrast, the range of the pulse height distribution with the NaI scintillation detector was closer to the photon spectrum (0 to 240 keV). Conclusions: The corrected spectrum demonstrates that using a FLUKA Monte Carlo code and an algorithm based on the Poisson distribution are effective methods in removing the distortion due to the pileup in LINAC spectra when measuring with NaI and plastic scintillation detectors. The agreement between the corrected and measured spectra indicates that Monte Carlo modeling can accurately determine the spectrum of a LINAC machine at the maze entrance.