Allpix Squared Simulation with A Pretermined Mixture of Particle Directions

Greetings,

I would like to setup an Allpix² simulation, that simulates particles according to the directions, described in a .csv file, like:

# nx, ny, nz
0, 0, 1
1, 0, 1
0, 1, 1

and consecutively (I mean, event 0 corresponds to row 2 and so on…). Any idea on how this could be done?

Thank you,

Andrew

Hi @Andrew

without touching code the only solution I can think of is to configure a particle gun via a G4 macro file, and use a different file for each of your events. Since I presume there will be many, that’s not an optimal solution.

If you have a look at the DepositionCosmics module, we have essentially implemented exactly what you would want to do there: we have an external “list” of particles (getting them from the CRY cosmic ray simulation framework), we configure the G4 particle gun accordingly (see here) and call GeneratePrimaries and let G4 do the rest. The module inherits from DepositionGeant4 which does all the heavy lifting.

I guess for your use case, a new module would be in order. Before implementing this with a custom syntax, however, you might want to have a look if some of the established formats could suit you. For example, there is the HepMC format that also generators such as Pythia write, and Geant4 has a some advanced examples how to read and process them. I guess that a generic DepositionHepMC module could be of use for others too.

If you’d like to have a chat, let me know!

/Simon

1 Like

Hi @simonspa ,

Thank you a lot for the reply! I had a look yesterday on the links but had a hard time understanding everything. I am also slightly acquainted with building modules in Allpix Squared, but haven’t built a complete one myself yet. I will have a second dive on this during the weekend and I will send you an email on Monday if I can’t figure out something.

Thank you very much for the help!

Andreas

1 Like

Hello,

I am interested in the same thing, since the Deposition Reader does not work in my case. I have a root file from ginie which I want to use as a particle gun. Each event has different kind of particles that I have to shoot (probably in the same position before my geometry).
The root file that I would like to import, which I can change it also to a text or csv (no problem for me) has the following structure:


But I do not want to use all this information. I want to import the number of event, the particle code, the energy, the px,py,pz which is the momentum of each particle and to define the position. Let me know if you need more information! Thank you a lot in advance!
Kind regards,
Rafaella

1 Like

Hi @rkotitsa

Pretty similar to what I want to do as well…I would like to configure the energy of the particle + directions + particle codes before hand. I haven’t got much done yet, as I have to learn a bit of GEANT4 (but I am progressing a bit slowly) and understand the structure of DepositionGeant4 + DepositionReader before I start making the Allpix Module.

Yours,

Andreas

PS: Welcome to the Forum :smiley: !

1 Like

Hello all,

Thank you a lot @Andrew! I would like to add an additional requirement if it is possible. It is the id of the particle before the pdg (in the previous screenshot). It is the id to identify each particle inside the event. You can find an example of the root file in: /afs/cern.ch/user/r/rkotitsa/public/ginie

Thank you,
Rafaella

1 Like

Hi @rkotitsa @Andrew

I went ahead and hacked together a new module, dubbed DepositionGenerator, that read sin a file of primary particles and emits them via the Geant4 ParticleGun.\

Here is the code: src/modules/DepositionGenerator · g4gun · Allpix Squared / Allpix Squared · GitLab

The module currently only reads the GENIE data described by @rkotitsa, so @Andrew if you have any update on what the requirements from your side are we could add another reader to it - this should be very straight forward.

Cheers,
Simon

1 Like

Thank you a lot @simonspa :slight_smile:

Hi @simonspa,

Thank you a lot for sharing this. No worries about the format of the data. The format provided by @rkotitsa should do the job for me as well. I have been able to do work without such a module but this makes my life a lot easier! …and faster. I was trying to built one myself from scratch, and I learned a lot of GEANT4 through that process (I have never used GEANT4 before), but could never managed to make a complete module out of it. Perhaps this should be generalized into some general module, as @simonspa mentioned above, I am pretty sure that would be convenient for a lot of people!

Yours,

Andreas

Hi @Andrew

happy it will also work for you as it is now. I am planning to extend it to cover the HepMC3 format and maybe some additional interfaces once I have time for it.

All the best,
Simon

1 Like

Hi @simonspa

Let me know if you need any help with this. Also, the bug I mentioned in a previous email is now gone :), so we can progress with the study we want to perform :slight_smile:

Yours,

Andreas

Great to hear - I hope it wasn’t on our side :smiley:

1 Like