12 #include <analysis/modules/ParticlePrinter/ParticlePrinterModule.h>
15 #include <framework/datastore/StoreObjPtr.h>
18 #include <framework/logging/Logger.h>
21 #include <analysis/dataobjects/ParticleList.h>
22 #include <analysis/VariableManager/Manager.h>
45 setDescription(
"Prints specified variables for all particles in the specified particle list to screen (useful for debugging).\n"
46 "Event-based variables can be printed by not specifying the particle list (empty string).");
47 setPropertyFlags(c_ParallelProcessingCertified);
50 addParam(
"listName", m_listName,
"name of ParticleList",
string(
""));
51 addParam(
"fullPrint", m_fullPrint,
"execute Particle's internal print() function",
true);
52 vector<string> defaultVariables;
53 addParam(
"variables", m_variables,
"names of variables to be printed (see Variable::Manager)", defaultVariables);
57 void ParticlePrinterModule::initialize()
59 if (!m_listName.empty()) {
64 bool valid = m_decaydescriptor.init(m_listName);
66 B2ERROR(
"ParticlePrinterModule::initialize Invalid input DecayString: " << m_listName);
68 int nProducts = m_decaydescriptor.getNDaughters();
70 B2ERROR(
"ParticlePrinterModule::initialize Invalid input DecayString " << m_listName
71 <<
". DecayString should not contain any daughters, only the mother particle.");
75 void ParticlePrinterModule::event()
77 bool includingVars = !(m_variables.empty());
80 if (m_listName.empty() && includingVars) {
81 printVariables(
nullptr);
88 B2ERROR(
"ParticleList " << m_listName <<
" not found");
92 if (!m_listName.empty() && plist->getListSize() == 0)
return;
94 B2INFO(
"[ParticlePrinterModule] START ------------------------------");
98 for (
unsigned i = 0; i < plist->getListSize(); i++) {
99 const Particle* particle = plist->getParticle(i);
104 B2INFO(
" - " << particle->getArrayIndex() <<
" = " << particle->getPDGCode() <<
"[" << i <<
"]");
105 if (particle->getParticleSource() == Particle::EParticleSourceObject::c_Composite) {
107 for (
int idx : particle->getDaughterIndices())
108 s +=
" " + std::to_string(idx);
109 B2INFO(
" o) daughter indices =" << s);
111 printVariables(particle);
114 B2INFO(
"[ParticlePrinterModule] END ------------------------------");
118 void ParticlePrinterModule::printVariables(
const Particle* particle)
const
122 for (
auto& varName : m_variables) {
123 auto var = manager.getVariable(varName);
124 if (var ==
nullptr) {
125 B2ERROR(
"ParticlePrinter: Variable::Manager doesn't have variable" << varName);
127 double value = var->function(particle);
128 B2INFO(
" o) " << varName <<
" = " << value);