Belle II Software  release-05-02-19
ParticleCopierModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Anze Zupanc *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 // Own include
12 #include <analysis/modules/ParticleCopier/ParticleCopierModule.h>
13 
14 
15 // framework - DataStore
16 #include <framework/datastore/StoreArray.h>
17 #include <framework/datastore/StoreObjPtr.h>
18 
19 // framework aux
20 #include <framework/logging/Logger.h>
21 
22 // dataobjects
23 #include <analysis/dataobjects/Particle.h>
24 #include <analysis/dataobjects/ParticleList.h>
25 
26 // utilities
27 #include <analysis/utility/ParticleCopy.h>
28 
29 using namespace std;
30 
31 namespace Belle2 {
37  //-----------------------------------------------------------------
38  // Register module
39  //-----------------------------------------------------------------
40 
41  REG_MODULE(ParticleCopier)
42 
43  //-----------------------------------------------------------------
44  // Implementation
45  //-----------------------------------------------------------------
46 
48  {
49  setDescription("Replaces each Particle in the ParticleList with its copy.\n"
50  "Particle's (grand)^n-daughter Particles are copied as well.\n"
51  "The existing relations of the original Particle (or it's (grand-)^n-daughters)\n"
52  "are copied as well.");
53  setPropertyFlags(c_ParallelProcessingCertified);
54 
55  // Add parameters
56  vector<string> defaultList;
57  addParam("inputListNames", m_inputListNames,
58  "list of input ParticleList names", defaultList);
59  }
60 
61  void ParticleCopierModule::initialize()
62  {
63  // Input lists
64  for (const std::string& listName : m_inputListNames) {
65  StoreObjPtr<ParticleList>().isRequired(listName);
66  }
67  }
68 
69  void ParticleCopierModule::event()
70  {
71  const StoreArray<Particle> particles;
72 
73  // copy all particles from input lists that pass selection criteria into plist
74  for (const auto& inputListName : m_inputListNames) {
75  const StoreObjPtr<ParticleList> plist(inputListName);
76 
77  const unsigned int origSize = plist->getListSize();
78  std::vector<Particle*> copies(origSize);
79 
80  for (unsigned i = 0; i < origSize; i++) {
81  const Particle* origP = plist->getParticle(i);
82 
83  // copy the particle
84  Particle* copyP = ParticleCopy::copyParticle(origP);
85  copies.at(i) = copyP;
86  }
87 
88  // clear the original list and fill it with copies
89  plist->clear();
90  for (unsigned i = 0; i < origSize; i++)
91  plist->addParticle(copies[i]);
92 
93  unsigned int copySize = plist->getListSize();
94 
95  if (copySize != origSize)
96  B2FATAL("Size of the ParticleList " << inputListName
97  << " has changed while copying the Particles! original size = "
98  << origSize << " vs. new size = " << copySize);
99 
100  }
101  }
103 } // end Belle2 namespace
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::ParticleCopierModule
Module for creating copies of Particles.
Definition: ParticleCopierModule.h:46
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::StoreArray< Particle >