How to use GPS and sample particles' positions from subtracted volume?

Hey Everyone,

I am able to sample my particles from regular shapes (sphere, rectangle etc, via GPS defined in macro). How can I randomly sample particle’s positions from a custom physical volume defined in DetectorConstruction?

My physical volume of interest is detector volume/shape subtracted from a large sphere; to replicate random generation of events around the detector. Also let me know if there is a better way to implement this? I know I can take care of this in post analysis but wondering if G4 can already take care of this?

https://geant4-userdoc.web.cern.ch/UsersGuides/ForApplicationDeveloper/html/GettingStarted/generalParticleSource.html

you could sample from a larger volume (e.g., the whole sphere you subtract the detector shape from), and then apply /gps/pos/confine to the physical volume.

@weller : Thanks, based on your suggestion I tried the following. To make it simplistic, I am interested in sampling/confining the events to 1-cm annular region (subtracted volume) of two spheres:

//Subtraction of two spheres, giving 1-cm annular region
G4VSolid*
Sphere_out = new G4Sphere("Sphere_out",0.*cm, 10.*cm,0.0*deg,360.0*deg,0.*deg,180.*deg); // outside sphere

G4VSolid* Sphere_in = new G4Sphere("Sphere_in",0.*cm, 9.*cm,0.0*deg,360.0*deg,0.*deg,180.*deg); // inside sphere

G4SubtractionSolid *Sphere_net = new G4SubtractionSolid("SphereNet",Sphere_out,Sphere_in); // sample subtracted volume
fSS_sphere_logic = new G4LogicalVolume(Sphere_net,fWorldMater,"SphereNet");
                   new G4PVPlacement(0,                         
                                     G4ThreeVector(0.,0.,0.0*cm),
                                     fSS_sphere_logic,
                                     "SphereNet_Phys",
                                     fWorldLogical,
                                     false, 
                                     0,
                                     checkForOverlaps); 

Then I use the following in macro, note that the dimension/position of this sphere matches to the outer sphere as you mentioned.

/gps/pos/type Volume
/gps/pos/shape Sphere
/gps/pos/centre 0. 0. 0. cm
/gps/pos/radius 10 cm
/gps/pos/confine SphereNet_Phys

Plotting the initial position of each event, however, still gives me a 10-cm sphere, not the annular region. What am I doing wrong?

hm, that’s something for the experts then. maybe it only checks if it is within the outmost envelope of the phys volume!?

if it is just the hollow sphere, have you tried /gps/pos/inner_radius ? (or confine to a hollow sphere with min radius >0, no need for subtraction there anyways) in principle confining to the subtraction solid would be useful…

„Sets the inner radius [default 0 cm] for annuli. The units can only be micron, mm, cm, m or km.“
Don’t know if for the (hollow) sphere it works the same way.

@weller: Yeah, so it is just sampling everything that is inside of the outer envelope. I wanted to restrict that to region between inner and outer envelope.

I tried Annulus with gps/pos/inner_radius but that’s a planar source! It acts like a ring, not a spherical shell. There isn’t a volumetric version of that as far as I see.

I will wait if anyone else has got any suggestions to take care of this.

this is the code that is executed when generating a confined primary position:

no trace of any envelope, just the Navigator checking if the point is inside or outside. So even with a hollow physical volume, this should work.

are your image slices or projections? :wink:

Thanks for sharing. The images are starting position of each event that I exported in post-analysis.