Belle II Software  release-06-00-14
TOPCalPulseGeneratorModule.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 <top/modules/TOPDoublePulseGenerator/TOPCalPulseGeneratorModule.h>
11 #include <top/geometry/TOPGeometryPar.h>
12 
13 // framework - DataStore
14 #include <framework/datastore/StoreArray.h>
15 
16 // framework aux
17 #include <framework/logging/Logger.h>
18 
19 // root
20 #include <TRandom.h>
21 
22 
23 using namespace std;
24 
25 namespace Belle2 {
31  using namespace TOP;
32 
33  //-----------------------------------------------------------------
34  // Register module
35  //-----------------------------------------------------------------
36 
37  REG_MODULE(TOPCalPulseGenerator)
38 
39  //-----------------------------------------------------------------
40  // Implementation
41  //-----------------------------------------------------------------
42 
44 
45  {
46  // set module description
47  setDescription("Realistic generator of calibration double pulses. "
48  "Needs TOPDigitizer to digitize");
49  setPropertyFlags(c_ParallelProcessingCertified);
50 
51  // Add parameters
52  addParam("moduleIDs", m_moduleIDs,
53  "list of slots for which to generate cal pulse, empty list means all slots.",
54  m_moduleIDs);
55  m_asicChannels.push_back(0);
56  addParam("asicChannels", m_asicChannels,
57  "ASIC calibration channels (0 - 7), empty list means all channels.",
58  m_asicChannels);
59  // default for these three below are set according to laser run 8/414
60  addParam("amplitude", m_amplitude, "amplitude of cal pulse [ADC counts]", 600.0);
61  addParam("delay", m_delay, "delay of cal pulse [ns]", 10.5);
62  addParam("windowSize", m_windowSize, "size of time window in which to generate cal pulses [ns]", 8.0);
63  }
64 
65 
66  void TOPCalPulseGeneratorModule::initialize()
67  {
68  // Output
69 
70  m_calPulses.registerInDataStore();
71 
72  // prepare vectors to loop on
73 
74  const auto* geo = TOPGeometryPar::Instance()->getGeometry();
75 
76  if (m_moduleIDs.empty()) {
77  for (const auto& module : geo->getModules()) {
78  m_moduleIDs.push_back(module.getModuleID());
79  }
80  } else {
81  for (auto moduleID : m_moduleIDs) {
82  if (!geo->isModuleIDValid(moduleID))
83  B2ERROR("Invalid module ID found in input list: " << moduleID);
84  }
85  }
86 
87  if (m_asicChannels.empty()) {
88  for (unsigned ch = 0; ch < 8; ch++) m_asicChannels.push_back(ch);
89  } else {
90  for (unsigned ch : m_asicChannels) {
91  if (ch > 7)
92  B2ERROR("Invalid ASIC channel found in input list: " << ch);
93  }
94  }
95 
96  }
97 
98 
99  void TOPCalPulseGeneratorModule::event()
100  {
101  const auto& chMapper = TOPGeometryPar::Instance()->getChannelMapper();
102 
103  double time = m_delay + gRandom->Uniform(m_windowSize);
104  for (auto moduleID : m_moduleIDs) {
105  for (unsigned asic = 0; asic < 64; asic++) {
106  for (auto asicChannel : m_asicChannels) {
107  unsigned channel = asic * 8 + asicChannel;
108  auto pixelID = chMapper.getPixelID(channel);
109  m_calPulses.appendNew(moduleID, channel, pixelID, time, m_amplitude);
110  }
111  }
112  }
113 
114  }
115 
117 } // end Belle2 namespace
118 
Base class for Modules.
Definition: Module.h:72
Generator of calibration pulses Output to TOPSimCalPulses.
#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.
record to be used to store ASIC info