HepMC3 event record library
|
HepMC3 comes with an optional "Search" library for finding particles related to other particles or vertices. It provides a set of functions to perform simple search operations e.g.
The purpose of Relatives is to be able to wrap any viable class in a common interface for finding relatives from a particle or vertex. Examples are provided in the form of the _parents and _children classes. These do not inherit from Raltives, but they do implement the necessary functions. The _parents and _children class are not intended to be used directly, but they are aliased by wrapping in the RelativesInterface:
Note as well that the _parents and _children classes use some utility aliases to help declare the appropriately consted return type. For example
has a return type GenParticles_type that is a vector of GenParticlePtr that is consted if GenObject_type is const, but is not consted if GenObject_type is not consted. Note as well the use of enable_if so that a single implementation can be used for both the const and non-const version of the functions. For the simple case of _parents the four required funcs could have been implemented directly without such templating, but for more complicated relatives it avoids duplicated code.
In addition to the RelativesInterface wrapper, Relatives.h also contains a Recursive class that can wrap the underlying relation in recursion. For example, recursion applied to the parents relationship provides all of the ancestors, i.e. parents repeatedly applied to the output of parents. The only additional requirement to use the Recursive wrapper is that the underlying class must implement a vertex(GenParticlePtr) method that returns the appropriate vertex to follow from a given GenParticle. As long as a class has such a method, it is possible to make a recursive version of it
The Relatives class contains static implementations of the Parents, Children, Ancestors and Descendants relatives, which can be accessed and used as follows
A Filter is any object that has an operator that takes as input a ConstGenParticlePtr and returns a bool that reflects whether the input particle passes the filter requirements or not. Filter is defined in Filter.h as
Filter.h also contains some logical operators that allow filters to be combined to create new filters, for example
Filter.h additionally contains a dummy filter that always accepts every possible particle. This may be needed in functions that require a default filter. The dummy filter is accessed as
It is possible to define a Filter by hand. However, there are some utility classes to define Filters based on features that can be obtained from GenParticles
The Feature interface is defined in Feature.h. The interface is templated on a Feature_type that is any type that can be extracted from a GenParticle. This is very flexible, and the only criteria is that the Feature must have the set of comparison operators. While the templated Feature is general enough to be used with any type of Feature, there are specialisations for both integral and floating point features. The specialisations will cover the vast majority of Features that are likely to be useful, although note that Attributes may be a source of more complicated Features.
To create a Feature, one need only wrap a lambda expression in the Feature interface. For example, to create a Feature based on particle status or pT:
The more general form for any type of Feature would be
Having created a Feature, it can be used to create Filters for particle selection. Applying operators to Features creates the Filter, which is a functor that evaluates on a particle. For example
It is also possible to make a new Feature from the absolute value of a previous Feature, e.g.
Some standard features are contained within the non-templated Selector class
Selector is a simplified interface that contains some predefined Features that can be used to search. Selector defines comparisons operators for both integral and floating point types, as well as the following selection Features:
Selector::STATUS Selector::PDG_ID Selector::PT Selector::ENERGY Selector::RAPIDITY Selector::ETA Selector::PHI Selector::ET Selector::MASS Selector::ATTRIBUTE(const std::string)
So, for example, a filter can be defined as follows
As with Feature, it is possible to take tbe absolute value of a Selector. However, note that while Featue is templated, Selector is abstract and so it is not possible for abs() to return a Selector object directly, only a pointer
Note that the ATTRIBUTE selection is different from the others and does not have the full set of comparison operators. This is a current limitation of the Attributes, which are not guaranteed to offer all comparisons. ATTRIBUTE takes a string, which is the name of the attribute, and permits the equality operator and the method exists, which checks if the attribute is even present
The function applyFilter is used to apply the Filter to a set of particles. See for example examples/BasicExamples/basic_tree.cc
Last update 27 Oct 2020