Belle II Software development
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 header.
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
23using namespace std;
24using namespace Belle2;
25
26//-----------------------------------------------------------------
27// Register module
28//-----------------------------------------------------------------
29
30REG_MODULE(RestOfEventPrinter);
31
32//-----------------------------------------------------------------
33// Implementation
34//-----------------------------------------------------------------
35
37{
38 // set module description (e.g. insert text)
39 setDescription("Prints basic or detailed RestOfEvent info to screen. It is possible to print out ROEMasks for specific mask names as well.");
41
42 // Add parameters
43 std::vector<std::string> emptyVector;
44
45 addParam("maskNames", m_maskNames, "List of all mask names for which the info will be printed.", emptyVector);
46 addParam("fullPrint", m_fullPrint, "If true, print whole masks content.", false);
47 addParam("unpackComposites", m_unpackComposites, "If true, replace composites by their daughters", true);
48}
49
51{
53}
54
56{
57 B2INFO("[RestOfEventPrinterModule] START ----------------------------------------");
58
59 StoreObjPtr<RestOfEvent> roe("RestOfEvent");
60
61 if (roe.isValid()) {
62
63 const Particle* part = roe->getRelatedFrom<Particle>();
64 const MCParticle* mcpart = part->getRelated<MCParticle>();
65
66 int relatedPDG = part->getPDGCode();
67 int relatedMCPDG;
68 if (mcpart)
69 relatedMCPDG = mcpart->getPDG();
70 else
71 relatedMCPDG = -1;
72
73 // Start printing
74 B2INFO(" - " << "ROE related to particle with" << LogVar("PDG", relatedPDG));
75 B2INFO(" - " << "ROE related to MC particle with" << LogVar("PDG", relatedMCPDG));
76
78
79 for (const auto& maskName : m_maskNames) {
80 if (!roe->hasMask(maskName)) continue;
81 B2INFO(" - " << "Info for ROEMask with name: \'" << maskName << "\'");
82 roe->print(maskName, m_unpackComposites);
83
84 if (m_fullPrint) {
85 printMaskParticles(roe->getParticles(maskName));
86 }
87 }
88 } else
89 B2ERROR("RestOfEvent object not valid! Did you build ROE?");
90
91 B2INFO("[RestOfEventPrinterModule] END ------------------------------------------");
92}
93
94void RestOfEventPrinterModule::printMaskParticles(const std::vector<const Particle*>& maskParticles) const
95{
96 for (auto* particle : maskParticles) {
97 particle->print();
98 }
99}
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
Class to store reconstructed particles.
Definition: Particle.h:76
int getPDGCode(void) const
Returns PDG code.
Definition: Particle.h:465
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
bool m_fullPrint
True: Print whole masks content.
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
std::vector< std::string > m_maskNames
List of all mask names for which the info will be printed.
bool m_unpackComposites
True: Replace composite particles or V0 by their daughters, default is true.
void printMaskParticles(const std::vector< const Particle * > &maskParticles) const
Prints out values of the specific ROE mask.
static constexpr const char * c_defaultMaskName
Default mask name.
Definition: RestOfEvent.h:60
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
Class to store variables with their name which were sent to the logging service.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:649
Abstract base class for different kinds of events.
STL namespace.