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