Commit aabf3c1e authored by Sandro Christian Wenzel's avatar Sandro Christian Wenzel
Browse files

VNavigator: add interface more useful for Geant4; Improve Benchmarker

Add interface not needing NavigationStates but only volume types.
Useful for Geant4 integration.

Make NavigationKernelBenchmarker more realistic by using a configurable
finite physics step.
parent 3f643ce5
......@@ -67,11 +67,13 @@ public:
NavigationState & /*out_state*/) const = 0;
//! as above ... also returns the safety ... does not give_back an out_state
//! but the in_state might be modified to contain the next daughter when
//! user specifies indicateDaughterHit = true
VECCORE_ATT_HOST_DEVICE
virtual Precision ComputeStepAndSafety(Vector3D<Precision> const & /*globalpoint*/,
Vector3D<Precision> const & /*globaldir*/, Precision /*(physics) step limit */,
NavigationState const & /*in_state*/, bool /*calcsafety*/,
Precision & /*safety*/) const = 0;
NavigationState & /*in_state*/, bool /*calcsafety*/, Precision & /*safety*/,
bool indicateDaughterHit = false) const = 0;
// an alias interface ( using TGeo name )
VECCORE_ATT_HOST_DEVICE
......@@ -109,6 +111,17 @@ public:
NavigationState const * /*in_state*/, NavigationState * /*out_state*/,
Precision & /*step*/, VPlacedVolume const *& /*hitcandidate*/) const = 0;
/// check if a ray given by localpoint, localdir intersects with any daughter. Possibility
/// to pass a volume which is blocked/should be ignored in the query. Updates the step as well as the hitcandidate
/// volume. (This version is useful for G4; assemblies not supported)
VECCORE_ATT_HOST_DEVICE
virtual bool CheckDaughterIntersections(LogicalVolume const * /*lvol*/, Vector3D<Precision> const & /*localpoint*/,
Vector3D<Precision> const & /*localdir*/, VPlacedVolume const * /*blocked*/,
Precision & /*step*/, VPlacedVolume const *& /*hitcandidate*/) const
{
return false;
}
// interfaces for vector/basket navigation
virtual void ComputeStepsAndPropagatedStates(SOA3D<Precision> const & /*globalpoints*/,
SOA3D<Precision> const & /*globaldirs*/,
......@@ -465,8 +478,8 @@ public:
VECCORE_ATT_HOST_DEVICE
virtual Precision ComputeStepAndSafety(Vector3D<Precision> const &globalpoint, Vector3D<Precision> const &globaldir,
Precision step_limit, NavigationState const &in_state, bool calcsafety,
Precision &safety) const override
Precision step_limit, NavigationState &in_state, bool calcsafety,
Precision &safety, bool indicateDaughterHit = false) const override
{
// FIXME: combine this kernel and the one for ComputeStep() into one generic function
#ifdef DEBUGNAV
......@@ -511,6 +524,7 @@ public:
->Impl::CheckDaughterIntersections(lvol, localpoint, localdir, &in_state, out_state, step, hitcandidate);
}
}
if (indicateDaughterHit && hitcandidate) in_state.Push(hitcandidate);
return Min(step, step_limit);
}
......@@ -537,8 +551,9 @@ public:
// fall back to scalar interface for tail treatment
for (; i < size; ++i) {
out_steps[i] = ((Impl *)this)
->Impl::ComputeStepAndSafety(globalpoints[i], globaldirs[i], step_limits[i], *in_states[i],
calcsafeties[i], out_safeties[i]);
->Impl::ComputeStepAndSafety(globalpoints[i], globaldirs[i], step_limits[i],
*const_cast<NavigationState *>(in_states[i]), calcsafeties[i],
out_safeties[i]);
}
i = decltype(size){0};
for (; i < size; ++i)
......@@ -913,7 +928,7 @@ public:
virtual const char *GetName() const override { return GetClassName(); }
}; // end class VNavigatorHelper
}
} // end namespace
} // namespace VECGEOM_IMPL_NAMESPACE
} // namespace vecgeom
#endif /* NAVIGATION_VNAVIGATOR_H_ */
......@@ -69,6 +69,8 @@ bool gBenchVecInterface = false;
bool gAnalyseOutStates = false;
bool gBenchWithSafety = false;
bool gSpecializedLib = false;
double gMAXSTEP = vecgeom::kInfLength; // global variable to configure max step asked in ComputeStep
std::string gSpecLibName;
VNavigator const *gSpecializedNavigator;
......@@ -222,10 +224,10 @@ __attribute__((noinline)) void benchmarkROOTNavigator(SOA3D<Precision> const &po
safeties[i] = rootnav->Safety(true);
}
if (WithReloc) {
volatile TGeoNode *node = rootnav->FindNextBoundaryAndStep(kInfLength);
volatile TGeoNode *node = rootnav->FindNextBoundaryAndStep(gMAXSTEP);
(void)node;
} else {
volatile TGeoNode *node = rootnav->FindNextBoundary(kInfLength);
volatile TGeoNode *node = rootnav->FindNextBoundary(gMAXSTEP);
(void)node;
}
steps[i] = rootnav->GetStep();
......@@ -305,7 +307,7 @@ __attribute__((noinline)) void benchmarkG4Navigator(SOA3D<Precision> const &poin
for (decltype(points.size()) i = 0; i < points.size(); ++i) {
G4ThreeVector g4pos(points[i].x() * cm, points[i].y() * cm, points[i].z() * cm);
G4ThreeVector g4dir(dirs[i].x(), dirs[i].y(), dirs[i].z());
G4double maxStep = kInfLength;
G4double maxStep = gMAXSTEP;
// false --> locate from top
G4VPhysicalVolume const *vol = g4nav.LocateGlobalPointAndSetup(g4pos, &g4dir, false);
......@@ -358,10 +360,10 @@ __attribute__((noinline)) void benchNavigator(VNavigator const *se, SOA3D<Precis
timer.Start();
for (decltype(points.size()) i = 0; i < points.size(); ++i) {
if (WithSafety) {
steps[i] = se->ComputeStepAndSafetyAndPropagatedState(points[i], dirs[i], vecgeom::kInfLength, *inpool[i],
*outpool[i], true, safeties[i]);
steps[i] = se->ComputeStepAndSafetyAndPropagatedState(points[i], dirs[i], gMAXSTEP, *inpool[i], *outpool[i], true,
safeties[i]);
} else {
steps[i] = se->ComputeStepAndPropagatedState(points[i], dirs[i], vecgeom::kInfLength, *inpool[i], *outpool[i]);
steps[i] = se->ComputeStepAndPropagatedState(points[i], dirs[i], gMAXSTEP, *inpool[i], *outpool[i]);
}
}
timer.Stop();
......@@ -395,9 +397,10 @@ __attribute__((noinline)) void benchNavigatorNoReloc(VNavigator const *se, SOA3D
timer.Start();
for (decltype(points.size()) i = 0; i < points.size(); ++i) {
if (WithSafety) {
steps[i] = se->ComputeStepAndSafety(points[i], dirs[i], vecgeom::kInfLength, *inpool[i], true, safeties[i]);
steps[i] = se->ComputeStepAndSafety(points[i], dirs[i], gMAXSTEP, *const_cast<NavigationState *>(inpool[i]), true,
safeties[i]);
} else {
steps[i] = se->ComputeStep(points[i], dirs[i], vecgeom::kInfLength, *inpool[i], *outpool[i]);
steps[i] = se->ComputeStep(points[i], dirs[i], gMAXSTEP, *inpool[i], *outpool[i]);
}
}
timer.Stop();
......@@ -424,8 +427,9 @@ __attribute__((noinline)) void benchVectorNavigator(SOA3D<Precision> const &__re
NavStatePool &__restrict__ outpool)
{
Precision *step_max = (double *)vecCore::AlignedAlloc(32, sizeof(double) * points.size());
for (decltype(points.size()) i = 0; i < points.size(); ++i)
step_max[i] = vecgeom::kInfLength;
for (decltype(points.size()) i = 0; i < points.size(); ++i) {
step_max[i] = gMAXSTEP;
}
Precision *steps = (double *)vecCore::AlignedAlloc(32, sizeof(double) * points.size());
Precision *safeties = nullptr;
bool *calcs;
......@@ -481,11 +485,13 @@ __attribute__((noinline)) void benchVectorNavigatorNoReloc(SOA3D<Precision> cons
NavStatePool &__restrict__ outpool)
{
Precision *step_max = (double *)vecCore::AlignedAlloc(32, sizeof(double) * points.size());
for (decltype(points.size()) i = 0; i < points.size(); ++i)
step_max[i] = vecgeom::kInfLength;
for (decltype(points.size()) i = 0; i < points.size(); ++i) {
step_max[i] = gMAXSTEP;
}
Precision *steps = (double *)vecCore::AlignedAlloc(32, sizeof(double) * points.size());
Precision *safeties = nullptr;
bool *calcs;
if (WithSafety) {
safeties = (double *)vecCore::AlignedAlloc(32, sizeof(double) * points.size());
calcs = (bool *)vecCore::AlignedAlloc(32, sizeof(bool) * points.size());
......@@ -546,6 +552,14 @@ void benchDifferentNavigators(SOA3D<Precision> const &points, SOA3D<Precision> c
std::cerr << "##\n";
RUNBENCH((benchNavigator<WithSafety>(NewSimpleNavigator<true>::Instance(), points, dirs, pool, outpool)));
std::cerr << "##\n";
#ifdef VECGEOM_ROOT
benchmarkROOTNavigator<WithSafety>(points, dirs);
#ifdef VECGEOM_GEANT4
benchmarkG4Navigator<WithSafety>(points, dirs);
#endif // VECGEOM_GEANT4
#endif
#ifdef BENCH_GENERATED_NAVIGATOR
RUNBENCH((benchNavigator<GeneratedNavigator, WithSafety>(points, dirs, pool, outpool)));
outpool.ToFile("generatedoutpool.bin");
......@@ -662,6 +676,13 @@ int main(int argc, char *argv[])
if (!strcmp(argv[i], "--statetrans")) gAnalyseOutStates = true;
// whether to benchmark navigation with safeties
if (!strcmp(argv[i], "--withsafety")) gBenchWithSafety = true;
// to set the maxstep number
if (!strcmp(argv[i], "--maxstep")) {
if (i + 1 < argc) {
gMAXSTEP = atof(argv[i + 1]);
std::cout << "setting maxstep to " << gMAXSTEP << "\n";
}
}
// to set the number of tracks
if (!strcmp(argv[i], "--ntracks")) {
if (i + 1 < argc) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment