11 #include <analysis/modules/PrintMCParticles/PrintMCParticlesModule.h>
13 #include <mdst/dataobjects/MCParticle.h>
15 #include <boost/format.hpp>
17 #include <TDatabasePDG.h>
34 setDescription(
"Print an MCParticle List");
37 addParam(
"storeName", m_particleList,
"Name of the StoreArray to print",
string(
""));
38 addParam(
"onlyPrimaries", m_onlyPrimaries,
"Show only primary particles",
true);
39 addParam(
"maxLevel", m_maxLevel,
"Show only up to specified depth level, -1 means no limit", -1);
42 void PrintMCParticlesModule::initialize()
44 m_mcparticles.isRequired(m_particleList);
47 void PrintMCParticlesModule::event()
50 m_seen.resize(m_mcparticles.getEntries() + 1,
false);
51 B2INFO(
"Content from MCParticle list '" + m_mcparticles.getName() +
"':");
54 for (
int i = 0; i < m_mcparticles.getEntries(); i++) {
56 if (mc.getMother() != NULL)
continue;
62 void PrintMCParticlesModule::printTree(
const MCParticle& mc,
int level)
64 if (m_onlyPrimaries && !mc.hasStatus(MCParticle::c_PrimaryParticle))
return;
67 if (m_maxLevel >= 0 && level > m_maxLevel)
return;
70 for (
int i = 0; i < level; i++) indent +=
" ";
71 TDatabasePDG* pdb = TDatabasePDG::Instance();
72 TParticlePDG* pdef = pdb->GetParticle(mc.getPDG());
73 string name = pdef ? (string(
" (") + pdef->GetTitle() +
")") :
"";
75 if (m_seen[mc.getIndex()]) {
76 B2INFO(boost::format(
"%4d %s%10d%s*") % mc.getIndex() % indent % mc.getPDG() % name);
79 const TVector3& p = mc.getMomentum();
80 const TVector3& v = mc.getVertex();
82 B2INFO(boost::format(
"%3d %s%5d%s%30tE:%10.3e m:%10.3e p:(%10.3e,%10.3e,%10.3e) v:(%10.3e,%10.3e,%10.3e), t:%10.3e,%10.3e, s:%d, c:%d")
83 % mc.getIndex() % indent % mc.getPDG() % name
84 % mc.getEnergy() % mc.getMass()
85 % p.X() % p.Y() % p.Z()
86 % v.X() % v.Y() % v.Z()
87 % mc.getProductionTime() % mc.getDecayTime()
88 % mc.getStatus() % mc.getCharge()
91 const vector<MCParticle*> daughters = mc.getDaughters();
93 printTree(*daughter, level);
95 m_seen[mc.getIndex()] =
true;