TGeoManager - tracking crossed volumes

I’ve got:

  1. a ROOT-file resident: KEY: TGeoManager DetectorGeometry;1 Detector Geometry
  2. two “space” points “P0(x0, y0, z0)” and “P1(x1, y1, z1)”

I need to find the list of all “DetectorGeometry” volumes that a straight line from “P0” to “P1” crosses.

And maybe also another way … I’d like to be able to simply ask whether a particular “DetectorGeometry” volume will be crossed by a straight line from “P0” to “P1” (without creating the full list of all volumes that are crossed first).

Is there any example source code which I could start with?

Thanks in advance.


Have a look in $ROOTSYS/test/stressGeometry.cxx:FindRad(). You will have to make it work with different input and collect only the volume names, but the traversal algorithm is there. If you want to see if a given volume is crossed, you just do:

gGeoManager->InitTrack(P0, dir); // dir is the normalized direction of (P0, P1) vector
gGeoManager->FindNextBoundary(1.E50, "/path/to/detector/element");
if (gGeoManager->GetStep()< 1.E20) printf("Volume hit at %g\n", gGeoManager->GetStep());


1 Like