HepMC3 event record library
search
include
HepMC3
Filter.h
Go to the documentation of this file.
1
// -*- C++ -*-
2
//
3
// This file is part of HepMC
4
// Copyright (C) 2014-2019 The HepMC collaboration (see AUTHORS for details)
5
//
6
///
7
/// @file Filter.h
8
/// @brief Defines Filter operations for combingin Filters
9
///
10
#ifndef HEPMC3_FILTER_H
11
#define HEPMC3_FILTER_H
12
13
#include "
HepMC3/GenParticle.h
"
14
#include <functional>
15
namespace
HepMC3
{
16
/// @brief type of Filter
17
using
Filter
= std::function<bool(ConstGenParticlePtr)>;
18
19
/// @brief Apply a Filter to a list of GenParticles
20
/// Returns a vector of GenParticles that satisfy the Filter
21
inline
std::vector<GenParticlePtr>
applyFilter
(
const
Filter
&filter,
const
std::vector<GenParticlePtr> &particles) {
22
std::vector<GenParticlePtr> result;
23
for
(GenParticlePtr p: particles) {
24
if
(filter(p)) result.push_back(p);
25
}
26
return
result;
27
}
28
29
/// @brief Apply a Filter to a list of ConstGenParticles
30
/// Returns a vector of ConstGenParticles that satisfy the Filter
31
inline
std::vector<ConstGenParticlePtr>
applyFilter
(
const
Filter
&filter,
const
std::vector<ConstGenParticlePtr> &particles) {
32
std::vector<ConstGenParticlePtr> result;
33
for
(ConstGenParticlePtr p: particles) {
34
if
(filter(p)) result.push_back(p);
35
}
36
return
result;
37
}
38
39
/// @brief A Filter that will accept all particles
40
/// This might be needed if a signature requires a default Filter
41
inline
bool
ACCEPT_ALL
(ConstGenParticlePtr dummy) {
42
return
true
;
43
}
44
45
/// @brief The logical AND of two Filters is itself a Filter
46
inline
Filter
operator &&
(
const
Filter
& lhs,
const
Filter
&rhs) {
47
return
[lhs, rhs](ConstGenParticlePtr p)->
bool
{
return
lhs(p) && rhs(p); };
48
}
49
50
/// @brief The logical OR of two Filters is itself a Filter
51
inline
Filter
operator ||
(
const
Filter
& lhs,
const
Filter
&rhs) {
52
return
[lhs, rhs](ConstGenParticlePtr p)->
bool
{
return
lhs(p) || rhs(p); };
53
}
54
55
/// @brief The negation of a Filter is itself a Filter
56
inline
Filter
operator !
(
const
Filter
&rhs) {
57
return
[rhs](ConstGenParticlePtr p)->
bool
{
return
! (rhs(p));};
58
}
59
60
}
61
#endif
HepMC3::operator&&
Filter operator&&(const Filter &lhs, const Filter &rhs)
The logical AND of two Filters is itself a Filter.
Definition:
Filter.h:46
HepMC3::applyFilter
std::vector< GenParticlePtr > applyFilter(const Filter &filter, const std::vector< GenParticlePtr > &particles)
Apply a Filter to a list of GenParticles Returns a vector of GenParticles that satisfy the Filter.
Definition:
Filter.h:21
HepMC3
HepMC3 main namespace.
Definition:
AnalysisExample.h:19
GenParticle.h
Definition of class GenParticle.
HepMC3::operator||
Filter operator||(const Filter &lhs, const Filter &rhs)
The logical OR of two Filters is itself a Filter.
Definition:
Filter.h:51
HepMC3::Filter
std::function< bool(ConstGenParticlePtr)> Filter
type of Filter
Definition:
Filter.h:17
HepMC3::ACCEPT_ALL
bool ACCEPT_ALL(ConstGenParticlePtr dummy)
A Filter that will accept all particles This might be needed if a signature requires a default Filter...
Definition:
Filter.h:41
HepMC3::operator!
Filter operator!(const Filter &rhs)
The negation of a Filter is itself a Filter.
Definition:
Filter.h:56
Generated on Tue Jul 14 2020 00:00:00 for HepMC3 event record library by
1.8.18