Belle II Software development
ParticleSelectorModule.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// Own header.
10#include <analysis/modules/ParticleSelector/ParticleSelectorModule.h>
11
12// framework aux
13#include <framework/logging/Logger.h>
14
15// dataobjects
16#include <analysis/dataobjects/Particle.h>
17
18using namespace std;
19using namespace Belle2;
20
21//-----------------------------------------------------------------
22// Register module
23//-----------------------------------------------------------------
24
25REG_MODULE(ParticleSelector);
26
27//-----------------------------------------------------------------
28// Implementation
29//-----------------------------------------------------------------
30
32{
33 setDescription("Removes Particles from given ParticleList that do not pass specified selection criteria.");
34
36
37 addParam("decayString", m_decayString,
38 "Input ParticleList name (see :ref:`DecayString`).");
39
41 "Selection criteria to be applied, see `cut_strings_selections`",
42 std::string(""));
43}
44
46{
47 // obtain the input and output particle lists from the decay string
48 bool valid = m_decaydescriptor.init(m_decayString);
49 if (!valid)
50 B2ERROR("ParticleSelectorModule::initialize Invalid input DecayString: " << m_decayString);
51
52 int nProducts = m_decaydescriptor.getNDaughters();
53 if (nProducts > 0)
54 B2ERROR("ParticleSelectorModule::initialize Invalid input DecayString " << m_decayString
55 << ". DecayString should not contain any daughters, only the mother particle.");
56
57 // Mother particle
58 const DecayDescriptorParticle* mother = m_decaydescriptor.getMother();
59
60 const int pdgCode = mother->getPDGCode();
61 string listLabel = mother->getLabel();
62 m_listName = mother->getFullName();
63 // Some labels are reserved for the particle loader which loads all particles of the corresponding type.
64 // If people applied cuts on these particle lists, very dangerous bugs could be introduced.
65 // An exception is made for the gamma:all list. This can be limited to photons from the ECL only.
66 if (Const::finalStateParticlesSet.contains(Const::ParticleType(abs(pdgCode))) and listLabel == "all") {
67 if (abs(pdgCode) == Const::photon.getPDGCode() and m_cutParameter == "isFromECL")
69 else
70 B2FATAL("You are trying to apply a cut on the list " << m_listName <<
71 " but the label 'all' is protected for lists of final-state particles." <<
72 " It could introduce *very* dangerous bugs.");
73 } else if (listLabel == "V0") {
74 // the label V0 is also protected
75 B2FATAL("You are trying to apply a cut on the list " << m_listName <<
76 " but the label " << listLabel << " is protected and can not be reduced.");
77 } else if (abs(pdgCode) == Const::neutron.getPDGCode()) {
78 // neutron particle lists get an exception since no all list is filled for them
80 }
81
82 m_particleList.isRequired(m_listName);
83
85
86 B2INFO("ParticleSelector: " << m_listName);
87 B2INFO(" -> With cuts : " << m_cutParameter);
88}
89
91{
93 m_particleList->setEditable(true);
94
95 // loop over list only if cuts should be applied
96 if (!m_cutParameter.empty()) {
97 std::vector<unsigned int> toRemove;
98 unsigned int n = m_particleList->getListSize();
99 for (unsigned i = 0; i < n; i++) {
100 const Particle* part = m_particleList->getParticle(i);
101 if (!m_cut->check(part)) toRemove.push_back(part->getArrayIndex());
102 }
103 m_particleList->removeParticles(toRemove);
104 }
105
107 m_particleList->setEditable(false);
108}
The ParticleType class for identifying different particle types.
Definition Const.h:408
static const ParticleType neutron
neutron particle
Definition Const.h:675
static const ParticleSet finalStateParticlesSet
set of final set particles that can be created by the ParticleLoader
Definition Const.h:657
static const ParticleType photon
photon particle
Definition Const.h:673
Represents a particle in the DecayDescriptor.
int getPDGCode() const
Return PDG code.
std::string getFullName() const
returns the full name of the particle full_name = name:label
std::string getLabel() const
The label of this particle, "default" returned, when no label set.
static std::unique_ptr< GeneralCut > compile(const std::string &cut)
Definition GeneralCut.h:84
void setDescription(const std::string &description)
Sets the description of the module.
Definition Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition Module.cc:208
Module()
Constructor.
Definition Module.cc:30
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition Module.h:80
bool m_allowRemovalOfFSParticles
true if final-state particles can be removed from the particleList
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
std::string m_decayString
Input DecayString specifying the particle being selected.
std::string m_listName
output particle list name
std::unique_ptr< Variable::Cut > m_cut
cut object which performs the cuts
std::string m_cutParameter
selection criteria
DecayDescriptor m_decaydescriptor
Decay descriptor of the particle being selected.
StoreObjPtr< ParticleList > m_particleList
particle list
Class to store reconstructed particles.
Definition Particle.h:76
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
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.