Belle II Software  release-06-02-00
SelectDaughtersModule.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 <analysis/modules/SelectDaughters/SelectDaughtersModule.h>
10 
11 // dataobjects
12 #include <analysis/dataobjects/Particle.h>
13 #include <analysis/dataobjects/ParticleList.h>
14 
15 // Magnetic field
16 #include <framework/geometry/BFieldManager.h>
17 
18 using namespace std;
19 
20 using namespace Belle2;
21 
22 //-----------------------------------------------------------------
23 // Register the Module
24 //-----------------------------------------------------------------
25 REG_MODULE(SelectDaughters)
26 
27 //-----------------------------------------------------------------
28 // Implementation
29 //-----------------------------------------------------------------
30 
32 {
33  // Set module properties
34  setDescription("SelectDaughters");
35 
36  //Parameter definitions
37  addParam("listName", m_listName, "name of particle list", string(""));
38  addParam("decayString", m_decayString, "specifies which daughter particles will remain", string(""));
39 
40 }
41 
42 void SelectDaughtersModule::initialize()
43 {
44  if (m_decayString != "") {
45  m_decaydescriptor.init(m_decayString);
46  }
47 }
48 
49 void SelectDaughtersModule::event()
50 {
51 
52  StoreObjPtr<ParticleList> plist(m_listName);
53  if (!plist) {
54  B2ERROR("ParticleList " << m_listName << " not found");
55  return;
56  }
57  if (m_decayString == "") {
58  B2ERROR("decay descriptor cannot be empty");
59  return;
60  }
61 
62  unsigned int n = plist->getListSize();
63  for (unsigned i = 0; i < n; i++) {
64  Particle* particle = plist->getParticle(i);
65 
66  std::vector<Particle*> daughters = particle->getDaughters();
67  std::vector<const Particle*> selParticles = m_decaydescriptor.getSelectionParticles(particle);
68 
69  for (auto& daughter : daughters) {
70  bool isSel = false;
71  for (auto& selParticle : selParticles) {
72  if (daughter == selParticle) isSel = true;
73  }
74  if (!isSel) particle->removeDaughter(daughter);
75  }
76  }
77 }
Base class for Modules.
Definition: Module.h:72
Class to store reconstructed particles.
Definition: Particle.h:74
Redefine (select) the daughters of a particle.
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:95
#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.