Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:01:11

0001 // -*- C++ -*-
0002 //
0003 // This file is part of HepMC
0004 // Copyright (C) 2014-2023 The HepMC collaboration (see AUTHORS for details)
0005 //
0006 ///
0007 /// @file Filter.h
0008 /// @brief Defines Filter operations for combingin Filters
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 /// @brief type of Filter
0019 using Filter = std::function<bool(ConstGenParticlePtr)>;
0020 
0021 /// @brief Apply a Filter to a list of GenParticles
0022 /// Returns a vector of GenParticles that satisfy the Filter
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 /// @brief Apply a Filter to a list of ConstGenParticles
0032 /// Returns a vector of ConstGenParticles that satisfy the Filter
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 /// @brief A Filter that will accept all particles
0042 /// This might be needed if a signature requires a default Filter
0043 inline bool ACCEPT_ALL(ConstGenParticlePtr /*dummy*/) {
0044     return true;
0045 }
0046 
0047 /// @brief The logical AND of two Filters is itself a Filter
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 /// @brief The logical OR of two Filters is itself a Filter
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 /// @brief The negation of a Filter is itself a Filter
0058 inline Filter operator !(const Filter &rhs) {
0059     return [rhs](ConstGenParticlePtr p)->bool{return !(rhs(p));};
0060 }
0061 
0062 }
0063 #endif