Belle II Software  release-05-02-19
PrintMCParticlesModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <analysis/modules/PrintMCParticles/PrintMCParticlesModule.h>
12 
13 #include <mdst/dataobjects/MCParticle.h>
14 
15 #include <boost/format.hpp>
16 
17 #include <TDatabasePDG.h>
18 
19 using namespace std;
20 using namespace Belle2;
21 
22 //-----------------------------------------------------------------
23 // Register the Module
24 //-----------------------------------------------------------------
25 REG_MODULE(PrintMCParticles)
26 
27 //-----------------------------------------------------------------
28 // Implementation
29 //-----------------------------------------------------------------
30 
32 {
33  //Set module properties
34  setDescription("Print an MCParticle List");
35 
36  //Parameter definition
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);
40 }
41 
42 void PrintMCParticlesModule::initialize()
43 {
44  m_mcparticles.isRequired(m_particleList);
45 }
46 
47 void PrintMCParticlesModule::event()
48 {
49  m_seen.clear();
50  m_seen.resize(m_mcparticles.getEntries() + 1, false);
51  B2INFO("Content from MCParticle list '" + m_mcparticles.getName() + "':");
52 
53  //Loop over the top level particles (no mother particle exists)
54  for (int i = 0; i < m_mcparticles.getEntries(); i++) {
55  MCParticle& mc = *m_mcparticles[i];
56  if (mc.getMother() != NULL) continue;
57  printTree(mc, 0);
58  }
59 }
60 
61 
62 void PrintMCParticlesModule::printTree(const MCParticle& mc, int level)
63 {
64  if (m_onlyPrimaries && !mc.hasStatus(MCParticle::c_PrimaryParticle)) return;
65 
66  //Only show up to max level
67  if (m_maxLevel >= 0 && level > m_maxLevel) return;
68  ++level;
69  string indent = "";
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() + ")") : "";
74 
75  if (m_seen[mc.getIndex()]) {
76  B2INFO(boost::format("%4d %s%10d%s*") % mc.getIndex() % indent % mc.getPDG() % name);
77  return;
78  }
79  const TVector3& p = mc.getMomentum();
80  const TVector3& v = mc.getVertex();
81 
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()
89  );
90 
91  const vector<MCParticle*> daughters = mc.getDaughters();
92  for (MCParticle* daughter : daughters) {
93  printTree(*daughter, level);
94  }
95  m_seen[mc.getIndex()] = true;
96 }
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::PrintMCParticlesModule
The PrintMCParticles module.
Definition: PrintMCParticlesModule.h:42
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::MCParticle
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:43