Importing particle information from external ascii file in Primary Generator

Dear Geant4 developers and users, I would like to import the particle information from an external ascii file event wise in the primary generator. In each event there are four particle generating with different energies, theta and phi. In summary, I would like to generate a vertex and add four-particle in each event. The direction of particles are described by theta and phi. So, I have in total of 12 columns with the required information. Is there any way to perform this operation more efficiently. I understand it will be good to make a generator for this purpose in order to get the time optimization, However, it is not so straight forward. Any kind of help will be highly appreciated. Thank you in advance.

As a starting point, take a look at the advanced/medical_linac example in ‘’ - there is a phase space routine implemented.