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