HepMC3 event record library
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 
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 vector<GenParticlePtr> applyFilter(const Filter &filter, const vector<GenParticlePtr> &particles){
22  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 vector<ConstGenParticlePtr> applyFilter(const Filter &filter, const vector<ConstGenParticlePtr> &particles){
32  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
Filter operator&&(const Filter &lhs, const Filter &rhs)
The logical AND of two Filters is itself a Filter.
Definition: Filter.h:46
Definition of class GenParticle.
Filter operator||(const Filter &lhs, const Filter &rhs)
The logical OR of two Filters is itself a Filter.
Definition: Filter.h:51
Filter operator!(const Filter &rhs)
The negation of a Filter is itself a Filter.
Definition: Filter.h:56
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
vector< GenParticlePtr > applyFilter(const Filter &filter, const vector< GenParticlePtr > &particles)
Apply a Filter to a list of GenParticles Returns a vector of GenParticles that satisfy the Filter...
Definition: Filter.h:21