Belle II Software light-2406-ragdoll
ParticleListHelper.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#pragma once
9
10#include <framework/datastore/StoreObjPtr.h>
11#include <framework/datastore/StoreArray.h>
12#include <analysis/dataobjects/Particle.h>
13#include <analysis/dataobjects/ParticleList.h>
14
15#include <string>
16#include <optional>
17
18namespace Belle2 {
23 class Particle;
24 class DecayDescriptor;
25
49 public:
51 ParticleListHelper() = default;
55 explicit ParticleListHelper(const std::string& listname, bool save = true): ParticleListHelper()
56 {
57 registerList(listname, save);
58 }
66 void registerList(const std::string& listname, bool save = true);
74 void registerList(const DecayDescriptor& decay, bool save = true);
77 int getPDGCode() const { return m_pdg; }
79 bool isSelfConjugated() const { return not m_antiList.has_value(); }
82 void create();
83
89 template<class ...Args> Particle& add(Args&& ... args)
90 {
91 auto index = m_particles.getEntries();
92 // cppcheck doesn't seem to understand the forwarding of arguments and
93 // throws an erroneous warning about reassigning appendNew
94 //
95 // cppcheck-suppress redundantAssignment
96 // cppcheck-suppress redundantInitialization
97 auto particle = m_particles.appendNew(std::forward<Args>(args)...);
98 m_list->addParticle(index, particle->getPDGCode(), particle->getFlavorType());
99 return *particle;
100 }
101
103 Particle& addParticle(const Particle& particle) { return add(particle); }
110 Particle& addParticle(const ROOT::Math::PxPyPzEVector& momentum, bool conjugated = false)
111 {
112 return add(momentum, m_pdg * ((conjugated and not isSelfConjugated()) ? -1 : 1));
113 }
114
115 private:
121 std::optional<StoreObjPtr<ParticleList>> m_antiList;
123 int m_pdg;
124 };
126}
The DecayDescriptor stores information about a decay tree or parts of a decay tree.
Class to help managing creation and adding to ParticleLists.
int getPDGCode() const
Return the pdg code of the main list.
bool isSelfConjugated() const
Return whether or not this list is self conjugated.
Particle & add(Args &&... args)
Add a particle to the list by forwarding all arguments to the constructor of the Particle object: Any...
ParticleListHelper(const std::string &listname, bool save=true)
Construct and initialize right away.
StoreObjPtr< ParticleList > m_list
Store object for the list.
StoreArray< Particle > m_particles
Store array for the particles.
int m_pdg
PDG code of the list.
ParticleListHelper()=default
Default constructor, does nothing.
Particle & addParticle(const Particle &particle)
Non-templated convenience function to add a particle from an existing particle object.
Particle & addParticle(const ROOT::Math::PxPyPzEVector &momentum, bool conjugated=false)
Non-templated convenience function to add a particle from simple four momentum and an indicator wheth...
std::optional< StoreObjPtr< ParticleList > > m_antiList
Optional store object for the conjugated list if that exists.
Class to store reconstructed particles.
Definition: Particle.h:75
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:246
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
void registerList(const std::string &listname, bool save=true)
Register a list by name.
void create()
Create the list objects.
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24