Belle II Software  release-06-00-14
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 include
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 
18 using namespace std;
19 
20 namespace Belle2 {
26  //-----------------------------------------------------------------
27  // Register module
28  //-----------------------------------------------------------------
29 
30  REG_MODULE(ParticleWeightingLookUpCreator)
31 
32  //-----------------------------------------------------------------
33  // Implementation
34  //-----------------------------------------------------------------
35 
37 
38  {
39  setDescription("Creates test LookUp table");
40  listOfNoIdEntries empty_noid_list;
41  addParam("tableIDNotSpec", m_tableIDNotSpec, "Bin:weight info map without specific bin-numbering scheme", empty_noid_list);
42  listOfSpecificIDEntries empty_specificid_list;
43  addParam("tableIDSpec", m_tableIDSpec, "Bin:weight info map with specific bin-numbering scheme", empty_specificid_list);
44  addParam("tableName", m_tableName, "Name of the LookUp table");
45  addParam("outOfRangeWeight", m_outOfRangeWeight, "Weight info for out-of-range partiles");
46  addParam("experimentLow", m_experimentLow, "Interval of validity, ex.low");
47  addParam("experimentHigh", m_experimentHigh, "Interval of validity, ex.high");
48  addParam("runLow", m_runLow, "Interval of validity, run low");
49  addParam("runHigh", m_runHigh, "Interval of validity, run high");
50  }
51 
55  NDBin ParticleWeightingLookUpCreatorModule::NDBinTupleToNDBin(const NDBinTuple& bin_tuple)
56  {
57  NDBin binning;
58  for (auto bin_1d : bin_tuple) {
59  std::string axis_name = bin_1d.first;
60  double min_val = std::get<0>(bin_1d.second);
61  double max_val = std::get<1>(bin_1d.second);
62  lims = new ParticleWeightingBinLimits(min_val, max_val);
63  binning.insert(std::make_pair(axis_name, lims));
64  }
65  return binning;
66  }
67 
68  void ParticleWeightingLookUpCreatorModule::initialize()
69  {
71 
72  if (!m_outOfRangeWeight.empty()) {
73  table.defineOutOfRangeWeight(m_outOfRangeWeight);
74  }
75 
76  if (!m_tableIDNotSpec.empty() and m_tableIDSpec.empty()) {
77  for (auto entry : m_tableIDNotSpec) {
78  WeightInfo info = std::get<0>(entry);
79  NDBin bin = NDBinTupleToNDBin(std::get<1>(entry));
80  table.addEntry(info, bin);
81  }
82  } else if (!m_tableIDSpec.empty() and m_tableIDNotSpec.empty()) {
83  for (auto entry : m_tableIDSpec) {
84  noIdEntry noid = std::get<0>(entry);
85  double bin_id = std::get<1>(entry);
86  WeightInfo info = std::get<0>(noid);
87  NDBin bin = NDBinTupleToNDBin(std::get<1>(noid));
88  table.addEntry(info, bin, bin_id);
89  }
90  } else {
91  B2ERROR("Please define one table: with OR without specific bin IDs");
92  }
93 
94  if (!m_outOfRangeWeight.empty()) {
95  table.defineOutOfRangeWeight(m_outOfRangeWeight);
96  }
97  B2INFO("Printing LookUp table");
98  table.printParticleWeightingLookUpTable();
99 
101  importer.construct(table);
102  importer.import(Belle2::IntervalOfValidity(m_experimentLow, m_runLow, m_experimentHigh, m_runHigh));
103 
104  }
105 
106  void ParticleWeightingLookUpCreatorModule::terminate()
107  {
108  if (lims != nullptr) {
109  delete lims;
110  }
111  }
112 
114 } // end Belle2 namespace
115 
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
Just pair of numbers - min and max values of bin border.
Module that creates LookUpTable and upload it to the DB.
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.
#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.