Advancements in Computing and Simulation Techniques for the HIBEAM-NNBAR Experiment \firstname First author \lastname First author \fnsep, \firstname Second author \lastname Second author \fnsep, \firstname Third author \lastname Third author \fnsep, \firstname Bernhard \lastname Meirose \fnsep, \firstname Jorge \lastname Amaral, \firstname Alexander \lastname Burgman, \firstname Matthias \lastname Holl, \firstname Ernesto \lastname Kemp, \firstname Adam \lastname Kozela, \firstname David \lastname Milstead, \firstname André \lastname Nepomuceno, \firstname Anders \lastname Oskarsson, \firstname Krzysztof \lastname Pysz, \firstname Valentina \lastname Santoro, \firstname Tiago \lastname Quirino, \firstname Blahoslav \lastname Rataj, \firstname Gabriel \lastname Silva, \firstname Samuel \lastname Silverstein, \firstname Magnus \lastname Wolke, \firstname Lucas \lastname Åstrand Abstract The HIBEAM-NNBAR program is a proposed two-stage experiment at the European Spallation Source focusing on searches for baryon number violation processes as well as ultralight dark matter. This paper presents recent advancements in computing and simulation, including machine learning for event selection, fast parametric simulations for detector studies, and detailed modeling of the time projection chamber and readout electronics. 1 Introduction The HIBEAM-NNBAR experiment ( Addazi:2020nlz ) is a multidisciplinary, two-stage program at the European Spallation Source (ESS) Garoby_2017 . The first stage, HIBEAM Santoro:2023izd , includes high-sensitivity searches for neutron oscillations, sterile neutrons, and axions, as well as searches for exotic neutron decays. The second stage, NNBAR Santoro:2024lvc , will have a discovery potential three orders of magnitude higher than the last neutron-antineutron oscillation search conducted in the 1990s at the Institut Laue-Langevin Baldo-Ceolin:1994hzw . This paper summarizes advancements in computing and simulation for the HIBEAM-NNBAR program, building on the developments presented in our previous paper Barrow:2021deh . The paper is organized as follows. Section 2 describes some of the machine learning techniques implemented in HIBEAM, followed by a discussion on the use of fast parametric simulations in Section 3 . Section 4 focuses on simulations of the time projection chamber (TPC), while Section 5 describes the simulation framework designed to replicate detector readout behavior. A brief summary is presented in Section 6 . 2 Machine learning Machine learning (ML), a branch of artificial intelligence (AI), enables computers to learn from data without explicit programming. It is particularly effective for problems lacking deterministic solutions, where algorithms identify patterns in data. In HIBEAM-NNBAR, ML enhances neutron-antineutron annihilation event selection, improving signal discrimination from background processes. The HIBEAM simulation dataset, used for training and evaluation, contains 369,569 events. The signal consists of neutrons converting into antineutrons and annihilating within a carbon nucleus, producing multi-pion events. Background events, primarily cosmic rays, were generated using the CRY library CRY and simulated interacting with the annihilation detector. Each event is represented by 49 high-level variables, including TPC_tracks (number of TPC tracks), Scint_eDep (scintillator energy deposition), and Inv_mass (invariant mass). The dataset is split into training (40%), validation (10%), and test (50%) sets. Models tested include Logistic Regression, Decision Trees, Random Forests, Extreme Gradient Boosting (XGBoost), and Light Gradient Boosting (LGBM). These were implemented in Python using the libraries scikit-learn (version 1.2.2), XGBoost (version 2.0.3), and LightGBM (version 4.0.5), respectively. HIBEAM-NNBAR requires 100% background rejection. To achieve this, we developed a custom metric penalizing false positives: C_{\text{metric}}=\frac{FN+(\beta-1)\cdot FP}{\beta} (1) where FN and FP are false negatives and false positives, respectively, and \beta=1000 . The model, trained with this metric, is optimized using the validation set to determine the optimal threshold. Hyperparameter tuning is performed using the OPTUNA framework akiba2019 . It presents a straightforward interface that can be used with the mentioned models to find he best hyperparameters. Table 1 : Signal/background separation results in the test set. Model Metric Variable Threshold Rejection Efficiency Random Forest (Optuna) Custom 49 0.933 100 95.81 XGB (Optuna) Custom 49 0.999 100 98.71 LGBM (Optuna) Custom 49 0.999 100 98.69 LGBM (Optuna) + Corr. Custom 26 0.997 100 98.00 LGBM (Optuna) + PCA Custom 17 0.999 100 74.00 Table 1 summarizes the results. Random Forest, XGB, and LGBM achieved 100% background rejection with high efficiency. To simplify the analysis, we applied correlation selection, reducing the number of variables to 26 while maintaining 100% rejection and 98% efficiency. Principal Component Analysis (PCA) further reduced variables to 14, but efficiency dropped to 74%. These results demonstrate that 100% background rejection is achievable with ML. Current efforts focus on minimizing the number of input variables and applying explainable AI techniques samek2019explainable to derive interpretable insights, potentially offering new perspectives on standard cut-based selections. 3 Fast Simulation Full Monte Carlo-based simulations are computationally expensive. In early detector design studies, such detail may be unnecessary. Instead, a faster approach, with reduced complexity, improves processing speed. Fast simulation techniques, widely used in high-energy physics, replace step-by-step particle interactions with parameterized detector responses. This work develops fast simulations for the HIBEAM-NNBAR experiment, particularly for the electromagnetic calorimeter. Fast Simulation of the HIBEAM Calorimeter This approach was used to develop a fast simulation for the NNBAR electromagnetic and hadronic calorimeters, as well as for a potential HIBEAM electromagnetic calorimeter. The NNBAR and HIBEAM electromagnetic calorimeters are made of lead glass, while the NNBAR hadronic calorimeter consists of a stack of 10 scintillator slats. In this section, we focus on the fast simulation of the HIBEAM electromagnetic calorimeter. The WASA Scintillator Electromagnetic Calorimeter (SEC) was part of an experiment aimed at investigating light meson production in light ion collisions and rare \eta meson decays at the CELSIUS storage ring in Uppsala Bargholtz_2008 . The SEC is a strong candidate for the HIBEAM electromagnetic calorimeter. To study the performance of the WASA SEC in reconstructing neutral pions, charged pions, and protons, a fast detector simulation was developed. For photons, the parametrization of the signal of interest—energy deposits—was constructed based on the detector’s energy resolution for a two-photon signal, as given in reference Bargholtz_2008 : \frac{\sigma_{E}}{E}=\frac{0.05}{\sqrt{E[\text{GeV}]}} (2) This parametrization was implemented in Geant4 GEANT4:2002zbu . A simplified version of the SEC was used, where the actual calorimeter geometry was modeled as a hollow cylinder with an inner radius of 32.5 cm, an outer radius of 63.5 cm, and a length of 109 cm. When an incoming particle (photon or electron) reaches the calorimeter, the deposited energy is determined through Gaussian smearing of the particle’s kinetic energy, with the Gaussian width set by the detector resolution. The code was validated by simulating the decay of \eta mesons into photons and neutral pions (which subsequently decay into photons) and comparing the fast detector simulation results with real data recorded by the WASA calorimeter. We found good agreement between the fast simulation and real data. Additionally, a fast simulation of photon-pair detection from the decay of neutral pions—a key signal for neutron annihilation studies—was performed. Note that at this stage, fast simulation smears photon energies only, without altering their positions or simulating shower development. Thus, shower overlaps are not considered, and photons are well separated by construction. Figure 1(a) shows the reconstructed neutral pion mass from the fast simulation of a photon pair detected by the calorimeter, originating from the decay of neutral pions with kinetic energies of 200 MeV. Figure 1(b) illustrates the calorimeter’s geometrical acceptance as a function of \pi^{0} kinetic energy. As shown, for energies around 150 MeV—the typical energy of \pi^{0} from annihilation—the acceptance is approximately 73%. (a) (b) Figure 1 : (a) Reconstructed \pi^{0} invariant mass and (b) SEC geometrical acceptance. For the charged pion response, the data used to derive the parametrization were obtained from an experiment using a detector array of seven pure CsI crystals, with dimensions similar to those of the SEC crystal, located at the proton synchrotron at KEK Yamazaki:1997zv . CsI crystals effectively stop charged pions with kinetic energies up to \sim 150 MeV. For kinetic energies above \sim 200 MeV, the pions punch through the detector unless nuclear reactions occur, resulting in an energy loss peak at around 140 MeV, which is nearly independent of the incident kinetic energy. The spectrum for \sim 190 MeV pions includes contributions from both stopped and punched-through pions and is treated as a special case in the parametrization. A Gaussian function is fitted to the pion energy distributions in the crystal for different initial kinetic energies, and the fitted Gaussian distribution widths are used to determine the resolution. Figure 2(a) shows the resolution obtained for the pion kinetic energies available in the data, along with a fitted resolution function. The parametrization for charged pion energy loss is given by \frac{\sigma_{E}}{E}=\frac{9.3}{E[\text{MeV}]}. (3) For the special case (kinetic energy \sim 190 MeV), the resolution is \sigma_{E}/E=0.16 . A similar approach was used to simulate the detector response to protons, using data from MERCHEZ1989133 . The resolution model is given by \frac{\sigma_{E}}{E}=\frac{a}{\sqrt{E\,[\text{GeV}]}}\,+\,b, (4) with fitted parameters a=0.00068 and b=0.0036 . Figure 2(b) shows a fast simulation of charged pions and protons expected from the annihilation signal in the HIBEAM calorimeter. The peak observed at around 150 MeV reflects the fact that pions with higher kinetic energies punch through the detector and contribute to an energy peak at \sim 150 MeV. (a) (b) Figure 2 : (a) Energy loss resolution for charged pions in a CsI crystal, with fitted curve, and (b) fast simulation of annihilation signal in the HIBEAM electromagnetic calorimeter. 4 TPC Simulation A TPC is a detector that reconstructs charged particle tracks in a gaseous volume. Fast readout electronics enable 3D tracking in high track-density environments. As a particle traverses the gas, it ionizes atoms along its path. Under a uniform electric field, the ionization electrons drift toward a segmented anode, forming a 2D (XY) projection. The third coordinate (Z) is determined from the drift time, which depends on the gas properties. The planned TPC features charge amplifier GEM detectors in the XY plane, followed by charge collection pads. An electric field in the induction region reduces electron cloud diffusion, enhancing spatial resolution. The collected charge’s impact positions (XY) and known drift time enable full track reconstruction. Three key studies are required for TPC development: (1) Computational simulations using Garfield++ schindler_heinrich_garfield_2010 to assess resolution, (2) Optimization of readout pad geometry, considering zigzag pads for improved resolution, and (3) Readout electronics development. The simulation framework integrates Matlab© MATLAB , COMSOL© COMSOL , and Garfield++ Pfeiffer:2018yam . Matlab© generates TPC geometries, which COMSOL© processes for mesh generation and electric field calculations. The output feeds into Garfield++, which simulates particle interactions with gas. The setup tested includes a 23.1\times 10.0\times 10.0 cm 3 TPC with three 10\times 10 cm 2 GEMs, an 80% Ar/20% CO 2 gas mixture, and a 287.3 V/cm field. A sample of 21 muons (1 GeV) is simulated in random directions. The framework allows rapid configuration changes via Matlab scripting. Garfield++ outputs ROOT files containing electron drift data for analysis. Using parallel computing, multiple particles are simulated concurrently. Figure 3 displays reconstructed muon trajectories. Figure 3 : Simulated muon trajectories in the TPC. Track reconstruction depends on the zigzag pad geometry. Figure 4 compares three designs: the current prototype, a version with twice the pad count, and one with steeper angles. The readout consists of 10 rows, each with 25 pads. Figure 5 shows reconstructed tracks for the prototype design. Table 2 presents residuals in y and z. Since this is a simulation, direct comparisons with true particle trajectories are possible. Increasing pad count improves z-resolution, while y-resolution is limited by the number of rows. Future work will optimize the zigzag design for maximal spatial resolution. Figure 4 : Zigzag pad designs: Double pads (left), Prototype (center), Double angle (right). Figure 5 : Reconstructed tracks (dashed lines mark GEM positions). Table 2 : Reconstructed track residuals (all values in cm) Prototype Double Pads Double Angle Number of pads 250 510 250 Estimated residuals y 0.005 \pm 0.153 0.008 \pm 0.143 0.002 \pm 0.177 Estimated residuals z 0.000 \pm 0.099 0.000 \pm 0.074 0.000 \pm 0.060 Real Path residuals y 0.007 \pm 0.042 0.004 \pm 0.038 0.009 \pm 0.060 Real Path residuals z 0.002 \pm 0.027 0.003 \pm 0.014 0.005 \pm 0.017 5 Readout Simulation The readout simulation framework models detector readout channels under experimental conditions, assessing their influence on data acquisition from the Hadronic Range Detector (HDR), Lead Glass EM Calorimeter (LEC), and TPC. It provides a structured approach to simulate signal acquisition, incorporating key physical and electronic processes relevant to the HIBEAM-NNBAR experiment. A similar framework is being developed by Luna et al. ( luna2024 ) , with this work expanding upon comparable methodologies. Figure 6 presents a flowchart outlining the framework, which ensures consistency between simulated and experimental conditions. It enables detailed investigations into noise propagation and signal distortions. Figure 6 : Flowchart of the simulation framework for TPC, HDR, or LEC readout channels. The framework consists of four main steps: Event Timing , modeled using a Poisson distribution to capture the stochastic nature of particle interactions; Energy Distribution , simulated via Geant4 to provide realistic event-by-event deposition profiles; Readout Electronics Modeling , which incorporates pulse shaping, amplification, and digitization effects; and Electronic Noise , added as a Gaussian-distributed component to simulate signal distortions. The signal generation process follows a mathematical model where event occurrences are governed by a Poisson-distributed random variable t\sim f_{\tau}(t) , defining a Bernoulli-distributed detection function p(t) , which, in discrete time with sample period T_{s} , is represented as p[n] . The deposited energy amplitude, represented as A[n]\sim f_{A}(a) , leads to the energy signal a[n]=p[n]\cdot A[n] . Readout electronics shape the signal via convolution with the impulse response h[n] , producing r[n]=a[n]*h[n]+e[n] , where e[n] is Gaussian noise. Figure 7 shows an example of simulated signals over a few samples, assuming a 20 MHz sampling rate and an exponential decay pulse with a 0.15 \mu s time constant. Figure 7 : Results of simulated signal operations in the framework. This simulation framework provides a robust environment for studying noise propagation and distortions in the readout system. It ensures alignment between simulated signals and experimental data, aiding in the evaluation of their impact on higher-level physics analyses, ensuring the reliability of the detector system. 6 Summary This paper discusses advancements in computing and simulation techniques for the HIBEAM-NNBAR experiment at the European Spallation Source. Key topics include machine learning applications for event selection, fast parametric simulations to streamline detector studies, and detailed simulations of the time projection chamber to enhance spatial resolution. Additionally, efforts to model readout electronics are presented, addressing noise propagation and signal distortions to improve data acquisition. 7