10 #include <analysis/modules/ParticlePrinter/ParticlePrinterModule.h>
13 #include <framework/logging/Logger.h>
16 #include <analysis/VariableManager/Manager.h>
39 setDescription(
"Prints specified variables for all particles in the specified particle list to screen (useful for debugging).\n"
40 "Event-based variables can be printed by not specifying the particle list (empty string).");
41 setPropertyFlags(c_ParallelProcessingCertified);
44 addParam(
"listName", m_listName,
"name of ParticleList",
string(
""));
45 addParam(
"fullPrint", m_fullPrint,
"execute Particle's internal print() function",
true);
46 vector<string> defaultVariables;
47 addParam(
"variables", m_variables,
"names of variables to be printed (see Variable::Manager)", defaultVariables);
51 void ParticlePrinterModule::initialize()
53 if (!m_listName.empty()) {
54 m_plist.isRequired(m_listName);
57 bool valid = m_decaydescriptor.init(m_listName);
59 B2ERROR(
"ParticlePrinterModule::initialize Invalid input DecayString: " << m_listName);
61 int nProducts = m_decaydescriptor.getNDaughters();
63 B2ERROR(
"ParticlePrinterModule::initialize Invalid input DecayString " << m_listName
64 <<
". DecayString should not contain any daughters, only the mother particle.");
68 void ParticlePrinterModule::event()
70 bool includingVars = !(m_variables.empty());
73 if (m_listName.empty() && includingVars) {
74 printVariables(
nullptr);
80 B2ERROR(
"ParticleList " << m_listName <<
" not found");
84 if (!m_listName.empty() && m_plist->getListSize() == 0)
return;
86 B2INFO(
"[ParticlePrinterModule] START ------------------------------");
90 for (
unsigned i = 0; i < m_plist->getListSize(); i++) {
91 const Particle* particle = m_plist->getParticle(i);
96 B2INFO(
" - " << particle->getArrayIndex() <<
" = " << particle->getPDGCode() <<
"[" << i <<
"]");
97 if (particle->getParticleSource() == Particle::EParticleSourceObject::c_Composite) {
99 for (
int idx : particle->getDaughterIndices())
100 s +=
" " + std::to_string(idx);
101 B2INFO(
" o) daughter indices =" << s);
103 printVariables(particle);
106 B2INFO(
"[ParticlePrinterModule] END ------------------------------");
110 void ParticlePrinterModule::printVariables(
const Particle* particle)
const
114 for (
auto& varName : m_variables) {
115 auto var = manager.getVariable(varName);
116 if (var ==
nullptr) {
117 B2ERROR(
"ParticlePrinter: Variable::Manager doesn't have variable" << varName);
119 double value = var->function(particle);
120 B2INFO(
" o) " << varName <<
" = " << value);
prints particle list to screen
Class to store reconstructed particles.
Global list of available variables.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.