Belle II Software  release-05-02-19
RestOfEventInterpreterModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2013 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Matic Lubej, Sviatoslav Bilokin *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <analysis/modules/RestOfEventInterpreter/RestOfEventInterpreterModule.h>
12 
13 #include <analysis/dataobjects/ParticleList.h>
14 #include <analysis/dataobjects/Particle.h>
15 #include <analysis/dataobjects/RestOfEvent.h>
16 
17 #include <framework/datastore/StoreArray.h>
18 #include <framework/datastore/StoreObjPtr.h>
19 
20 #include <framework/logging/Logger.h>
21 #include <framework/core/ModuleParam.templateDetails.h>
22 
23 #include <iostream>
24 
25 using namespace std;
26 
27 namespace Belle2 {
33  //-----------------------------------------------------------------
34  // Register the Module
35  //-----------------------------------------------------------------
36  REG_MODULE(RestOfEventInterpreter)
37 
38  //-----------------------------------------------------------------
39  // Implementation
40  //-----------------------------------------------------------------
41 
43  {
44  // Set module properties
45  setDescription("Creates a mask (vector of boolean values) for tracks and clusters in RestOfEvent.");
46  setPropertyFlags(c_ParallelProcessingCertified);
47 
48  // Add parameters
49  std::vector<std::tuple<std::string, std::string, std::string>> emptyROEMask;
50 
51  addParam("particleList", m_particleList, "Name of the ParticleList");
52 
53  addParam("ROEMasks", m_ROEMasks,
54  "List of (maskName, trackSelectionCut, eclClusterSelectionCut) tuples that specify all ROE masks of a specific particle to be created.",
55  emptyROEMask);
56 
57  addParam("update", m_update, "Set true for updating a-priori charged stable fractions used in calculation of ROE 4-momentum",
58  false);
59 
60  }
61 
62  void RestOfEventInterpreterModule::initialize()
63  {
64  // input
65  StoreObjPtr<ParticleList>().isRequired(m_particleList);
66  StoreArray<Particle> particles;
67  particles.isRequired();
68 
69  for (auto ROEMask : m_ROEMasks) {
70  // parsing of the input tuple (maskName, trackSelectionCut, eclClusterSelectionCut, fractions)
71 
72  std::string maskName = get<0>(ROEMask);
73  std::string trackSelection = get<1>(ROEMask);
74  std::string eclClusterSelection = get<2>(ROEMask);
75 
76  std::shared_ptr<Variable::Cut> trackCut = std::shared_ptr<Variable::Cut>(Variable::Cut::compile(trackSelection));
77  std::shared_ptr<Variable::Cut> eclClusterCut = std::shared_ptr<Variable::Cut>(Variable::Cut::compile(eclClusterSelection));
78 
79  m_maskNames.push_back(maskName);
80  m_trackCuts.insert(stringAndCutMap::value_type(maskName, trackCut));
81  m_eclClusterCuts.insert(stringAndCutMap::value_type(maskName, eclClusterCut));
82 
83  B2INFO("RestOfEventInterpreter added ROEMask with specific fractions under name \'" << maskName << "\' with track cuts: " <<
84  trackSelection << " and eclCluster cuts: " << eclClusterSelection);
85  }
86  }
87 
88  void RestOfEventInterpreterModule::event()
89  {
90  StoreObjPtr<ParticleList> plist(m_particleList);
91 
92  unsigned int nParts = plist->getListSize();
93 
94  for (unsigned i = 0; i < nParts; i++) {
95  const Particle* particle = plist->getParticle(i);
96  auto* roe = particle->getRelatedTo<RestOfEvent>("ALL");
97  for (auto& maskName : m_maskNames) {
98  if (!m_update) {
99  roe->initializeMask(maskName, "ROEInterpreterModule");
100  }
101  roe->updateMaskWithCuts(maskName, m_trackCuts.at(maskName), m_eclClusterCuts.at(maskName), nullptr, m_update);
102  }
103  }
104  }
105 
107 }
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::RestOfEvent
This is a general purpose class for collecting reconstructed MDST data objects that are not used in r...
Definition: RestOfEvent.h:59
Belle2::RestOfEventInterpreterModule
Creates a mask (vector of boolean values) for tracks and clusters in RestOfEvent regarding their usag...
Definition: RestOfEventInterpreterModule.h:41
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::RestOfEvent::initializeMask
void initializeMask(const std::string &name, const std::string &origin="unknown")
Initialize new mask.
Definition: RestOfEvent.cc:135
Belle2::Particle
Class to store reconstructed particles.
Definition: Particle.h:77
Belle2::StoreArray< Particle >