Citation: Baran, M.; Tabor, Z.; Rzecki, K.; Ziaja, P.; Szumlak, T.; Kaleci´ nska, K.; Michczy ´ nski, J.; Rachwal, B.; Waligórski, M.P.R.; Sarrut, D. Application of Conditional Generative Adversarial Networks to Efficiently Generate Photon Phase Space in Medical Linear Accelerators of Different Primary Beam Parameters. Appl. Sci. 2023, 13, 7204. https://doi.org/10.3390/app13127204 Academic Editor: Yutaka Ishibashi Received: 9 May 2023 Revised: 1 June 2023 Accepted: 8 June 2023 Published: 16 June 2023 Copyright: © 2023 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https:// creativecommons.org/licenses/by/ 4.0/). applied sciences Article Application of Conditional Generative Adversarial Networks to Efficiently Generate Photon Phase Space in Medical Linear Accelerators of Different Primary Beam Parameters Mateusz Baran 1,2 , Zbislaw Tabor 1,2 , Krzysztof Rzecki 1,2, * , Przemyslaw Ziaja 1 , Tomasz Szumlak 1 , Kamila Kaleci ´ nska 1 , Jakub Michczy ´ nski 1 , Bartlomiej Rachwal 1,2 , Michael P. R. Waligórski 2,3 and David Sarrut 4 1 AGH University of Krakow, 30 Mickiewicz Ave., 30-059 Krakow, Poland; mbaran@agh.edu.pl (M.B.); ztabor@agh.edu.pl (Z.T.); prz.ziaja@gmail.com(P.Z.); szumlak@agh.edu.pl (T.S.); kamila.kalecinska@agh.edu.pl (K.K.); kubamichcz@gmail.com (J.M.); brachwal@agh.edu.pl (B.R.) 2 Faculty of Materials Science and Physics, Cracow University of Technology, Podchor ˛ zych 1, 30-084 Krakow, Poland; z5waligo@cyf-kr.edu.pl 3 Institute of Nuclear Physics, Polish Academy of Sciences, Radzikowskiego 152, 31-342 Krakow, Poland 4 Centre Léon Bérard, CREATIS, 28 Rue Laënnec, 69373 Lyon, France; david.sarrut@creatis.insa-lyon.fr * Correspondence: krz@agh.edu.pl Abstract: Successful application of external photon beam therapy in oncology requires that the dose delivered by a medical linear accelerator and distributed within the patient’s body is accurately calculated. Monte Carlo simulation is currently the most accurate method for this purpose but is computationally too extensive for routine clinical application. A very elaborate and time-consuming part of such Monte Carlo simulation is generation of the full set (phase space) of ionizing radiation components (mainly photons) to be subsequently used in simulating dose delivery to the patient. We propose a method of generating phase spaces in medical linear accelerators through learning, by artificial intelligence models, the joint multidimensional probability density distribution of the photon properties (their location in space, energy, and momentum). The models are conditioned with respect to the parameters of the primary electron beam (unique to each medical accelerator), which, through Bremsstrahlung, generates the therapeutical beam of ionizing radiation. Two variants of conditional generative adversarial networks are chosen, trained, and compared. We also present the second-best type of deep learning architecture that we studied: a variational autoencoder. Differences between dose distributions obtained in a water phantom, in a test phantom, and in real patients using generative-adversarial-network-based and Monte-Carlo-based phase spaces are very close to each other, as indicated by the values of standard quality assurance tools of radiotherapy. Particle generation with generative adversarial networks is three orders of magnitude faster than with Monte Carlo. The proposed GAN model, together with our earlier machine-learning-based method of tuning the primary electron beam of an MC simulator, delivers a complete solution to the problem of tuning a Monte Carlo simulator against a physical medical accelerator. Keywords: cancer; machine learning; medical simulations; neural networks; radiation therapy 1. Introduction External photon beam therapy (EBRT) is universally applied in treating oncological diseases. The success of EBRT crucially depends on accuracy in the design and delivery of the therapy plan, the quality of which must be evaluated prior to its actual delivery to the patient. As determined by several factors, which include the type of cancer, the patient’s condition, and other medical considerations, the medical staff of the oncology team formulate the therapy goals of EBRT, which are next implemented within the treatment planning system (TPS). The therapy plan is then designed by the TPS to best meet the Appl. Sci. 2023, 13, 7204. https://doi.org/10.3390/app13127204 https://www.mdpi.com/journal/applsci