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#include <boost/foreach.hpp>
16
17#include <TDatabasePDG.h>
18
19using namespace std;
20using namespace Belle2;
21
22//-----------------------------------------------------------------
23// Register the Module
24//-----------------------------------------------------------------
25REG_MODULE(PrintTauTauMCParticles);
26
27//-----------------------------------------------------------------
28// Implementation
29//-----------------------------------------------------------------
30
32{
33 B2DEBUG(100, "PrintTauTauMCParticles called:");
34 //Set module properties
35 setDescription("Print an MCParticle Collection");
36
37 //Parameter definition
38 addParam("collectionName", m_particleList, "Collection to print", string(""));
39 addParam("onlyPrimaries", m_onlyPrimaries, "Show only primary particles", true);
40 addParam("maxLevel", m_maxLevel, "Show only up to specified depth level, -1 means no limit", -1);
41}
42
43
45{
47 m_seen.clear();
48 m_seen.resize(MCParticles.getEntries() + 1, false);
49 B2INFO("Content from MCParticle Collection '" + m_particleList + "':");
50 for (int i = 0; i < MCParticles.getEntries(); i++) {
51 MCParticle& p = *MCParticles[i];
52 char buf[200];
53 int moID = 0;
54 MCParticle* q = p.getMother();
55 if (q != NULL) {
56 moID = q->getIndex();
57 }
58 sprintf(buf, "PMC: %3d %4u %8d %4d %4d %4d %9.4f %9.4f %9.4f %9.4f",
59 p.getIndex(), p.getStatus(), p.getPDG(), moID,
60 p.getFirstDaughter(), p.getLastDaughter(),
61 p.get4Vector().Px(), p.get4Vector().Py(),
62 p.get4Vector().Pz(), p.get4Vector().E());
63 B2INFO(buf);
64 }
65 //Loop over the primary particles (no mother particle exists)
66 for (int i = 0; i < MCParticles.getEntries(); i++) {
67 MCParticle& mc = *MCParticles[i];
68 if (!(mc.getMother() != NULL && mc.getMother()->getIndex() <= 3)) continue;
69 printTree(mc, 0);
70 }
71}
72
73
75{
76 if (m_onlyPrimaries && !mc.hasStatus(MCParticle::c_PrimaryParticle)) return;
77 //Only show up to max level
78 if (m_maxLevel >= 0 && level > m_maxLevel) return;
79 ++level;
80 string indent = "";
81 for (int i = 0; i < 2 * level; i++) indent += " ";
82 TDatabasePDG* pdb = TDatabasePDG::Instance();
83 TParticlePDG* pdef = pdb->GetParticle(mc.getPDG());
84 string name = pdef ? (string(" (") + pdef->GetTitle() + ")") : "";
85
86 if (m_seen[mc.getIndex()]) {
87 B2INFO(boost::format("%4d %s%10d%s*") % mc.getIndex() % indent % mc.getPDG() % name);
88 return;
89 }
90 const ROOT::Math::XYZVector& p = mc.getMomentum();
91 const ROOT::Math::XYZVector& v = mc.getVertex();
92 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")
93 % mc.getIndex() % indent % mc.getPDG() % name
94 % p.X() % p.Y() % p.Z()
95 % v.X() % v.Y() % v.Z()
96 % mc.getProductionTime() % mc.getDecayTime()
97 % mc.getStatus() % mc.getCharge()
98 );
99
100 const vector<MCParticle*> daughters = mc.getDaughters();
101 BOOST_FOREACH(MCParticle * daughter, daughters) {
102 printTree(*daughter, level);
103 }
104 m_seen[mc.getIndex()] = true;
105}
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:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.
STL namespace.