Skip to content
Snippets Groups Projects
Commit 2d4f66ce authored by Nils Krumnack's avatar Nils Krumnack
Browse files

add options for sorting/limiting view containers

It is more or less standard to have objects sorted in pt, so we may as
well offer that as an option.  Also, sometimes it may be useful only
to produce the first N objects of a type, so I added that option as
well.


Former-commit-id: 21b665b5a06f9aff0f56ae792bf8e4c222c09df0
parent 7d88b65b
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,7 @@
#include <SystematicsHandles/SysReadHandle.h>
#include <SystematicsHandles/SysWriteHandle.h>
#include <SystematicsHandles/SysListHandle.h>
#include <limits>
namespace CP
{
......@@ -61,6 +62,12 @@ namespace CP
private:
std::vector<SelectionType> m_ignore;
private:
bool m_sortPt {false};
private:
std::size_t m_sizeLimit {std::numeric_limits<std::size_t>::max()};
/// the list of accessors and cut ignore list
private:
std::vector<std::pair<std::unique_ptr<ISelectionAccessor>,SelectionType> > m_accessors;
......
......@@ -44,6 +44,19 @@ namespace CP
if (keep)
output->push_back (particle);
}
if (m_sortPt)
{
std::sort (output->begin(), output->end(), [] (const xAOD::IParticle *a, const xAOD::IParticle *b) {return a->pt() > b->pt();});
}
// This is not necessarily the most efficient mechanism, as we add
// elements that then get removed again. However, if we do sort
// objects, this is the safest mechanism to really get the first N
// objects. Plus it should still be reasonably performant and few
// people are expected to use this option anyways.
if (output->size() > m_sizeLimit)
output->resize (m_sizeLimit);
ANA_CHECK (evtStore()->record (output.release(), m_outputHandle.getName (sys)));
return StatusCode::SUCCESS;
......@@ -87,6 +100,8 @@ namespace CP
/// isn't supported as a property type for AnaAlgorithm right now
declareProperty ("selection", m_selection, "the list of selection decorations");
declareProperty ("ignore", m_ignore, "the list of cuts to *ignore* for each selection");
declareProperty ("sortPt", m_sortPt, "whether to sort objects in pt");
declareProperty ("sizeLimit", m_sizeLimit, "the limit on the size of the output container");
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment