Visualize primary vertices

I’m developing a generator that randomly samples points in an arbitrary solid. I would like to be able to visualize the 3D distribution of such points along with the implemented geometry, for debugging purposes.

I was able to start particles from the points and visualize trajectories, as described in the manual. This helps a bit, but I was wondering whether there is any trick to only draw the starting point. I could not find anything helpful in the forum and on the manual.

If the answer is negative, I guess I can always save the (x, y, z) triples on disk at runtime and try to plot them with some other toolkit (e.g. ROOT).

It is not so difficult to generate a random point inside a solid using rejection sampling. Below is the code:

G4ThreeVector GetPointInSolid(const G4VSolid* solid)
  // get bounding box                                                                                                   
  G4ThreeVector pmin, pmax;
  solid->BoundingLimits(pmin, pmax);

  // generate point inside bounding box                                                                                 
  // return if point is inside solid                                                                                    
  for (G4int i=0; i<100000; ++i)
    G4double x = pmin.x() + (pmax.x() - pmin.x())*G4QuickRand();
    G4double y = pmin.y() + (pmax.y() - pmin.y())*G4QuickRand();
    G4double z = pmin.z() + (pmax.z() - pmin.z())*G4QuickRand();
    G4ThreeVector p(x, y, z);
    if (solid->Inside(p) == kInside) return p;
  return G4ThreeVector(); // all tries failed, return p(0,0,0)                                                          

I would like to know whether it’s possible to visualize the points together with the geometry, not how to write the generator.

The short answer is: yes, it is possible. I didn’t do it myself, but there are several examples where you can see such possibility. For example you can visualise your geometry as a cloud of points:

/vis/viewer/set/style cloud

The trick is the following:

  • specify the material of the World as a water
  • specify the gun particles as very low energy electrons

Then the trajectories will look like points.

Below are pictures from basic example B1:

/run/beamOn 100

/gun/energy 1 keV
/run/beamOn 100

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.