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
15#include "R3BNeulandPoint.h"
16#include <gtest/gtest.h>
17
18// NOLINTBEGIN (cppcoreguidelines-avoid-magic-numbers)
19namespace
20{
21 constexpr auto proton_pid = 2212;
22 constexpr auto neutron_pid = 2112;
23 constexpr auto electron_pid = 11;
25
26 TEST(NeulandPointFilterTest, test_setters_getters)
27 {
28 auto filter = ParticleFilter{};
29 EXPECT_EQ(filter.GetMode(), ParticleFilter::Mode::pass);
30 EXPECT_EQ(filter.GetMinEnergy(), 0.);
31 EXPECT_EQ(filter.GetMaxEnergy(), 0.);
32
33 filter.SetMode(ParticleFilter::Mode::whitelist);
34 EXPECT_EQ(filter.GetMode(), ParticleFilter::Mode::whitelist);
35
36 filter.SetMaxEnergy(1.);
37 EXPECT_EQ(filter.GetMaxEnergy(), 1.);
38
39 filter.SetMinEnergy(1.);
40 EXPECT_EQ(filter.GetMinEnergy(), 1.);
41
42 filter.Reset();
43 EXPECT_EQ(filter.GetMode(), ParticleFilter::Mode::pass);
44 EXPECT_EQ(filter.GetMinEnergy(), 0.);
45 EXPECT_EQ(filter.GetMaxEnergy(), 0.);
46 }
47
48 TEST(NeulandPointFilterTest, test_global_closed_range)
49 {
50 auto point = R3BNeulandPoint{};
51 point.SetParticleId(proton_pid);
52 constexpr auto test_energy_gev = 0.7;
53 point.SetEnergyLoss(test_energy_gev);
54
55 auto filter = R3B::Neuland::ParticleFilter{};
56 auto test_min_energy = 0.6;
57 auto test_max_energy = 0.9;
58 filter.SetMinEnergy(test_min_energy);
59 filter.SetMaxEnergy(test_max_energy);
60
61 EXPECT_TRUE(filter.IsPointAllowed(point));
62
63 test_min_energy = 0.8;
64 test_max_energy = 0.9;
65 filter.SetMinEnergy(test_min_energy);
66 filter.SetMaxEnergy(test_max_energy);
67
68 EXPECT_FALSE(filter.IsPointAllowed(point));
69 }
70
71 TEST(NeulandPointFilterTest, test_global_open_range)
72 {
73 auto point = R3BNeulandPoint{};
74 point.SetParticleId(proton_pid);
75 auto test_energy_gev = 0.7;
76 point.SetEnergyLoss(test_energy_gev);
77
78 auto filter = R3B::Neuland::ParticleFilter{};
79 auto test_min_energy = 0.6;
80 auto test_max_energy = 0.2;
81 filter.SetMinEnergy(test_min_energy);
82 filter.SetMaxEnergy(test_max_energy);
83
84 EXPECT_TRUE(filter.IsPointAllowed(point));
85
86 test_energy_gev = 0.1;
87 point.SetEnergyLoss(test_energy_gev);
88
89 filter.SetMinEnergy(test_min_energy);
90 filter.SetMaxEnergy(test_max_energy);
91
92 EXPECT_TRUE(filter.IsPointAllowed(point));
93
94 test_energy_gev = 0.5;
95 point.SetEnergyLoss(test_energy_gev);
96
97 filter.SetMinEnergy(test_min_energy);
98 filter.SetMaxEnergy(test_max_energy);
99
100 EXPECT_FALSE(filter.IsPointAllowed(point));
101
102 test_energy_gev = 1;
103 test_min_energy = 0.2;
104 point.SetEnergyLoss(test_energy_gev);
105
106 filter.SetMinEnergy(test_min_energy);
107 filter.SetMaxEnergy(test_min_energy);
108
109 EXPECT_TRUE(filter.IsPointAllowed(point));
110 }
111
112 TEST(NeulandPointFilterTest, test_blacklist_mode)
113 {
114 auto filter = ParticleFilter{ ParticleFilter::Mode::blacklist };
115
116 auto proton_point = R3BNeulandPoint{};
117 proton_point.SetParticleId(proton_pid);
118 proton_point.SetEnergyLoss(0.7);
119
120 auto neutron_point = R3BNeulandPoint{};
121 neutron_point.SetParticleId(neutron_pid);
122 neutron_point.SetEnergyLoss(0.7);
123
124 filter.AddParticle("proton", 0.6, 0.8);
125 EXPECT_FALSE(filter.IsPointAllowed(proton_point));
126 EXPECT_TRUE(filter.IsPointAllowed(neutron_point));
127
128 proton_point.SetEnergyLoss(0.5);
129 EXPECT_TRUE(filter.IsPointAllowed(proton_point));
130 }
131
132 TEST(NeulandPointFilterTest, test_whitelist_mode)
133 {
134 auto filter = ParticleFilter{ ParticleFilter::Mode::whitelist };
135
136 auto proton_point = R3BNeulandPoint{};
137 proton_point.SetParticleId(proton_pid);
138 proton_point.SetEnergyLoss(0.7);
139
140 auto neutron_point = R3BNeulandPoint{};
141 neutron_point.SetParticleId(neutron_pid);
142 neutron_point.SetEnergyLoss(0.7);
143
144 filter.AddParticle("proton", 0.6, 0.8);
145 EXPECT_TRUE(filter.IsPointAllowed(proton_point));
146 EXPECT_FALSE(filter.IsPointAllowed(neutron_point));
147
148 proton_point.SetEnergyLoss(0.5);
149 EXPECT_FALSE(filter.IsPointAllowed(proton_point));
150
151 filter.AddParticle("proton");
152 EXPECT_TRUE(filter.IsPointAllowed(proton_point));
153
154 filter.Reset();
155 filter.AddParticle("proton", 0.6, 0.8);
156 }
157
158 TEST(NeulandPointFilterTest, test_multi_particles)
159 {
160 auto proton_point = R3BNeulandPoint{};
161 proton_point.SetParticleId(proton_pid);
162 proton_point.SetEnergyLoss(0.7);
163
164 auto neutron_point = R3BNeulandPoint{};
165 neutron_point.SetParticleId(neutron_pid);
166 neutron_point.SetEnergyLoss(0.4);
167
168 auto electron_point = R3BNeulandPoint{};
169 electron_point.SetParticleId(electron_pid);
170 electron_point.SetEnergyLoss(0.1);
171
172 auto filter = ParticleFilter{ ParticleFilter::Mode::blacklist };
173 filter.AddParticle("e-", 0., 1.);
174
175 EXPECT_FALSE(filter.IsPointAllowed(electron_point));
176 EXPECT_TRUE(filter.IsPointAllowed(proton_point));
177 EXPECT_TRUE(filter.IsPointAllowed(neutron_point));
178
179 filter.SetMode(ParticleFilter::Mode::whitelist);
180
181 EXPECT_TRUE(filter.IsPointAllowed(electron_point));
182 EXPECT_FALSE(filter.IsPointAllowed(proton_point));
183 EXPECT_FALSE(filter.IsPointAllowed(neutron_point));
184 }
185} // namespace
186// NOLINTEND (cppcoreguidelines-avoid-magic-numbers)
void SetMinEnergy(double energy)
Set the global energy range with a minimum value.
void SetParticleId(int particle_id)