11 #include <analysis/modules/ParticleStats/ParticleStatsModule.h>
12 #include <analysis/dataobjects/ParticleList.h>
13 #include <framework/core/Environment.h>
14 #include <framework/datastore/StoreArray.h>
15 #include <framework/datastore/StoreObjPtr.h>
26 setDescription(
"Make a summary of specific ParticleLists.");
28 addParam(
"particleLists", m_strParticleLists,
"List of ParticleLists", vector<string>());
33 m_PassMatrix =
nullptr;
34 m_MultiplicityMatrix =
nullptr;
37 void ParticleStatsModule::initialize()
39 unsigned nParticleLists = m_strParticleLists.size();
40 for (
unsigned i = 0; i < nParticleLists; ++i) {
41 bool valid = m_decaydescriptor.init(m_strParticleLists[i]);
43 B2ERROR(
"Invalid input list name: " << m_strParticleLists[i]);
45 int nProducts = m_decaydescriptor.getNDaughters();
47 B2ERROR(
"ParticleStatsModule::initialize Invalid input DecayString " << m_strParticleLists[i]
48 <<
". DecayString should not contain any daughters, only the mother particle.");
51 B2INFO(
"Number of ParticleLists studied " << nParticleLists <<
" ");
53 m_PassMatrix =
new TMatrix(nParticleLists, nParticleLists + 1);
54 m_MultiplicityMatrix =
new TMatrix(nParticleLists, 4);
61 void ParticleStatsModule::event()
64 int nParticleLists = m_strParticleLists.size();
67 for (
int iList = 0; iList < nParticleLists; ++iList) {
71 B2INFO(
"ParticleListi " << m_strParticleLists[iList] <<
" not found");
74 if (!particlelist->getListSize())
continue;
78 (*m_MultiplicityMatrix)(iList, 0) = (*m_MultiplicityMatrix)(iList, 0)
79 + particlelist->getNParticlesOfType(ParticleList::c_FlavorSpecificParticle)
80 + particlelist->getNParticlesOfType(ParticleList::c_FlavorSpecificParticle,
true)
81 + particlelist->getNParticlesOfType(ParticleList::c_SelfConjugatedParticle);
84 if (particlelist->getNParticlesOfType(ParticleList::c_FlavorSpecificParticle)) {
85 (*m_MultiplicityMatrix)(iList, 1) = (*m_MultiplicityMatrix)(iList, 1)
86 + particlelist->getNParticlesOfType(ParticleList::c_FlavorSpecificParticle);
90 if (particlelist->getNParticlesOfType(ParticleList::c_FlavorSpecificParticle,
true)) {
91 (*m_MultiplicityMatrix)(iList, 2) = (*m_MultiplicityMatrix)(iList, 2)
92 + particlelist->getNParticlesOfType(ParticleList::c_FlavorSpecificParticle,
true);
95 if (particlelist->getNParticlesOfType(ParticleList::c_SelfConjugatedParticle)) {
96 (*m_MultiplicityMatrix)(iList, 3) = (*m_MultiplicityMatrix)(iList, 3)
97 + particlelist->getNParticlesOfType(ParticleList::c_SelfConjugatedParticle);
101 for (
int jList = 0; jList < nParticleLists; ++jList) {
103 if (!particlelistj) {
104 B2INFO(
"ParticleListj " << m_strParticleLists[jList] <<
" not found");
107 if (!particlelistj->getListSize())
continue;
108 (*m_PassMatrix)(iList, jList) = (*m_PassMatrix)(iList, jList) + 1.;
109 if (iList != jList)unique =
false;
116 if (unique)(*m_PassMatrix)(iList, nParticleLists) = (*m_PassMatrix)(iList, nParticleLists) + 1.;
120 m_nParticles += Particles.getEntries();
125 void ParticleStatsModule::terminate()
127 B2INFO(
"ParticleStats Summary: \n");
128 auto m_nEvents = (float)Environment::Instance().getNumberOfEvents();
129 int nParticleLists = m_strParticleLists.size();
130 for (
int iList = 0; iList < nParticleLists; ++iList) {
131 for (
int jList = 0; jList < nParticleLists + 1; ++jList) {
132 (*m_PassMatrix)(iList, jList) = (*m_PassMatrix)(iList, jList) / (
float) m_nEvents;
136 for (
int iList = 0; iList < nParticleLists; ++iList) {
137 for (
int jList = 0; jList < nParticleLists + 1; ++jList) {
139 && (*m_PassMatrix)(iList, iList) > 0.)(*m_PassMatrix)(iList, jList) = (*m_PassMatrix)(iList, jList) / (*m_PassMatrix)(iList,
144 std::ostringstream stream;
145 stream <<
"=======================================================================\n";
147 stream <<
"|Retention";
148 for (
int iList = 0; iList < nParticleLists; ++iList) {
149 stream <<
"|\t" << Form(
"%5d", iList);
151 stream <<
"| Unique \n";
152 for (
int iList = 0; iList < nParticleLists; ++iList) {
153 stream << Form(
"%14s(%2d)", m_strParticleLists[iList].c_str(), iList) <<
"\t|";
154 stream <<
"\t" << Form(
"%6.4f", (*m_PassMatrix)(iList, iList));
155 for (
int jList = 0; jList < nParticleLists + 1; ++jList) {
156 if (iList != jList) stream <<
"\t" << Form(
"%6.4f", (*m_PassMatrix)(iList, jList));
157 if (iList == jList) stream <<
"\t" << Form(
"%6.4f", 1.0);
161 B2INFO(stream.str());
164 stream <<
"\n======================================================================\n";
165 stream <<
" Average Candidate Multiplicity (ACM) and ACM for Passed Events (ACMPE) \n";
166 stream <<
"\t\t\t| All Particles \t\t| Particles \t\t| AntiParticles \t\t\n";
167 stream <<
"\t\t\t| ACM\t\t| ACMPE\t\t| ACM\t\t| ACMPE\t\t| ACM\t\t| ACMPE \n";
168 for (
int iList = 0; iList < nParticleLists; ++iList) {
169 stream << Form(
"%14s(%2d)", m_strParticleLists[iList].c_str(), iList) <<
"\t|";
171 for (
int iFlav = 0; iFlav < 4; ++iFlav) {
172 stream <<
"\t" << Form(
"%8.4f", (*m_MultiplicityMatrix)(iList, iFlav) / m_nEvents);
173 stream <<
"\t" << Form(
"%8.4f", (*m_MultiplicityMatrix)(iList, iFlav) / m_nEvents / (*m_PassMatrix)(iList, iList));
177 B2INFO(stream.str());
180 stream <<
"\n=======================================================\n";
181 stream <<
"Total Retention: " << Form(
"%6.4f\n", (
float)m_nPass / (
float)m_nEvents);
182 stream <<
"Total Number of Particles created in the DataStore: " << m_nParticles;
183 stream <<
"\n=======================================================\n";
184 B2INFO(stream.str());
187 delete m_MultiplicityMatrix;