11 #include <analysis/dataobjects/ParticleList.h>
14 #include <framework/datastore/StoreArray.h>
15 #include <framework/datastore/StoreObjPtr.h>
18 #include <framework/logging/Logger.h>
19 #include <framework/utilities/HTML.h>
27 ParticleList::~ParticleList()
32 void ParticleList::initialize(
int pdg,
const std::string& name,
const std::string& particleStoreName)
36 m_particleStore = particleStoreName;
38 m_thisListName = name;
39 m_antiListName.clear();
42 void ParticleList::setParticleCollectionName(
const std::string& name,
bool forAntiParticle)
44 m_particleStore = name;
46 if (forAntiParticle and !m_antiListName.empty())
47 getAntiParticleList().setParticleCollectionName(name,
false);
50 void ParticleList::addParticle(
const Particle* particle)
52 if (particle->getArrayName() != m_particleStore) {
53 B2ERROR(
"ParticleList::addParticle particle is from different store array, not added");
57 int iparticle = particle->getArrayIndex();
59 B2ERROR(
"ParticleList::addParticle particle is not in a store array, not added");
63 int pdg = particle->getPDGCode();
65 addParticle((
unsigned) iparticle, pdg, type,
true);
68 void ParticleList::bindAntiParticleList(
ParticleList& antiList,
bool includingAntiList)
73 if (abs(m_pdgbar) != abs(m_pdg))
74 B2ERROR(
"ParticleList::bindAntiParticleList invalid (inconsistent) PDG codes!");
76 if (includingAntiList)
82 if (abs(pdg) != abs(getPDGCode())) {
83 B2ERROR(
"ParticleList::addParticle PDG codes do not match, not added");
87 if (type == Particle::c_Unflavored) {
92 if (std::find(m_scList.begin(), m_scList.end(), iparticle) == m_scList.end()) {
93 m_scList.push_back(iparticle);
95 B2WARNING(
"ParticleList::addParticle Trying to add Particle with index=" << iparticle
96 <<
" to the ParticleList=" << m_thisListName <<
" that is already included!");
101 if (includingAntiList and !m_antiListName.empty())
102 getAntiParticleList().addParticle(iparticle, pdg, type,
false);
103 }
else if (type == Particle::c_Flavored) {
104 unsigned antiParticle = (pdg == getPDGCode()) ? 0 : 1;
107 getAntiParticleList().addParticle(iparticle, pdg, type,
false);
109 if (std::find(m_fsList.begin(), m_fsList.end(), iparticle) == m_fsList.end()) {
110 m_fsList.push_back(iparticle);
112 B2WARNING(
"ParticleList::addParticle Trying to add Particle with index=" << iparticle
113 <<
" to the ParticleList=" << m_thisListName <<
"that is already included! Particle not added");
117 B2ERROR(
"ParticleList::addParticle invalid flavor type, not added");
121 void ParticleList::removeParticles(
const std::vector<unsigned int>& toRemove,
bool removeFromAntiList)
123 std::vector<int> newList;
125 for (
int i : m_fsList) {
126 if (std::find(toRemove.begin(), toRemove.end(), i) == toRemove.end())
127 newList.push_back(i);
133 for (
int i : m_scList) {
134 if (std::find(toRemove.begin(), toRemove.end(), i) == toRemove.end())
135 newList.push_back(i);
139 if (removeFromAntiList and !m_antiListName.empty()) {
140 getAntiParticleList().removeParticles(toRemove,
false);
144 void ParticleList::clear(
bool includingAntiList)
149 if (includingAntiList and !m_antiListName.empty()) {
150 getAntiParticleList().clear(
false);
154 Particle* ParticleList::getParticle(
unsigned i,
bool includingAntiList)
const
158 if (i < m_fsList.size()) {
159 return Particles[m_fsList[i]];
160 }
else if (i < m_fsList.size() + m_scList.size()) {
161 i -= m_fsList.size();
162 return Particles[m_scList[i]];
165 if (includingAntiList and !m_antiListName.empty())
166 return getAntiParticleList().getParticle(i - m_fsList.size() - m_scList.size(),
false);
171 unsigned ParticleList::getListSize(
bool includingAntiList)
const
176 size += m_fsList.size();
178 size += m_scList.size();
180 if (includingAntiList) {
182 size += getNParticlesOfType(EParticleType::c_FlavorSpecificParticle,
true);
188 const std::vector<int>& ParticleList::getList(
EParticleType K,
bool forAntiParticle)
const
190 if (!forAntiParticle) {
191 if (K == c_FlavorSpecificParticle)
196 const static std::vector<int> emptyList;
197 if (m_antiListName.empty())
200 return getAntiParticleList().getList(K);
204 bool ParticleList::contains(
const Particle* p,
bool includingAntiList)
const
206 const int index = p->getArrayIndex();
207 for (
int i = 0; i < 3; i++) {
208 if (i == 1 && !includingAntiList)
211 const std::vector<int>& currentList = getList((i < 2) ? c_FlavorSpecificParticle : c_SelfConjugatedParticle, i == 1);
212 if (std::find(currentList.begin(), currentList.end(), index) != currentList.end())
218 void ParticleList::print()
const
220 B2INFO(HTML::htmlToPlainText(getInfoHTML()));
223 std::string ParticleList::getInfoHTML()
const
225 std::stringstream stream;
226 unsigned thisFSCount = getNParticlesOfType(c_FlavorSpecificParticle);
227 unsigned thisSCCount = getNParticlesOfType(c_SelfConjugatedParticle);
228 unsigned antiFSCount = getNParticlesOfType(c_FlavorSpecificParticle,
true);
229 unsigned antiSCCount = getNParticlesOfType(c_SelfConjugatedParticle,
true);
231 if (!m_antiListName.empty()) {
232 stream <<
" ParticleLists: " << m_thisListName <<
" (" << thisFSCount <<
"+" << thisSCCount <<
")"
233 <<
" + " << m_antiListName <<
" (" << antiFSCount <<
"+" << antiSCCount <<
")";
235 stream <<
" ParticleList : " << m_thisListName <<
" (" << thisFSCount <<
"+" << thisSCCount <<
")";
237 return HTML::escape(stream.str());
244 if (!m_antiList->isValid()) {
245 B2FATAL(
"Anti-particle list " << m_antiListName <<
" for " << m_thisListName <<
246 " not found, even though one was set via bindAntiParticleList(). Maybe you only saved one list into a .root file?");