Belle II Software development
TagUniqueSignalModule.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#include <analysis/modules/TagUniqueSignal/TagUniqueSignalModule.h>
9
10#include <analysis/dataobjects/Particle.h>
11#include <mdst/dataobjects/MCParticle.h>
12#include <analysis/dataobjects/ParticleList.h>
13
14#include <framework/datastore/StoreObjPtr.h>
15#include <framework/logging/Logger.h>
16
17#include <set>
18
19using namespace std;
20using namespace Belle2;
21
22
23//-----------------------------------------------------------------
24// Register module
25//-----------------------------------------------------------------
26
27REG_MODULE(TagUniqueSignal);
28
30{
31 setDescription("Mark true (target=1) candidates from input list via extra-info field. Only the first true candidate associated with an MCParticle is marked.");
33
34 // Add parameters
35 addParam("particleList", m_particleList, "Input ParticleList name");
36 addParam("target", m_targetVariable, "Variable which defines signal and background.", std::string("isSignal"));
37 addParam("extraInfoName", m_extraInfoName,
38 "Extra-info field added to all particles in the input list. 1 for unique signal, 0 for background or duplicates.",
39 string("uniqueSignal"));
40}
41
43{
45
47
48 m_targetVar = manager.getVariable(m_targetVariable);
49 if (m_targetVar == nullptr) {
50 B2ERROR("TagUniqueSignal: Variable::Manager doesn't have variable" << m_targetVariable);
51 }
52}
53
55{
57 if (!inPList)
58 return;
59
60
61 const int size = inPList->getListSize();
62 std::set<const MCParticle*> foundMCParticles;
63 for (int i = 0; i < size; i++) {
64 Particle* part = inPList->getParticle(i);
65 const MCParticle* mcp = part->getRelated<MCParticle>();
66 float extraInfoValue = 0.0;
67 if (mcp) {
68 if ((m_targetVar->variabletype == Variable::Manager::VariableDataType::c_double and std::get<double>(m_targetVar->function(part)))
69 or (m_targetVar->variabletype == Variable::Manager::VariableDataType::c_int and std::get<int>(m_targetVar->function(part)))
70 or (m_targetVar->variabletype == Variable::Manager::VariableDataType::c_bool and std::get<bool>(m_targetVar->function(part)))) {
71 const bool was_inserted = foundMCParticles.insert(mcp).second;
72 if (was_inserted)
73 extraInfoValue = 1.0;
74 }
75 }
76 if (part->hasExtraInfo(m_extraInfoName)) {
77 B2WARNING("Extra Info with given name is already set! This module can only be used once per particle.");
78 } else {
79 part->addExtraInfo(m_extraInfoName, extraInfoValue);
80 }
81 }
82}
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:75
bool hasExtraInfo(const std::string &name) const
Return whether the extra info with the given name is set.
Definition: Particle.cc:1266
void addExtraInfo(const std::string &name, double value)
Sets the user-defined data of given name to the given value.
Definition: Particle.cc:1336
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
std::string m_targetVariable
Variable which defines signal and background.
std::string m_particleList
input ParticleList name
const Variable::Manager::Var * m_targetVar
Pointer to target variable stored in the variable manager.
std::string m_extraInfoName
output extra-info name
Global list of available variables.
Definition: Manager.h:101
static Manager & Instance()
get singleton instance.
Definition: Manager.cc:25
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:560
#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.
STL namespace.
VariableDataType variabletype
data type of variable
Definition: Manager.h:133
FunctionPtr function
Pointer to function.
Definition: Manager.h:147