R3BROOT
R3B analysis software
Toggle main menu visibility
Loading...
Searching...
No Matches
NeulandParticleFilter.cxx
Go to the documentation of this file.
1
#include "
NeulandParticleFilter.h
"
2
#include "
R3BException.h
"
3
#include "
R3BNeulandPoint.h
"
4
#include <fmt/core.h>
5
#include <fmt/ranges.h>
// NOLINT
6
#include <magic_enum/magic_enum.hpp>
7
#include <range/v3/view/zip.hpp>
8
#include <string>
9
#include <utility>
10
11
namespace
R3B::Neuland
12
{
13
namespace
14
{
15
inline
auto
check_if_within_range(
double
value, std::pair<double, double> min_max) ->
bool
16
{
17
18
if
(min_max.first == min_max.second)
19
{
20
return
true
;
21
}
22
if
(min_max.first < min_max.second)
23
{
24
return
(value > min_max.first) and (value < min_max.second);
25
}
26
return
(value > min_max.first) or (value < min_max.second);
27
}
28
}
// namespace
29
30
auto
ParticleFilter::Create
(
const
Options
& options) ->
ParticleFilter
31
{
32
if
(options.particle_names.size() != options.energy_range_maxs.size())
33
{
34
throw
R3B::logic_error
(fmt::format(
35
"Number of particle types specified (={}) is not equal to the number of range maximum (={})."
,
36
options.particle_names.size(),
37
options.energy_range_maxs.size()));
38
}
39
if
(options.particle_names.size() != options.energy_range_mins.size())
40
{
41
throw
R3B::logic_error
(fmt::format(
42
"Number of particle types specified (={}) is not equal to the number of range minimum (={})."
,
43
options.particle_names.size(),
44
options.energy_range_mins.size()));
45
}
46
47
auto
filter =
ParticleFilter
{ options.mode };
48
filter.SetMaxEnergy(options.global_max_energy);
49
filter.SetMinEnergy(options.global_min_energy);
50
51
for
(
auto
[type, range_min, range_max] :
52
ranges::views::zip(options.particle_names, options.energy_range_mins, options.energy_range_maxs))
53
{
54
filter.AddParticle(type, range_min, range_max);
55
}
56
57
return
filter;
58
}
59
60
auto
ParticleFilter::IsPointAllowed
(
const
R3BNeulandPoint
& neuland_point) ->
bool
61
{
62
if
(not check_if_within_range(neuland_point.GetEnergyLoss(),
63
std::pair{ minimum_allowed_energy_, maximum_allowed_energy_ }))
64
{
65
return
false
;
66
}
67
68
switch
(
mode_
)
69
{
70
case
Mode::whitelist
:
71
return
is_allowed_with_whitelist
(neuland_point);
72
case
Mode::blacklist
:
73
return
is_allowed_with_blacklist
(neuland_point);
74
case
Mode::pass
:
75
return
true
;
76
}
77
return
true
;
78
}
79
80
void
ParticleFilter::AddParticle
(
const
std::string& particle_name,
double
min_energy,
double
max_energy)
81
{
82
const
auto
pid =
pdg_converter_
.
get_pid
(particle_name);
83
if
(
list_
.find(pid) ==
list_
.end())
84
{
85
list_
.emplace(pid, std::pair{ min_energy, max_energy });
86
}
87
else
88
{
89
list_
.at(pid) = std::pair{ min_energy, max_energy };
90
}
91
}
92
93
auto
ParticleFilter::is_allowed_with_whitelist
(
const
R3BNeulandPoint
& neuland_point) ->
bool
94
{
95
const
auto
particle_pid = neuland_point.GetPID();
96
if
(
list_
.find(particle_pid) !=
list_
.end())
97
{
98
return
check_if_within_range(neuland_point.GetEnergyLoss(),
list_
.at(particle_pid));
99
}
100
return
false
;
101
}
102
103
auto
ParticleFilter::is_allowed_with_blacklist
(
const
R3BNeulandPoint
& neuland_point) ->
bool
104
{
105
const
auto
particle_pid = neuland_point.GetPID();
106
if
(
list_
.find(particle_pid) !=
list_
.end())
107
{
108
return
not check_if_within_range(neuland_point.GetEnergyLoss(),
list_
.at(particle_pid));
109
}
110
return
true
;
111
}
112
113
auto
ParticleFilter::Print
() -> std::string
114
{
115
return
fmt::format(
"Filter Content: \n"
116
"=============================\n"
117
"-- Mode: {}\n"
118
"-- Global minimun energy:{}\n"
119
"-- Global maximum energy: {}\n"
120
"-- particles: {}\n"
121
"============================="
,
122
magic_enum::enum_name(
mode_
),
123
minimum_allowed_energy_
,
124
maximum_allowed_energy_
,
125
list_
);
126
}
127
128
void
ParticleFilter::Reset
()
129
{
130
mode_
=
Mode::pass
;
131
minimum_allowed_energy_
= 0.;
132
maximum_allowed_energy_
= 0.;
133
list_
.clear();
134
}
135
}
// namespace R3B::Neuland
NeulandParticleFilter.h
R3BException.h
R3BNeulandPoint.h
R3B::Neuland::ParticleFilter::mode_
Mode mode_
Filtering mode.
Definition
NeulandParticleFilter.h:162
R3B::Neuland::ParticleFilter::maximum_allowed_energy_
double maximum_allowed_energy_
global maximum engergy in GeV
Definition
NeulandParticleFilter.h:164
R3B::Neuland::ParticleFilter::ParticleFilter
ParticleFilter()=default
Default constructor.
R3B::Neuland::ParticleFilter::IsPointAllowed
auto IsPointAllowed(const R3BNeulandPoint &neuland_point) -> bool
Check if the neuland point is allowed.
Definition
NeulandParticleFilter.cxx:60
R3B::Neuland::ParticleFilter::Reset
void Reset()
Reset.
Definition
NeulandParticleFilter.cxx:128
R3B::Neuland::ParticleFilter::Print
auto Print() -> std::string
Print the configuration of the current filter.
Definition
NeulandParticleFilter.cxx:113
R3B::Neuland::ParticleFilter::is_allowed_with_whitelist
auto is_allowed_with_whitelist(const R3BNeulandPoint &neuland_point) -> bool
Definition
NeulandParticleFilter.cxx:93
R3B::Neuland::ParticleFilter::Create
static auto Create(const Options &options) -> ParticleFilter
Generator for the filter object from the configuration.
Definition
NeulandParticleFilter.cxx:30
R3B::Neuland::ParticleFilter::list_
std::unordered_map< int32_t, std::pair< double, double > > list_
Whitelist with min energy values [GeV].
Definition
NeulandParticleFilter.h:165
R3B::Neuland::ParticleFilter::Mode::pass
@ pass
Definition
NeulandParticleFilter.h:30
R3B::Neuland::ParticleFilter::Mode::blacklist
@ blacklist
Definition
NeulandParticleFilter.h:29
R3B::Neuland::ParticleFilter::Mode::whitelist
@ whitelist
Definition
NeulandParticleFilter.h:28
R3B::Neuland::ParticleFilter::AddParticle
void AddParticle(const std::string &particle_name, double min_energy=0., double max_energy=0.)
Add particle to the list.
Definition
NeulandParticleFilter.cxx:80
R3B::Neuland::ParticleFilter::minimum_allowed_energy_
double minimum_allowed_energy_
global minimum engergy in GeV
Definition
NeulandParticleFilter.h:163
R3B::Neuland::ParticleFilter::is_allowed_with_blacklist
auto is_allowed_with_blacklist(const R3BNeulandPoint &neuland_point) -> bool
Definition
NeulandParticleFilter.cxx:103
R3B::Neuland::ParticleFilter::pdg_converter_
PDGConverter pdg_converter_
Definition
NeulandParticleFilter.h:166
R3B::PDGConverter::get_pid
auto get_pid(const std::string &name) -> int32_t
Definition
R3BPDGConverter.cxx:126
R3B::logic_error
Definition
R3BException.h:32
R3BNeulandPoint
Definition
R3BNeulandPoint.h:29
R3B::Neuland
Simulation of NeuLAND Bar/Paddle.
Definition
R3BNeulandAnalysisApp.cxx:44
R3B::Neuland::ParticleFilter::Options
Option structure to create a filter.
Definition
NeulandParticleFilter.h:44
neuland
digitizing
NeulandParticleFilter.cxx
Generated by
1.18.0