Exemple #1
0
int main()
{
  constexpr int nSamples = 512;
  SimpleSphere sphere("Visualizer Sphere", 15., 20., 0., 2 * PI / 3., PI / 4., PI / 6.);
  AOS3D<Precision> points(nSamples);

  for (int i = 0; i < nSamples; ++i) {
    Vector3D<Precision> sample;
    do {
      sample = volumeUtilities::SamplePoint(Vector3D<Precision>(20, 20, 20));
    } while (!sphere.Contains(sample));
    points.set(i, sample);
  }
  points.resize(nSamples);
  Visualizer visualizer;
  visualizer.AddVolume(sphere);
  visualizer.AddPoints(points);
  visualizer.Show();
  return 0;
}
int main(int argc, char *argv[])
{
  OPTION_INT(ntracks, 10000);
  OPTION_INT(nreps, 3);
  OPTION_STRING(geometry, "navBench");
  OPTION_STRING(logvol, "world");
  OPTION_DOUBLE(bias, 0.8f);
#ifdef VECGEOM_ROOT
  OPTION_BOOL(vis, false);
#endif

  // default values used above are always printed.  If help true, stop now, so user will know which options
  // are available, and what the default values are.
  OPTION_BOOL(help, false);
  if (help) return 0;

  if (geometry.compare("navBench") == 0) {
    const VPlacedVolume *world = SetupGeometry();

#ifdef VECGEOM_ROOT
    // Exporting to ROOT file
    RootGeoManager::Instance().ExportToROOTGeometry(world, "navBench.root");
    RootGeoManager::Instance().Clear();
#endif
  }

// Now try to read back in.  This is needed to make comparisons to VecGeom easily,
// since it builds VecGeom geometry based on the ROOT geometry and its TGeoNodes.
#ifdef VECGEOM_ROOT
  auto rootgeom = geometry + ".root";
  RootGeoManager::Instance().set_verbose(0);
  RootGeoManager::Instance().LoadRootGeometry(rootgeom.c_str());
#endif

#ifdef VECGEOM_GEANT4
  auto g4geom = geometry + ".gdml";
  G4GeoManager::Instance().LoadG4Geometry(g4geom.c_str());
#endif

// Visualization
#ifdef VECGEOM_ROOT
  if (vis) { // note that visualization block returns, excluding the rest of benchmark
    Visualizer visualizer;
    const VPlacedVolume *world = GeoManager::Instance().GetWorld();
    world                      = GeoManager::Instance().FindPlacedVolume(logvol.c_str());
    visualizer.AddVolume(*world);

    Vector<Daughter> const *daughters = world->GetLogicalVolume()->GetDaughtersp();
    for (size_t i = 0; i < daughters->size(); ++i) {
      VPlacedVolume const *daughter = (*daughters)[i];
      Transformation3D const &trf1  = *(daughter->GetTransformation());
      visualizer.AddVolume(*daughter, trf1);

      // Vector<Daughter> const* daughters2 = daughter->GetLogicalVolume()->daughtersp();
      // for(int ii=0; ii<daughters2->size(); ++ii) {
      //   VPlacedVolume const* daughter2 = (*daughters2)[ii];
      //   Transformation3D const& trf2 = *(daughter2->transformation());
      //   Transformation3D comb = trf1;
      //   comb.MultiplyFromRight(trf2);
      //   visualizer.AddVolume(*daughter2, comb);
      // }
    }

    visualizer.Show();
    return 0;
  }
#endif

  std::cout << "\n*** Validating VecGeom navigation...\n";

  const LogicalVolume *startVolume = GeoManager::Instance().GetWorld()->GetLogicalVolume();
  if (logvol.compare("world") != 0) {
    startVolume = GeoManager::Instance().FindLogicalVolume(logvol.c_str());
  }

  std::cout << "NavigationBenchmark: logvol=<" << logvol << ">, startVolume=<"
            << (startVolume ? startVolume->GetLabel() : "NULL") << ">\n";
  if (startVolume) std::cout << *startVolume << "\n";

  // prepare tracks to be used for validation
  int np = Min(ntracks, 1000); // no more than 1000 points used for validation
  SOA3D<Precision> points(np);
  SOA3D<Precision> dirs(np);
  SOA3D<Precision> locpts(np);
  vecgeom::volumeUtilities::FillGlobalPointsAndDirectionsForLogicalVolume(startVolume, locpts, points, dirs, bias, np);

  Precision *maxSteps = (Precision *)vecCore::AlignedAlloc(32, sizeof(Precision) * np);
  for (int i    = 0; i < np; ++i)
    maxSteps[i] = 10. * RNG::Instance().uniform();

  // Must be validated before being benchmarked
  bool ok = validateVecGeomNavigation(np, points, dirs, maxSteps);
  if (!ok) {
    std::cout << "VecGeom validation failed." << std::endl;
    return 1;
  }
  std::cout << "VecGeom validation passed." << std::endl;

  // on mic.fnal.gov CPUs, loop execution takes ~70sec for ntracks=10M
  while (ntracks <= 10000) {
    std::cout << "\n*** Running navigation benchmarks with ntracks=" << ntracks << " and nreps=" << nreps << ".\n";
    runNavigationBenchmarks(startVolume, ntracks, nreps, maxSteps, bias);
    ntracks *= 10;
  }

  /*
  // GPU part
    int nDevice;
    cudaGetDeviceCount(&nDevice);

    if(nDevice > 0) {
      cudaDeviceReset();
    }
    else {
      std::cout << "No Cuda Capable Device ... " << std::endl;
      return 0;
    }
  */

  // cleanup
  delete[] maxSteps;
  return 0;
}