Attach Source to Geometry

Hi everyone,
I have a cylinder source. Now I want to attach the source to the cylinder volume for simulation.
If my cylinder volume is rotated or translated between runs, the source position will also be changed.
I don’t know if we can use the GPS source or the ParticleGun to perform this task.
Please help me. Thank you in advance.

Unfortunately what you want to do is much more complicated than one would hope. In particular you can’t do what you want with pure GPS, you have to write a custom PrimaryGeneratorAction which locates the cylinder in your world volume and generates primary coordinates. If your cylinder is a direct child of the world volume, this isn’t too bad, but if you have nested volumes where the intermediate volume may also be offset or rotated, you have to compute the compound transformation, since the primary particle’s coordinates must always be in the world volume.

I use the attached class to do what you’re describing. It hss good examples of how to compute the compound transform for volumes in arbitrarily-deep hierarchies. If what you really want is to use the GPS to translate and rotate a cylinder to align with the relevant volume in your geometry, you could use something like those functions to find the relevant transform, then update the GPS with those values.

GPSVolumeSampling.hh (4.7 KB)
GPSVolumeSampling.cc (18.3 KB)

@bloer Thank you for your help