Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing CRY generator as a new source inside TRestGeant4ParticleSourceCry #116

Merged
merged 26 commits into from
Nov 18, 2023

Conversation

jgalan
Copy link
Member

@jgalan jgalan commented Nov 3, 2023

jgalan Large: 419 Powered by Pull Request Badge

The following PR implements an interface to CRY generator that can be plugged to restG4. All the access to CRY libraries is inside the class TRestGeant4ParticleSourceCry, which has been inspired on TRestGeant4ParticleSourceDecay0.

The class allows to configure/setup the CRY generator and it implements a method to update the particles for each event.

This PR requires minor contributions to restG4 and framework repositories.


In order to link the CRY libraries to libRestGeant4 we need to generate the shared object from the static library libCRY.a.

This can be done with the following command:

gcc -shared -o libCRY.so -Wl,--whole-archive libCRY.a -Wl,--no-whole-archive

Once we have generated the libCRY.so we need to compile REST with the new option.

cmake -DREST_G4=ON -DREST_CRY_PATH=/path/to/cry/main/directory/

And we can use the new example added to restG4.

cd source/packages/restG4/examples/12.Generators/
restG4 CryGenerator.rml

10 events will be generated in this example, stored in the output file CryGenerator.root. We can open to inspect:

restRoot CryGenerator.root

And access the new particle source generator metadata:

Screenshot 2023-11-05 at 19 19 09

And check the generator events:

Screenshot 2023-11-05 at 19 20 31

In the previous image we can see how the CRY generator has produced an electron and a neutron.

The event header contains also the source position, but only the one for the first (or last) particle. This is redundant information, but incomplete, since we need to really look to the tracks to understand what are the particles produced by the generator. Perhaps it would be better to remove those fields from TRestGeant4Event? @lobis?

I have seen that TRestGeant4ParticleSource defines PrintParticleSource but perhaps this should be migrated to PrintMetadata? @nkx111

I let @Jaime-AA to play around and validate the generator.

I was surprised that when I define altitude = 2100m, the particle is still produced at z=0, I guess one needs to use zoffset so that the particles are generated at that altitude.

@jgalan jgalan changed the title TRestGeant4PrimaryGeneratorInfo. Adding CRY generator type Adding CRY generator as a new source inside TRestGeant4ParticleSourceCry Nov 3, 2023
@nkx111
Copy link
Member

nkx111 commented Nov 3, 2023

Maybe it's interesting to add a new class like TRestGeant4ParticleSourceDecay0 that can generate muons during simulation?

@jgalan jgalan requested a review from lobis November 4, 2023 05:31
@jgalan
Copy link
Member Author

jgalan commented Nov 4, 2023

Maybe it's interesting to add a new class like TRestGeant4ParticleSourceDecay0 that can generate muons during simulation?

The present implementation will do exactly that using the CRY generator.

So, I don't understand, what do you mean? You mean the present cosmic generator implemented inside PrimaryGeneratorAction inside restG4 to be transferred to something like TRestGeant4ParticleSourceCosmics?

@jgalan jgalan changed the title Adding CRY generator as a new source inside TRestGeant4ParticleSourceCry Implementing CRY generator as a new source inside TRestGeant4ParticleSourceCry Nov 5, 2023
@jgalan jgalan requested a review from a team November 5, 2023 19:16
@nkx111
Copy link
Member

nkx111 commented Nov 6, 2023

So, I don't understand, what do you mean? You mean the present cosmic generator implemented inside PrimaryGeneratorAction inside restG4 to be transferred to something like TRestGeant4ParticleSourceCosmics?

Yes! Actually there was a naming convention that when you want to add external generators the class name should be TRestGeant4ParticleSourceXXX, where XXX is the name of the generator.

From my point of view, CRY(and also decay0) is just a random number generator. That is, every time you call a certain method, it will randomize the energy and angle of a particle according to the muon spectrum. Those information can be well kept in TRestGeant4Particle, which can be passed to restG4 with common code in PrimaryGeneratorAction.

I was surprised that when I define altitude = 2100m, the particle is still produced at z=0, I guess one needs to use zoffset so that the particles are generated at that altitude.

I guess the altitude only changes the muon energy distribution. In any case your simulation origin is not necessarily same as your lab altitude. Perhaps we need to add some options inside rml, such as the lab altitude, longitude and latitude. We may also need a definition of source volume (normally in muon simulation we set the particles to be generated from a very large horizontal plane above the detector)

@nkx111
Copy link
Member

nkx111 commented Nov 6, 2023

I have seen that TRestGeant4ParticleSource defines PrintParticleSource but perhaps this should be migrated to PrintMetadata? @nkx111

Yes, this shall be OK.

@jgalan
Copy link
Member Author

jgalan commented Nov 7, 2023

We may also need a definition of source volume (normally in muon simulation we set the particles to be generated from a very large horizontal plane above the detector)

Actually I think it is the CRY generator the responsible to do this. It is generating particles in a 2-dimensional box with dimensions subboxLength and at a position given by zoffset.

Those values can now be updated in the RML, they are metadata members of the generator.

@jgalan
Copy link
Member Author

jgalan commented Nov 7, 2023

One last thing that needs to be integrated is the random generator seed. It is always producing the same sequence.

@jgalan jgalan requested a review from Jaime-AA November 9, 2023 09:18
@jgalan jgalan marked this pull request as ready for review November 13, 2023 14:27
Copy link

@Jaime-AA Jaime-AA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The REST implementation works correctly. The only thing is that I had to generate the shared library of CRY using objects created with the -fPIC flag (something about the CRY installation)

@jgalan jgalan merged commit 2502b87 into master Nov 18, 2023
63 checks passed
@jgalan jgalan deleted the jgalan_cry branch November 18, 2023 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants