General Particle Source using Input File

Hello,
I am using Geant4.6.p01 on Ubuntu.

I have a list of particle positions and velocities generated from a different source. I would like to use these particles as a source for Geant4 simulations. Looking at the Particle Gun or General Particle Source, it would seem that I can generate particles for a wide range of possibilities, but I can’t find a general source where a file is read and the information regarding each individual particle is determined and then the particle is fired in Geant4 using the parameters read from a file.
One way would be to run Geant4 many times over with one particle simulated each time for each particle in the file. Is there a better and faster way to do this ?

Thanks in advance
Chris

Since the input file format is specfic to your application, you’re going to have to write your own code to parse it anyway.

You may write your own {{G4VUserPrimaryGeneratorAction}} subclass, which would contain either a {{G4ParticleGun}} data member, or your own {{G4VPrimaryGenerator}} subclass.

In your GeneratorAction, you’d open the input file. At the start of the event, read the next line (or whatever) of the file, and use the information you read to configure the generator (e.g., {{G4ParticleGun}}) appropriately, to create primaries from that information.

Thanks Mike,
I will get cracking on it.
Chris

See my posting here: CSV input file.

But you’ll certainly need to use GPS.

1 Like

Just curious, Tim. Why would you need GPS if you’re reading in the track-by-track kinematics from a file? In our experiment’s framework (CDMS), I set that up using G4ParticleGun, with my generator calling in to set position, momentum, blah blah blah, for each track, and making a primary vertex and primary particle for it.

Hi Mike,

it was a while ago I “hacked” (modified would be too kinder expression) TestEm7 to suit. IIRC I found that GPS was much more versatile than Gun but I’ll happily recant if I’m wrong.

Happy Easter.

T

Hi, Tim. You are quite right that GPS is much more versatile. Gun is about as simple as you can get – one particle at a time. If you want anything complicated, you have to write your own, and call Gun multiple times, for each track.

I need your help. Do you about geant4 examples of medical, please?

Hello Sarah,
I work on low energy electrons in materials, but not on medical examples. I looked at your earlier post about neuron and chem1, but I don’t know these examples - where are they ? I am also unclear what you are trying to do. Do you have good experience with C++ ?

Chris Walker
PS where are you based ? I am at the University of York, UK

Hello Chris,

I know the basics of C++ and practice and learn about classes and objects. I just try to uncomments the line of codes in files but it do not work. I try to add libraries but also not work. The major error is the declaration of variables and sometimes the passing arguments to functions are not the same so give again error. I think the problem is to modify or uncomment the lines but I do not understand why these lines are wrote , because you know, it is a limited space to modify but I am not the owner of this code. I try to email the owner, but he told me that he is very busy, so I try to find others who can share with me their ideas to solve these problems. So, if you want to help, the module name is neuron. The files which I try to just uncomment the lines are TimeStepAction.cc, Run.cc, ITTrackingAction.cc. I try to get the number of molecules outside and inside the neuron structure. Due to the interactions of protons with molecules of water (water is close to neuron ).

If you can not or do not have time. Could you help me to know a student to have time and can help me about this, please? OR work on any module of medical in geant4?

Thanks for your time,
Sarah
my email: abdelazizsarah4@gmail.com

Hi Sarah,
I have downloaded the chem1 and neuron examples, but it might take me a while to look through the examples and understand them as I am still going up the learning curve with Geant4. It seems to me that you are a new starter with Geant4.

Is your supervisor (or someone at your institution) acquainted with Geant4? Are you able to ‘pick their brains’ ?!

I found the youtube tutorials here:
https://www.youtube.com/playlist?list=PLLybgCU6QCGWgzNYOV0SKen9vqg4KXeVL

useful, even though I am (like you) working with much lower energy electrons (but I am not working on a medical application).
Best Wishes
Chris

Hi Sarah,
I have had a quick look at the chem1 and neuron examples. Clearly, the neuron example is much more complicated. I think by trying to change the neuron example you are “jumping in at the deep end”. It would be much better to start with the simple chem1 example and gradually increase the complexity (aiming towards simulating a neuron) as the young man does in the youtube videos - and test at each stage.
I hope you feel that the task ahead of you is not too overwhelming.
Best Wishes
Chris

Hi Chris,
Yes Chris. As you say I am alone and my colleagues do not have ideas about this program. Also, this is my the second year to understand the lines of source files of neuron module. Yes, It is very complicated and I learn more about OOP in C++ to understand more about theses codes. Thanks for your kindness and for your help and your time. I will follow your advice and see this video and see the simple examples which may be help. My study focuses on the effect of radiation on the neuron cells so I use geant4 to simulate this effect. So, I hope after sometime, I return again if you are not mind to send to you about what I will modify in the codes, if you are better than me in coding with C++ . Sorry for bothering you.
Thanks,
Sarah
Email: abdelazizsarah4@gmail.com

Hi Sarah,
I can have a look at your codes later. I am not brilliant at C++ and I am still on the learning curve as regards Geant4 as well, but I might be able to help. Perhaps send me some codes in a few weeks…
Best Wishes
Chris

Hello!
I removed geant4.11.1 because I had problems related to zsh bus error and I can not solve it. So, I download geant4 .11.2. I want to copy the example neuron to a new directory (g4test) at the home but I want to check how to do CMake by the following lines.
1- ~%mkdir g4test

2- cd g4test

3- g4test%cp -r /Users/saraabdelaziz/Downloads/geant4-v11.2/examples/extended/medical/dna/neuron .

OR
% cp -r /usr/local/share/Geant4/examples/extended/medical/dna/neuron . I want to know which one of them I should use, please?

4- g4test%ls

5- neuron

6- g4test % mkdir neuron-build

7- g4test%cd neuron-build

8- neuron-build% cmake … BUT sometime in zsh terminal , it is not accepted …

SO should I replace with
% cmake …/neuron WHICH … refers to /Users/saraabdelaziz/g4test
Could you help me, please?
email: abdelazizsarah4@gmail.com

Thanks for your kind, Chris. Also, Please, If you know any funded school or conference related to geant4 or Monte Carlo techniques to radiation transport in water, I will be pleasure.

Hello Sarah,
I found this course:

I’m not sure how much it costs, but you can attend online. There seem to be discounts for students and people from developing nations.

Hope this helps.

Best Wishes
Chris

Hi again Sarah,
Sorry, but that was for an advanced course which I guess is not appropriate.

I note the course last year here:

had an opening registration date of February 29th, so I would suggest keeping a close look out near to this date next year. I will see if there are other courses.

Best Wishes
Chris

Hi Sarah,
I think the command :
cp -r /usr/local/share/Geant4/examples/extended/medical/dna/neuron .

should work (assuming the directory structure is the same as in the command).
You should have a number of files in the neuron directory which includes the file CMakeLists.txt

Note that in Linux a dot refers to your current directory and a double dot refers to the parent directory. Hence …/neuron refers to another subdirectory (called neuron) of your current directory (which should be neuron-build).
So the last command should be :
cmake …/neuron

(so two dots before /neuron not three)
If that doesn’t work, then maybe cmake isn’t installed (or you need to update the version of cmake) or maybe the CMakeLists.txt file isn’t found…

Best Wishes
Chris

Thanks. I will see it.