Belle II Software development
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 DecayDescriptor;
24
48 public:
50 ParticleListHelper() = default;
54 explicit ParticleListHelper(const std::string& listname, bool save = true): ParticleListHelper()
55 {
56 registerList(listname, save);
57 }
58
65 void registerList(const std::string& listname, bool save = true);
73 void registerList(const DecayDescriptor& decay, bool save = true);
76 int getPDGCode() const { return m_pdg; }
78 bool isSelfConjugated() const { return not m_antiList.has_value(); }
81 void create();
82
88 template<class ...Args> Particle& add(Args&& ... args)
89 {
90 auto index = m_particles.getEntries();
91 // cppcheck doesn't seem to understand the forwarding of arguments and
92 // throws an erroneous warning about reassigning appendNew
93 //
94 // cppcheck-suppress redundantAssignment
95 // cppcheck-suppress redundantInitialization
96 auto particle = m_particles.appendNew(std::forward<Args>(args)...);
97 m_list->addParticle(index, particle->getPDGCode(), particle->getFlavorType());
98 return *particle;
99 }
100
102 Particle& addParticle(const Particle& particle) { return add(particle); }
109 Particle& addParticle(const ROOT::Math::PxPyPzEVector& momentum, bool conjugated = false)
110 {
111 return add(momentum, m_pdg * ((conjugated and not isSelfConjugated()) ? -1 : 1));
112 }
113
114 private:
120 std::optional<StoreObjPtr<ParticleList>> m_antiList;
122 int m_pdg;
123 };
124
125}
The DecayDescriptor stores information about a decay tree or parts of a decay tree.
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:76
Accessor to arrays stored in the data store.
Definition StoreArray.h:113
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.