Belle II Software  release-06-00-14
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 
18 class TLorentzVector;
19 
20 namespace Belle2 {
25  class Particle;
26  class DecayDescriptor;
27 
51  public:
53  ParticleListHelper() = default;
57  explicit ParticleListHelper(const std::string& listname, bool save = true): ParticleListHelper()
58  {
59  registerList(listname, save);
60  }
68  void registerList(const std::string& listname, bool save = true);
76  void registerList(const DecayDescriptor& decay, bool save = true);
79  int getPDGCode() const { return m_pdg; }
81  bool isSelfConjugated() const { return not m_antiList.has_value(); }
84  void create();
85 
91  template<class ...Args> Particle& add(Args&& ... args)
92  {
93  auto index = m_particles.getEntries();
94  // cppcheck doesn't seem to understand the forwarding of arguments and
95  // throws an erroneous warning about reassigning appendNew
96  //
97  // cppcheck-suppress redundantAssignment
98  // cppcheck-suppress redundantInitialization
99  auto particle = m_particles.appendNew(std::forward<Args>(args)...);
100  m_list->addParticle(index, particle->getPDGCode(), particle->getFlavorType());
101  return *particle;
102  }
103 
105  Particle& addParticle(const Particle& particle) { return add(particle); }
112  Particle& addParticle(const TLorentzVector& momentum, bool conjugated = false)
113  {
114  return add(momentum, m_pdg * ((conjugated and not isSelfConjugated()) ? -1 : 1));
115  }
116 
117  private:
123  std::optional<StoreObjPtr<ParticleList>> m_antiList;
125  int m_pdg;
126  };
128 }
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.
Particle & addParticle(const Particle &particle)
Non-templated convenience function to add a particle from an existing particle object.
Particle & add(Args &&... args)
Add a particle to the list by forwarding all arguments to the constructor of the Particle object: Any...
bool isSelfConjugated() const
Return whether or not this list is self conjugated.
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 TLorentzVector &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:74
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:95
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.