HepMC3 event record library
Selector.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 Selector.h
8 /// @brief definition of /b Selector class
9 ///
10 #ifndef HEPMC3_SELECTOR_H
11 #define HEPMC3_SELECTOR_H
12 
13 #include "HepMC3/Filter.h"
14 #include "HepMC3/Feature.h"
16 
17 namespace HepMC3 {
18 /** @brief Forward declaration of SelectorWrapper */
19 template<typename T>
21 
22 class Selector;
23 /** @brief Declaration of ConstSelectorPtr */
24 using ConstSelectorPtr = std::shared_ptr<const Selector>;
25 
26 /**
27  * @brief Selector is an interface to "standard" Features that are valid
28  * for both integral and floating point comparisons
29  *
30  * You would use this in preference to the more general
31  * Feature<> templated type. A Selector is constructed from a
32  * function to extract features from particles, e.g.
33  *
34  * ConstSelectorPtr status = std::make_shared<SelectorWrapper<int> >([](ConstParticlePtr p)->int{return p->status();});
35  * ConstSelectorPtr pt = std::make_shared<SelectorWrapper<double> >([](ConstParticlePtr p)->double{return p->momentum().pt();});
36  *
37  * You can then use the Selector to construct Filter functions that
38  * evaluate on particles, e.g.
39  * Filter is_stable = (*status) == 1;
40  * bool stable = is_stable(p);
41  * bool beam = (*status == 4)(p);
42  *
43  * StandardSelector contains a few standard Selectors already defined, e.g.
44  *
45  * ConstGenParticlePtr p;
46  * (StandardSelector::STATUS == 1)(p);
47  * (StandardSelector::PT > 15.)(p);
48  * (abs(StandardSelector::RAPIDITY) < 2.5)(p);
49  *
50  * you can also combined them e.g.
51  *
52  * Filter myCuts = (StandardSelector::PT > 15.) && (*abs(StandardSelector::RAPIDITY) < 2.5) || (StandardSelector::PT > 100.);
53  * bool passCuts = myCuts(p);
54  */
55 class Selector {
56 
57 public:
58 /** @brief Destructor */
59  virtual ~Selector() {};
60 
61  virtual Filter operator > (int value) const = 0;
62  virtual Filter operator > (double value) const = 0;
63 
64  virtual Filter operator >= (int value) const = 0;
65  virtual Filter operator >= (double value) const = 0;
66 
67  virtual Filter operator < (int value) const = 0;
68  virtual Filter operator < (double value) const = 0;
69 
70  virtual Filter operator <= (int value) const = 0;
71  virtual Filter operator <= (double value) const = 0;
72 
73  virtual Filter operator == (int value) const = 0; ///< Equality
74  virtual Filter operator == (double value) const = 0; ///< Equality
75 
76  virtual Filter operator != (int value) const = 0; ///< NonEquality
77  virtual Filter operator != (double value) const = 0; ///< NonEquality
78 
79  virtual ConstSelectorPtr abs() const = 0;
80  static AttributeFeature ATTRIBUTE(const std::string &name);
81 
82 };
83 /** @brief SelectorWrapper */
84 template<typename Feature_type>
85 class SelectorWrapper : public Selector {
86 
87 public:
88 
89  SelectorWrapper(typename Feature<Feature_type>::Evaluator_type functor): m_internal(functor) {}
90 
91  Filter operator > (int value) const override {
92  return m_internal > value;
93  }
94 
95  Filter operator > (double value) const override {
96  return m_internal > value;
97  }
98 
99  Filter operator >= (int value) const override {
100  return m_internal >= value;
101  }
102 
103  Filter operator >= (double value) const override {
104  return m_internal >= value;
105  }
106 
107  Filter operator < (int value) const override {
108  return m_internal < value;
109  }
110 
111  Filter operator < (double value) const override {
112  return m_internal < value;
113  }
114 
115  Filter operator <= (int value) const override {
116  return m_internal <= value;
117  }
118 
119  Filter operator <= (double value) const override {
120  return m_internal <= value;
121  }
122 
123  Filter operator == (int value) const override {
124  return m_internal == value;
125  }
126 
127  Filter operator == (double value) const override {
128  return m_internal == value;
129  }
130 
131  Filter operator != (int value) const override {
132  return m_internal != value;
133  }
134 
135  Filter operator != (double value) const override {
136  return m_internal != value;
137  }
138 
139  ConstSelectorPtr abs() const override {
141  copy->m_internal = m_internal.abs();
142  return ConstSelectorPtr(copy);
143  }
144 
145 private:
146 
147  Feature<Feature_type> m_internal; ///< Internal feauture holder
148 
149 };
150 /** @brief ConstSelectorPtr abs*/
151 ConstSelectorPtr abs(const Selector &input);
152 
153 #ifndef NO_DECLSPEC_StandardSelector
154 #ifdef WIN32
155 #ifdef HepMC3search_EXPORTS
156 #define DECLSPEC_StandardSelector __declspec(dllexport)
157 #else
158 #define DECLSPEC_StandardSelector __declspec(dllimport)
159 #endif
160 #else
161 #define NO_DECLSPEC_StandardSelector
162 #endif
163 #endif
164 
165 /** @brief StandardSelector */
166 class StandardSelector: public Selector {
167 
168 public:
169 #ifdef NO_DECLSPEC_StandardSelector
170  static const SelectorWrapper<int> STATUS; ///< Status
171  static const SelectorWrapper<int> PDG_ID; ///< PDG ID
172  static const SelectorWrapper<double> PT; ///< Transverse momentum
173  static const SelectorWrapper<double> ENERGY; ///< Energy
174  static const SelectorWrapper<double> RAPIDITY; ///< Rapidity
175  static const SelectorWrapper<double> ETA; ///< Pseudorapidity
176  static const SelectorWrapper<double> PHI; ///< Azimuthal angle
177  static const SelectorWrapper<double> ET; ///< Transverse energy
178  static const SelectorWrapper<double> MASS; ///< Mass
179 #else
180  static const SelectorWrapper<int> DECLSPEC_StandardSelector STATUS; ///< Status
181  static const SelectorWrapper<int> DECLSPEC_StandardSelector PDG_ID; ///< PDG ID
182  static const SelectorWrapper<double> DECLSPEC_StandardSelector PT; ///< Transverse momentum
183  static const SelectorWrapper<double> DECLSPEC_StandardSelector ENERGY; ///< Energy
184  static const SelectorWrapper<double> DECLSPEC_StandardSelector RAPIDITY; ///< Rapidity
185  static const SelectorWrapper<double> DECLSPEC_StandardSelector ETA; ///< Pseudorapidity
186  static const SelectorWrapper<double> DECLSPEC_StandardSelector PHI; ///< Azimuthal angle
187  static const SelectorWrapper<double> DECLSPEC_StandardSelector ET; ///< Transverse energy
188  static const SelectorWrapper<double> DECLSPEC_StandardSelector MASS; ///< Mass
189 #endif
190 };
191 
192 }
193 #endif
static const SelectorWrapper< double > MASS
Mass.
Definition: Selector.h:178
static const SelectorWrapper< double > ET
Transverse energy.
Definition: Selector.h:177
static const SelectorWrapper< double > PT
Transverse momentum.
Definition: Selector.h:172
static const SelectorWrapper< int > PDG_ID
PDG ID.
Definition: Selector.h:171
static const SelectorWrapper< double > RAPIDITY
Rapidity.
Definition: Selector.h:174
Defines Filter operations for combingin Filters.
Defines Feature interface for selecting Particles according to extracted Features.
Feature< Feature_type > m_internal
Internal feauture holder.
Definition: Selector.h:147
virtual Filter operator!=(int value) const =0
NonEquality.
Filter for the attributes.
Filter operator==(int value) const override
Equality.
Definition: Selector.h:123
std::shared_ptr< const Selector > ConstSelectorPtr
Declaration of ConstSelectorPtr.
Definition: Selector.h:24
static const SelectorWrapper< double > ETA
Pseudorapidity.
Definition: Selector.h:175
Filter operator!=(int value) const override
NonEquality.
Definition: Selector.h:131
std::function< bool(ConstGenParticlePtr)> Filter
type of Filter
Definition: Filter.h:17
static const SelectorWrapper< double > PHI
Azimuthal angle.
Definition: Selector.h:176
StandardSelector.
Definition: Selector.h:166
AttributeFeature.
Forward declaration of SelectorWrapper.
Definition: Selector.h:20
Annotation for function names.
Definition: attr.h:36
Selector is an interface to &quot;standard&quot; Features that are valid for both integral and floating point c...
Definition: Selector.h:55
virtual Filter operator==(int value) const =0
Equality.
virtual ~Selector()
Destructor.
Definition: Selector.h:59
static const SelectorWrapper< int > STATUS
Status.
Definition: Selector.h:170
Feature< Feature_type > abs(const Feature< Feature_type > &input)
Obtain the absolute value of a Feature. This works as you&#39;d expect. If foo is a valid Feature...
Definition: Feature.h:316
static const SelectorWrapper< double > ENERGY
Energy.
Definition: Selector.h:173
Defines AttributeFeature for obtaining Filters to search by Attribute.