HepMC3 event record library: Selector.h Source File

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