Belle II Software  release-05-02-19
ParticleSelectorModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Marko Staric, Anze Zupanc *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 // Own include
12 #include <analysis/modules/ParticleSelector/ParticleSelectorModule.h>
13 
14 // framework - DataStore
15 #include <framework/datastore/StoreObjPtr.h>
16 
17 // framework aux
18 #include <framework/logging/Logger.h>
19 
20 // dataobjects
21 #include <analysis/dataobjects/Particle.h>
22 #include <analysis/dataobjects/ParticleList.h>
23 
24 using namespace std;
25 
26 namespace Belle2 {
32  //-----------------------------------------------------------------
33  // Register module
34  //-----------------------------------------------------------------
35 
36  REG_MODULE(ParticleSelector)
37 
38  //-----------------------------------------------------------------
39  // Implementation
40  //-----------------------------------------------------------------
41 
43  {
44  setDescription("Removes Particles from given ParticleList that do not pass specified selection criteria.");
45 
46  setPropertyFlags(c_ParallelProcessingCertified);
47 
48  addParam("decayString", m_decayString,
49  "Input ParticleList name (see :ref:`DecayString`).");
50 
51  addParam("cut", m_cutParameter,
52  "Selection criteria to be applied, see `cut_strings_selections`",
53  std::string(""));
54  }
55 
56  void ParticleSelectorModule::initialize()
57  {
58  // obtain the input and output particle lists from the decay string
59  bool valid = m_decaydescriptor.init(m_decayString);
60  if (!valid)
61  B2ERROR("ParticleSelectorModule::initialize Invalid input DecayString: " << m_decayString);
62 
63  int nProducts = m_decaydescriptor.getNDaughters();
64  if (nProducts > 0)
65  B2ERROR("ParticleSelectorModule::initialize Invalid input DecayString " << m_decayString
66  << ". DecayString should not contain any daughters, only the mother particle.");
67 
68  // Mother particle
69  const DecayDescriptorParticle* mother = m_decaydescriptor.getMother();
70 
71  m_listName = mother->getFullName();
72 
73  StoreObjPtr<ParticleList> particleList(m_listName);
74  particleList.isRequired(m_listName);
75 
76  m_cut = Variable::Cut::compile(m_cutParameter);
77 
78  B2INFO("ParticleSelector: " << m_listName);
79  B2INFO(" -> With cuts : " << m_cutParameter);
80  }
81 
82  void ParticleSelectorModule::event()
83  {
84  StoreObjPtr<ParticleList> plist(m_listName);
85  bool existingList = plist.isValid();
86 
87  if (!existingList) {
88  B2WARNING("Input list " << m_listName << " was not created?");
89  return;
90  }
91 
92  // loop over list only if cuts should be applied
93  if (!m_cutParameter.empty()) {
94  std::vector<unsigned int> toRemove;
95  unsigned int n = plist->getListSize();
96  for (unsigned i = 0; i < n; i++) {
97  const Particle* part = plist->getParticle(i);
98  if (!m_cut->check(part)) toRemove.push_back(part->getArrayIndex());
99  }
100  plist->removeParticles(toRemove);
101  }
102  }
104 } // end Belle2 namespace
105 
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::DecayDescriptorParticle
Represents a particle in the DecayDescriptor.
Definition: DecayDescriptorParticle.h:37
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::Particle
Class to store reconstructed particles.
Definition: Particle.h:77
Belle2::ParticleSelectorModule
Loops over all Particles in the ParticleList and removes those Particles from the ParticleList that d...
Definition: ParticleSelectorModule.h:42
Belle2::StoreObjPtr::isValid
bool isValid() const
Check whether the object was created.
Definition: StoreObjPtr.h:120