Skip to content
Snippets Groups Projects
Forked from atlas / athena
7219 commits behind, 15 commits ahead of the upstream repository.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
Celeritas.cxx 2.67 KiB
#include "Celeritas.h"

#include <G4Threading.hh>
#include <G4Version.hh>
#include <accel/AlongStepFactory.hh>
#include <celeritas/field/UniformFieldData.hh>
#include <celeritas/io/ImportData.hh>
#include <celeritas/Types.hh>
#include <corecel/sys/Environment.hh>
#include <accel/LocalTransporter.hh>
#include <accel/SetupOptions.hh>
#include <accel/SharedParams.hh>

#include <memory>

using namespace celeritas;

// Global shared setup options
SetupOptions& CelerSetupOptions()
{
  static SetupOptions options = [] {
    // Construct setup options the first time CelerSetupOptions is invoked
    SetupOptions so;

    // auto& env = environment();
    // env.insert({"CELER_LOG", "debug"});
    // env.insert({"CELER_LOG_LOCAL", "debug"});


    // NOTE: these numbers are appropriate for CPU execution
    so.max_num_tracks = 65536;
    // This will eventually go
    so.max_num_events = 16;
    so.initializer_capacity = 4194304;
    so.secondary_stack_factor = 2.0;
    so.max_steps = 1000000;
    so.track_order = TrackOrder::init_charge;

    // Set along-step factory
    so.make_along_step = celeritas::UniformAlongStepFactory();


    // Celeritas does not support EmStandard MSC physics above 100 MeV
    so.ignore_processes = {"CoulombScat"};
    if (G4VERSION_NUMBER >= 1110)
    {
        // Default Rayleigh scattering 'MinKinEnergyPrim' is no longer
        // consistent
        so.ignore_processes.push_back("Rayl");
    }

    // Use Celeritas "hit processor" to call back to Geant4 SDs.
    so.sd.enabled = true;
    so.sd.track = true;
    so.sd.energy_deposition = true;
    // Using the pre-step point, reconstruct the G4 touchable handle.
    so.sd.locate_touchable = true;
    // Pre-step time is used
    so.sd.pre.global_time = true;
    so.sd.post.global_time = true;

    // To confirm whether Athena needs zero energy deposition step. This is currently a
    // global option for all detectors, so if any SDs extract data from tracks
    // with no local energy deposition over the step, it must be set to false.
    so.sd.ignore_zero_deposition = false;

    so.action_times = false;
    // so.cuda_stack_size = 32000;
    // so.cuda_heap_size = 10000000;
    // Turn on for debugging
    // so.geometry_output_file = "geometry.gdml";
    // so.offload_output_file = "primaries.hepmc3";

    return so;
  }();
  return options;
}

// Shared data and GPU setup
SharedParams& CelerSharedParams()
{
  static SharedParams sp;
  return sp;
}

// Thread-local transporter
LocalTransporter& CelerLocalTransporter()
{
  static G4ThreadLocal LocalTransporter lt;
  return lt;
}

// Thread-local offload interface
SimpleOffload& CelerSimpleOffload()
{
  static G4ThreadLocal SimpleOffload so;
  return so;
}