Belle II Software  release-06-02-00
SkimFilterModule.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/SkimFilter/SkimFilterModule.h>
10 #include <analysis/dataobjects/ParticleList.h>
11 #include <framework/core/Environment.h>
12 #include <framework/datastore/StoreObjPtr.h>
13 #include <boost/algorithm/string/split.hpp>
14 #include <boost/algorithm/string/replace.hpp>
15 #include <boost/algorithm/string/classification.hpp>
16 #include <TString.h>
17 
18 using namespace std;
19 using namespace Belle2;
20 using namespace boost::algorithm;
21 
22 // Register module in the framework
23 REG_MODULE(SkimFilter)
24 
26 {
27  //Set module properties
28  setDescription("Filter based on ParticleLists, by setting return value to true if at least one of the given lists is not empty.");
29  setPropertyFlags(c_ParallelProcessingCertified);
30  //Parameter definition
31  addParam("particleLists", m_strParticleLists, "List of ParticleLists", vector<string>());
32 
33  // initializing the rest of private members
34  m_nPass = 0;
35 }
36 
37 void SkimFilterModule::initialize()
38 {
39 
40  int nParticleLists = m_strParticleLists.size();
41  B2INFO("Number of ParticleLists studied " << nParticleLists << " ");
42 
43  m_nPass = 0;
44 }
45 
46 void SkimFilterModule::event()
47 {
48 
49  setReturnValue(0);
50 
51  // number of ParticleLists
52  int nParticleLists = m_strParticleLists.size();
53  bool pass = false;
54  for (int iList = 0; iList < nParticleLists; ++iList) {
55 
56  StoreObjPtr<ParticleList> particlelist(m_strParticleLists[iList]);
57  if (!particlelist) {
58  B2INFO("ParticleList " << m_strParticleLists[iList] << " not found");
59  continue;
60  } else {
61  if (particlelist->getListSize() == 0)continue;
62  pass = true;
63  }
64 
65  }
66 
67  if (pass) m_nPass++;
68  //module condition
69  setReturnValue(pass);
70 
71 }
72 
73 void SkimFilterModule::terminate()
74 {
75  B2INFO("SkimFilter Summary: \n");
76  std::ostringstream stream;
77  stream << "\n=======================================================\n";
78  stream << "Total Retention: " << Form("%6.4f\n", (float)m_nPass / (float)Environment::Instance().getNumberOfEvents());
79  stream << "\n=======================================================\n";
80  B2INFO(stream.str());
81 }
Base class for Modules.
Definition: Module.h:72
This module filters events based on presence of candidates in a list of ParticleLists.
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.