Belle II Software  release-05-02-19
AlignmentGeneratorModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2013 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: tadeas *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <alignment/modules/AlignmentGenerator/AlignmentGeneratorModule.h>
12 
13 #include <alignment/dbobjects/VXDAlignment.h>
14 #include <framework/database/Database.h>
15 #include <vxd/dataobjects/VxdID.h>
16 #include <vxd/geometry/GeoCache.h>
17 
18 #include <TRandom.h>
19 
20 #include <boost/algorithm/string.hpp>
21 
22 using namespace Belle2;
23 
24 //-----------------------------------------------------------------
25 // Register the Module
26 //-----------------------------------------------------------------
27 REG_MODULE(AlignmentGenerator)
28 
29 //-----------------------------------------------------------------
30 // Implementation
31 //-----------------------------------------------------------------
32 
34 {
35  std::vector<std::string> emptyData;
36  std::vector<int> infiniteIov{0, 0, -1, -1};
37 
38  setPropertyFlags(c_ParallelProcessingCertified);
39  // Set module properties
40  setDescription("Generates VXD alignment."
41  "Generated alignment overrides any existing one in reconstruction if done with this module. "
42  "The generated object can also be stored as payload in the (local) DB, to keep track of it."
43  );
44 
45  // Parameter definitions
46  addParam("payloadIov", m_payloadIov, "IoV of the payload to be created. List "
47  "of four numbers: first experiment, first run, last experiment, "
48  "last run", infiniteIov);
49  addParam("createPayload", m_createPayload, "Store the generated alignment as payload in DB?", bool(false));
50  addParam("data", m_data,
51  "Data for alignment in format ['layer.ladder.sensor, parameter_no, distribution=fix|gaus|uniform, value', ...]",
52  emptyData);
53  addParam("payloadName", m_payloadName, "Name of generated alignment payload in database. If empty, default is used",
54  std::string(""));
55 
56 }
57 
59 {
60  auto data = new VXDAlignment();
61 
62  for (auto& id : VXD::GeoCache::getInstance().getListOfSensors()) {
63  for (auto paramData : m_data) {
64  std::vector<std::string> paramDataParts;
65  boost::algorithm::split(paramDataParts, paramData, boost::is_any_of(","));
66  if (paramDataParts.size() != 4)
67  B2FATAL("Error parsing alignment data.");
68 
69  boost::trim(paramDataParts[0]);
70  boost::trim(paramDataParts[1]);
71  boost::trim(paramDataParts[2]);
72  boost::trim(paramDataParts[3]);
73 
74  VxdID idMask(paramDataParts[0]);
75  int paramID = std::stoi(paramDataParts[1]);
76  std::string distro = paramDataParts[2];
77  double value = std::stod(paramDataParts[3]);
78 
79  double generatedValue = 0.;
80  if (distro == "fix") generatedValue = value;
81  else if (distro == "gaus") generatedValue = gRandom->Gaus(0., value);
82  else if (distro == "uniform") generatedValue = gRandom->Uniform(-value, value);
83  else B2FATAL("Unknown distribution for parameter generation: " << distro << " Valid options are fix|gaus|uniform");
84 
85  if (idMask.getLayerNumber() && id.getLayerNumber() != idMask.getLayerNumber()) continue;
86  if (idMask.getLadderNumber() && id.getLadderNumber() != idMask.getLadderNumber()) continue;
87  if (idMask.getSensorNumber() && id.getSensorNumber() != idMask.getSensorNumber()) continue;
88 
89  data->set(id, paramID, generatedValue);
90  }
91  }
92 
93  std::string name = (m_payloadName == "") ? DBStore::objectName<VXDAlignment>("") : m_payloadName;
94 
95  B2WARNING("Overriding VXDAlignment in DBStore with new object. This will affect reconstruction if done in this job.");
97 
98  if (m_createPayload) {
99  if (m_payloadIov.size() != 4)
100  B2FATAL("Payload IoV incorrect. Should be list of four numbers.");
101 
102  B2INFO("Storing VXDAlignment payload in DB.");
104  Database::Instance().storeData(name, data, iov);
105  }
106 
107 }
108 
109 
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::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
Belle2::DBStore::addConstantOverride
void addConstantOverride(const std::string &name, TObject *obj, bool oneRun=false)
Add constant override payload.
Definition: DBStore.cc:204
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Database::storeData
bool storeData(const std::string &name, TObject *object, const IntervalOfValidity &iov)
Store an object in the database.
Definition: Database.cc:152
Belle2::VxdID::getLadderNumber
baseType getLadderNumber() const
Get the ladder id.
Definition: VxdID.h:108
Belle2::AlignmentGeneratorModule::initialize
virtual void initialize() override
Generate misalignment and store in database.
Definition: AlignmentGeneratorModule.cc:58
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::AlignmentGeneratorModule
Generate VXD misalignment and store in database.
Definition: AlignmentGeneratorModule.h:38
Belle2::VXD::GeoCache::getInstance
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:215
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::AlignmentGeneratorModule::m_payloadName
std::string m_payloadName
Name of generated misalignment in database.
Definition: AlignmentGeneratorModule.h:56
Belle2::DBStore::Instance
static DBStore & Instance()
Instance of a singleton DBStore.
Definition: DBStore.cc:36
Belle2::AlignmentGeneratorModule::m_createPayload
bool m_createPayload
Whether to create and store the payload in database.
Definition: AlignmentGeneratorModule.h:54
Belle2::VxdID::getSensorNumber
baseType getSensorNumber() const
Get the sensor id.
Definition: VxdID.h:110
Belle2::AlignmentGeneratorModule::m_payloadIov
std::vector< int > m_payloadIov
IoV for the payload.
Definition: AlignmentGeneratorModule.h:53
Belle2::Database::Instance
static Database & Instance()
Instance of a singleton Database.
Definition: Database.cc:54
Belle2::AlignmentGeneratorModule::m_data
std::vector< std::string > m_data
Data for misalignment generation.
Definition: AlignmentGeneratorModule.h:55
Belle2::VxdID::getLayerNumber
baseType getLayerNumber() const
Get the layer id.
Definition: VxdID.h:106
Belle2::VXDAlignment
VXD alignment (and maybe some calibration) parameters.
Definition: VXDAlignment.h:29