R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
testNeulandPointFilter.cxx
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3 * Copyright (C) 2019-2023 Members of R3B Collaboration *
4 * *
5 * This software is distributed under the terms of the *
6 * GNU General Public Licence (GPL) version 3, *
7 * copied verbatim in the file "LICENSE". *
8 * *
9 * In applying this license GSI does not waive the privileges and immunities *
10 * granted to it by virtue of its status as an Intergovernmental Organization *
11 * or submit itself to any jurisdiction. *
12 ******************************************************************************/
13
14#include "NeulandPointFilter.h"
15#include "R3BNeulandPoint.h"
16#include <bitset>
17#include <gtest/gtest.h>
18
19namespace
20{
21
22 namespace neuland = ::R3B::Neuland;
23
26 // Test for ParticleToBitSet function
27
28 TEST(TestNeulandPointFilter, ParticleToBitSetTest)
29 {
30 auto bitset = neuland::ParticleToBitSet(BitSetParticle::proton);
31 EXPECT_EQ(bitset.to_ulong(), 0x0001);
32
33 bitset = ParticleToBitSet(BitSetParticle::neutron);
34 EXPECT_EQ(bitset.to_ulong(), 0x0002);
35
36 bitset = ParticleToBitSet(BitSetParticle::gamma);
37 EXPECT_EQ(bitset.to_ulong(), 0x0020);
38 }
39
40 // Test for BitSetToParticle function
41 TEST(TestNeulandPointFilter, BitSetToParticleTest)
42 {
43 constexpr auto proton_bitsetid = 0x0001;
44 auto particle = neuland::BitSetToParticle(std::bitset<ParticleBitsetSize>{ proton_bitsetid });
45 EXPECT_EQ(particle, BitSetParticle::proton);
46
47 constexpr auto neutron_bitsetid = 0x0002;
48 particle = neuland::BitSetToParticle(std::bitset<ParticleBitsetSize>{ neutron_bitsetid });
49 EXPECT_EQ(particle, BitSetParticle::neutron);
50
51 constexpr auto gamma_bitsetid = 0x0020;
52 particle = neuland::BitSetToParticle(std::bitset<ParticleBitsetSize>{ gamma_bitsetid });
53 EXPECT_EQ(particle, BitSetParticle::gamma);
54 }
55
56 // Test for CheckCriteria function
57 TEST(TestNeulandPointFilter, CheckCriteriaTest)
58 {
59 EXPECT_TRUE(CheckCriteria(BitSetParticle::proton, BitSetParticle::proton));
60 EXPECT_FALSE(CheckCriteria(BitSetParticle::proton, BitSetParticle::neutron));
61 EXPECT_TRUE(CheckCriteria(BitSetParticle::proton, BitSetParticle::neutron | BitSetParticle::proton));
62 }
63
64 // Test for PidToBitSetParticle function
65 TEST(TestNeulandPointFilter, PidToBitSetParticleTest)
66 {
67 EXPECT_EQ(neuland::PidToBitSetParticle(2212), BitSetParticle::proton);
68 EXPECT_EQ(neuland::PidToBitSetParticle(2112), BitSetParticle::neutron);
69 EXPECT_EQ(neuland::PidToBitSetParticle(22), BitSetParticle::gamma);
70 }
71
72 // Test for NeulandPointFilter class
73 TEST(TestNeulandPointFilter, SetFilterTest)
74 {
75 NeulandPointFilter filter;
76 filter.SetFilter(BitSetParticle::proton);
77 EXPECT_EQ(filter.GetFilter(), BitSetParticle::proton);
78
79 filter.SetFilter(BitSetParticle::neutron, 0.5);
80 EXPECT_EQ(filter.GetFilter(), BitSetParticle::neutron);
81 EXPECT_EQ(filter.GetMinimumAllowedEnergy(), 0.5);
82 }
83
84 // Test for NeulandPointFilter::ShouldNeulandPointBeFiltered function
85 TEST(NeulandPointFilterTest, ShouldNeulandPointBeFilteredTest)
86 {
87 constexpr auto proton_pid = 2212;
88 constexpr auto neutron_pid = 2112;
89 constexpr auto eLoss_proton = 0.7;
90 constexpr auto eLoss_neutron = 0.3;
91 const TVector3 sample_vector;
92
93 NeulandPointFilter filter;
94
95 const R3BNeulandPoint protonPoint(
96 0, 0, sample_vector, sample_vector, 0., 0., eLoss_proton, 0, 0., proton_pid, 0);
97 const R3BNeulandPoint neutronPoint(
98 0, 0, sample_vector, sample_vector, 0., 0., eLoss_neutron, 0, 0., neutron_pid, 0);
99
100 // Test filtering criteria for protons
101 filter.SetFilter(BitSetParticle::proton);
102 EXPECT_TRUE(filter.CheckFiltered(protonPoint));
103 EXPECT_FALSE(filter.CheckFiltered(neutronPoint));
104
105 // Test minimum energy filter
106 filter.SetFilter(BitSetParticle::neutron, 0.5);
107 EXPECT_TRUE(filter.CheckFiltered(neutronPoint));
108 EXPECT_FALSE(filter.CheckFiltered(protonPoint));
109 }
110} // namespace
void SetFilter(R3B::Neuland::BitSetParticle filtered_particles)
auto GetMinimumAllowedEnergy() const -> double
auto GetFilter() const -> R3B::Neuland::BitSetParticle
auto CheckFiltered(const R3BNeulandPoint &neuland_point) -> bool
Simulation of NeuLAND Bar/Paddle.
constexpr auto ParticleToBitSet(BitSetParticle particle)
constexpr auto ParticleBitsetSize
auto CheckCriteria(BitSetParticle particle, BitSetParticle criteria) -> bool