1 #include <analysis/utility/ParticleSubset.h>
3 #include <analysis/dataobjects/ParticleList.h>
4 #include <framework/datastore/StoreObjPtr.h>
6 #include <unordered_set>
11 void keepParticle(
const Particle* p, std::unordered_set<int>* indicesToKeep)
13 indicesToKeep->insert(p->getArrayIndex());
14 unsigned int n = p->getNDaughters();
15 for (
unsigned int i = 0; i < n; i++) {
16 keepParticle(p->getDaughter(i), indicesToKeep);
23 std::unordered_set<int> indicesToKeep;
24 for (
const auto& l : listNames) {
29 if (list->getParticleCollectionName() ==
m_set->getName()) {
30 const int n = list->getListSize();
31 for (
int i = 0; i < n; i++) {
32 const Particle* p = list->getParticle(i);
33 keepParticle(p, &indicesToKeep);
36 B2ERROR(
"ParticleList " << l <<
" uses Particle array '" << list->getParticleCollectionName() <<
37 "', but ParticleSubset uses different array '" <<
m_set->getName() <<
"'!");
42 auto selector = [indicesToKeep](
const Particle * p) ->
bool {
43 int idx = p->getArrayIndex();
44 return indicesToKeep.count(idx) == 1;
53 unsigned int n = p.m_daughterIndices.size();
54 for (
unsigned int i = 0; i < n; i++) {
55 p.m_daughterIndices[i] = oldToNewMap.at(p.m_daughterIndices[i]);
58 p.m_arrayPointer = arrayPtr;
65 for (
const auto& entry : entryMap) {
66 if (!entry.second.ptr or !entry.second.object->InheritsFrom(ParticleList::Class()))
69 auto* list =
static_cast<ParticleList*
>(entry.second.ptr);
70 if (list->getParticleCollectionName() ==
m_set->getName()) {
79 const std::vector<int> oldList(vec);
81 for (
const int idx : oldList) {
82 const auto& it = oldToNewMap.find(idx);
83 if (it != oldToNewMap.end())
84 vec.push_back(it->second);