IAP GITLAB

Skip to content
Snippets Groups Projects
testParticleCut.cc 4.19 KiB
Newer Older
felix@home's avatar
felix@home committed

/*
 * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
 *
 * See file AUTHORS for a list of contributors.
 *
 * This software is distributed under the terms of the GNU General Public
 * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
 * the license.
 */

#include <corsika/process/particle_cut/ParticleCut.h>

#include <corsika/environment/Environment.h>
#include <corsika/geometry/Point.h>
#include <corsika/geometry/RootCoordinateSystem.h>
#include <corsika/geometry/Vector.h>
#include <corsika/units/PhysicalUnits.h>
#include <corsika/utl/CorsikaFenv.h>

#include <corsika/setup/SetupStack.h>

#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one
                          // cpp file
#include <catch2/catch.hpp>

using namespace corsika;
using namespace corsika::process::particle_cut;
using namespace corsika::units;
using namespace corsika::units::si;

TEST_CASE("ParticleCut", "[processes]") {
  feenableexcept(FE_INVALID);
  using EnvType = environment::Environment<setup::IEnvironmentModel>;
  EnvType env;
  const geometry::CoordinateSystem& rootCS = env.GetCoordinateSystem();
felix@home's avatar
felix@home committed

  // setup empty particle stack
  setup::Stack stack;
  stack.Clear();
  // two energies
  const HEPEnergyType Eabove = 1_TeV;
  const HEPEnergyType Ebelow = 10_GeV;
  // list of arbitrary particles
  std::vector<particles::Code> particleList = {
      particles::Code::PiPlus,   particles::Code::PiMinus, particles::Code::KPlus,
      particles::Code::KMinus,   particles::Code::K0Long,  particles::Code::K0Short,
      particles::Code::Electron, particles::Code::MuPlus,  particles::Code::NuE,
      particles::Code::Neutron};

  SECTION("cut invisible") {
felix@home's avatar
felix@home committed

    ParticleCut cut(20_GeV);

felix@home's avatar
felix@home committed
    // add primary particle to stack
felix@home's avatar
felix@home committed
    auto particle = stack.AddParticle(
        std::tuple<particles::Code, units::si::HEPEnergyType,
                   corsika::stack::MomentumVector, geometry::Point, units::si::TimeType>{
felix@home's avatar
felix@home committed
            particles::Code::Proton, Eabove,
felix@home's avatar
felix@home committed
            corsika::stack::MomentumVector(rootCS, {0_GeV, 0_GeV, 0_GeV}),
            geometry::Point(rootCS, 0_m, 0_m, 0_m), 0_ns});
felix@home's avatar
felix@home committed
    // view on secondary particles
    corsika::stack::SecondaryView view(particle);
    // ref. to primary particle through the secondary view.
    // only this way the secondary view is populated
    auto projectile = view.GetProjectile();
    // add secondaries, all with energies above the threshold
    // only cut is by species
felix@home's avatar
felix@home committed
    for (auto proType : particleList)
felix@home's avatar
felix@home committed
      projectile.AddSecondary(std::tuple<particles::Code, units::si::HEPEnergyType,
                                         corsika::stack::MomentumVector, geometry::Point,
                                         units::si::TimeType>{
felix@home's avatar
felix@home committed
          proType, Eabove, corsika::stack::MomentumVector(rootCS, {0_GeV, 0_GeV, 0_GeV}),
          geometry::Point(rootCS, 0_m, 0_m, 0_m), 0_ns});

felix@home's avatar
felix@home committed
    cut.DoSecondaries(view);

    REQUIRE(view.GetSize() == 6);
  }

  SECTION("cut low energy") {
    ParticleCut cut(20_GeV);

    // add primary particle to stack
    auto particle = stack.AddParticle(
        std::tuple<particles::Code, units::si::HEPEnergyType,
                   corsika::stack::MomentumVector, geometry::Point, units::si::TimeType>{
            particles::Code::Proton, Eabove,
            corsika::stack::MomentumVector(rootCS, {0_GeV, 0_GeV, 0_GeV}),
            geometry::Point(rootCS, 0_m, 0_m, 0_m), 0_ns});
    // view on secondary particles
felix@home's avatar
felix@home committed
    corsika::stack::SecondaryView view(particle);
felix@home's avatar
felix@home committed
    // ref. to primary particle through the secondary view.
    // only this way the secondary view is populated
    auto projectile = view.GetProjectile();
    // add secondaries, all with energies below the threshold
    // only cut is by species
    for (auto proType : particleList)
      projectile.AddSecondary(std::tuple<particles::Code, units::si::HEPEnergyType,
                                         corsika::stack::MomentumVector, geometry::Point,
                                         units::si::TimeType>{
          proType, Ebelow, corsika::stack::MomentumVector(rootCS, {0_GeV, 0_GeV, 0_GeV}),
          geometry::Point(rootCS, 0_m, 0_m, 0_m), 0_ns});

felix@home's avatar
felix@home committed
    cut.DoSecondaries(view);
felix@home's avatar
felix@home committed

    REQUIRE(view.GetSize() == 0);