9 #include <analysis/modules/ParticleStats/ParticleStatsModule.h> 
   10 #include <analysis/dataobjects/ParticleList.h> 
   11 #include <framework/core/Environment.h> 
   12 #include <framework/datastore/StoreObjPtr.h> 
   13 #include <nlohmann/json.hpp> 
   37   for (
unsigned i = 0; i < 
m_nLists; ++i) {
 
   43       B2ERROR(
"ParticleStatsModule::initialize Invalid input DecayString " << 
m_strParticleLists[i]
 
   44               << 
". DecayString should not contain any daughters, only the mother particle.");
 
   46   B2INFO(
"Number of ParticleLists to be studied: " << 
m_nLists << 
" ");
 
   58   for (
unsigned iList = 0; iList < 
m_nLists; ++iList) {
 
   66     if (!particlelist->getListSize()) 
continue;
 
   77                                         + particlelist->getNParticlesOfType(ParticleList::c_FlavorSpecificParticle)
 
   78                                         + particlelist->getNParticlesOfType(ParticleList::c_FlavorSpecificParticle, 
true)
 
   79                                         + particlelist->getNParticlesOfType(ParticleList::c_SelfConjugatedParticle);
 
   82     if (particlelist->getNParticlesOfType(ParticleList::c_FlavorSpecificParticle))
 
   84                                           + particlelist->getNParticlesOfType(ParticleList::c_FlavorSpecificParticle);
 
   87     if (particlelist->getNParticlesOfType(ParticleList::c_FlavorSpecificParticle, 
true))
 
   89                                           + particlelist->getNParticlesOfType(ParticleList::c_FlavorSpecificParticle, 
true);
 
   92     if (particlelist->getNParticlesOfType(ParticleList::c_SelfConjugatedParticle))
 
   94                                           + particlelist->getNParticlesOfType(ParticleList::c_SelfConjugatedParticle);
 
  100     for (
unsigned jList = 0; jList < 
m_nLists; ++jList) {
 
  104       if (!particlelistj) {
 
  108       if (!particlelistj->getListSize()) 
continue;
 
  111       (*m_PassMatrix)(iList, jList) = (*
m_PassMatrix)(iList, jList) + 1.;
 
  112       if (iList != jList) unique = 
false;
 
  130   B2INFO(
"ParticleStats Summary:");
 
  131   std::ostringstream stream;
 
  137   for (
unsigned iList = 0; iList < 
m_nLists; ++iList)
 
  138     for (
unsigned jList = 0; jList < 
m_nLists + 1; ++jList)
 
  141   for (
unsigned iList = 0; iList < 
m_nLists; ++iList)
 
  142     for (
unsigned jList = 0; jList < 
m_nLists + 1; ++jList)
 
  143       if (iList != jList && (*
m_PassMatrix)(iList, iList) > 0.)
 
  149     stream << 
"=======================================================================\n";
 
  150     stream << 
" Pass matrix (for i, j: fraction passing selection i also passes selection j)\n\n";
 
  154     for (
unsigned iList = 0; iList < 
m_nLists; ++iList)
 
  155       stream << 
"|" << Form(
"  %5d", iList);
 
  156     stream << 
"| Unique|\n";
 
  159     for (
unsigned iList = 0; iList < 
m_nLists; ++iList) {
 
  163       for (
unsigned jList = 0; jList < 
m_nLists + 1; ++jList) { 
 
  164         if (iList != jList) {
 
  165           stream << Form(
" %6.4f|", (*
m_PassMatrix)(iList, jList));
 
  167           json[
"Pass matrix"][
m_strParticleLists[iList].c_str()][jName.c_str()] = (*m_PassMatrix)(iList, jList);
 
  169         if (iList == jList) {
 
  170           stream << Form(
" %6.4f|", 1.0);
 
  177     B2INFO(stream.str()); 
 
  184   stream << 
"\n======================================================================\n";
 
  185   stream << 
" Average Candidate Multiplicity (ACM) and ACM for Passed Events (ACMPE) \n\n";
 
  188   stream << 
"                             |   All Particles   |     Particles     |  Anti-particles   |  Self-conjugates  |\n";
 
  189   stream << 
"                  | Retention|      ACM|    ACMPE|      ACM|    ACMPE|      ACM|    ACMPE|      ACM|    ACMPE|\n";
 
  192   for (
unsigned iList = 0; iList < 
m_nLists; ++iList) {
 
  197     stream << Form(
"    %6.4f|", (*
m_PassMatrix)(iList, iList));
 
  200     float retRate = (*m_PassMatrix)(iList, iList);
 
  201     json[
"Retention"][pName][
"Retention"] = retRate;
 
  202     std::string flavs[4] = {
"All Particles", 
"Particles", 
"Anti Particles",  
"Self-conjugates"};
 
  204     for (
int iFlav = 0; iFlav < 4; ++iFlav) {
 
  206       json[
"Retention"][pName][Form(
"%s ACM", flavs[iFlav].c_str())] = (*m_MultiplicityMatrix)(iList, iFlav) / nEvents;
 
  209       json[
"Retention"][pName][Form(
"%s ACPME", flavs[iFlav].c_str())] = (*m_MultiplicityMatrix)(iList,
 
  215   B2INFO(stream.str()); 
 
  219   stream << 
"\n======================================================================\n";
 
  220   stream << 
"Total Retention: " << 
m_nPass << 
" events passing / " << nEvents << 
" events processed = " << Form(
"%6.4f\n",
 
  221          (
float)
m_nPass / (
float)nEvents);
 
  222   stream << 
"Total Number of Particles created in the DataStore: " << 
m_nParticles;
 
  223   stream << 
"\n======================================================================\n";
 
  224   json[
"Total retention"] = 
m_nPass / nEvents;
 
  225   json[
"Events passing"] = 
m_nPass;
 
  226   json[
"Events processed"] = nEvents;
 
  228   B2INFO(stream.str());
 
  231     jsonFile << json.dump(2) << std::endl;
 
bool init(const std::string &str)
Initialise the DecayDescriptor from given string.
int getNDaughters() const
return number of direct daughters.
unsigned int getNumberOfEvents() const
Return the number of events, from either input or EventInfoSetter, or -n command line override (if le...
static Environment & Instance()
Static method to get a reference to the Environment instance.
void setDescription(const std::string &description)
Sets the description of the module.
TMatrix * m_PassMatrix
Pass matrix for the particle lists.
TMatrix * m_MultiplicityMatrix
Particle multiplicities for the particle lists.
bool m_printPassMatrix
Shall we also calculate and print out the pass matrix?
virtual void initialize() override
Initialises the module.
virtual void event() override
Fill the particle stats matrices for each event.
std::string m_outputFile
Name of output file.
StoreArray< Particle > m_particles
StoreArray of Particles.
virtual void terminate() override
Print out the arrays as a table in B2INFO.
std::vector< std::string > m_strParticleLists
The particle lists to produce statistics about.
int m_nParticles
Count the total number of particles.
unsigned m_nLists
The number of particle lists.
int m_nPass
Number of events with Particle candidates.
DecayDescriptor m_decaydescriptor
Decay descriptor of the particle being selected.
ParticleStatsModule()
Constructor.
Type-safe access to single objects in the data store.
REG_MODULE(B2BIIConvertBeamParams)
Register the module.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Abstract base class for different kinds of events.