9 #include <analysis/dataobjects/ParticleList.h>
12 #include <framework/datastore/StoreArray.h>
13 #include <framework/datastore/StoreObjPtr.h>
16 #include <framework/logging/Logger.h>
17 #include <framework/utilities/HTML.h>
25 ParticleList::~ParticleList()
30 void ParticleList::initialize(
int pdg,
const std::string& name,
const std::string& particleStoreName)
34 m_particleStore = particleStoreName;
36 m_thisListName = name;
37 m_antiListName.clear();
40 void ParticleList::setParticleCollectionName(
const std::string& name,
bool forAntiParticle)
42 m_particleStore = name;
44 if (forAntiParticle and !m_antiListName.empty())
45 getAntiParticleList().setParticleCollectionName(name,
false);
48 void ParticleList::addParticle(
const Particle* particle)
50 if (particle->getArrayName() != m_particleStore) {
51 B2ERROR(
"ParticleList::addParticle particle is from different store array, not added");
55 int iparticle = particle->getArrayIndex();
57 B2ERROR(
"ParticleList::addParticle particle is not in a store array, not added");
61 int pdg = particle->getPDGCode();
63 addParticle((
unsigned) iparticle, pdg, type,
true);
66 void ParticleList::bindAntiParticleList(
ParticleList& antiList,
bool includingAntiList)
71 if (abs(m_pdgbar) != abs(m_pdg))
72 B2ERROR(
"ParticleList::bindAntiParticleList invalid (inconsistent) PDG codes!");
74 if (includingAntiList)
80 if (abs(pdg) != abs(getPDGCode())) {
81 B2ERROR(
"ParticleList::addParticle PDG codes do not match, not added");
85 if (type == Particle::c_Unflavored) {
90 if (std::find(m_scList.begin(), m_scList.end(), iparticle) == m_scList.end()) {
91 m_scList.push_back(iparticle);
93 B2WARNING(
"ParticleList::addParticle Trying to add Particle with index=" << iparticle
94 <<
" to the ParticleList=" << m_thisListName <<
" that is already included!");
99 if (includingAntiList and !m_antiListName.empty())
100 getAntiParticleList().addParticle(iparticle, pdg, type,
false);
101 }
else if (type == Particle::c_Flavored) {
102 unsigned antiParticle = (pdg == getPDGCode()) ? 0 : 1;
105 getAntiParticleList().addParticle(iparticle, pdg, type,
false);
107 if (std::find(m_fsList.begin(), m_fsList.end(), iparticle) == m_fsList.end()) {
108 m_fsList.push_back(iparticle);
110 B2WARNING(
"ParticleList::addParticle Trying to add Particle with index=" << iparticle
111 <<
" to the ParticleList=" << m_thisListName <<
"that is already included! Particle not added");
115 B2ERROR(
"ParticleList::addParticle invalid flavor type, not added");
119 void ParticleList::removeParticles(
const std::vector<unsigned int>& toRemove,
bool removeFromAntiList)
121 std::vector<int> newList;
123 for (
int i : m_fsList) {
124 if (std::find(toRemove.begin(), toRemove.end(), i) == toRemove.end())
125 newList.push_back(i);
131 for (
int i : m_scList) {
132 if (std::find(toRemove.begin(), toRemove.end(), i) == toRemove.end())
133 newList.push_back(i);
137 if (removeFromAntiList and !m_antiListName.empty()) {
138 getAntiParticleList().removeParticles(toRemove,
false);
142 void ParticleList::clear(
bool includingAntiList)
147 if (includingAntiList and !m_antiListName.empty()) {
148 getAntiParticleList().clear(
false);
152 Particle* ParticleList::getParticle(
unsigned i,
bool includingAntiList)
const
156 if (i < m_fsList.size()) {
157 return Particles[m_fsList[i]];
158 }
else if (i < m_fsList.size() + m_scList.size()) {
159 i -= m_fsList.size();
160 return Particles[m_scList[i]];
163 if (includingAntiList and !m_antiListName.empty())
164 return getAntiParticleList().getParticle(i - m_fsList.size() - m_scList.size(),
false);
169 unsigned ParticleList::getListSize(
bool includingAntiList)
const
174 size += m_fsList.size();
176 size += m_scList.size();
178 if (includingAntiList) {
180 size += getNParticlesOfType(EParticleType::c_FlavorSpecificParticle,
true);
186 const std::vector<int>& ParticleList::getList(
EParticleType K,
bool forAntiParticle)
const
188 if (!forAntiParticle) {
189 if (K == c_FlavorSpecificParticle)
194 const static std::vector<int> emptyList;
195 if (m_antiListName.empty())
198 return getAntiParticleList().getList(K);
202 bool ParticleList::contains(
const Particle* p,
bool includingAntiList)
const
204 const int index = p->getArrayIndex();
205 for (
int i = 0; i < 3; i++) {
206 if (i == 1 && !includingAntiList)
209 const std::vector<int>& currentList = getList((i < 2) ? c_FlavorSpecificParticle : c_SelfConjugatedParticle, i == 1);
210 if (std::find(currentList.begin(), currentList.end(), index) != currentList.end())
216 void ParticleList::print()
const
218 B2INFO(HTML::htmlToPlainText(getInfoHTML()));
221 std::string ParticleList::getInfoHTML()
const
223 std::stringstream stream;
224 unsigned thisFSCount = getNParticlesOfType(c_FlavorSpecificParticle);
225 unsigned thisSCCount = getNParticlesOfType(c_SelfConjugatedParticle);
226 unsigned antiFSCount = getNParticlesOfType(c_FlavorSpecificParticle,
true);
227 unsigned antiSCCount = getNParticlesOfType(c_SelfConjugatedParticle,
true);
229 if (!m_antiListName.empty()) {
230 stream <<
" ParticleLists: " << m_thisListName <<
" (" << thisFSCount <<
"+" << thisSCCount <<
")"
231 <<
" + " << m_antiListName <<
" (" << antiFSCount <<
"+" << antiSCCount <<
")";
233 stream <<
" ParticleList : " << m_thisListName <<
" (" << thisFSCount <<
"+" << thisSCCount <<
")";
235 return HTML::escape(stream.str());
242 if (!m_antiList->isValid()) {
243 B2FATAL(
"Anti-particle list " << m_antiListName <<
" for " << m_thisListName <<
244 " not found, even though one was set via bindAntiParticleList(). Maybe you only saved one list into a .root file?");
ParticleList is a container class that stores a collection of Particle objects.
void bindAntiParticleList(ParticleList &antiList, bool includingAntiList=true)
Binds particle and anti-particle ParticleLists.
int getPDGCode() const
Returns PDG code.
std::string getParticleListName() const
Returns the name this ParticleList.
EParticleType
Type of Particle (determines in which of the two internal lists the particle is stored).
Class to store reconstructed particles.
EFlavorType
describes flavor type, see getFlavorType().
Accessor to arrays stored in the data store.
Type-safe access to single objects in the data store.
Abstract base class for different kinds of events.