Belle II Software  release-05-01-25
ParticleListHelper.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <framework/datastore/StoreObjPtr.h>
13 #include <framework/datastore/StoreArray.h>
14 #include <analysis/dataobjects/Particle.h>
15 #include <analysis/dataobjects/ParticleList.h>
16 
17 #include <string>
18 #include <optional>
19 
20 class TLorentzVector;
21 
22 namespace Belle2 {
27  class Particle;
28  class DecayDescriptor;
29 
53  public:
55  ParticleListHelper() = default;
59  explicit ParticleListHelper(const std::string& listname, bool save = true): ParticleListHelper()
60  {
61  registerList(listname, save);
62  }
70  void registerList(const std::string& listname, bool save = true);
78  void registerList(const DecayDescriptor& decay, bool save = true);
81  int getPDGCode() const { return m_pdg; }
83  bool isSelfConjugated() const { return not m_antiList.has_value(); }
86  void create();
87 
93  template<class ...Args> Particle& add(Args&& ... args)
94  {
95  auto index = m_particles.getEntries();
96  // cppcheck doesn't seem to understand the forwarding of arguments and
97  // throws an erroneous warning about reassigning appendNew
98  //
99  // cppcheck-suppress redundantAssignment
100  // cppcheck-suppress redundantInitialization
101  auto particle = m_particles.appendNew(std::forward<Args>(args)...);
102  m_list->addParticle(index, particle->getPDGCode(), particle->getFlavorType());
103  return *particle;
104  }
105 
107  Particle& addParticle(const Particle& particle) { return add(particle); }
114  Particle& addParticle(const TLorentzVector& momentum, bool conjugated = false)
115  {
116  return add(momentum, m_pdg * ((conjugated and not isSelfConjugated()) ? -1 : 1));
117  }
118 
119  private:
125  std::optional<StoreObjPtr<ParticleList>> m_antiList;
127  int m_pdg;
128  };
130 }
Belle2::StoreArray::appendNew
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:256
Belle2::ParticleListHelper::ParticleListHelper
ParticleListHelper(const std::string &listname, bool save=true)
Construct and initialize right away.
Definition: ParticleListHelper.h:59
Belle2::ParticleListHelper::isSelfConjugated
bool isSelfConjugated() const
Return whether or not this list is self conjugated.
Definition: ParticleListHelper.h:83
Belle2::ParticleListHelper::m_list
StoreObjPtr< ParticleList > m_list
Store object for the list.
Definition: ParticleListHelper.h:123
Belle2::ParticleListHelper::m_pdg
int m_pdg
PDG code of the list.
Definition: ParticleListHelper.h:127
Belle2::ParticleListHelper::addParticle
Particle & addParticle(const TLorentzVector &momentum, bool conjugated=false)
Non-templated convenience function to add a particle from simple four momentum and an indicator wheth...
Definition: ParticleListHelper.h:114
Belle2::ParticleListHelper::add
Particle & add(Args &&... args)
Add a particle to the list by forwarding all arguments to the constructor of the Particle object: Any...
Definition: ParticleListHelper.h:93
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::ParticleListHelper::m_particles
StoreArray< Particle > m_particles
Store array for the particles.
Definition: ParticleListHelper.h:121
Belle2::ParticleListHelper::m_antiList
std::optional< StoreObjPtr< ParticleList > > m_antiList
Optional store object for the conjugated list if that exists.
Definition: ParticleListHelper.h:125
Belle2::ParticleListHelper
Class to help managing creation and adding to ParticleLists.
Definition: ParticleListHelper.h:52
Belle2::Particle
Class to store reconstructed particles.
Definition: Particle.h:77
Belle2::ParticleListHelper::registerList
void registerList(const std::string &listname, bool save=true)
Register a list by name.
Definition: ParticleListHelper.cc:28
Belle2::ParticleListHelper::create
void create()
Create the list objects.
Definition: ParticleListHelper.cc:50
Belle2::DecayDescriptor
The DecayDescriptor stores information about a decay tree or parts of a decay tree.
Definition: DecayDescriptor.h:43
Belle2::ParticleListHelper::addParticle
Particle & addParticle(const Particle &particle)
Non-templated convenience function to add a particle from an existing particle object.
Definition: ParticleListHelper.h:107
Belle2::StoreArray< Particle >
Belle2::ParticleListHelper::ParticleListHelper
ParticleListHelper()=default
Default constructor, does nothing.
Belle2::StoreArray::getEntries
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:226
Belle2::ParticleListHelper::getPDGCode
int getPDGCode() const
Return the pdg code of the main list.
Definition: ParticleListHelper.h:81