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