Belle II Software  release-06-00-14
SignalSideVariablesToExtraInfoModule.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/SignalSideVariablesToExtraInfo/SignalSideVariablesToExtraInfoModule.h>
10 #include <framework/core/ModuleParam.templateDetails.h>
11 #include <framework/datastore/StoreArray.h>
12 
13 #include <analysis/dataobjects/Particle.h>
14 #include <analysis/dataobjects/RestOfEvent.h>
15 
16 using namespace Belle2;
17 
18 //-----------------------------------------------------------------
19 // Register the Module
20 //-----------------------------------------------------------------
21 REG_MODULE(SignalSideVariablesToExtraInfo)
22 
23 //-----------------------------------------------------------------
24 // Implementation
25 //-----------------------------------------------------------------
26 
28 {
29  // Set module properties
30  setDescription("The module writes property (value of specified variable) of single particle\n"
31  "found in the input ParticleList as an ExtraInfo to the Particle related to\n"
32  "the current ROE. This module is intended to be executed only in for_each ROE\n"
33  "path.");
34 
35  // Parameter definitions
36  std::map<std::string, std::string> emptymap;
37  addParam("particleListName", m_particleListName, "The input particleList name. This list should contain at most 1 particle",
38  std::string(""));
39  addParam("variableToExtraInfo", m_variableToExtraInfo,
40  "Dictionary of variables and extraInfo names to save in the extra-info field.",
41  emptymap);
42 }
43 
45 {
47  m_inputList.isRequired(m_particleListName);
48 
49  for (const auto& pair : m_variableToExtraInfo) {
51  if (!var) {
52  B2ERROR("Variable '" << pair.first << "' is not available in Variable::Manager!");
53  } else {
54  m_functions.push_back(var->function);
55  m_extraInfoNames.push_back(pair.second);
56  }
57  }
58 }
59 
61 {
63  unsigned int n = plist->getListSize();
64 
65  if (n == 0)
66  return;
67 
68  if (n > 1)
69  B2WARNING("Input ParticleList " << m_particleListName << " contains more than 1 particle. plist.size = " << n);
70 
71  StoreObjPtr<RestOfEvent> roe("RestOfEvent");
72  if (roe.isValid()) {
73  auto* signalSide = roe->getRelated<Particle>();
74 
75  const unsigned int nVars = m_functions.size();
76  for (unsigned int iVar = 0; iVar < nVars; iVar++) {
77  if (signalSide->hasExtraInfo(m_extraInfoNames[iVar])) {
78  B2WARNING("Extra info with given name " << m_extraInfoNames[iVar] << " already set, I won't set it again.");
79  } else {
80  signalSide->addExtraInfo(m_extraInfoNames[iVar], m_functions[iVar](plist->getParticle(0)));
81  }
82  }
83  }
84 }
Base class for Modules.
Definition: Module.h:72
Class to store reconstructed particles.
Definition: Particle.h:74
The module writes property of single particle found in the input ParticleList as an ExtraInfo to the ...
std::string m_particleListName
The input particleList name.
virtual void initialize() override
Register input and output data.
StoreObjPtr< ParticleList > m_inputList
input particle list
std::map< std::string, std::string > m_variableToExtraInfo
Map of variable and extraInfo name to save in the extra-info field.
std::vector< Variable::Manager::FunctionPtr > m_functions
Vector of function pointers corresponding to given variables.
std::vector< std::string > m_extraInfoNames
Vector of extra info names.
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
const Var * getVariable(std::string name)
Get the variable belonging to the given key.
Definition: Manager.cc:31
static Manager & Instance()
get singleton instance.
Definition: Manager.cc:25
#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.
A variable returning a floating-point value for a given Particle.
Definition: Manager.h:133