HepMC event record
include/HepMC/Search/FindParticles.h
1 // -*- C++ -*-
2 //
3 // This file is part of HepMC
4 // Copyright (C) 2014 The HepMC collaboration (see AUTHORS for details)
5 //
6 #ifndef HEPMC_SEARCH_FINDPARTICLES_H
7 #define HEPMC_SEARCH_FINDPARTICLES_H
8 /**
9  * @file FindParticles.h
10  * @brief Definition of \b class FindParticles
11  *
12  * @class HepMC::FindParticles
13  * @brief Search engine for GenEvent class
14  *
15  * @ingroup search_engine
16  *
17  */
18 #include "HepMC/Search/FilterList.h"
19 #include "HepMC/Data/SmartPointer.h"
20 
21 namespace HepMC {
22 
23 
24 class GenEvent;
25 
26 
27 /** @brief List of methods of searching through all particles in the event */
28 enum FilterType {
29  FIND_ALL,
30  FIND_FIRST,
31  FIND_LAST
32 };
33 /// Compatibility name
34 using FilterEvent = FilterType;
35 
36 
37 class FindParticles {
38 //
39 // Constructors
40 //
41 public:
42 
43  /** @brief GenEvent-based constructor */
44  FindParticles(const GenEvent &evt, FilterEvent filter_type, FilterList filter_list = FilterList() );
45 
46  /** @brief GenParticle-based constructor */
47  FindParticles(const GenParticlePtr &p, Relationship filter_type, FilterList filter_list = FilterList() );
48 
49  /** @brief GenVertex-based constructor */
50  FindParticles(const GenVertexPtr &v, Relationship filter_type, FilterList filter_list = FilterList() );
51 
52 
53  /** @brief Narrow down the results applying additional filters */
54  void narrow_down( FilterList filter_list );
55 //
56 // Functions
57 //
58 private:
59  /** @brief Check if particle passed all filters */
60  bool passed_all_filters(const GenParticlePtr &p, FilterList &filter_list);
61 
62  /** @brief Check if all ancestors passed the filter
63  *
64  * Recursively check all particles and production vertices of these particles
65  */
66  void recursive_check_ancestors(const GenVertexPtr &v, FilterList &filter_list);
67 
68  /** @brief Check if all descendants passed the filter
69  *
70  * Recursively check all particles and end vertices of these particles
71  */
72  void recursive_check_descendants(const GenVertexPtr &v, FilterList &filter_list);
73 //
74 // Accessors
75 //
76 public:
77  const vector<GenParticlePtr>& results() const { return m_results; } //!< Get results
78 
79 //
80 // Fields
81 //
82 private:
83  vector<GenParticlePtr> m_results; //!< List of results
84  vector<GenVertexPtr> m_checked_vertices; //!< List of already checked vertices
85 };
86 
87 
88  /// @name Finding via unbound functions (returns by copy)
89  //@{
90 
91  /** @brief Find from GenEvent */
92  inline vector<GenParticlePtr> findParticles(const GenEvent &evt, FilterEvent filter_type, FilterList filter_list = FilterList() ) {
93  return FindParticles(evt, filter_type, filter_list).results();
94  }
95 
96  /** @brief Find from GenParticle */
97  inline vector<GenParticlePtr> findParticles(const GenParticlePtr &p, Relationship filter_type, FilterList filter_list = FilterList() ) {
98  return FindParticles(p, filter_type, filter_list).results();
99  }
100 
101  /** @brief Find from GenVertex */
102  inline vector<GenParticlePtr> findParticles(const GenVertexPtr &v, Relationship filter_type, FilterList filter_list = FilterList() ) {
103  return FindParticles(v, filter_type, filter_list).results();
104  }
105 
106  //@}
107 
108 
109 } // namespace HepMC
110 
111 #endif
bool passed_all_filters(const GenParticlePtr &p, FilterList &filter_list)
Check if particle passed all filters.
SmartPointer< class GenParticle > GenParticlePtr
Smart pointer to GenParticle.
FindParticles(const GenEvent &evt, FilterEvent filter_type, FilterList filter_list=FilterList())
GenEvent-based constructor.
const vector< GenParticlePtr > & results() const
Get results.
void narrow_down(FilterList filter_list)
Narrow down the results applying additional filters.
vector< GenVertexPtr > m_checked_vertices
List of already checked vertices.
FilterType FilterEvent
Compatibility name.
FilterType
List of methods of searching through all particles in the event.
void recursive_check_descendants(const GenVertexPtr &v, FilterList &filter_list)
Check if all descendants passed the filter.
vector< GenParticlePtr > findParticles(const GenEvent &evt, FilterEvent filter_type, FilterList filter_list=FilterList())
Find from GenEvent.
void recursive_check_ancestors(const GenVertexPtr &v, FilterList &filter_list)
Check if all ancestors passed the filter.
Definition of template class SmartPointer.
vector< GenParticlePtr > m_results
List of results.
SmartPointer< class GenVertex > GenVertexPtr
Smart pointer to GenVertex.
Relationship
List of methods of searching starting from a particle or vertex.