Belle II Software development
InclusiveParticleCheckerModule.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 <generators/modules/InclusiveParticleCheckerModule.h>
10#include <framework/core/ModuleParam.templateDetails.h>
11#include <framework/particledb/EvtGenDatabasePDG.h>
12#include <iomanip>
13
14using namespace Belle2;
15
16namespace {
19 class GetPDGCode: public boost::static_visitor<int> {
20 public:
22 int operator()(int i) const
23 {
24 return i;
25 }
27 int operator()(const std::string& i) const
28 {
29 auto* p = Belle2::EvtGenDatabasePDG::Instance()->GetParticle(i.c_str());
30 if (!p) {
31 B2ERROR("Unknown particle name: " << i);
32 return 0;
33 }
34 return p->PdgCode();
35 }
36 };
37}
38
39//-----------------------------------------------------------------
40// Register the Module
41//-----------------------------------------------------------------
42REG_MODULE(InclusiveParticleChecker);
43
44//-----------------------------------------------------------------
45// Implementation
46//-----------------------------------------------------------------
47
49{
50 // Set module properties
51 setDescription(R"DOC(
52Check for the existence of one or more inclusive particles in the list of
53generated particles. If any of the particles is found the event is accepted and
54the return value is set to True. Otherwise the return value is set to false.
55
56The particles to look for can either be given as numerical pdg codes or as
57particle names or even as a mix of both:
58
59>>> checker = path.add_module("InclusiveParticleChecker", particles = [11, "pi+"])
60
61Valid names are defined in the ``evt.pdl`` of evtgen and can be inspected using
62either the `pdg` module or ``b2help-particles``.
63
64This module is intended for inclusive signal generation where we run a
65generator which produces generic events and we require a certain particle to be
66present in the resulting list of particles.
67)DOC");
68
69 // Parameter definitions
70 addParam("particles", m_particles, "Name or PDG code of the particles to look for. "
71 "If any of those is found in the event the event is accepted");
72 addParam("includeConjugates", m_includeConjugates, "If true look for either the "
73 "particles or their charge conjugates", true);
74}
75
77{
79 for(const auto &p: m_particles) {
80 int pdg = boost::apply_visitor(GetPDGCode(), p);
81 if(pdg==0) continue;
82 m_particleCodes.insert(pdg);
84 const auto* anti = EvtGenDatabasePDG::Instance()->GetParticle(-pdg);
85 if(anti) {
86 m_particleCodes.insert(-pdg);
87 }
88 }
89 }
90 B2INFO("Accepting events which contain one of the following particles:");
91 for(int i: m_particleCodes){
92 B2INFO(" - Particle " << std::quoted(EvtGenDatabasePDG::Instance()->GetParticle(i)->GetName())
93 << " (" << i << ")");
94 }
95}
96
98{
99 bool found{false};
100 for(const MCParticle& p: m_mcParticles){
101 if(m_particleCodes.count(p.getPDG())>0) {
102 found = true;
103 break;
104 }
105 }
106 setReturnValue(found);
107}
static EvtGenDatabasePDG * Instance()
Instance method that loads the EvtGen table.
InclusiveParticleCheckerModule()
Constructor: Sets the description, the properties and the parameters of the module.
virtual void initialize() override
Register input and output data.
virtual void event() override
Look for the particle and set the return type.
bool m_includeConjugates
If true require either the particle or its charge conjugate.
std::vector< boost::variant< std::string, int > > m_particles
Name or PDG string of the particle to look for.
StoreArray< MCParticle > m_mcParticles
List of generated particles.
std::set< int > m_particleCodes
Set of PDG codes to look for.
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setReturnValue(int value)
Sets the return value for this module as integer.
Definition: Module.cc:220
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
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.