Belle II Software  release-05-02-19
ParticleWeightingLookUpCreatorModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2018 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Ilya Komarov *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 // Own include
12 #include <analysis/modules/ParticleWeightingLookUpCreator/ParticleWeightingLookUpCreatorModule.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 
20 using namespace std;
21 
22 namespace Belle2 {
28  //-----------------------------------------------------------------
29  // Register module
30  //-----------------------------------------------------------------
31 
32  REG_MODULE(ParticleWeightingLookUpCreator)
33 
34  //-----------------------------------------------------------------
35  // Implementation
36  //-----------------------------------------------------------------
37 
39 
40  {
41  setDescription("Creates test LookUp table");
42  listOfNoIdEntries empty_noid_list;
43  addParam("tableIDNotSpec", m_tableIDNotSpec, "Bin:weight info map without specific bin-numbering scheme", empty_noid_list);
44  listOfSpecificIDEntries empty_specificid_list;
45  addParam("tableIDSpec", m_tableIDSpec, "Bin:weight info map with specific bin-numbering scheme", empty_specificid_list);
46  addParam("tableName", m_tableName, "Name of the LookUp table");
47  addParam("outOfRangeWeight", m_outOfRangeWeight, "Weight info for out-of-range partiles");
48  addParam("experimentLow", m_experimentLow, "Interval of validity, ex.low");
49  addParam("experimentHigh", m_experimentHigh, "Interval of validity, ex.high");
50  addParam("runLow", m_runLow, "Interval of validity, run low");
51  addParam("runHigh", m_runHigh, "Interval of validity, run high");
52  }
53 
57  NDBin ParticleWeightingLookUpCreatorModule::NDBinTupleToNDBin(const NDBinTuple& bin_tuple)
58  {
59  NDBin binning;
60  for (auto bin_1d : bin_tuple) {
61  std::string axis_name = bin_1d.first;
62  double min_val = std::get<0>(bin_1d.second);
63  double max_val = std::get<1>(bin_1d.second);
64  lims = new ParticleWeightingBinLimits(min_val, max_val);
65  binning.insert(std::make_pair(axis_name, lims));
66  }
67  return binning;
68  }
69 
70  void ParticleWeightingLookUpCreatorModule::initialize()
71  {
73 
74  if (!m_outOfRangeWeight.empty()) {
75  table.defineOutOfRangeWeight(m_outOfRangeWeight);
76  }
77 
78  if (!m_tableIDNotSpec.empty() and m_tableIDSpec.empty()) {
79  for (auto entry : m_tableIDNotSpec) {
80  WeightInfo info = std::get<0>(entry);
81  NDBin bin = NDBinTupleToNDBin(std::get<1>(entry));
82  table.addEntry(info, bin);
83  }
84  } else if (!m_tableIDSpec.empty() and m_tableIDNotSpec.empty()) {
85  for (auto entry : m_tableIDSpec) {
86  noIdEntry noid = std::get<0>(entry);
87  double bin_id = std::get<1>(entry);
88  WeightInfo info = std::get<0>(noid);
89  NDBin bin = NDBinTupleToNDBin(std::get<1>(noid));
90  table.addEntry(info, bin, bin_id);
91  }
92  } else {
93  B2ERROR("Please define one table: with OR without specific bin IDs");
94  }
95 
96  if (!m_outOfRangeWeight.empty()) {
97  table.defineOutOfRangeWeight(m_outOfRangeWeight);
98  }
99  B2INFO("Printing LookUp table");
100  table.printParticleWeightingLookUpTable();
101 
103  importer.construct(table);
104  importer.import(Belle2::IntervalOfValidity(m_experimentLow, m_runLow, m_experimentHigh, m_runHigh));
105 
106  }
107 
108  void ParticleWeightingLookUpCreatorModule::terminate()
109  {
110  if (lims != NULL) {
111  delete lims;
112  }
113  }
114 
116 } // end Belle2 namespace
117 
Belle2::WeightInfo
std::map< std::string, double > WeightInfo
Weight information: a line from the weight lookup table.
Definition: ParticleWeightingLookUpTable.h:31
Belle2::IntervalOfValidity
A class that describes the interval of experiments/runs for which an object in the database is valid.
Definition: IntervalOfValidity.h:35
Belle2::ParticleWeightingBinLimits
Just pair of numbers - min and max values of bin border.
Definition: ParticleWeightingBinLimits.h:31
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::ParticleWeightingLookUpTable
Class for handling LookUp tables.
Definition: ParticleWeightingLookUpTable.h:38
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::ParticleWeightingLookUpCreatorModule
Module that creates LookUpTable and upload it to the DB.
Definition: ParticleWeightingLookUpCreatorModule.h:47
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::DBImportObjPtr
Class for importing a single object to the database.
Definition: DBImportObjPtr.h:33
Belle2::NDBin
std::map< std::string, ParticleWeightingBinLimits * > NDBin
N-dim bin: pairs of bin limits with name of the axis variable.
Definition: ParticleWeightingKeyMap.h:42
Belle2::NDBinTuple
std::map< std::string, BinLimitsTuple > NDBinTuple
the NDimensional tuple of bin limits
Definition: ParticleWeightingLookUpCreatorModule.h:38
Belle2::listOfNoIdEntries
std::vector< noIdEntry > listOfNoIdEntries
List of entries for table to be created from without specified ID.
Definition: ParticleWeightingLookUpCreatorModule.h:41
Belle2::listOfSpecificIDEntries
std::vector< specificIDEntry > listOfSpecificIDEntries
List of entries for table to be created from with specified ID.
Definition: ParticleWeightingLookUpCreatorModule.h:42
Belle2::noIdEntry
std::tuple< WeightInfo, NDBinTuple > noIdEntry
the ID
Definition: ParticleWeightingLookUpCreatorModule.h:39