## 3 Code Functionality  
This section details the functionality and development of a simple algorithm to determine the first arrival time of TNSA-generated ions from the above-discussed TOF spectra. Of the 24 datasets, 15 were used as training data while the remaining 9 were used as a confirmation test set, a separate set of data that was not used in the code development but was instead utilized to confirm the validity and functionality of the finished code operating on a set of data hitherto unseen. The development and operation of the code itself will now be discussed before concluding with the validity test. For the construction of the algorithm to accurately detect the maximum proton energy of a TOF dataset, a similar code that was written in python was used as a baseline. This early code provided two methods of calculation of the maximum proton energy, the former using a basic calculative measure in which the beginning of the curve was taken as the first signal point to exceed the value of three times the standard deviation of the noise data. This value was chosen based on trial and error testing of the code. The latter of the two methods was derived via processing the time-domain data into an energy distribution (the results of which are shown in Figure 1) via Equation (1) as previously shown. The maximum energy could, therefore, be taken from the resulting plots largest energy value. This code was expanded upon in order to provide a higher level of accuracy for the maximum energy and improved user experience. Below, these changes are detailed, and in the results section we will compare the accuracy of the original and newly designed methods of maximum energy determination (note that, due to the infinitesimal nature of the maximum proton energy, we are limited by the noise floor of the detector and so our maximum energy is defined by some arbitrary conditions, as will be detailed later). Both the original base code and the improved code were constructed exclusively in Python 3.11.0, with data analysis mainly performed using the libraries numpy, pandas, and scipy. The first step towards accurate energy determination is pinpoint isolation of the photopeak which, due to its often sudden-spiked nature can in most cases be identified within the signal noise. A system was designed to calculate an estimate quantifiable value of the datasets noise by calculating the average of all modulus values and the standard deviation within the first 2% of the data points within the set. This number was manually chosen based on the observation that the photopeak did not lie within this range in any observed data. The modulus values must be used for the averaging process as the noise fluctuates equally about zero, meaning the standard average provides no measurement of the noise magnitude, and the modulus can instead be used to define an average value above zero, about which the signal consistently lies. The photopeak time-of-arrival is then taken as the first voltage signal point to exceed this average modulus noise value plus twice the standard deviation. This formula was again chosen through a trial and error process using the full number of gathered datasets for its development and was found to consistently pinpoint the photopeak to within an acceptably small margin of uncertainty for all of the datasets provided. This process also defines the photopeak as the rising edge point as opposed to the highest value, however, due to the inherent thinness of the photopeak relative to the datasets full-time scope, this approximation maintains validity (in a dataset of 50,000 points spanning 10 \(\upmu\)s, the photopeak spans five datapoints, or 0.1 ns). This method pinpointed the photopeak exactly in 18 out of the 18 sets in which there was a visible photopeak, however, in the case of the remaining six datasets no photopeak was discernable from the noise due to experimental limitation.