Belle II Software  release-05-02-19
ParticleStatsModule.cc
1 /**************************************************************************
2 * BASF2 (Belle Analysis Framework 2) *
3 * Copyright(C) 2010 - Belle II Collaboration *
4 * *
5 * Author: The Belle II Collaboration *
6 * Contributors: ParticleStats, Anze Zupanc *
7 * *
8 * This software is provided "as is" without any warranty. *
9 **************************************************************************/
10 
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>
16 
17 using namespace std;
18 using namespace Belle2;
19 
20 // Register module in the framework
21 REG_MODULE(ParticleStats)
22 
24 {
25  //Set module properties
26  setDescription("Make a summary of specific ParticleLists.");
27  //Parameter definition
28  addParam("particleLists", m_strParticleLists, "List of ParticleLists", vector<string>());
29 
30  // initializing the rest of private memebers
31  m_nPass = 0;
32  m_nParticles = 0;
33  m_PassMatrix = nullptr;
34  m_MultiplicityMatrix = nullptr;
35 }
36 
37 void ParticleStatsModule::initialize()
38 {
39  unsigned nParticleLists = m_strParticleLists.size();
40  for (unsigned i = 0; i < nParticleLists; ++i) {
41  bool valid = m_decaydescriptor.init(m_strParticleLists[i]);
42  if (!valid)
43  B2ERROR("Invalid input list name: " << m_strParticleLists[i]);
44 
45  int nProducts = m_decaydescriptor.getNDaughters();
46  if (nProducts > 0)
47  B2ERROR("ParticleStatsModule::initialize Invalid input DecayString " << m_strParticleLists[i]
48  << ". DecayString should not contain any daughters, only the mother particle.");
49  }
50 
51  B2INFO("Number of ParticleLists studied " << nParticleLists << " ");
52 
53  m_PassMatrix = new TMatrix(nParticleLists, nParticleLists + 1);
54  m_MultiplicityMatrix = new TMatrix(nParticleLists, 4); // 0 All particles; 1 Negative; 2 Positive; 3 SelfConjugated
55 
56  m_nPass = 0;
57 
58  m_nParticles = 0;
59 }
60 
61 void ParticleStatsModule::event()
62 {
63  // number of ParticleLists
64  int nParticleLists = m_strParticleLists.size();
65  bool unique = true;
66  bool pass = false;
67  for (int iList = 0; iList < nParticleLists; ++iList) {
68 
69  StoreObjPtr<ParticleList> particlelist(m_strParticleLists[iList]);
70  if (!particlelist) {
71  B2INFO("ParticleListi " << m_strParticleLists[iList] << " not found");
72  continue;
73  } else {
74  if (!particlelist->getListSize())continue;
75 
76  pass = true;
77  // All Particles&Anti-Particles
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);
82 
83  // Particles
84  if (particlelist->getNParticlesOfType(ParticleList::c_FlavorSpecificParticle)) {
85  (*m_MultiplicityMatrix)(iList, 1) = (*m_MultiplicityMatrix)(iList, 1)
86  + particlelist->getNParticlesOfType(ParticleList::c_FlavorSpecificParticle);
87  }
88 
89  // Anti-Particles
90  if (particlelist->getNParticlesOfType(ParticleList::c_FlavorSpecificParticle, true)) {
91  (*m_MultiplicityMatrix)(iList, 2) = (*m_MultiplicityMatrix)(iList, 2)
92  + particlelist->getNParticlesOfType(ParticleList::c_FlavorSpecificParticle, true);
93  }
94 
95  if (particlelist->getNParticlesOfType(ParticleList::c_SelfConjugatedParticle)) {
96  (*m_MultiplicityMatrix)(iList, 3) = (*m_MultiplicityMatrix)(iList, 3)
97  + particlelist->getNParticlesOfType(ParticleList::c_SelfConjugatedParticle);
98  }
99 
100 
101  for (int jList = 0; jList < nParticleLists; ++jList) {
102  StoreObjPtr<ParticleList> particlelistj(m_strParticleLists[jList]);
103  if (!particlelistj) {
104  B2INFO("ParticleListj " << m_strParticleLists[jList] << " not found");
105  continue;
106  } else {
107  if (!particlelistj->getListSize())continue;
108  (*m_PassMatrix)(iList, jList) = (*m_PassMatrix)(iList, jList) + 1.;
109  if (iList != jList)unique = false;
110 
111  }
112  }
113  }
114 
115 
116  if (unique)(*m_PassMatrix)(iList, nParticleLists) = (*m_PassMatrix)(iList, nParticleLists) + 1.;
117 
118  }
119  StoreArray<Particle> Particles;
120  m_nParticles += Particles.getEntries();
121 
122  if (pass)m_nPass++;
123 }
124 
125 void ParticleStatsModule::terminate()
126 {
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;
133  }
134  }
135 
136  for (int iList = 0; iList < nParticleLists; ++iList) {
137  for (int jList = 0; jList < nParticleLists + 1; ++jList) {
138  if (iList != jList
139  && (*m_PassMatrix)(iList, iList) > 0.)(*m_PassMatrix)(iList, jList) = (*m_PassMatrix)(iList, jList) / (*m_PassMatrix)(iList,
140  iList) ;
141  }
142  }
143 
144  std::ostringstream stream;
145  stream << "=======================================================================\n";
146  stream << "\t\t\t";
147  stream << "|Retention";
148  for (int iList = 0; iList < nParticleLists; ++iList) {
149  stream << "|\t" << Form("%5d", iList);
150  }
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);
158  }
159  stream << "\n";
160  }
161  B2INFO(stream.str());
162  stream.str("");
163 
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|";
170 
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));
174  }
175  stream << "\n";
176  }
177  B2INFO(stream.str());
178 
179  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());
185 
186  delete m_PassMatrix;
187  delete m_MultiplicityMatrix;
188 }
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::ParticleStatsModule
This module summarises the ParticleLists in the event.
Definition: ParticleStatsModule.h:37
Belle2::Module
Base class for Modules.
Definition: Module.h:74
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::StoreArray< Particle >