Belle II Software  release-06-02-00
RestOfEventPrinterModule.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 // Own include
10 #include <analysis/modules/RestOfEventPrinter/RestOfEventPrinterModule.h>
11 
12 // framework - DataStore
13 #include <framework/datastore/StoreArray.h>
14 #include <framework/datastore/StoreObjPtr.h>
15 
16 // framework aux
17 #include <framework/logging/Logger.h>
18 
19 // dataobjects
20 #include <analysis/dataobjects/RestOfEvent.h>
21 #include <mdst/dataobjects/MCParticle.h>
22 
23 #include <iostream>
24 
25 using namespace std;
26 
27 namespace Belle2 {
33  //-----------------------------------------------------------------
34  // Register module
35  //-----------------------------------------------------------------
36 
37  REG_MODULE(RestOfEventPrinter)
38 
39  //-----------------------------------------------------------------
40  // Implementation
41  //-----------------------------------------------------------------
42 
44  {
45  // set module description (e.g. insert text)
46  setDescription("Prints basic or detailed RestOfEvent info to screen. It is possible to print out ROEMasks for specific mask names as well.");
47  setPropertyFlags(c_ParallelProcessingCertified);
48 
49  // Add parameters
50  std::vector<std::string> emptyVector;
51 
52  addParam("maskNames", m_maskNames, "List of all mask names for which the info will be printed.", emptyVector);
53  addParam("fullPrint", m_fullPrint, "If true, print whole masks content.", false);
54  addParam("unpackComposites", m_unpackComposites, "If true, replace composites by their daughters", true);
55  }
56 
57  void RestOfEventPrinterModule::initialize()
58  {
60  }
61 
62  void RestOfEventPrinterModule::event()
63  {
64  B2INFO("[RestOfEventPrinterModule] START ----------------------------------------");
65 
66  StoreObjPtr<RestOfEvent> roe("RestOfEvent");
67 
68  if (roe.isValid()) {
69 
70  const Particle* part = roe->getRelated<Particle>();
71  const MCParticle* mcpart = part->getRelated<MCParticle>();
72 
73  int relatedPDG = part->getPDGCode();
74  int relatedMCPDG;
75  if (mcpart)
76  relatedMCPDG = mcpart->getPDG();
77  else
78  relatedMCPDG = -1;
79 
80  // Start printing
81  B2INFO(" - " << "ROE related to particle with PDG: " << relatedPDG);
82  B2INFO(" - " << "ROE related to MC particle with PDG: " << relatedMCPDG);
83 
84  roe->print("", m_unpackComposites);
85 
86  for (const auto& maskName : m_maskNames) {
87  if (!roe->hasMask(maskName)) continue;
88  B2INFO(" - " << "Info for ROEMask with name: \'" << maskName << "\'");
89  roe->print(maskName, m_unpackComposites);
90 
91  if (m_fullPrint) {
92  printMaskParticles(roe->getParticles(maskName));
93  }
94  }
95  } else
96  B2ERROR("RestOfEvent object not valid! Did you build ROE?");
97 
98  B2INFO("[RestOfEventPrinterModule] END ------------------------------------------");
99  }
100 
101  void RestOfEventPrinterModule::printMaskParticles(const std::vector<const Particle*>& maskParticles) const
102  {
103  for (auto* particle : maskParticles) {
104  particle->print();
105  }
106  }
108 } // end Belle2 namespace
109 
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
Base class for Modules.
Definition: Module.h:72
Class to store reconstructed particles.
Definition: Particle.h:74
prints ROE information and masks to screen
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:95
bool isValid() const
Check whether the object was created.
Definition: StoreObjPtr.h:110
#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.