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
17namespace HepMC3 {
18/** @brief Forward declaration of SelectorWrapper */
19template<typename T>
20class SelectorWrapper;
21
22class Selector;
23/** @brief Declaration of ConstSelectorPtr */
24using 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 * Selector contains a few standard Selectors already defined, e.g.
44 *
45 * ConstGenParticlePtr p;
46 * (Selector::STATUS == 1)(p);
47 * (Selector::PT > 15.)(p);
48 * (abs(Selector::RAPIDITY) < 2.5)(p);
49 *
50 * you can also combined them e.g.
51 *
52 * Filter myCuts = (Selector::PT > 15.) && (*abs(Selector::RAPIDITY) < 2.5) || (Selector::PT > 100.);
53 * bool passCuts = myCuts(p);
54 */
55class Selector {
56
57public:
58
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;
74 virtual Filter operator == (double value) const = 0;
75
76 virtual Filter operator != (int value) const = 0;
77 virtual Filter operator != (double value) const = 0;
78
79 virtual ConstSelectorPtr abs() const = 0;
80
81 static const SelectorWrapper<int> STATUS;
82 static const SelectorWrapper<int> PDG_ID;
83 static const SelectorWrapper<double> PT;
84 static const SelectorWrapper<double> ENERGY;
85 static const SelectorWrapper<double> RAPIDITY;
86 static const SelectorWrapper<double> ETA;
87 static const SelectorWrapper<double> PHI;
88 static const SelectorWrapper<double> ET;
89 static const SelectorWrapper<double> MASS;
90 static AttributeFeature ATTRIBUTE(const std::string &name);
91
92};
93/** @brief SelectorWrapper */
94template<typename Feature_type>
95class SelectorWrapper : public Selector {
96
97public:
98
99 SelectorWrapper(typename Feature<Feature_type>::Evaluator_type functor): m_internal(functor) {}
100
101 Filter operator > (int value) const override {
102 return m_internal > value;
103 }
104
105 Filter operator > (double value) const override {
106 return m_internal > value;
107 }
108
109 Filter operator >= (int value) const override {
110 return m_internal >= value;
111 }
112
113 Filter operator >= (double value) const override {
114 return m_internal >= value;
115 }
116
117 Filter operator < (int value) const override {
118 return m_internal < value;
119 }
120
121 Filter operator < (double value) const override {
122 return m_internal < value;
123 }
124
125 Filter operator <= (int value) const override {
126 return m_internal <= value;
127 }
128
129 Filter operator <= (double value) const override {
130 return m_internal <= value;
131 }
132
133 Filter operator == (int value) const override {
134 return m_internal == value;
135 }
136
137 Filter operator == (double value) const override {
138 return m_internal == value;
139 }
140
141 Filter operator != (int value) const override {
142 return m_internal != value;
143 }
144
145 Filter operator != (double value) const override {
146 return m_internal != value;
147 }
148
149 ConstSelectorPtr abs() const override {
151 copy->m_internal = m_internal.abs();
152 return ConstSelectorPtr(copy);
153 }
154
155private:
156
157 Feature<Feature_type> m_internal;
158
159};
160/** @brief ConstSelectorPtr abs*/
161ConstSelectorPtr abs(const Selector &input);
162
163}
164#endif
Defines AttributeFeature for obtaining Filters to search by Attribute.
Defines Feature interface for selecting Particles according to extracted Features.
Defines Filter operations for combingin Filters.
Filter for the attributes.
Expose GenericFeature interface to derived Feature class.
Definition: Feature.h:161
Selector is an interface to "standard" Features that are valid for both integral and floating point c...
Definition: Selector.h:55
HepMC3 main namespace.
Definition: ReaderGZ.h:28
std::function< bool(ConstGenParticlePtr)> Filter
type of Filter
Definition: Filter.h:17
std::shared_ptr< const Selector > ConstSelectorPtr
Declaration of ConstSelectorPtr.
Definition: Selector.h:24
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:316