Belle II Software development
PrintTauTauMCParticlesModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include "../include/PrintTauTauMCParticlesModule.h"
10#include <mdst/dataobjects/MCParticle.h>
11
12#include <framework/datastore/StoreArray.h>
13
14#include <boost/format.hpp>
15
16#include <TDatabasePDG.h>
17
18using namespace std;
19using namespace Belle2;
20
21//-----------------------------------------------------------------
22// Register the Module
23//-----------------------------------------------------------------
24REG_MODULE(PrintTauTauMCParticles);
25
26//-----------------------------------------------------------------
27// Implementation
28//-----------------------------------------------------------------
29
31{
32 B2DEBUG(100, "PrintTauTauMCParticles called:");
33 //Set module properties
34 setDescription("Print an MCParticle Collection");
35
36 //Parameter definition
37 addParam("collectionName", m_particleList, "Collection 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
44{
46 m_seen.clear();
47 m_seen.resize(MCParticles.getEntries() + 1, false);
48 B2INFO("Content from MCParticle Collection '" + m_particleList + "':");
49 for (int i = 0; i < MCParticles.getEntries(); i++) {
50 MCParticle& p = *MCParticles[i];
51 char buf[200];
52 int moID = 0;
53 MCParticle* q = p.getMother();
54 if (q != NULL) {
55 moID = q->getIndex();
56 }
57 sprintf(buf, "PMC: %3d %4u %8d %4d %4d %4d %9.4f %9.4f %9.4f %9.4f",
58 p.getIndex(), p.getStatus(), p.getPDG(), moID,
59 p.getFirstDaughter(), p.getLastDaughter(),
60 p.get4Vector().Px(), p.get4Vector().Py(),
61 p.get4Vector().Pz(), p.get4Vector().E());
62 B2INFO(buf);
63 }
64 //Loop over the primary particles (no mother particle exists)
65 for (int i = 0; i < MCParticles.getEntries(); i++) {
66 MCParticle& mc = *MCParticles[i];
67 if (!(mc.getMother() != NULL && mc.getMother()->getIndex() <= 3)) continue;
68 printTree(mc, 0);
69 }
70}
71
72
74{
75 if (m_onlyPrimaries && !mc.hasStatus(MCParticle::c_PrimaryParticle)) return;
76 //Only show up to max level
77 if (m_maxLevel >= 0 && level > m_maxLevel) return;
78 ++level;
79 string indent = "";
80 for (int i = 0; i < 2 * level; i++) indent += " ";
81 TDatabasePDG* pdb = TDatabasePDG::Instance();
82 TParticlePDG* pdef = pdb->GetParticle(mc.getPDG());
83 string name = pdef ? (string(" (") + pdef->GetTitle() + ")") : "";
84
85 if (m_seen[mc.getIndex()]) {
86 B2INFO(boost::format("%4d %s%10d%s*") % mc.getIndex() % indent % mc.getPDG() % name);
87 return;
88 }
89 const ROOT::Math::XYZVector& p = mc.getMomentum();
90 const ROOT::Math::XYZVector& v = mc.getVertex();
91 B2INFO(boost::format("%3d %s%5d%s%20tp:(%10.3e, %10.3e, %10.3e) v:(%10.3e, %10.3e, %10.3e), t:%10.3e,%10.3e, s:%d, c:%d")
92 % mc.getIndex() % indent % mc.getPDG() % name
93 % p.X() % p.Y() % p.Z()
94 % v.X() % v.Y() % v.Z()
95 % mc.getProductionTime() % mc.getDecayTime()
96 % mc.getStatus() % mc.getCharge()
97 );
98
99 const vector<MCParticle*> daughters = mc.getDaughters();
100 for (MCParticle* daughter : daughters) {
101 printTree(*daughter, level);
102 }
103 m_seen[mc.getIndex()] = true;
104}
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
@ c_PrimaryParticle
bit 0: Particle is primary particle.
Definition: MCParticle.h:47
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
virtual void event() override
Method is called for each event.
std::vector< bool > m_seen
Tag the particles which were already visited using their index.
int m_maxLevel
Show only up to specified depth level.
std::string m_particleList
The name of the MCParticle collection.
bool m_onlyPrimaries
Print only primary particles.
void printTree(const MCParticle &mc, int level=0)
Loops recursively over the MCParticle list and prints information about each particle.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:649
Abstract base class for different kinds of events.
STL namespace.