9 #include <analysis/modules/VariablesToExtraInfo/VariablesToExtraInfoModule.h> 
   11 #include <framework/logging/Logger.h> 
   12 #include <framework/core/ModuleParam.templateDetails.h> 
   19 VariablesToExtraInfoModule::VariablesToExtraInfoModule()
 
   21   setDescription(
"For each particle in the input list the selected variables are saved in an extra-info field with the given name. Can be used when wanting to save variables before modifying them, e.g. when performing vertex fits.");
 
   22   setPropertyFlags(c_ParallelProcessingCertified);
 
   24   std::map<std::string, std::string> emptymap;
 
   25   addParam(
"particleList", m_inputListName, 
"Name of particle list with reconstructed particles.");
 
   26   addParam(
"variables", m_variables,
 
   27            "Dictionary of variables and extraInfo names to save in the extra-info field.\n" 
   28            "Variables are taken from Variable::Manager, and are identical to those available to e.g. ParticleSelector.",
 
   30   addParam(
"decayString", m_decayString, 
"DecayString specifying the daughter Particle to be included in the ParticleList",
 
   32   addParam(
"overwrite", m_overwrite,
 
   33            "-1/0/1/2: Overwrite if lower / don't overwrite / overwrite if higher / always overwrite, in case if extra info with given name already exists",
 
   37 VariablesToExtraInfoModule::~VariablesToExtraInfoModule() = 
default;
 
   39 void VariablesToExtraInfoModule::initialize()
 
   41   m_particles.isRequired();
 
   42   m_inputList.isRequired(m_inputListName);
 
   45   for (
const auto& pair : m_variables) {
 
   48       B2ERROR(
"Variable '" << pair.first << 
"' is not available in Variable::Manager!");
 
   50       m_functions.push_back(var->function);
 
   51       m_extraInfoNames.push_back(pair.second);
 
   55   if (not m_decayString.empty()) {
 
   56     m_writeToDaughter = 
true;
 
   58     bool valid = m_pDDescriptor.init(m_decayString);
 
   60       B2ERROR(
"VariablesToExtraInfoModule::initialize Invalid Decay Descriptor: " << m_decayString);
 
   64 void VariablesToExtraInfoModule::event()
 
   67     B2WARNING(
"Input list " << m_inputList.getName() << 
" was not created?");
 
   71   const unsigned int numParticles = m_inputList->getListSize();
 
   72   for (
unsigned int i = 0; i < numParticles; i++) {
 
   73     Particle* p = m_inputList->getParticle(i);
 
   75     if (not m_writeToDaughter) {
 
   78       std::vector<const Particle*> selparticles = m_pDDescriptor.getSelectionParticles(p);
 
   79       for (
auto& selparticle : selparticles) {
 
   80         Particle* daug = m_particles[selparticle->getArrayIndex()];
 
   81         addExtraInfo(p, daug);
 
   87 void VariablesToExtraInfoModule::addExtraInfo(
const Particle* source, 
Particle* destination)
 
   89   const unsigned int nVars = m_functions.size();
 
   90   for (
unsigned int iVar = 0; iVar < nVars; iVar++) {
 
   91     double value = std::numeric_limits<double>::quiet_NaN();
 
   92     if (std::holds_alternative<double>(m_functions[iVar](source))) {
 
   93       value = std::get<double>(m_functions[iVar](source));
 
   94     } 
else if (std::holds_alternative<int>(m_functions[iVar](source))) {
 
   95       value = std::get<int>(m_functions[iVar](source));
 
   96     } 
else if (std::holds_alternative<bool>(m_functions[iVar](source))) {
 
   97       value = std::get<bool>(m_functions[iVar](source));
 
  100       double current = destination->
getExtraInfo(m_extraInfoNames[iVar]);
 
  101       if (m_overwrite == -1) {
 
  103           destination->
setExtraInfo(m_extraInfoNames[iVar], value);
 
  104       } 
else if (m_overwrite == 1) {
 
  106           destination->
setExtraInfo(m_extraInfoNames[iVar], value);
 
  107       } 
else if (m_overwrite == 0) {
 
  108         B2WARNING(
"Extra info with given name " << m_extraInfoNames[iVar] << 
" already set, I won't set it again.");
 
  109       } 
else if (m_overwrite == 2) {
 
  110         destination->
setExtraInfo(m_extraInfoNames[iVar], value);
 
  114       destination->
addExtraInfo(m_extraInfoNames[iVar], value);
 
Class to store reconstructed particles.
void setExtraInfo(const std::string &name, double value)
Sets the user-defined data of given name to the given value.
bool hasExtraInfo(const std::string &name) const
Return whether the extra info with the given name is set.
void addExtraInfo(const std::string &name, double value)
Sets the user-defined data of given name to the given value.
double getExtraInfo(const std::string &name) const
Return given value if set.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.
A variable returning a floating-point value for a given Particle.