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