Belle II Software  release-05-02-19
SelectDaughtersModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Luigi Li Gioi *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <analysis/modules/SelectDaughters/SelectDaughtersModule.h>
12 
13 // dataobjects
14 #include <analysis/dataobjects/Particle.h>
15 #include <analysis/dataobjects/ParticleList.h>
16 
17 // Magnetic field
18 #include <framework/geometry/BFieldManager.h>
19 
20 using namespace std;
21 
22 using namespace Belle2;
23 
24 //-----------------------------------------------------------------
25 // Register the Module
26 //-----------------------------------------------------------------
27 REG_MODULE(SelectDaughters)
28 
29 //-----------------------------------------------------------------
30 // Implementation
31 //-----------------------------------------------------------------
32 
34 {
35  // Set module properties
36  setDescription("SelectDaughters");
37 
38  //Parameter definitions
39  addParam("listName", m_listName, "name of particle list", string(""));
40  addParam("decayString", m_decayString, "specifies which daughter particles will remain", string(""));
41 
42 }
43 
44 void SelectDaughtersModule::initialize()
45 {
46  if (m_decayString != "") {
47  m_decaydescriptor.init(m_decayString);
48  }
49 }
50 
51 void SelectDaughtersModule::event()
52 {
53 
54  StoreObjPtr<ParticleList> plist(m_listName);
55  if (!plist) {
56  B2ERROR("ParticleList " << m_listName << " not found");
57  return;
58  }
59  if (m_decayString == "") {
60  B2ERROR("decay descriptor cannot be empty");
61  return;
62  }
63 
64  unsigned int n = plist->getListSize();
65  for (unsigned i = 0; i < n; i++) {
66  Particle* particle = plist->getParticle(i);
67 
68  std::vector<Particle*> daughters = particle->getDaughters();
69  std::vector<const Particle*> selParticles = m_decaydescriptor.getSelectionParticles(particle);
70 
71  for (auto& daughter : daughters) {
72  bool isSel = false;
73  for (auto& selParticle : selParticles) {
74  if (daughter == selParticle) isSel = true;
75  }
76  if (!isSel) particle->removeDaughter(daughter);
77  }
78  }
79 }
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
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::SelectDaughtersModule
Redefine (select) the daughters of a particle.
Definition: SelectDaughtersModule.h:38