8#include <analysis/utility/ParticleSubset.h>
10#include <analysis/dataobjects/ParticleList.h>
11#include <framework/datastore/StoreObjPtr.h>
13#include <unordered_set>
18 void keepParticle(
const Particle* p, std::unordered_set<int>* indicesToKeep)
20 indicesToKeep->insert(p->getArrayIndex());
21 unsigned int n = p->getNDaughters();
22 for (
unsigned int i = 0; i < n; i++) {
23 keepParticle(p->getDaughter(i), indicesToKeep);
30 std::unordered_set<int> indicesToKeep;
31 for (
const auto& l : listNames) {
36 if (list->getParticleCollectionName() ==
m_set->
getName()) {
37 const int n = list->getListSize();
38 for (
int i = 0; i < n; i++) {
39 const Particle* p = list->getParticle(i);
40 keepParticle(p, &indicesToKeep);
43 B2ERROR(
"ParticleList " << l <<
" uses Particle array '" << list->getParticleCollectionName() <<
44 "', but ParticleSubset uses different array '" <<
m_set->
getName() <<
"'!");
49 auto selector = [indicesToKeep](
const Particle * p) ->
bool {
50 int idx = p->getArrayIndex();
51 return indicesToKeep.count(idx) == 1;
60 unsigned int n = p.m_daughterIndices.size();
61 for (
unsigned int i = 0; i < n; i++) {
62 p.m_daughterIndices[i] = oldToNewMap.at(p.m_daughterIndices[i]);
65 p.m_arrayPointer = arrayPtr;
72 for (
const auto& entry : entryMap) {
73 if (!entry.second.ptr or !entry.second.object->InheritsFrom(ParticleList::Class()))
76 auto* list =
static_cast<ParticleList*
>(entry.second.ptr);
77 if (list->getParticleCollectionName() ==
m_set->
getName()) {
86 const std::vector<int> oldList(vec);
88 for (
const int idx : oldList) {
89 const auto& it = oldToNewMap.find(idx);
90 if (it != oldToNewMap.end())
91 vec.push_back(it->second);
StoreEntryMap & getStoreEntryMap(EDurability durability)
Get a reference to the object/array map.
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
static DataStore & Instance()
Instance of singleton Store.
ParticleList is a container class that stores a collection of Particle objects.
void removeParticlesNotInLists(const std::vector< std::string > &listNames)
Removes all Particles that are not in one of the given ParticleLists (or daughters of Particles in th...
void select(std::function< bool(const Particle *)> f)
select Particles for which f returns true, discard others
static void fixVector(std::vector< int > &vec, const std::map< int, int > &oldToNewMap)
replace entries in vec via oldToNewMap, removing those not found.
void fixParticles(const std::map< int, int > &oldToNewMap)
fix daughter indices, reset m_arrayPointer
void fixParticleLists(const std::map< int, int > &oldToNewMap)
fix contents of particlelists by updating indices or removing entries.
Class to store reconstructed particles.
StoreArray< Particle > * m_set
The array we use as input.
const std::string & getName() const
Return name under which the object is saved in the DataStore.
TClonesArray * getPtr() const
Raw access to the underlying TClonesArray.
Type-safe access to single objects in the data store.
Abstract base class for different kinds of events.