Belle II Software light-2406-ragdoll
ParticleWeightingLookUpCreatorModule.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/ParticleWeightingLookUpCreator/ParticleWeightingLookUpCreatorModule.h>
11
12// framework aux
13#include <framework/core/ModuleParam.templateDetails.h>
14#include <framework/database/DBImportObjPtr.h>
15#include <framework/logging/Logger.h>
16
17
18using namespace std;
19using namespace Belle2;
20
21//-----------------------------------------------------------------
22// Register module
23//-----------------------------------------------------------------
24
25REG_MODULE(ParticleWeightingLookUpCreator);
26
27//-----------------------------------------------------------------
28// Implementation
29//-----------------------------------------------------------------
30
32
33{
34 setDescription("Creates test LookUp table");
35 listOfNoIdEntries empty_noid_list;
36 addParam("tableIDNotSpec", m_tableIDNotSpec, "Bin:weight info map without specific bin-numbering scheme", empty_noid_list);
37 listOfSpecificIDEntries empty_specificid_list;
38 addParam("tableIDSpec", m_tableIDSpec, "Bin:weight info map with specific bin-numbering scheme", empty_specificid_list);
39 addParam("tableName", m_tableName, "Name of the LookUp table");
40 addParam("outOfRangeWeight", m_outOfRangeWeight, "Weight info for out-of-range partiles");
41 addParam("experimentLow", m_experimentLow, "Interval of validity, ex.low");
42 addParam("experimentHigh", m_experimentHigh, "Interval of validity, ex.high");
43 addParam("runLow", m_runLow, "Interval of validity, run low");
44 addParam("runHigh", m_runHigh, "Interval of validity, run high");
45}
46
51{
52 NDBin binning;
53 for (auto bin_1d : bin_tuple) {
54 std::string axis_name = bin_1d.first;
55 double min_val = std::get<0>(bin_1d.second);
56 double max_val = std::get<1>(bin_1d.second);
57 lims = new ParticleWeightingBinLimits(min_val, max_val);
58 binning.insert(std::make_pair(axis_name, lims));
59 }
60 return binning;
61}
62
64{
66
67 if (!m_outOfRangeWeight.empty()) {
68 table.defineOutOfRangeWeight(m_outOfRangeWeight);
69 }
70
71 if (!m_tableIDNotSpec.empty() and m_tableIDSpec.empty()) {
72 for (auto entry : m_tableIDNotSpec) {
73 WeightInfo info = std::get<0>(entry);
74 NDBin bin = NDBinTupleToNDBin(std::get<1>(entry));
75 table.addEntry(info, bin);
76 }
77 } else if (!m_tableIDSpec.empty() and m_tableIDNotSpec.empty()) {
78 for (auto entry : m_tableIDSpec) {
79 noIdEntry noid = std::get<0>(entry);
80 double bin_id = std::get<1>(entry);
81 WeightInfo info = std::get<0>(noid);
82 NDBin bin = NDBinTupleToNDBin(std::get<1>(noid));
83 table.addEntry(info, bin, bin_id);
84 }
85 } else {
86 B2ERROR("Please define one table: with OR without specific bin IDs");
87 }
88
89 if (!m_outOfRangeWeight.empty()) {
90 table.defineOutOfRangeWeight(m_outOfRangeWeight);
91 }
92 B2INFO("Printing LookUp table");
93 table.printParticleWeightingLookUpTable();
94
96 importer.construct(table);
98
99}
100
102{
103 if (lims != nullptr) {
104 delete lims;
105 }
106}
Class for importing a single object to the database.
A class that describes the interval of experiments/runs for which an object in the database is valid.
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
Just pair of numbers - min and max values of bin border.
listOfNoIdEntries m_tableIDNotSpec
List of entries for table to be created from without specified ID.
virtual void initialize() override
Initialize the Module.
NDBin NDBinTupleToNDBin(const NDBinTuple &bin_tuple)
Currently, std::pair can not be retrieved from python list We will get ParticleWeightingLookUpTable e...
virtual void terminate() override
Clean up anything created in initialize().
ParticleWeightingBinLimits * lims
object holding bin limits
listOfSpecificIDEntries m_tableIDSpec
List of entries for table to be created from with specified ID.
WeightInfo m_outOfRangeWeight
Weight info for out-of-range bin.
std::tuple< WeightInfo, NDBinTuple > noIdEntry
the ID
std::vector< specificIDEntry > listOfSpecificIDEntries
List of entries for table to be created from with specified ID.
std::map< std::string, BinLimitsTuple > NDBinTuple
the NDimensional tuple of bin limits
std::vector< noIdEntry > listOfNoIdEntries
List of entries for table to be created from without specified ID.
std::map< std::string, ParticleWeightingBinLimits * > NDBin
N-dim bin: pairs of bin limits with name of the axis variable.
std::map< std::string, double > WeightInfo
Weight information: a line from the weight lookup table.
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.
Definition: ClusterUtils.h:24
STL namespace.