Belle II Software development
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#include <analysis/dbobjects/ParticleWeightingBinLimits.h>
13
14// framework aux
15#include <framework/core/ModuleParam.templateDetails.h>
16#include <framework/database/DBImportObjPtr.h>
17#include <framework/logging/Logger.h>
18
19
20using namespace std;
21using namespace Belle2;
22
23//-----------------------------------------------------------------
24// Register module
25//-----------------------------------------------------------------
26
27REG_MODULE(ParticleWeightingLookUpCreator);
28
29//-----------------------------------------------------------------
30// Implementation
31//-----------------------------------------------------------------
32
34
35{
36 setDescription("Creates test LookUp table");
37 listOfNoIdEntries empty_noid_list;
38 addParam("tableIDNotSpec", m_tableIDNotSpec, "Bin:weight info map without specific bin-numbering scheme", empty_noid_list);
39 listOfSpecificIDEntries empty_specificid_list;
40 addParam("tableIDSpec", m_tableIDSpec, "Bin:weight info map with specific bin-numbering scheme", empty_specificid_list);
41 addParam("tableName", m_tableName, "Name of the LookUp table");
42 addParam("outOfRangeWeight", m_outOfRangeWeight, "Weight info for out-of-range partiles");
43 addParam("experimentLow", m_experimentLow, "Interval of validity, ex.low");
44 addParam("experimentHigh", m_experimentHigh, "Interval of validity, ex.high");
45 addParam("runLow", m_runLow, "Interval of validity, run low");
46 addParam("runHigh", m_runHigh, "Interval of validity, run high");
47}
48
53{
54 NDBin binning;
55 for (auto bin_1d : bin_tuple) {
56 std::string axis_name = bin_1d.first;
57 double min_val = std::get<0>(bin_1d.second);
58 double max_val = std::get<1>(bin_1d.second);
59 lims = new ParticleWeightingBinLimits(min_val, max_val);
60 binning.insert(std::make_pair(axis_name, lims));
61 }
62 return binning;
63}
64
66{
68
69 if (!m_outOfRangeWeight.empty()) {
70 table.defineOutOfRangeWeight(m_outOfRangeWeight);
71 }
72
73 if (!m_tableIDNotSpec.empty() and m_tableIDSpec.empty()) {
74 for (auto entry : m_tableIDNotSpec) {
75 WeightInfo info = std::get<0>(entry);
76 NDBin bin = NDBinTupleToNDBin(std::get<1>(entry));
77 table.addEntry(info, bin);
78 }
79 } else if (!m_tableIDSpec.empty() and m_tableIDNotSpec.empty()) {
80 for (auto entry : m_tableIDSpec) {
81 noIdEntry noid = std::get<0>(entry);
82 double bin_id = std::get<1>(entry);
83 WeightInfo info = std::get<0>(noid);
84 NDBin bin = NDBinTupleToNDBin(std::get<1>(noid));
85 table.addEntry(info, bin, bin_id);
86 }
87 } else {
88 B2ERROR("Please define one table: with OR without specific bin IDs");
89 }
90
91 if (!m_outOfRangeWeight.empty()) {
92 table.defineOutOfRangeWeight(m_outOfRangeWeight);
93 }
94 B2INFO("Printing LookUp table");
95 table.printParticleWeightingLookUpTable();
96
98 importer.construct(table);
100
101}
102
104{
105 if (lims != nullptr) {
106 delete lims;
107 }
108}
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.
void setDescription(const std::string &description)
Sets the description of the module.
Definition Module.cc:214
Module()
Constructor.
Definition Module.cc:30
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: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.