Back to home page

EIC code displayed by LXR

 
 

    


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

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 Selector.h
0008 /// @brief definition of \b Selector class
0009 ///
0010 #ifndef HEPMC3_SELECTOR_H
0011 #define HEPMC3_SELECTOR_H
0012 
0013 #include <string>
0014 #include <memory>
0015 #include "HepMC3/Filter.h"
0016 #include "HepMC3/Feature.h"
0017 #include "HepMC3/AttributeFeature.h"
0018 
0019 namespace HepMC3 {
0020 /** @brief  Forward declaration of SelectorWrapper */
0021 template<typename T>
0022 class SelectorWrapper;
0023 
0024 class Selector;
0025 /** @brief Declaration of ConstSelectorPtr */
0026 using ConstSelectorPtr = std::shared_ptr<const Selector>;
0027 
0028 /**
0029  *  @brief Selector is an interface to "standard" Features that are valid
0030  *  for both integral and floating point comparisons
0031  *
0032  *  You would use this in preference to the more general
0033  *  Feature<> templated type.  A Selector is constructed from a
0034  *  function to extract features from particles, e.g.
0035  *
0036  *  ConstSelectorPtr status = std::make_shared<SelectorWrapper<int> >([](ConstParticlePtr p)->int{return p->status();});
0037  *  ConstSelectorPtr pt = std::make_shared<SelectorWrapper<double> >([](ConstParticlePtr p)->double{return p->momentum().pt();});
0038  *
0039  *  You can then use the Selector to construct Filter functions that
0040  *  evaluate on particles, e.g.
0041  *  Filter is_stable = (*status) == 1;
0042  *  bool stable = is_stable(p);
0043  *  bool beam = (*status == 4)(p);
0044  *
0045  *  StandardSelector contains a few standard Selectors already defined, e.g.
0046  *
0047  *  ConstGenParticlePtr p;
0048  *  (StandardSelector::STATUS == 1)(p);
0049  *  (StandardSelector::PT > 15.)(p);
0050  *  (abs(StandardSelector::RAPIDITY) < 2.5)(p);
0051  *
0052  *  you can also combined them e.g.
0053  *
0054  *  Filter myCuts = (StandardSelector::PT > 15.) && (*abs(StandardSelector::RAPIDITY) < 2.5) || (StandardSelector::PT > 100.);
0055  *  bool passCuts = myCuts(p);
0056  */
0057 class Selector {
0058 public:
0059 /** @brief  Destructor */
0060     virtual ~Selector() {};
0061 
0062     virtual Filter operator > (int value) const = 0;        ///< Operator >
0063     virtual Filter operator > (double value) const = 0;     ///< Operator >
0064 
0065     virtual Filter operator >= (int value) const = 0;       ///< Operator >=
0066     virtual Filter operator >= (double value) const = 0;    ///< Operator >=
0067 
0068     virtual Filter operator < (int value) const = 0;        ///< Operator <
0069     virtual Filter operator < (double value) const = 0;     ///< Operator <
0070 
0071     virtual Filter operator <= (int value) const = 0;       ///< Operator <=
0072     virtual Filter operator <= (double value) const = 0;    ///< Operator <=
0073 
0074     virtual Filter operator == (int value) const = 0;      ///< Equality
0075     virtual Filter operator == (double value) const = 0;      ///< Equality
0076 
0077     virtual Filter operator != (int value) const = 0;      ///< NonEquality
0078     virtual Filter operator != (double value) const = 0;      ///< NonEquality
0079 
0080     virtual ConstSelectorPtr abs() const = 0;    ///< abs function
0081     static AttributeFeature ATTRIBUTE(const std::string &name);  ///< ATTRIBUTE function
0082 };
0083 /** @brief  SelectorWrapper */
0084 template<typename Feature_type>
0085 class SelectorWrapper : public Selector {
0086 public:
0087     /// @brief Constructor
0088     SelectorWrapper(typename Feature<Feature_type>::Evaluator_type functor): m_internal(functor) {}
0089 
0090     /// @brief Operator >
0091     Filter operator > (int value) const override {
0092         return m_internal > value;
0093     }
0094 
0095     /// @brief Operator >
0096     Filter operator > (double value) const override {
0097         return m_internal > value;
0098     }
0099 
0100     /// @brief Operator >=
0101     Filter operator >= (int value) const override {
0102         return m_internal >= value;
0103     }
0104 
0105     /// @brief Operator >=
0106     Filter operator >= (double value) const override {
0107         return m_internal >= value;
0108     }
0109 
0110     /// @brief Operator <
0111     Filter operator < (int value) const override {
0112         return m_internal < value;
0113     }
0114 
0115     /// @brief Operator <
0116     Filter operator < (double value) const override {
0117         return m_internal < value;
0118     }
0119 
0120     /// @brief Operator <=
0121     Filter operator <= (int value) const override {
0122         return m_internal <= value;
0123     }
0124 
0125     /// @brief Operator <=
0126     Filter operator <= (double value) const override {
0127         return m_internal <= value;
0128     }
0129 
0130     /// @brief Operator ==
0131     Filter operator == (int value) const override {
0132         return m_internal == value;
0133     }
0134 
0135     /// @brief Operator ==
0136     Filter operator == (double value) const override {
0137         return m_internal == value;
0138     }
0139 
0140     /// @brief Operator !=
0141     Filter operator != (int value) const override {
0142         return m_internal != value;
0143     }
0144 
0145     /// @brief Operator !=
0146     Filter operator != (double value) const override {
0147         return m_internal != value;
0148     }
0149 
0150     /// @brief Function abs
0151     ConstSelectorPtr abs() const override {
0152         SelectorWrapper<Feature_type> *copy = new SelectorWrapper<Feature_type>(*this);
0153         copy->m_internal = m_internal.abs();
0154         return ConstSelectorPtr(copy);
0155     }
0156 
0157 private:
0158     Feature<Feature_type> m_internal;  ///< Internal feauture holder
0159 };
0160 /** @brief ConstSelectorPtr abs*/
0161 ConstSelectorPtr abs(const Selector &input);
0162 
0163 #if defined(WIN32) && !defined(HEPMC3search_NO_StandardSelector_EXPORTS)
0164 #ifdef HepMC3search_EXPORTS
0165 #define HEPMC3search_StandardSelector_EXPORT_API __declspec(dllexport)
0166 #else
0167 #define HEPMC3search_StandardSelector_EXPORT_API  __declspec(dllimport)
0168 #endif
0169 #else
0170 #define HEPMC3search_StandardSelector_EXPORT_API
0171 #endif
0172 
0173 /** @brief  StandardSelector */
0174 class StandardSelector: public Selector {
0175 public:
0176     HEPMC3search_StandardSelector_EXPORT_API static const SelectorWrapper<int>    STATUS;   ///< Status
0177     HEPMC3search_StandardSelector_EXPORT_API static const SelectorWrapper<int>    PDG_ID;   ///< PDG ID
0178     HEPMC3search_StandardSelector_EXPORT_API static const SelectorWrapper<double>  PT;       ///< Transverse momentum
0179     HEPMC3search_StandardSelector_EXPORT_API static const SelectorWrapper<double>  ENERGY;   ///< Energy
0180     HEPMC3search_StandardSelector_EXPORT_API static const SelectorWrapper<double>  RAPIDITY; ///< Rapidity
0181     HEPMC3search_StandardSelector_EXPORT_API static const SelectorWrapper<double>  ETA;      ///< Pseudorapidity
0182     HEPMC3search_StandardSelector_EXPORT_API static const SelectorWrapper<double>  PHI;      ///< Azimuthal angle
0183     HEPMC3search_StandardSelector_EXPORT_API static const SelectorWrapper<double>  ET;       ///< Transverse energy
0184     HEPMC3search_StandardSelector_EXPORT_API static const SelectorWrapper<double>  MASS;     ///< Mass
0185 };
0186 
0187 }
0188 #endif