File indexing completed on 2025-01-18 10:01:11
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef HEPMC3_FILTER_H
0011 #define HEPMC3_FILTER_H
0012
0013 #include <vector>
0014 #include <functional>
0015 #include "HepMC3/GenParticle.h"
0016
0017 namespace HepMC3 {
0018
0019 using Filter = std::function<bool(ConstGenParticlePtr)>;
0020
0021
0022
0023 inline std::vector<GenParticlePtr> applyFilter(const Filter &filter, const std::vector<GenParticlePtr> &particles) {
0024 std::vector<GenParticlePtr> result;
0025 for (GenParticlePtr p: particles) {
0026 if (filter(p)) result.push_back(p);
0027 }
0028 return result;
0029 }
0030
0031
0032
0033 inline std::vector<ConstGenParticlePtr> applyFilter(const Filter &filter, const std::vector<ConstGenParticlePtr> &particles) {
0034 std::vector<ConstGenParticlePtr> result;
0035 for (ConstGenParticlePtr p: particles) {
0036 if (filter(p)) result.push_back(p);
0037 }
0038 return result;
0039 }
0040
0041
0042
0043 inline bool ACCEPT_ALL(ConstGenParticlePtr ) {
0044 return true;
0045 }
0046
0047
0048 inline Filter operator && (const Filter & lhs, const Filter &rhs) {
0049 return [lhs, rhs](ConstGenParticlePtr p)->bool{return lhs(p) && rhs(p); };
0050 }
0051
0052
0053 inline Filter operator || (const Filter & lhs, const Filter &rhs) {
0054 return [lhs, rhs](ConstGenParticlePtr p)->bool{return lhs(p) || rhs(p); };
0055 }
0056
0057
0058 inline Filter operator !(const Filter &rhs) {
0059 return [rhs](ConstGenParticlePtr p)->bool{return !(rhs(p));};
0060 }
0061
0062 }
0063 #endif